diff options
author | 2016-04-16 08:36:09 -0500 | |
---|---|---|
committer | 2016-04-16 08:36:09 -0500 | |
commit | 95309f461e5274151c97830945ba69d49cccef12 (patch) | |
tree | 6e62ee8894d92c8cc11c383230070f3b6994aa7d /plugins/cheat/init.lua | |
parent | bff9111a30bf49c4847b071a0fa5489159c65c5e (diff) |
plugins/cheat: load multiple files and fix load failure (nw)
Diffstat (limited to 'plugins/cheat/init.lua')
-rw-r--r-- | plugins/cheat/init.lua | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index c15b662675f..ec5078fedf0 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -72,8 +72,9 @@ function cheat.startplugin() local function load_cheats() local filename = emu.romname() local json = require("json") - local file = emu.file(manager:machine():options().entries.cheatpath:value():gsub("([^;]+)", "%1;%1/cheat"), 1) - + local newcheats = {} + local path = manager:machine():options().entries.cheatpath:value():gsub("([^;]+)", "%1;%1/cheat") + local file = emu.file(path, 1) if emu.softname() ~= "" then for name, image in pairs(manager:machine().images) do if image:exists() and image:software_list_name() ~= "" then @@ -81,17 +82,27 @@ function cheat.startplugin() end end end - - if file:open(filename .. ".json") then - local xml = require("cheat/xml_conv") - - if file:open(filename .. ".xml") then - return {} + function add(addcheats) + if not next(newcheats) then + newcheats = addcheats + else + for num, cheat in pairs(addcheats) do + newcheats[#newcheats + 1] = cheat + end end - return xml.conv_cheat(file:read(file:size())) end - - return json.parse(file:read(file:size())) + local ret = file:open(filename .. ".json") + while not ret do + add(json.parse(file:read(file:size()))) + ret = file:open_next() + end + local xml = require("cheat/xml_conv") + ret = file:open(filename .. ".xml") + while not ret do + add(xml.conv_cheat(file:read(file:size()))) + ret = file:open_next() + end + return newcheats end local function draw_text(screen, x, y, color, form, ...) |