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.
This commit is contained in:
Clownacy 2020-10-11 15:58:48 +01:00
parent f3ff030869
commit 8d296f0385
3 changed files with 18 additions and 8 deletions

View file

@ -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);

View file

@ -5,6 +5,9 @@
#include <string.h>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#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;
}

View file

@ -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))