From 8d296f03850a2b981a90a6a62bb3663bd9effd4f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sun, 11 Oct 2020 15:58:48 +0100 Subject: [PATCH] Allow backend to specify data folder On the 3DS, I want the data files to go in the read-only ROMFS, while save data goes on the SD card. This is impossible with the current system, so I'm changing it. The other backends will need updating to support this. --- src/Backends/Misc.h | 2 +- src/Backends/Platform/3DS.cpp | 15 +++++++++++++-- src/Main.cpp | 9 ++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Backends/Misc.h b/src/Backends/Misc.h index b7be75d0..ece4bbae 100644 --- a/src/Backends/Misc.h +++ b/src/Backends/Misc.h @@ -89,7 +89,7 @@ enum bool Backend_Init(void (*drag_and_drop_callback)(const char *path), void (*window_focus_callback)(bool focus)); void Backend_Deinit(void); void Backend_PostWindowCreation(void); -bool Backend_GetBasePath(std::string *string_buffer); +bool Backend_GetPaths(std::string *module_path, std::string *data_path); void Backend_HideMouse(void); void Backend_SetWindowIcon(const unsigned char *rgb_pixels, size_t width, size_t height); void Backend_SetCursor(const unsigned char *rgba_pixels, size_t width, size_t height); diff --git a/src/Backends/Platform/3DS.cpp b/src/Backends/Platform/3DS.cpp index 78e0eea3..c684d761 100644 --- a/src/Backends/Platform/3DS.cpp +++ b/src/Backends/Platform/3DS.cpp @@ -5,6 +5,9 @@ #include #include +#include +#include + #include <3ds.h> bool Backend_Init(void (*drag_and_drop_callback)(const char *path), void (*window_focus_callback)(bool focus)) @@ -45,9 +48,17 @@ void Backend_PostWindowCreation(void) // Nothing to do here } -bool Backend_GetBasePath(std::string *string_buffer) +bool Backend_GetPaths(std::string *module_path, std::string *data_path) { - *string_buffer = "romfs:"; + // Create the CSE2 folder if it doesn't already exist + mkdir("sdmc:/3ds", 0777); + mkdir("sdmc:/3ds/cse2", 0777); + + // Configuration files and save data goes on the read-write SD card + *module_path = "sdmc:/3ds/cse2"; + + // Data goes in the read-only ROMFS + *data_path = "romfs:"; return true; } diff --git a/src/Main.cpp b/src/Main.cpp index b8b4aa17..f1301ca7 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -106,8 +106,8 @@ int main(int argc, char *argv[]) if (!Backend_Init(DragAndDropCallback, WindowFocusCallback)) return EXIT_FAILURE; - // Get executable's path - if (!Backend_GetBasePath(&gModulePath)) + // Get executable's path, and path of the data folder + if (!Backend_GetPaths(&gModulePath, &gDataPath)) { // Fall back on argv[0] if the backend cannot provide a path gModulePath = argv[0]; @@ -120,10 +120,9 @@ int main(int argc, char *argv[]) break; } } - } - // Get path of the data folder - gDataPath = gModulePath + "/data"; + gDataPath = gModulePath + "/data"; + } CONFIGDATA conf; if (!LoadConfigData(&conf))