From ff452ec3702cc7ef367112ea0e0725c8ac44231c Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 2 Oct 2023 14:48:58 +0200 Subject: [PATCH] config: allow adding custom roms paths to config file --- CMakeLists.txt | 1 - external/libcross2d | 2 +- src/cores/main.cpp | 3 - src/cores/pfbneo/sources/pfbneo_config.cpp | 40 +++++++++--- src/cores/pfbneo/sources/pfbneo_config.h | 20 ------ src/cores/pfbneo/sources/pfbneo_romlist.cpp | 6 +- src/cores/pfbneo/sources/pfbneo_utility.cpp | 3 +- src/cores/pgba/sources/pgba_config.cpp | 19 +++--- src/cores/pgba/sources/pgba_config.h | 6 -- src/cores/pgen/sources/pgen_config.cpp | 23 ++++--- src/cores/pgen/sources/pgen_config.h | 14 ----- src/cores/pnes/sources/pnes_config.cpp | 19 +++--- src/cores/pnes/sources/pnes_config.h | 6 -- src/cores/psnes/sources/psnes_config.cpp | 19 +++--- src/cores/psnes/sources/psnes_config.h | 6 -- src/skeleton/pemu_config.cpp | 68 ++++++++++++++++----- src/skeleton/pemu_config.h | 17 +++--- src/skeleton/romlist.cpp | 23 ++++--- src/skeleton/ui_menu.cpp | 6 +- 19 files changed, 167 insertions(+), 134 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20abca42..0e87f34d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ set(OPTION_BUILTIN_LIBCONFIG OFF CACHE BOOL "Build libconfig from sources") set(OPTION_BUILTIN_MINIZIP OFF CACHE BOOL "Build minizip from sources") set(OPTION_MPV_PLAYER ON CACHE BOOL "Add support for video snaps (mpv)") set(OPTION_UPDATE_CONFIG OFF CACHE BOOL "Force config file updating") -set(OPTION_FTP_SERVER OFF CACHE BOOL "Embedded ftp server") #################### # BUILD OPTIONS #################### diff --git a/external/libcross2d b/external/libcross2d index be2d504c..bcaf05d4 160000 --- a/external/libcross2d +++ b/external/libcross2d @@ -1 +1 @@ -Subproject commit be2d504cd7b1c228d5ba09b23c82657cafec9a50 +Subproject commit bcaf05d4b4739df34e18690be02ee76755f24ba9 diff --git a/src/cores/main.cpp b/src/cores/main.cpp index 27d17e21..12b05721 100644 --- a/src/cores/main.cpp +++ b/src/cores/main.cpp @@ -44,9 +44,6 @@ int main(int argc, char **argv) { auto uiState = new PEMUUiMenuState(pemu_ui); pemu_ui->init(uiRomList, uiMenu, uiEmu, uiState); - // save/update config - cfg->save(); - while (!pemu_ui->done) { pemu_ui->flip(); } diff --git a/src/cores/pfbneo/sources/pfbneo_config.cpp b/src/cores/pfbneo/sources/pfbneo_config.cpp index be60c71c..0f3439ee 100644 --- a/src/cores/pfbneo/sources/pfbneo_config.cpp +++ b/src/cores/pfbneo/sources/pfbneo_config.cpp @@ -14,13 +14,6 @@ using namespace pemu; PFBAConfig::PFBAConfig(c2d::Io *io, int version) : PEMUConfig(io, "PFBNEO", version) { printf("PFBNConfig(%s, v%i)\n", getPath().c_str(), version); - /// add custom roms paths to config - for (const auto &gl: PFBAConfig::getCoreGameListInfo()) { - std::string path = io->getDataPath() + gl.rom_path + "/"; - getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, path}); - io->create(path); - } - /// MAIN OPTIONS get(PEMUConfig::OptId::UI_SHOW_ZIP_NAMES)->setArrayIndex(0); @@ -65,6 +58,35 @@ PFBAConfig::PFBAConfig(c2d::Io *io, int version) : PEMUConfig(io, "PFBNEO", vers get(PEMUConfig::OptId::EMU_AUDIO_FREQ)->setFlags(PEMUConfig::Flags::HIDDEN); #endif - // "c2dui_romlist" will also reload config, but we need new roms paths - load(); + // "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths + PEMUConfig::load(); + + // add custom rom path + PEMUConfig::addRomPath("ARCADE", io->getDataPath() + "arcade/", {HARDWARE_PREFIX_ARCADE, 0, "Arcade"}); + PEMUConfig::addRomPath("CHANNELF", io->getDataPath() + "channelf/", {HARDWARE_PREFIX_CHANNELF, 0, "Channel F"}); + PEMUConfig::addRomPath("COLECO", io->getDataPath() + "coleco/", {HARDWARE_PREFIX_COLECO, 0, "ColecoVision"}); + PEMUConfig::addRomPath("FDS", io->getDataPath() + "fds/", {HARDWARE_PREFIX_FDS, 0, "NES FDS"}); + PEMUConfig::addRomPath("GAMEGEAR", io->getDataPath() + "gamegear/", + {HARDWARE_PREFIX_SEGA_GAME_GEAR, 0, "Sega Game Gear"}); + PEMUConfig::addRomPath("MEGADRIVE", io->getDataPath() + "megadrive/", + {HARDWARE_PREFIX_SEGA_MEGADRIVE, 0, "Sega Megadrive"}); + PEMUConfig::addRomPath("MSX", io->getDataPath() + "msx/", {HARDWARE_PREFIX_MSX, 0, "MSX"}); + PEMUConfig::addRomPath("NES", io->getDataPath() + "nes/", {HARDWARE_PREFIX_NES, 0, "NES"}); + PEMUConfig::addRomPath("NGP", io->getDataPath() + "ngp/", {HARDWARE_PREFIX_NGP, 0, "Neo Geo Pocket"}); + PEMUConfig::addRomPath("PCE", io->getDataPath() + "pce/", {HARDWARE_PCENGINE_PCENGINE, 0, "PC Engine"}); + PEMUConfig::addRomPath("SG1000", io->getDataPath() + "sg1000/", {HARDWARE_PREFIX_SEGA_SG1000, 0, "Sega SG-1000"}); + PEMUConfig::addRomPath("SGX", io->getDataPath() + "sgx/", {HARDWARE_PCENGINE_SGX, 0, "PC Engine SGX"}); + PEMUConfig::addRomPath("MASTERSYSTEM", io->getDataPath() + "sms/", + {HARDWARE_PREFIX_SEGA_MASTER_SYSTEM, 0, "Sega Master System"}); + PEMUConfig::addRomPath("SPECTRUM", io->getDataPath() + "spectrum/", {HARDWARE_PREFIX_SPECTRUM, 0, "ZX Spectrum"}); + PEMUConfig::addRomPath("TG16", io->getDataPath() + "tg16/", {HARDWARE_PCENGINE_TG16, 0, "PC Engine TG16"}); + + // save newly added roms paths + PEMUConfig::save(); + + // create roms paths if needed + auto paths = getRomPaths(); + for (const auto &path: paths) { + io->create(path.path); + } } diff --git a/src/cores/pfbneo/sources/pfbneo_config.h b/src/cores/pfbneo/sources/pfbneo_config.h index 3e516c0b..277f7125 100644 --- a/src/cores/pfbneo/sources/pfbneo_config.h +++ b/src/cores/pfbneo/sources/pfbneo_config.h @@ -13,26 +13,6 @@ class PFBAConfig : public pemu::PEMUConfig { public: PFBAConfig(c2d::Io *io, int version); - std::vector getCoreGameListInfo() override { - return { - {{HARDWARE_PREFIX_ARCADE, 0, "Arcade"}, "ARCADE", "arcade"}, - {{HARDWARE_PREFIX_CHANNELF, 0, "Channel F"}, "CHANNELF", "channelf"}, - {{HARDWARE_PREFIX_COLECO, 0, "ColecoVision"}, "COLECO", "coleco"}, - {{HARDWARE_PREFIX_FDS, 0, "NES FDS"}, "FDS", "fds"}, - {{HARDWARE_PREFIX_SEGA_GAME_GEAR, 0, "Sega Game Gear"}, "GAMEGEAR", "gamegear"}, - {{HARDWARE_PREFIX_SEGA_MEGADRIVE, 0, "Sega Megadrive"}, "MEGADRIVE", "megadrive"}, - {{HARDWARE_PREFIX_MSX, 0, "MSX"}, "MSX", "msx"}, - {{HARDWARE_PREFIX_NES, 0, "NES"}, "NES", "nes"}, - {{HARDWARE_PREFIX_NGP, 0, "Neo Geo Pocket"}, "NGP", "ngp"}, - {{HARDWARE_PCENGINE_PCENGINE, 0, "PC Engine"}, "PCE", "pce"}, - {{HARDWARE_PREFIX_SEGA_SG1000, 0, "Sega SG-1000"}, "SG1000", "sg1000"}, - {{HARDWARE_PCENGINE_SGX, 0, "PC Engine SGX"}, "SGX", "sgx"}, - {{HARDWARE_PREFIX_SEGA_MASTER_SYSTEM, 0, "Sega Master System"}, "MASTERSYSTEM", "sms"}, - {{HARDWARE_PREFIX_SPECTRUM, 0, "ZX Spectrum"}, "SPECTRUM", "spectrum"}, - {{HARDWARE_PCENGINE_TG16, 0, "PC Engine TG16"}, "TG16", "tg16"} - }; - } - std::vector getCoreHiddenOptionToEnable() override { return { PEMUConfig::OptId::UI_FILTER_CLONES, diff --git a/src/cores/pfbneo/sources/pfbneo_romlist.cpp b/src/cores/pfbneo/sources/pfbneo_romlist.cpp index daa398cb..d1a0f3e7 100644 --- a/src/cores/pfbneo/sources/pfbneo_romlist.cpp +++ b/src/cores/pfbneo/sources/pfbneo_romlist.cpp @@ -45,11 +45,13 @@ void PFBNRomList::build(const ss_api::GameList::GameAddedCb &cb) { } }); - // remove custom "ARCADE" system added from "getCoreGameListInfo" + // remove custom "ARCADE" system added from "RomList::build" gameList->systemList.remove(HARDWARE_PREFIX_ARCADE); - // sort systems std::sort(gameList->systemList.systems.begin(), gameList->systemList.systems.end(), Api::sortSystemByName); + // update system filtering option + auto opt = ui->getConfig()->get(PEMUConfig::OptId::UI_FILTER_SYSTEM); + opt->setArray(gameList->systemList.getNames()); // update config ui->getConfig()->load(); diff --git a/src/cores/pfbneo/sources/pfbneo_utility.cpp b/src/cores/pfbneo/sources/pfbneo_utility.cpp index 9d3275bc..58e5e52b 100644 --- a/src/cores/pfbneo/sources/pfbneo_utility.cpp +++ b/src/cores/pfbneo/sources/pfbneo_utility.cpp @@ -73,6 +73,7 @@ PFBNEOUtility::GameInfo PFBNEOUtility::getGameInfo(const Game &game) { gameInfo.sysId = (int) prefix; switch (prefix) { case HARDWARE_PREFIX_MISC_PRE90S: + gameInfo.sysId = 0x43214321; gameInfo.sysName = "PRE-90S (MISC)"; break; case HARDWARE_PREFIX_SEGA: @@ -88,7 +89,7 @@ PFBNEOUtility::GameInfo PFBNEOUtility::getGameInfo(const Game &game) { gameInfo.sysName = "CAVE"; break; case HARDWARE_PREFIX_IGS_PGM: - gameInfo.sysName = "IGS PGM"; + gameInfo.sysName = "PGM (IGS)"; break; case HARDWARE_PREFIX_MISC_POST90S: gameInfo.sysName = "POST-90S (MISC)"; diff --git a/src/cores/pgba/sources/pgba_config.cpp b/src/cores/pgba/sources/pgba_config.cpp index f131b09a..47681511 100644 --- a/src/cores/pgba/sources/pgba_config.cpp +++ b/src/cores/pgba/sources/pgba_config.cpp @@ -9,14 +9,19 @@ using namespace c2d; using namespace pemu; PGBAConfig::PGBAConfig(c2d::Io *io, int version) : PEMUConfig(io, "PGBA", version) { - // add custom roms paths to config - for (const auto &gl: PGBAConfig::getCoreGameListInfo()) { - getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"}); - } - // no need for auto-scaling mode getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0); - // "c2dui_romlist" will also reload config, but we need new roms paths - load(); + // "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths + PEMUConfig::load(); + + // add custom rom path + PEMUConfig::addRomPath("GBA", io->getDataPath() + "roms/", {12, 0, "Game Boy Advance"}); + PEMUConfig::save(); + + // create roms paths if needed + auto paths = getRomPaths(); + for (const auto &path: paths) { + io->create(path.path); + } } diff --git a/src/cores/pgba/sources/pgba_config.h b/src/cores/pgba/sources/pgba_config.h index 93eee492..ce1339d8 100644 --- a/src/cores/pgba/sources/pgba_config.h +++ b/src/cores/pgba/sources/pgba_config.h @@ -14,12 +14,6 @@ class PGBAConfig : public pemu::PEMUConfig { public: PGBAConfig(c2d::Io *io, int version); - std::vector getCoreGameListInfo() override { - return { - {{12, 0, "Game Boy Advance"}, "GBA", "roms"} - }; - } - std::string getCoreVersion() override { return std::string(projectName) + projectVersion; } diff --git a/src/cores/pgen/sources/pgen_config.cpp b/src/cores/pgen/sources/pgen_config.cpp index f1b7bf30..f89c19cb 100644 --- a/src/cores/pgen/sources/pgen_config.cpp +++ b/src/cores/pgen/sources/pgen_config.cpp @@ -9,14 +9,23 @@ using namespace c2d; using namespace pemu; PGENConfig::PGENConfig(c2d::Io *io, int version) : PEMUConfig(io, "PGEN", version) { - // add custom roms paths to config - for (const auto &gl: getCoreGameListInfo()) { - getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"}); - } - // no need for auto-scaling mode getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0); - // "c2dui_romlist" will also reload config, but we need new roms paths - load(); + // "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths + PEMUConfig::load(); + + // add custom rom path + PEMUConfig::addRomPath("MEGADRIVE", io->getDataPath() + "megadrive/", {1, 0, "Megadrive"}); + PEMUConfig::addRomPath("MASTERSYSTEM", io->getDataPath() + "mastersystem/", {2, 0, "Master System"}); + PEMUConfig::addRomPath("GAMEGEAR", io->getDataPath() + "gamegear/", {21, 0, "Game Gear"}); + PEMUConfig::addRomPath("MEGACD", io->getDataPath() + "megacd/", {20, 0, "Mega-CD"}); + PEMUConfig::addRomPath("SG1000", io->getDataPath() + "sg1000/", {109, 0, "SG-1000"}); + PEMUConfig::save(); + + // create roms paths if needed + auto paths = getRomPaths(); + for (const auto &path: paths) { + io->create(path.path); + } } diff --git a/src/cores/pgen/sources/pgen_config.h b/src/cores/pgen/sources/pgen_config.h index 22631590..ca144615 100644 --- a/src/cores/pgen/sources/pgen_config.h +++ b/src/cores/pgen/sources/pgen_config.h @@ -12,20 +12,6 @@ class PGENConfig : public pemu::PEMUConfig { public: PGENConfig(c2d::Io *io, int version); - ~PGENConfig() override { - printf("PGENConfig::~PGENConfig()\n"); - } - - std::vector getCoreGameListInfo() override { - return { - {{1, 0, "Megadrive"}, "MEGADRIVE", "megadrive"}, - {{2, 0, "Master System"}, "MASTERSYSTEM", "mastersystem"}, - {{21, 0, "Game Gear"}, "GAMEGEAR", "gamegear"}, - {{20, 0, "Mega-CD"}, "MEGACD", "megacd"}, - {{109, 2, "SG-1000"}, "SG1000", "sg1000"} - }; - } - std::vector getCoreHiddenOptionToEnable() override { return {PEMUConfig::OptId::UI_FILTER_SYSTEM}; } diff --git a/src/cores/pnes/sources/pnes_config.cpp b/src/cores/pnes/sources/pnes_config.cpp index 22cc9bab..4415ba5f 100644 --- a/src/cores/pnes/sources/pnes_config.cpp +++ b/src/cores/pnes/sources/pnes_config.cpp @@ -11,11 +11,6 @@ using namespace pemu; PNESConfig::PNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PNES", version) { printf("PNESConfig(%s, v%i)\n", getPath().c_str(), version); - // add custom roms paths to config - for (const auto &gl: PNESConfig::getCoreGameListInfo()) { - getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"}); - } - // no need for auto-scaling mode on pnes getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0); @@ -25,6 +20,16 @@ PNESConfig::PNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PNES", versio getOption(PEMUConfig::OptId::JOY_B)->setInteger(KEY_JOY_A_DEFAULT); #endif - // "c2dui_romlist" will also reload config, but we need new roms paths - load(); + // "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths + PEMUConfig::load(); + + // add custom rom path + PEMUConfig::addRomPath("NES", io->getDataPath() + "roms/", {3, 0, "NES"}); + PEMUConfig::save(); + + // create roms paths if needed + auto paths = getRomPaths(); + for (const auto &path: paths) { + io->create(path.path); + } } diff --git a/src/cores/pnes/sources/pnes_config.h b/src/cores/pnes/sources/pnes_config.h index 8c09bae2..c81f47b8 100644 --- a/src/cores/pnes/sources/pnes_config.h +++ b/src/cores/pnes/sources/pnes_config.h @@ -11,12 +11,6 @@ class PNESConfig : public pemu::PEMUConfig { public: PNESConfig(c2d::Io *io, int version); - std::vector getCoreGameListInfo() override { - return { - {{3, 0, "NES"}, "NES", "roms"} - }; - } - std::string getCoreVersion() override { return "Nestopia 1.52.0"; } diff --git a/src/cores/psnes/sources/psnes_config.cpp b/src/cores/psnes/sources/psnes_config.cpp index c4adf9ac..0ce7a4bc 100644 --- a/src/cores/psnes/sources/psnes_config.cpp +++ b/src/cores/psnes/sources/psnes_config.cpp @@ -11,11 +11,6 @@ using namespace pemu; PSNESConfig::PSNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PSNES", version) { printf("PSNESConfig(%s, v%i)\n", getPath().c_str(), version); - // add custom roms paths to config - for (const auto &gl: PSNESConfig::getCoreGameListInfo()) { - getGroup(CFG_ID_ROMS)->addOption({gl.cfg_name, io->getDataPath() + gl.rom_path + "/"}); - } - auto group = getGroup(PEMUConfig::GrpId::EMULATION); if (!group) { printf("PSNESConfig: error, group not found (MENU_ROM_OPTIONS)\n"); @@ -43,6 +38,16 @@ PSNESConfig::PSNESConfig(c2d::Io *io, int version) : PEMUConfig(io, "PSNES", ver // no need for auto-scaling mode getOption(PEMUConfig::OptId::EMU_SCALING_MODE)->setArray({"ASPECT", "INTEGER"}, 0); - // "c2dui_romlist" will also reload config, but we need new roms paths - load(); + // "romlist.cpp" (RomList::build) will also reload config, but we need new roms paths + PEMUConfig::load(); + + // add custom rom path + PEMUConfig::addRomPath("SNES", io->getDataPath() + "roms/", {4, 0, "Super Nintendo"}); + PEMUConfig::save(); + + // create roms paths if needed + auto paths = getRomPaths(); + for (const auto &path: paths) { + io->create(path.path); + } } diff --git a/src/cores/psnes/sources/psnes_config.h b/src/cores/psnes/sources/psnes_config.h index 7e95213d..80f790d3 100644 --- a/src/cores/psnes/sources/psnes_config.h +++ b/src/cores/psnes/sources/psnes_config.h @@ -13,12 +13,6 @@ class PSNESConfig : public pemu::PEMUConfig { public: PSNESConfig(c2d::Io *io, int version); - std::vector getCoreGameListInfo() override { - return { - {{4, 0, "Super Nintendo"}, "SNES", "roms"} - }; - } - std::string getCoreVersion() override { return "snes9x: " + std::string(VERSION); } diff --git a/src/skeleton/pemu_config.cpp b/src/skeleton/pemu_config.cpp index 2ab8253d..5030fcd8 100644 --- a/src/skeleton/pemu_config.cpp +++ b/src/skeleton/pemu_config.cpp @@ -183,13 +183,62 @@ bool PEMUConfig::loadGame(const Game &game) { return true; } -bool PEMUConfig::save(bool isGame) { - if (isGame) { - if (!p_game_config) return false; - return p_game_config->save(); +bool PEMUConfig::saveGame() { + if (!p_game_config) return false; + return p_game_config->save(); +} + +bool PEMUConfig::addRomPath(const std::string &name, const std::string &path, const ss_api::System &system) { + printf("PEMUConfig::addRomPath: %s (system: %s, path: %s)\n", + name.c_str(), system.name.c_str(), path.c_str()); + auto roms = config_lookup(libConfigGetInstance(), std::string(getName() + ".ROMS").c_str()); + if (config_setting_get_member(roms, name.c_str())) { + printf("PEMUConfig::addRomPath: %s found in config file, skipping\n", name.c_str()); + return false; + } + + auto setting = config_setting_add(roms, name.c_str(), CONFIG_TYPE_LIST); + if (setting) { + // add system name + auto opt = config_setting_add(setting, "SYSTEM_NAME", CONFIG_TYPE_STRING); + config_setting_set_string(opt, system.name.c_str()); + // add system id + char sys[32]; + snprintf(sys, 31, "0x%08x", system.id); + opt = config_setting_add(setting, "SYSTEM_ID", CONFIG_TYPE_STRING); + config_setting_set_string(opt, sys); + // add roms path + opt = config_setting_add(setting, "PATH", CONFIG_TYPE_STRING); + config_setting_set_string(opt, path.c_str()); + return true; + } + + return false; +} + +std::vector PEMUConfig::getRomPaths() { + std::vector romPaths; + auto roms = config_lookup(libConfigGetInstance(), std::string(getName() + ".ROMS").c_str()); + if (!roms) { + printf("PEMUConfig::getRomPaths: config_lookup failed\n"); + return romPaths; + } + + int count = config_setting_length(roms); + for (int i = 0; i < count; ++i) { + auto setting = config_setting_get_elem(roms, i); + auto sysName = config_setting_get_elem(setting, 0); + auto sysId = config_setting_get_elem(setting, 1); + auto path = config_setting_get_elem(setting, 2); + if (sysName && sysId && path) { + std::string p = config_setting_get_string(path); + if (!Utility::endsWith(p, "/")) p += "/"; + auto id = Utility::parseHex(config_setting_get_string(sysId)); + romPaths.push_back({p, {(int) id, 0, config_setting_get_string(sysName)}}); + } } - return Config::save(); + return romPaths; } c2d::config::Option *PEMUConfig::getOption(int id, bool isGame) { @@ -204,15 +253,6 @@ c2d::config::Option *PEMUConfig::get(int id, bool isGame) { return getOption(id, isGame); } -std::string PEMUConfig::getRomPath(const std::string &name) { - auto group = getGroup(CFG_ID_ROMS); - if (!group) return ""; - - auto option = name.empty() ? &group->getOptions()->at(0) : group->getOption(name); - if (!option) return ""; - return option->getString(); -} - std::vector PEMUConfig::getKeyboardMapping(int player, bool isGame) { #ifndef NO_KEYBOARD return { diff --git a/src/skeleton/pemu_config.h b/src/skeleton/pemu_config.h index ac50d0bb..d9a55896 100644 --- a/src/skeleton/pemu_config.h +++ b/src/skeleton/pemu_config.h @@ -105,25 +105,26 @@ namespace pemu { END }; - struct GameListInfo { - ss_api::System system{}; - std::string cfg_name{}; - std::string rom_path{}; + struct RomPath { + std::string path; + ss_api::System system; }; PEMUConfig(c2d::Io *io, const std::string &name, int version = 1); - virtual ~PEMUConfig(); + ~PEMUConfig() override; bool loadGame(const ss_api::Game &game); - bool save(bool isGame = false); + bool saveGame(); c2d::config::Option *get(int id, bool isGame = false); c2d::config::Option *getOption(int id, bool isGame = false); - std::string getRomPath(const std::string &name = ""); + bool addRomPath(const std::string &name, const std::string &path, const ss_api::System &system); + + std::vector getRomPaths(); std::vector getKeyboardMapping(int player, bool isGame = false); @@ -140,8 +141,6 @@ namespace pemu { virtual std::vector getCoreSupportedExt() { return {".zip"}; } - virtual std::vector getCoreGameListInfo() { return {}; } - virtual std::vector getCoreHiddenOptionToEnable() { return {}; } private: diff --git a/src/skeleton/romlist.cpp b/src/skeleton/romlist.cpp index 83bf71e8..e9505cf8 100644 --- a/src/skeleton/romlist.cpp +++ b/src/skeleton/romlist.cpp @@ -57,21 +57,20 @@ void RomList::build(const ss_api::GameList::GameAddedCb &cb) { p_cb = cb; m_count = 0; - for (const auto &gamelist: cfg->getCoreGameListInfo()) { - // try to load a "gamelist.xml" from roms folder - std::string gameListPath = cfg->getRomPath(gamelist.cfg_name) + "gamelist.xml"; - gameList->append(gameListPath, cfg->getRomPath(gamelist.cfg_name), - false, filters, gamelist.system, false, [this](Game *game) { - if (p_cb) p_cb(game); - m_count++; - if (!(m_count % 200)) { - setLoadingText("Games: %li / %li", m_count, gameList->games.size()); - } - }); + auto romPaths = cfg->getRomPaths(); + for (const auto &p: romPaths) { + std::string gameListPath = p.path + "gamelist.xml"; + gameList->append(gameListPath, p.path, false, filters, p.system, false, [this](Game *game) { + if (p_cb) p_cb(game); + m_count++; + if (!(m_count % 200)) { + setLoadingText("Games: %li / %li", m_count, gameList->games.size()); + } + }); setLoadingText("Games: %li / %li", gameList->getAvailableCount(), gameList->games.size()); printf("RomList::build: %s, games found: %zu / %zu (system: %s (0x%08x))\n", gameListPath.c_str(), gameList->getAvailableCount(), - gameList->games.size(), gamelist.system.name.c_str(), gamelist.system.id); + gameList->games.size(), p.system.name.c_str(), p.system.id); } // sort lists diff --git a/src/skeleton/ui_menu.cpp b/src/skeleton/ui_menu.cpp index f1689879..2b253afb 100644 --- a/src/skeleton/ui_menu.cpp +++ b/src/skeleton/ui_menu.cpp @@ -402,7 +402,8 @@ bool UiMenu::onInput(c2d::Input::Player *players) { ui->getInput()->clear(); } else { // be sure options are saved before exiting - ui->getConfig()->save(isRomMenu); + if (isRomMenu) ui->getConfig()->saveGame(); + else ui->getConfig()->save(); needSave = false; ui->done = true; } @@ -426,7 +427,8 @@ void UiMenu::setVisibility(Visibility visibility, bool tweenPlay) { } if (visibility == Visibility::Hidden && needSave) { - ui->getConfig()->save(isRomMenu); + if (isRomMenu) ui->getConfig()->saveGame(); + else ui->getConfig()->save(); needSave = false; }