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
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1d075d49..4e86c57b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -766,6 +766,10 @@ if(DOCONFIG)
# Name debug builds "DoConfig_debug", to distinguish them
set_target_properties(DoConfig PROPERTIES DEBUG_OUTPUT_NAME "DoConfig_debug")
+ if(JAPANESE)
+ target_compile_definitions(DoConfig PRIVATE JAPANESE)
+ endif()
+
# Send executable to the build_en/build_jp directory
set_target_properties(DoConfig PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIRECTORY}
diff --git a/DoConfig/CMakeLists.txt b/DoConfig/CMakeLists.txt
index fe4cf2d0..2b08fd10 100644
--- a/DoConfig/CMakeLists.txt
+++ b/DoConfig/CMakeLists.txt
@@ -35,7 +35,8 @@ set_target_properties(DoConfig PROPERTIES
CXX_EXTENSIONS OFF
)
-target_link_libraries(DoConfig PRIVATE ${CMAKE_DL_LIBS})
+target_link_libraries(DoConfig PRIVATE ${CMAKE_DL_LIBS} ${sdl2_LDFLAGS})
+target_compile_options(DoConfig PRIVATE ${sdl2_CFLAGS})
target_include_directories(DoConfig PRIVATE "../external/glad/include")
target_compile_definitions(DoConfig PRIVATE IMGUI_IMPL_OPENGL_LOADER_GLAD)
diff --git a/DoConfig/DoConfig.cpp b/DoConfig/DoConfig.cpp
index c7bc5704..6ea8bee2 100644
--- a/DoConfig/DoConfig.cpp
+++ b/DoConfig/DoConfig.cpp
@@ -1,6 +1,8 @@
// Released under the MIT licence.
// See LICENCE.txt for details.
+#include <limits.h>
+#include <SDL_filesystem.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -40,23 +42,17 @@ int main(int argc, char *argv[])
char *config_path;
- for (size_t i = strlen(argv[0]);; --i)
- {
- if (i == 0 || argv[0][i - 1] == '\\' || argv[0][i - 1] == '/')
- {
- const char config_string[] = "Config.dat";
+ const char config_string[] = "Config.dat";
- config_path = (char*)malloc(i + sizeof(config_string));
+ config_path = (char*)malloc(PATH_MAX);
- if (config_path == NULL)
- return 1;
-
- memcpy(config_path, argv[0], i);
- memcpy(config_path + i, config_string, sizeof(config_string)); // Will copy null-character
+#ifdef JAPANESE
+ const char config_lang[] = "japanese";
+#else
+ const char config_lang[] = "english";
+#endif
- break;
- }
- }
+ sprintf(config_path, "%s/%s", SDL_GetPrefPath("cse2", config_lang), config_string);
/////////////////////
// Initialise GLFW //
diff --git a/src/Backends/Platform/SDL2.cpp b/src/Backends/Platform/SDL2.cpp
index b52aa5e3..dd31be5d 100644
--- a/src/Backends/Platform/SDL2.cpp
+++ b/src/Backends/Platform/SDL2.cpp
@@ -104,17 +104,15 @@ bool Backend_GetPaths(std::string *module_path, std::string *data_path)
return false;
#else
- char *base_path = SDL_GetBasePath();
- if (base_path == NULL)
- return false;
- // Trim the trailing '/'
- size_t base_path_length = strlen(base_path);
- base_path[base_path_length - 1] = '\0';
- *module_path = base_path;
- SDL_free(base_path);
+#ifdef JAPANESE
+ const char config_lang[] = "japanese";
+#else
+ const char config_lang[] = "english";
+#endif
- *data_path = *module_path + "/data";
+ *module_path = SDL_GetPrefPath("cse2", config_lang);
+ *data_path = std::string("/usr/share/cse2/") + config_lang + "/data";
return true;
#endif
|