Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / games / shipwright / lus-install-paths.patch
blobc14ecccfed0f5e5ebe1d761ad18256ecb74e1f94
1 Submodule libultraship contains modified content
2 diff --git a/libultraship/src/CMakeLists.txt b/libultraship/src/CMakeLists.txt
3 index 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})
8 #=================== Core ===================
10 +configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/install_config.h.in ${CMAKE_BINARY_DIR}/install_config.h @ONLY)
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 ===================
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
26 diff --git a/libultraship/src/core/Context.cpp b/libultraship/src/core/Context.cpp
27 index 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"
36 namespace LUS {
37 std::weak_ptr<Context> Context::mContext;
38 @@ -281,6 +282,18 @@ std::string Context::GetShortName() {
41 std::string Context::GetAppBundlePath() {
42 +#ifdef CMAKE_INSTALL_PREFIX
43 + static const std::string fpath = CMAKE_INSTALL_PREFIX;
44 + static int exists = -1;
46 + if (exists == -1) {
47 + exists = fpath.size() > 0 && std::filesystem::is_directory(fpath);
48 + }
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);
61 +#endif
62 #endif
64 return ".";
65 @@ -304,6 +318,13 @@ std::string Context::GetAppDirectoryPath() {
67 #endif
69 + char *prefpath = SDL_GetPrefPath(NULL, "soh");
70 + if (prefpath != NULL) {
71 + std::string ret(prefpath);
72 + SDL_free(prefpath);
73 + return ret;
74 + }
76 return ".";
79 @@ -315,7 +336,24 @@ std::string Context::GetPathRelativeToAppDirectory(const char* path) {
80 return GetAppDirectoryPath() + "/" + path;
83 +std::string Context::FindFileFromAllAppDirectories(const char* path) {
84 + std::string fpath;
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);
100 bool Context::DoesOtrFileExist() {
101 return mOtrFileExists;
103 -} // namespace LUS
104 \ No newline at end of file
105 +} // namespace LUS
106 diff --git a/libultraship/src/core/Context.h b/libultraship/src/core/Context.h
107 index 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);
116 Context(std::string name, std::string shortName);
118 diff --git a/libultraship/src/core/libultra/os.cpp b/libultraship/src/core/libultra/os.cpp
119 index 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
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;
138 \ No newline at end of file
140 diff --git a/libultraship/src/install_config.h.in b/libultraship/src/install_config.h.in
141 new file mode 100644
142 index 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@"