From 7af658f0897c6d6ad1f67b9d7a9bc60955c029a0 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 4 Dec 2019 22:46:33 +0100 Subject: Add a UNIX_PORTABLE build option, turning it off makes a build of melonDS suitable for systemwide installation. --- src/libui_sdl/Platform.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/libui_sdl/Platform.cpp') diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 94b3791..5cbf344 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -135,6 +135,63 @@ 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); + } + + return NULL; +} + +#else + FILE* OpenLocalFile(const char* path, const char* mode) { bool relpath = false; @@ -257,6 +314,13 @@ FILE* OpenLocalFile(const char* path, const char* mode) return NULL; } +FILE* OpenDataFile(const char* path) +{ + return OpenLocalFile(path, "r"); +} + +#endif + void* Thread_Create(void (*func)()) { -- cgit v1.2.3 From 959c37ead74968ef3bf8b66f852307f6e9fb10e3 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Wed, 4 Dec 2019 22:54:30 +0100 Subject: Open with rb instead of r in OpenDataFile to avoid potential problems with Windows. --- src/libui_sdl/Platform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libui_sdl/Platform.cpp') diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 5cbf344..8942927 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -316,7 +316,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) FILE* OpenDataFile(const char* path) { - return OpenLocalFile(path, "r"); + return OpenLocalFile(path, "rb"); } #endif -- cgit v1.2.3 From 4f87707cda26f9c6a7a70ad46232eefebc5a4d82 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 5 Dec 2019 00:11:52 +0100 Subject: If all else fails, look for data files (romlist.bin) in the current working direcoty. --- src/libui_sdl/Platform.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libui_sdl/Platform.cpp') diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 8942927..8b83a01 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -186,6 +186,9 @@ FILE* OpenDataFile(const char* path) } free(fullpath); } + + FILE* f = fopen(path, "rb"); + if (f) return f; return NULL; } -- cgit v1.2.3 From c5623c4dcd122278e45a363b655be67d845ecf63 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Thu, 19 Dec 2019 02:52:34 +0100 Subject: Change the config/data dirs from "melonds" to "melonDS" for consistency. --- src/libui_sdl/CMakeLists.txt | 2 +- src/libui_sdl/Platform.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libui_sdl/Platform.cpp') diff --git a/src/libui_sdl/CMakeLists.txt b/src/libui_sdl/CMakeLists.txt index 8c3d042..2d384e4 100644 --- a/src/libui_sdl/CMakeLists.txt +++ b/src/libui_sdl/CMakeLists.txt @@ -68,5 +68,5 @@ endif () install(FILES ../../net.kuribo64.melonDS.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) install(FILES ../../icon/melon_256x256.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps RENAME net.kuribo64.melonDS.png) -install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonds) +install(FILES ../../romlist.bin DESTINATION ${CMAKE_INSTALL_PREFIX}/share/melonDS) install(TARGETS melonDS RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 8b83a01..cc1b734 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -148,7 +148,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) else { // Check user configuration directory - std::string confpath = std::string(g_get_user_config_dir()) + "/melonds/"; + std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/"; g_mkdir_with_parents(confpath.c_str(), 0755); fullpath = confpath + path; } @@ -158,7 +158,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) FILE* OpenDataFile(const char* path) { - const char* melondir = "melonds"; + const char* melondir = "melonDS"; const char* const* sys_dirs = g_get_system_data_dirs(); const char* user_dir = g_get_user_data_dir(); @@ -238,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; @@ -300,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; } } -- cgit v1.2.3