Debian Codegraph @

debian/patches/lnx_write_directory.patch

raw symbols SCIP
1 Description: Write data to $XDG_DATA_HOME
2 Author: Sébastien Noel <[email protected]>
3 Forwarded: not-needed ; see https://github.com/DescentDevelopers/Descent3/pull/628
4 --- a/Descent3/descent.h
5 +++ b/Descent3/descent.h
6 @@ -182,6 +182,7 @@
7
8 // The "root" directory of the D3 file tree
9 extern char Base_directory[];
10 +extern char Base_directory_write[];
11
12 // Variable to preserve current path. TODO: redundant?
13 extern std::filesystem::path orig_pwd;
14 --- a/Descent3/init.cpp
15 +++ b/Descent3/init.cpp
16 @@ -1025,6 +1025,7 @@
17
18 // The "root" directory of the D3 file tree
19 char Base_directory[_MAX_PATH];
20 +char Base_directory_write[_MAX_PATH];
21
22 extern int Min_allowed_frametime;
23
24 @@ -1050,8 +1051,13 @@
25
26 debugging = (FindArg("-debug") != 0);
27
28 - if (FindArg("-logfile"))
29 - Debug_Logfile("d3.log");
30 + if (FindArg("-logfile")) {
31 + char logfile_path[_MAX_PATH];
32 + char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3");
33 + ddio_MakePath(logfile_path, prefPath, "d3.log", NULL);
34 + SDL_free(prefPath);
35 + Debug_Logfile(logfile_path);
36 + }
37
38 #endif
39
40 @@ -1421,6 +1427,19 @@
41 } else {
42 ddio_GetWorkingDir(Base_directory, sizeof(Base_directory));
43 }
44 + char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3");
45 + strncpy(Base_directory_write, prefPath, sizeof(Base_directory_write));
46 + SDL_free(prefPath);
47 +
48 + char working_path[_MAX_PATH];
49 + ddio_MakePath(working_path, Base_directory_write, "demo", NULL);
50 + if (!std::filesystem::is_directory(working_path)) {
51 + std::filesystem::create_directory(working_path);
52 + }
53 + ddio_MakePath(working_path, Base_directory_write, "savegame", NULL);
54 + if (!std::filesystem::is_directory(working_path)) {
55 + std::filesystem::create_directory(working_path);
56 + }
57
58 ddio_SetWorkingDir(Base_directory);
59
60 --- a/Descent3/ambient.cpp
61 +++ b/Descent3/ambient.cpp
62 @@ -293,7 +293,7 @@
63 CFILE *ofile;
64
65 #ifndef NEWEDITOR
66 - ddio_MakePath(filename, Base_directory, "data", "misc", AMBIENT_FILE_NAME, NULL);
67 + ddio_MakePath(filename, Base_directory_write, "data", "misc", AMBIENT_FILE_NAME, NULL);
68 #else
69 ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL);
70 #endif
71 --- a/Descent3/pilot.cpp
72 +++ b/Descent3/pilot.cpp
73 @@ -1724,7 +1724,7 @@
74 Pilot->get_filename(pfilename);
75
76 if (pfilename[0] != 0) {
77 - ddio_MakePath(filename, Base_directory, pfilename, NULL);
78 + ddio_MakePath(filename, Base_directory_write, pfilename, NULL);
79 return (ddio_DeleteFile(pfilename) == 1);
80 } else {
81 Int3(); // this is odd
82 @@ -1740,7 +1740,7 @@
83
84 strcpy(pfilename, pname);
85 strcat(pfilename, PLTEXTENSION);
86 - ddio_MakePath(filename, Base_directory, pfilename, NULL);
87 + ddio_MakePath(filename, Base_directory_write, pfilename, NULL);
88 return (ddio_DeleteFile(filename) == 1);
89 }
90 }
91 @@ -1782,7 +1782,7 @@
92 return;
93
94 // open and process file
95 - ddio_MakePath(filename, Base_directory, pfilename, NULL);
96 + ddio_MakePath(filename, Base_directory_write, pfilename, NULL);
97 try {
98 file = cfopen(filename, "rb");
99 if (!file)
100 @@ -1857,21 +1857,20 @@
101 switch (display_default_configs) {
102 case 0:
103 ASSERT(loop_count == 0);
104 - ddio_MakePath(search, Base_directory, PLTWILDCARD, NULL);
105 + ddio_MakePath(search, Base_directory_write, PLTWILDCARD, NULL);
106 break;
107 case 1:
108 - ddio_MakePath(search, Base_directory, (loop_count == 0) ? PLTWILDCARD : DPLTWILDCARD, NULL);
109 + ddio_MakePath(search, Base_directory_write, (loop_count == 0) ? PLTWILDCARD : DPLTWILDCARD, NULL);
110 break;
111 case 2:
112 ASSERT(loop_count == 0);
113 - ddio_MakePath(search, Base_directory, DPLTWILDCARD, NULL);
114 + ddio_MakePath(search, Base_directory_write, DPLTWILDCARD, NULL);
115 break;
116 default:
117 Int3();
118 break;
119 }
120
121 -
122 if (ddio_FindFileStart(search, buffer)) {
123
124 if (ignore_filename && !stricmp(ignore_filename, buffer)) {
125 @@ -3930,7 +3929,7 @@
126 Pilot->get_filename(pfilename);
127
128 // open and process file
129 - ddio_MakePath(filename, Base_directory, pfilename, NULL);
130 + ddio_MakePath(filename, Base_directory_write, pfilename, NULL);
131 CFILE *file = cfopen(filename, "rb");
132 if (!file)
133 return;
134 --- a/Descent3/pilot_class.cpp
135 +++ b/Descent3/pilot_class.cpp
136 @@ -422,7 +422,7 @@
137 char real_filename[_MAX_PATH];
138
139 // open and process file
140 - ddio_MakePath(real_filename, Base_directory, filename, NULL);
141 + ddio_MakePath(real_filename, Base_directory_write, filename, NULL);
142
143 if (new_file && cfexist(real_filename)) {
144 // the file already exists, we can't write out
145 @@ -516,7 +516,7 @@
146 char real_filename[_MAX_PATH];
147
148 // open and process file
149 - ddio_MakePath(real_filename, Base_directory, filename, NULL);
150 + ddio_MakePath(real_filename, Base_directory_write, filename, NULL);
151
152 if (!cfexist(real_filename)) {
153 // the file already exists, we can't write out
154
155 --- a/Descent3/game.cpp
156 +++ b/Descent3/game.cpp
157 @@ -1298,7 +1298,7 @@
158 count = 1;
159 while (!done) {
160 snprintf(str, sizeof(str), "Screenshot%.3d.png", count);
161 - ddio_MakePath(filename, Base_directory, str, NULL);
162 + ddio_MakePath(filename, Base_directory_write, str, NULL);
163 infile = (CFILE *)cfopen(filename, "rb");
164 if (infile == NULL) {
165 done = 1;
166
167 --- a/Descent3/gamesave.cpp
168 +++ b/Descent3/gamesave.cpp
169 @@ -350,7 +350,7 @@ void QuickSaveGame() {
170 i = Quicksave_game_slot;
171
172 snprintf(filename, sizeof(filename), "saveg00%d", i);
173 - ddio_MakePath(pathname, Base_directory, "savegame", filename, NULL);
174 + ddio_MakePath(pathname, Base_directory_write, "savegame", filename, NULL);
175
176 fp = fopen(pathname, "rb");
177 if (fp) {
178 @@ -393,7 +393,7 @@
179 #endif
180
181 // setup paths.
182 - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL);
183 + ddio_MakePath(savegame_dir, Base_directory_write, "savegame", NULL);
184 // ddio_MakePath(pathname, savegame_dir, "*.sav", NULL); -unused
185
186 // create savegame directory if it didn't exist before.
187 @@ -545,7 +545,7 @@ void __cdecl LoadGameDialogCB(newuiTiled
188
189 mprintf(0, "savegame slot=%d\n", id - SAVE_HOTSPOT_ID);
190
191 - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL);
192 + ddio_MakePath(savegame_dir, Base_directory_write, "savegame", NULL);
193 snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID));
194 ddio_MakePath(pathname, savegame_dir, filename, NULL);
195
196 @@ -588,7 +588,7 @@
197 }
198
199 // setup paths.
200 - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL);
201 + ddio_MakePath(savegame_dir, Base_directory_write, "savegame", NULL);
202 ddio_MakePath(pathname, savegame_dir, "*.sav", NULL);
203
204 // create savegame directory if it didn't exist before.
205
206 --- a/Descent3/demofile.cpp
207 +++ b/Descent3/demofile.cpp
208 @@ -358,7 +358,7 @@
209 if (stricmp(szfile + (strlen(szfile) - 4), ".dem") != 0) {
210 strcat(szfile, ".dem");
211 }
212 - ddio_MakePath(Demo_fname, Base_directory, "demo", szfile, NULL);
213 + ddio_MakePath(Demo_fname, Base_directory_write, "demo", szfile, NULL);
214 mprintf(0, "Saving demo to file: %s\n", Demo_fname);
215 // Try to create the file
216 Demo_cfp = cfopen(Demo_fname, "wb");
217 @@ -1423,7 +1423,7 @@
218
219 char file[_MAX_PATH * 2];
220
221 - ddio_MakePath(file, Base_directory, "demo", NULL);
222 + ddio_MakePath(file, Base_directory_write, "demo", NULL);
223
224 if (DoPathFileDialog(false, file, TXT_VIEWDEMO, "*.dem", PFDF_FILEMUSTEXIST)) {
225 strcpy(Demo_fname, file);
226 @@ -1681,7 +1681,7 @@
227 char wcard_fname[_MAX_PATH * 2];
228 char auto_fname[_MAX_PATH * 2];
229 int idx = 0;
230 - ddio_MakePath(wcard_fname, Base_directory, "demo", "*.dem", NULL);
231 + ddio_MakePath(wcard_fname, Base_directory_write, "demo", "*.dem", NULL);
232 if (ddio_FindFileStart(wcard_fname, auto_fname)) {
233 // Get to the next demo file we are scheduled to do.
234 while (idx < Demo_auto_idx) {
235
236 --- a/Descent3/multi.cpp
237 +++ b/Descent3/multi.cpp
238 @@ -8093,23 +8093,23 @@
239 break;
240 case NETFILE_ID_SHIP_TEX:
241 if (NetPlayers[playernum].ship_logo[0])
242 - ddio_MakePath(rval, Base_directory, "custom", "graphics", NetPlayers[playernum].ship_logo, NULL);
243 + ddio_MakePath(rval, Base_directory_write, "custom", "graphics", NetPlayers[playernum].ship_logo, NULL);
244 break;
245 case NETFILE_ID_VOICE_TAUNT1:
246 if (NetPlayers[playernum].voice_taunt1[0])
247 - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL);
248 + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL);
249 break;
250 case NETFILE_ID_VOICE_TAUNT2:
251 if (NetPlayers[playernum].voice_taunt2[0])
252 - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL);
253 + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL);
254 break;
255 case NETFILE_ID_VOICE_TAUNT3:
256 if (NetPlayers[playernum].voice_taunt3[0])
257 - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL);
258 + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL);
259 break;
260 case NETFILE_ID_VOICE_TAUNT4:
261 if (NetPlayers[playernum].voice_taunt4[0])
262 - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL);
263 + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL);
264 break;
265 default:
266 mprintf(0, "Unknown id (%d) passed to GetFileNameFromPlayerAndID()\n", id);
267 --- a/Descent3/multi_ui.cpp
268 +++ b/Descent3/multi_ui.cpp
269 @@ -1066,7 +1066,7 @@
270 void MultiDoConfigSave(void) {
271 char file[_MAX_PATH * 2];
272
273 - ddio_MakePath(file, Base_directory, "custom", "settings", NULL);
274 + ddio_MakePath(file, Base_directory_write, "custom", "settings", NULL);
275 if (DoPathFileDialog(true, file, TXT_MULTISAVESET, "*.mps", 0)) {
276 if (stricmp(file + (strlen(file) - 4), ".mps") != 0)
277 strcat(file, ".mps");
278 @@ -1077,7 +1077,7 @@
279 void MultiDoConfigLoad(void) {
280 char file[_MAX_PATH * 2];
281
282 - ddio_MakePath(file, Base_directory, "custom", "settings", NULL);
283 + ddio_MakePath(file, Base_directory_write, "custom", "settings", NULL);
284 if (DoPathFileDialog(false, file, TXT_MULTILOADSET, "*.mps", PFDF_FILEMUSTEXIST))
285 MultiLoadSettings(file);
286 }
287
288 --- a/editor/MainFrm.cpp
289 +++ b/editor/MainFrm.cpp
290 @@ -1461,7 +1461,7 @@
291 CreateNewMine();
292
293 // Setup include directories for OSIRIS
294 - ddio_MakePath(path, Base_directory, "data", "levels", NULL);
295 + ddio_MakePath(path, Base_directory_write, "data", "levels", NULL);
296 }
297
298 // Copied from winmain.cpp
299 --- a/editor/editor_lighting.cpp
300 +++ b/editor/editor_lighting.cpp
301 @@ -870,7 +870,7 @@
302
303 if (save_after_bsp) {
304 char filename[_MAX_PATH];
305 - ddio_MakePath(filename, Base_directory, "BSPSave.D3L", NULL);
306 + ddio_MakePath(filename, Base_directory_write, "BSPSave.D3L", NULL);
307
308 // Save the level to
309 SaveLevel(filename);
310 @@ -1140,7 +1140,7 @@
311 SqueezeLightmaps(0, -1);
312
313 char filename[_MAX_PATH + 1];
314 - ddio_MakePath(filename, Base_directory, "LightSave.D3L", NULL);
315 + ddio_MakePath(filename, Base_directory_write, "LightSave.D3L", NULL);
316
317 // Save the level to disk
318 SaveLevel(filename);
319 --- a/editor/gameeditor.cpp
320 +++ b/editor/gameeditor.cpp
321 @@ -620,7 +620,7 @@
322 if (Temp_level_saved) {
323 char filename[_MAX_PATH];
324
325 - ddio_MakePath(filename, Base_directory, "GameSave.D3L", NULL); // make explicit path
326 + ddio_MakePath(filename, Base_directory_write, "GameSave.D3L", NULL); // make explicit path
327 LoadLevel(filename);
328 Temp_level_saved = 0;
329 }
330