From bdfdbd8796e8b01cbede23c7e50e812628fda05c Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 4 Oct 2022 14:19:15 +1100 Subject: plugins/cheat: Overwrite existing hotkeys if all hotkeys are cleared (fixes GitHub #10387). --- plugins/cheat/init.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index f8f15b652f4..896fc1e101b 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -154,9 +154,10 @@ function cheat.startplugin() end end end + local path = emu.subst_env(manager.machine.options.entries.cheatpath:value():match("([^;]+)")) + local filepath = path .. "/" .. cheatname .. "_hotkeys.json" if #hotkeys > 0 then local json = require("json") - local path = emu.subst_env(manager.machine.options.entries.cheatpath:value():match("([^;]+)")) local attr = lfs.attributes(path) if not attr then lfs.mkdir(path) @@ -165,7 +166,7 @@ function cheat.startplugin() end if cheatname:find("/", 1, true) then local softpath = path .. "/" .. cheatname:match("([^/]+)") - local attr = lfs.attributes(softpath) + attr = lfs.attributes(softpath) if not attr then lfs.mkdir(softpath) elseif attr.mode ~= "directory" then -- uhhh? @@ -173,11 +174,21 @@ function cheat.startplugin() end end - local file = io.open(path .. "/" .. cheatname .. "_hotkeys.json", "w+") + local file = io.open(filepath, "w+") if file then file:write(json.stringify(hotkeys, {indent = true})) file:close() end + else + local attr = lfs.attributes(filepath) + if attr and (attr.mode == "file") then + local json = require("json") + local file = io.open(filepath, "w+") + if file then + file:write(json.stringify(hotkeys, {indent = true})) + file:close() + end + end end end -- cgit v1.2.3