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