summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/cheat
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2022-10-04 14:19:15 +1100
committer Vas Crabb <vas@vastheman.com>2022-10-04 14:19:38 +1100
commitbdfdbd8796e8b01cbede23c7e50e812628fda05c (patch)
tree3b874806ab6553ac6e295a52cb2f547f1179d59e /plugins/cheat
parent6befb00cbffe3b846f2e235c69c920deeacbe918 (diff)
plugins/cheat: Overwrite existing hotkeys if all hotkeys are cleared (fixes GitHub #10387).
Diffstat (limited to 'plugins/cheat')
-rw-r--r--plugins/cheat/init.lua17
1 files 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