From 20b692ae72a12fdb0d0fdeda1b14bb999428150e Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 16 Sep 2023 23:05:35 +0300 Subject: [PATCH] Add portable build option --- include/config.hpp | 1 + src/config.cpp | 2 ++ src/emulator.cpp | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 8398bb229..326ab2030 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -11,6 +11,7 @@ struct EmulatorConfig { bool sdCardInserted = true; bool sdWriteProtected = false; + bool usePortableBuild = false; bool chargerPlugged = true; // Default to 3% battery to make users suffer diff --git a/src/config.cpp b/src/config.cpp index b262a8a5f..59ee78f69 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -36,6 +36,7 @@ void EmulatorConfig::load(const std::filesystem::path& path) { auto general = generalResult.unwrap(); discordRpcEnabled = toml::find_or(general, "EnableDiscordRPC", false); + usePortableBuild = toml::find_or(general, "UsePortableBuild", false); } } @@ -102,6 +103,7 @@ void EmulatorConfig::save(const std::filesystem::path& path) { } data["General"]["EnableDiscordRPC"] = discordRpcEnabled; + data["General"]["UsePortableBuild"] = usePortableBuild; data["GPU"]["EnableShaderJIT"] = shaderJitEnabled; data["GPU"]["Renderer"] = std::string(Renderer::typeToString(rendererType)); diff --git a/src/emulator.cpp b/src/emulator.cpp index ec99b0fe4..40201d317 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -439,9 +439,19 @@ bool Emulator::loadROM(const std::filesystem::path& path) { // Get path for saving files (AppData on Windows, /home/user/.local/share/ApplcationName on Linux, etc) // Inside that path, we be use a game-specific folder as well. Eg if we were loading a ROM called PenguinDemo.3ds, the savedata would be in - // %APPDATA%/Alber/PenguinDemo/SaveData on Windows, and so on. We do this because games save data in their own filesystem on the cart - char* appData = SDL_GetPrefPath(nullptr, "Alber"); - const std::filesystem::path appDataPath = std::filesystem::path(appData); + // %APPDATA%/Alber/PenguinDemo/SaveData on Windows, and so on. We do this because games save data in their own filesystem on the cart. + // If the portable build setting is enabled, then those saves go in the executable directory instead + char* appData; + std::filesystem::path appDataPath; + + if (!config.usePortableBuild) { + appData = SDL_GetPrefPath(nullptr, "Alber"); + appDataPath = std::filesystem::path(appData); + } else { + appData = SDL_GetBasePath(); + appDataPath = std::filesystem::path(appData) / "Emulator Files"; + } + const std::filesystem::path dataPath = appDataPath / path.filename().stem(); const std::filesystem::path aesKeysPath = appDataPath / "sysdata" / "aes_keys.txt"; IOFile::setAppDataDir(dataPath);