aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/Platform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libui_sdl/Platform.cpp')
-rw-r--r--src/libui_sdl/Platform.cpp71
1 files changed, 69 insertions, 2 deletions
diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp
index 94b3791..cc1b734 100644
--- a/src/libui_sdl/Platform.cpp
+++ b/src/libui_sdl/Platform.cpp
@@ -135,6 +135,66 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist)
return ret;
}
+#if !defined(UNIX_PORTABLE) && !defined(__WIN32__)
+
+FILE* OpenLocalFile(const char* path, const char* mode)
+{
+ std::string fullpath;
+ if (path[0] == '/')
+ {
+ // If it's an absolute path, just open that.
+ fullpath = std::string(path);
+ }
+ else
+ {
+ // Check user configuration directory
+ std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/";
+ g_mkdir_with_parents(confpath.c_str(), 0755);
+ fullpath = confpath + path;
+ }
+
+ return OpenFile(fullpath.c_str(), mode, mode[0] != 'w');
+}
+
+FILE* OpenDataFile(const char* path)
+{
+ const char* melondir = "melonDS";
+ const char* const* sys_dirs = g_get_system_data_dirs();
+ const char* user_dir = g_get_user_data_dir();
+
+ // First check the user's data directory
+ char* fullpath = g_build_path("/", user_dir, melondir, path, NULL);
+ if (access(fullpath, R_OK) == 0)
+ {
+ FILE* f = fopen(fullpath, "r");
+ g_free(fullpath);
+ return f;
+ }
+ free(fullpath);
+
+ // Then check the system data directories
+ for (size_t i = 0; sys_dirs[i] != NULL; i++)
+ {
+ const char* dir = sys_dirs[i];
+ char* fullpath = g_build_path("/", dir, melondir, path, NULL);
+
+ if (access(fullpath, R_OK) == 0)
+ {
+ FILE* f = fopen(fullpath, "r");
+ g_free(fullpath);
+ return f;
+ }
+ free(fullpath);
+ }
+
+ FILE* f = fopen(path, "rb");
+ if (f) return f;
+
+ return NULL;
+}
+
+#else
+
FILE* OpenLocalFile(const char* path, const char* mode)
{
bool relpath = false;
@@ -178,7 +238,7 @@ FILE* OpenLocalFile(const char* path, const char* mode)
emudirpath[pathlen] = '\0';
}
- // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonds on Linux
+ // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonDS on Linux
FILE* f;
@@ -240,7 +300,7 @@ FILE* OpenLocalFile(const char* path, const char* mode)
{
// Now check XDG_CONFIG_HOME
// TODO: check for memory leak there
- std::string fullpath = std::string(g_get_user_config_dir()) + "/melonds/" + path;
+ std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path;
f = OpenFile(fullpath.c_str(), mode, true);
if (f) { delete[] emudirpath; return f; }
}
@@ -257,6 +317,13 @@ FILE* OpenLocalFile(const char* path, const char* mode)
return NULL;
}
+FILE* OpenDataFile(const char* path)
+{
+ return OpenLocalFile(path, "rb");
+}
+
+#endif
+
void* Thread_Create(void (*func)())
{