From 6d8869d23abc931509d1e1ec7886b1625896373c Mon Sep 17 00:00:00 2001 From: Elouan Martinet Date: Mon, 28 Oct 2024 09:05:17 +0100 Subject: [PATCH] Add an option to use current rom directory for config and saves --- README.md | 3 +++ include/arm11/config.h | 1 + source/arm11/config.c | 6 +++++- source/arm11/open_agb_firm.c | 24 ++++++++++++++++-------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9f9ee4a..9d90489 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,9 @@ General settings. `bool useGbaDb` - Use `gba_db.bin` to get save types * Default: `true` +`bool useSavesFolder` - Use `/3ds/open_agb_firm/saves` for save files instead of the ROM directory +* Default: `true` + ### Video Video-related settings. diff --git a/include/arm11/config.h b/include/arm11/config.h index 6d5a3cd..8179c75 100644 --- a/include/arm11/config.h +++ b/include/arm11/config.h @@ -39,6 +39,7 @@ typedef struct u8 backlightSteps; bool directBoot; bool useGbaDb; + bool useSavesFolder; // [video] u8 scaler; // 0 = 1:1, 1 = bilinear (GPU) x1.5, 2 = matrix (hardware) x1.5. diff --git a/source/arm11/config.c b/source/arm11/config.c index 0b08bb3..685a628 100644 --- a/source/arm11/config.c +++ b/source/arm11/config.c @@ -30,7 +30,8 @@ "backlight=64\n" \ "backlightSteps=5\n" \ "directBoot=false\n" \ - "useGbaDb=true\n\n" \ + "useGbaDb=true\n" \ + "useSavesFolder=true\n\n" \ "[video]\n" \ "scaler=2\n" \ "gbaGamma=2.2\n" \ @@ -55,6 +56,7 @@ OafConfig g_oafConfig = 5, // backlightSteps false, // directBoot true, // useGbaDb + true, // useSavesFolder // [video] 2, // scaler @@ -143,6 +145,8 @@ static int cfgIniCallback(void* user, const char* section, const char* name, con config->directBoot = (strcmp(value, "false") == 0 ? false : true); else if(strcmp(name, "useGbaDb") == 0) config->useGbaDb = (strcmp(value, "true") == 0 ? true : false); + else if(strcmp(name, "useSavesFolder") == 0) + config->useSavesFolder = (strcmp(value, "true") == 0 ? true : false); } else if(strcmp(section, "video") == 0) { diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index baeb943..05baff8 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -211,15 +211,23 @@ static Result showFileBrowser(char romAndSavePath[512]) static void rom2GameCfgPath(char romPath[512]) { - // Extract the file name and change the extension. - // For cfg2SavePath() we need to reserve 2 extra bytes/chars. - char tmpIniFileName[256]; - safeStrcpy(tmpIniFileName, strrchr(romPath, '/') + 1, 256 - 2); - strcpy(tmpIniFileName + strlen(tmpIniFileName) - 4, ".ini"); + if (g_oafConfig.useSavesFolder) + { + // Extract the file name and change the extension. + // For cfg2SavePath() we need to reserve 2 extra bytes/chars. + char tmpIniFileName[256]; + safeStrcpy(tmpIniFileName, strrchr(romPath, '/') + 1, 256 - 2); + strcpy(tmpIniFileName + strlen(tmpIniFileName) - 4, ".ini"); - // Construct the new path. - strcpy(romPath, OAF_SAVE_DIR "/"); - strcat(romPath, tmpIniFileName); + // Construct the new path. + strcpy(romPath, OAF_SAVE_DIR "/"); + strcat(romPath, tmpIniFileName); + } + else + { + // Change the extension to .ini. + strcpy(romPath + strlen(romPath) - 4, ".ini"); + } } static void gameCfg2SavePath(char cfgPath[512], const u8 saveSlot)