at 24.05-pre 146 lines 4.9 kB view raw
1Submodule libultraship contains modified content 2diff --git a/libultraship/src/CMakeLists.txt b/libultraship/src/CMakeLists.txt 3index f95c3c9..5b967b9 100644 4--- a/libultraship/src/CMakeLists.txt 5+++ b/libultraship/src/CMakeLists.txt 6@@ -74,7 +74,10 @@ target_sources(libultraship PRIVATE ${Source_Files__Controller}) 7 8 #=================== Core =================== 9 10+configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/install_config.h.in ${CMAKE_BINARY_DIR}/install_config.h @ONLY) 11+ 12 set(Source_Files__Core 13+ ${CMAKE_BINARY_DIR}/install_config.h 14 ${CMAKE_CURRENT_SOURCE_DIR}/core/Window.h 15 ${CMAKE_CURRENT_SOURCE_DIR}/core/Window.cpp 16 ${CMAKE_CURRENT_SOURCE_DIR}/core/ConsoleVariable.h 17@@ -329,7 +332,7 @@ endif() 18 #=================== Packages & Includes =================== 19 20 target_include_directories(libultraship 21- PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern 22+ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../extern ${CMAKE_BINARY_DIR} 23 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../extern/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/../extern/stb 24 ) 25 26diff --git a/libultraship/src/core/Context.cpp b/libultraship/src/core/Context.cpp 27index 776333e..fa546e6 100644 28--- a/libultraship/src/core/Context.cpp 29+++ b/libultraship/src/core/Context.cpp 30@@ -14,6 +14,7 @@ 31 #elif defined(__WIIU__) 32 #include "port/wiiu/WiiUImpl.h" 33 #endif 34+#include "install_config.h" 35 36 namespace LUS { 37 std::weak_ptr<Context> Context::mContext; 38@@ -281,6 +282,18 @@ std::string Context::GetShortName() { 39 } 40 41 std::string Context::GetAppBundlePath() { 42+#ifdef CMAKE_INSTALL_PREFIX 43+ static const std::string fpath = CMAKE_INSTALL_PREFIX; 44+ static int exists = -1; 45+ 46+ if (exists == -1) { 47+ exists = fpath.size() > 0 && std::filesystem::is_directory(fpath); 48+ } 49+ 50+ if (exists) { 51+ return fpath; 52+ } 53+#else 54 #ifdef __APPLE__ 55 FolderManager folderManager; 56 return folderManager.getMainBundlePath(); 57@@ -291,6 +304,7 @@ std::string Context::GetAppBundlePath() { 58 if (fpath != NULL) { 59 return std::string(fpath); 60 } 61+#endif 62 #endif 63 64 return "."; 65@@ -304,6 +318,13 @@ std::string Context::GetAppDirectoryPath() { 66 } 67 #endif 68 69+ char *prefpath = SDL_GetPrefPath(NULL, "soh"); 70+ if (prefpath != NULL) { 71+ std::string ret(prefpath); 72+ SDL_free(prefpath); 73+ return ret; 74+ } 75+ 76 return "."; 77 } 78 79@@ -315,7 +336,24 @@ std::string Context::GetPathRelativeToAppDirectory(const char* path) { 80 return GetAppDirectoryPath() + "/" + path; 81 } 82 83+std::string Context::FindFileFromAllAppDirectories(const char* path) { 84+ std::string fpath; 85+ 86+ // app configuration dir (eg. ~/.local/share) 87+ fpath = GetPathRelativeToAppDirectory(path); 88+ if (std::filesystem::exists(fpath)) { 89+ return fpath; 90+ } 91+ // app install dir (eg. /usr/) 92+ fpath = GetPathRelativeToAppBundle(path); 93+ if (std::filesystem::exists(fpath)) { 94+ return fpath; 95+ } 96+ // current dir 97+ return "./" + std::string(path); 98+} 99+ 100 bool Context::DoesOtrFileExist() { 101 return mOtrFileExists; 102 } 103-} // namespace LUS 104\ No newline at end of file 105+} // namespace LUS 106diff --git a/libultraship/src/core/Context.h b/libultraship/src/core/Context.h 107index c32f4dd..a9f1639 100644 108--- a/libultraship/src/core/Context.h 109+++ b/libultraship/src/core/Context.h 110@@ -26,6 +26,7 @@ class Context { 111 static std::string GetAppDirectoryPath(); 112 static std::string GetPathRelativeToAppDirectory(const char* path); 113 static std::string GetPathRelativeToAppBundle(const char* path); 114+ static std::string FindFileFromAllAppDirectories(const char* path); 115 116 Context(std::string name, std::string shortName); 117 118diff --git a/libultraship/src/core/libultra/os.cpp b/libultraship/src/core/libultra/os.cpp 119index 9058fe1..7d9387e 100644 120--- a/libultraship/src/core/libultra/os.cpp 121+++ b/libultraship/src/core/libultra/os.cpp 122@@ -21,8 +21,8 @@ int32_t osContInit(OSMesgQueue* mq, uint8_t* controllerBits, OSContStatus* statu 123 } 124 125 #ifndef __SWITCH__ 126- const char* controllerDb = "gamecontrollerdb.txt"; 127- int mappingsAdded = SDL_GameControllerAddMappingsFromFile(controllerDb); 128+ std::string controllerDb = LUS::Context::GetPathRelativeToAppBundle("gamecontrollerdb.txt"); 129+ int mappingsAdded = SDL_GameControllerAddMappingsFromFile(controllerDb.c_str()); 130 if (mappingsAdded >= 0) { 131 SPDLOG_INFO("Added SDL game controllers from \"{}\" ({})", controllerDb, mappingsAdded); 132 } else { 133@@ -90,4 +90,4 @@ int32_t osRecvMesg(OSMesgQueue* mq, OSMesg* msg, int32_t flag) { 134 mq->validCount--; 135 return 0; 136 } 137-} 138\ No newline at end of file 139+} 140diff --git a/libultraship/src/install_config.h.in b/libultraship/src/install_config.h.in 141new file mode 100644 142index 0000000..029753c 143--- /dev/null 144+++ b/libultraship/src/install_config.h.in 145@@ -0,0 +1 @@ 146+#cmakedefine CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"