From c8cc8a2520d02f50b6881f817801bb55848f6972 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sat, 18 Mar 2023 22:58:45 +0200 Subject: [PATCH] Add game folder to app data --- include/emulator.hpp | 5 ----- include/io_file.hpp | 6 +++--- src/emulator.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/emulator.hpp b/include/emulator.hpp index fe812e5c..590c267c 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -45,11 +45,6 @@ public: window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); glContext = SDL_GL_CreateContext(window); - // Get path for saving files (AppData on Windows, /home/user/.local/share/ApplcationName on Linux, etc) - char* appData = SDL_GetPrefPath(nullptr, "Alber"); - IOFile::setAppDataDir(appData); - SDL_free(appData); - reset(); } diff --git a/include/io_file.hpp b/include/io_file.hpp index cd62cbfb..4054b7fb 100644 --- a/include/io_file.hpp +++ b/include/io_file.hpp @@ -107,9 +107,9 @@ public: return handle; } - static void setAppDataDir(const char* dir) { - if (!dir) Helpers::panic("Failed to set app data directory"); - appData = std::filesystem::path(dir); + static void setAppDataDir(const std::filesystem::path& dir) { + if (dir == "") Helpers::panic("Failed to set app data directory"); + appData = dir; } static std::filesystem::path getAppData() { return IOFile::appData; } diff --git a/src/emulator.cpp b/src/emulator.cpp index 73846225..7f0ded12 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -49,6 +49,14 @@ void Emulator::runFrame() { } 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 dataPath = std::filesystem::path(appData) / path.filename().stem(); + IOFile::setAppDataDir(dataPath); + SDL_free(appData); + kernel.initializeFS(); auto extension = path.extension();