Skip to content

Commit

Permalink
Merge pull request #279 from wheremyfoodat/portable-build
Browse files Browse the repository at this point in the history
Add portable build option
  • Loading branch information
wheremyfoodat authored Sep 16, 2023
2 parents 1f8194d + 20b692a commit c0e3d6d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void EmulatorConfig::load(const std::filesystem::path& path) {
auto general = generalResult.unwrap();

discordRpcEnabled = toml::find_or<toml::boolean>(general, "EnableDiscordRPC", false);
usePortableBuild = toml::find_or<toml::boolean>(general, "UsePortableBuild", false);
}
}

Expand Down Expand Up @@ -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));

Expand Down
16 changes: 13 additions & 3 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c0e3d6d

Please sign in to comment.