Description: Write data to $XDG_DATA_HOME Author: Sébastien Noel Forwarded: not-needed ; see https://github.com/DescentDevelopers/Descent3/pull/628 --- a/Descent3/descent.h +++ b/Descent3/descent.h @@ -182,6 +182,7 @@ // The "root" directory of the D3 file tree extern char Base_directory[]; +extern char Base_directory_write[]; // Variable to preserve current path. TODO: redundant? extern std::filesystem::path orig_pwd; --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -1025,6 +1025,7 @@ // The "root" directory of the D3 file tree char Base_directory[_MAX_PATH]; +char Base_directory_write[_MAX_PATH]; extern int Min_allowed_frametime; @@ -1050,8 +1051,13 @@ debugging = (FindArg("-debug") != 0); - if (FindArg("-logfile")) - Debug_Logfile("d3.log"); + if (FindArg("-logfile")) { + char logfile_path[_MAX_PATH]; + char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3"); + ddio_MakePath(logfile_path, prefPath, "d3.log", NULL); + SDL_free(prefPath); + Debug_Logfile(logfile_path); + } #endif @@ -1421,6 +1427,19 @@ } else { ddio_GetWorkingDir(Base_directory, sizeof(Base_directory)); } + char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3"); + strncpy(Base_directory_write, prefPath, sizeof(Base_directory_write)); + SDL_free(prefPath); + + char working_path[_MAX_PATH]; + ddio_MakePath(working_path, Base_directory_write, "demo", NULL); + if (!std::filesystem::is_directory(working_path)) { + std::filesystem::create_directory(working_path); + } + ddio_MakePath(working_path, Base_directory_write, "savegame", NULL); + if (!std::filesystem::is_directory(working_path)) { + std::filesystem::create_directory(working_path); + } ddio_SetWorkingDir(Base_directory); --- a/Descent3/ambient.cpp +++ b/Descent3/ambient.cpp @@ -293,7 +293,7 @@ CFILE *ofile; #ifndef NEWEDITOR - ddio_MakePath(filename, Base_directory, "data", "misc", AMBIENT_FILE_NAME, NULL); + ddio_MakePath(filename, Base_directory_write, "data", "misc", AMBIENT_FILE_NAME, NULL); #else ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL); #endif --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -1724,7 +1724,7 @@ Pilot->get_filename(pfilename); if (pfilename[0] != 0) { - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory_write, pfilename, NULL); return (ddio_DeleteFile(pfilename) == 1); } else { Int3(); // this is odd @@ -1740,7 +1740,7 @@ strcpy(pfilename, pname); strcat(pfilename, PLTEXTENSION); - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory_write, pfilename, NULL); return (ddio_DeleteFile(filename) == 1); } } @@ -1782,7 +1782,7 @@ return; // open and process file - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory_write, pfilename, NULL); try { file = cfopen(filename, "rb"); if (!file) @@ -1857,21 +1857,20 @@ switch (display_default_configs) { case 0: ASSERT(loop_count == 0); - ddio_MakePath(search, Base_directory, PLTWILDCARD, NULL); + ddio_MakePath(search, Base_directory_write, PLTWILDCARD, NULL); break; case 1: - ddio_MakePath(search, Base_directory, (loop_count == 0) ? PLTWILDCARD : DPLTWILDCARD, NULL); + ddio_MakePath(search, Base_directory_write, (loop_count == 0) ? PLTWILDCARD : DPLTWILDCARD, NULL); break; case 2: ASSERT(loop_count == 0); - ddio_MakePath(search, Base_directory, DPLTWILDCARD, NULL); + ddio_MakePath(search, Base_directory_write, DPLTWILDCARD, NULL); break; default: Int3(); break; } - if (ddio_FindFileStart(search, buffer)) { if (ignore_filename && !stricmp(ignore_filename, buffer)) { @@ -3930,7 +3929,7 @@ Pilot->get_filename(pfilename); // open and process file - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory_write, pfilename, NULL); CFILE *file = cfopen(filename, "rb"); if (!file) return; --- a/Descent3/pilot_class.cpp +++ b/Descent3/pilot_class.cpp @@ -422,7 +422,7 @@ char real_filename[_MAX_PATH]; // open and process file - ddio_MakePath(real_filename, Base_directory, filename, NULL); + ddio_MakePath(real_filename, Base_directory_write, filename, NULL); if (new_file && cfexist(real_filename)) { // the file already exists, we can't write out @@ -516,7 +516,7 @@ char real_filename[_MAX_PATH]; // open and process file - ddio_MakePath(real_filename, Base_directory, filename, NULL); + ddio_MakePath(real_filename, Base_directory_write, filename, NULL); if (!cfexist(real_filename)) { // the file already exists, we can't write out --- a/Descent3/game.cpp +++ b/Descent3/game.cpp @@ -1298,7 +1298,7 @@ count = 1; while (!done) { snprintf(str, sizeof(str), "Screenshot%.3d.png", count); - ddio_MakePath(filename, Base_directory, str, NULL); + ddio_MakePath(filename, Base_directory_write, str, NULL); infile = (CFILE *)cfopen(filename, "rb"); if (infile == NULL) { done = 1; --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -350,7 +350,7 @@ void QuickSaveGame() { i = Quicksave_game_slot; snprintf(filename, sizeof(filename), "saveg00%d", i); - ddio_MakePath(pathname, Base_directory, "savegame", filename, NULL); + ddio_MakePath(pathname, Base_directory_write, "savegame", filename, NULL); fp = fopen(pathname, "rb"); if (fp) { @@ -393,7 +393,7 @@ #endif // setup paths. - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL); + ddio_MakePath(savegame_dir, Base_directory_write, "savegame", NULL); // ddio_MakePath(pathname, savegame_dir, "*.sav", NULL); -unused // create savegame directory if it didn't exist before. @@ -545,7 +545,7 @@ void __cdecl LoadGameDialogCB(newuiTiled mprintf(0, "savegame slot=%d\n", id - SAVE_HOTSPOT_ID); - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL); + ddio_MakePath(savegame_dir, Base_directory_write, "savegame", NULL); snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID)); ddio_MakePath(pathname, savegame_dir, filename, NULL); @@ -588,7 +588,7 @@ } // setup paths. - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL); + ddio_MakePath(savegame_dir, Base_directory_write, "savegame", NULL); ddio_MakePath(pathname, savegame_dir, "*.sav", NULL); // create savegame directory if it didn't exist before. --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -358,7 +358,7 @@ if (stricmp(szfile + (strlen(szfile) - 4), ".dem") != 0) { strcat(szfile, ".dem"); } - ddio_MakePath(Demo_fname, Base_directory, "demo", szfile, NULL); + ddio_MakePath(Demo_fname, Base_directory_write, "demo", szfile, NULL); mprintf(0, "Saving demo to file: %s\n", Demo_fname); // Try to create the file Demo_cfp = cfopen(Demo_fname, "wb"); @@ -1423,7 +1423,7 @@ char file[_MAX_PATH * 2]; - ddio_MakePath(file, Base_directory, "demo", NULL); + ddio_MakePath(file, Base_directory_write, "demo", NULL); if (DoPathFileDialog(false, file, TXT_VIEWDEMO, "*.dem", PFDF_FILEMUSTEXIST)) { strcpy(Demo_fname, file); @@ -1681,7 +1681,7 @@ char wcard_fname[_MAX_PATH * 2]; char auto_fname[_MAX_PATH * 2]; int idx = 0; - ddio_MakePath(wcard_fname, Base_directory, "demo", "*.dem", NULL); + ddio_MakePath(wcard_fname, Base_directory_write, "demo", "*.dem", NULL); if (ddio_FindFileStart(wcard_fname, auto_fname)) { // Get to the next demo file we are scheduled to do. while (idx < Demo_auto_idx) { --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -8093,23 +8093,23 @@ break; case NETFILE_ID_SHIP_TEX: if (NetPlayers[playernum].ship_logo[0]) - ddio_MakePath(rval, Base_directory, "custom", "graphics", NetPlayers[playernum].ship_logo, NULL); + ddio_MakePath(rval, Base_directory_write, "custom", "graphics", NetPlayers[playernum].ship_logo, NULL); break; case NETFILE_ID_VOICE_TAUNT1: if (NetPlayers[playernum].voice_taunt1[0]) - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL); + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL); break; case NETFILE_ID_VOICE_TAUNT2: if (NetPlayers[playernum].voice_taunt2[0]) - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL); + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL); break; case NETFILE_ID_VOICE_TAUNT3: if (NetPlayers[playernum].voice_taunt3[0]) - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL); + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL); break; case NETFILE_ID_VOICE_TAUNT4: if (NetPlayers[playernum].voice_taunt4[0]) - ddio_MakePath(rval, Base_directory, "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL); + ddio_MakePath(rval, Base_directory_write, "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL); break; default: mprintf(0, "Unknown id (%d) passed to GetFileNameFromPlayerAndID()\n", id); --- a/Descent3/multi_ui.cpp +++ b/Descent3/multi_ui.cpp @@ -1066,7 +1066,7 @@ void MultiDoConfigSave(void) { char file[_MAX_PATH * 2]; - ddio_MakePath(file, Base_directory, "custom", "settings", NULL); + ddio_MakePath(file, Base_directory_write, "custom", "settings", NULL); if (DoPathFileDialog(true, file, TXT_MULTISAVESET, "*.mps", 0)) { if (stricmp(file + (strlen(file) - 4), ".mps") != 0) strcat(file, ".mps"); @@ -1077,7 +1077,7 @@ void MultiDoConfigLoad(void) { char file[_MAX_PATH * 2]; - ddio_MakePath(file, Base_directory, "custom", "settings", NULL); + ddio_MakePath(file, Base_directory_write, "custom", "settings", NULL); if (DoPathFileDialog(false, file, TXT_MULTILOADSET, "*.mps", PFDF_FILEMUSTEXIST)) MultiLoadSettings(file); } --- a/editor/MainFrm.cpp +++ b/editor/MainFrm.cpp @@ -1461,7 +1461,7 @@ CreateNewMine(); // Setup include directories for OSIRIS - ddio_MakePath(path, Base_directory, "data", "levels", NULL); + ddio_MakePath(path, Base_directory_write, "data", "levels", NULL); } // Copied from winmain.cpp --- a/editor/editor_lighting.cpp +++ b/editor/editor_lighting.cpp @@ -870,7 +870,7 @@ if (save_after_bsp) { char filename[_MAX_PATH]; - ddio_MakePath(filename, Base_directory, "BSPSave.D3L", NULL); + ddio_MakePath(filename, Base_directory_write, "BSPSave.D3L", NULL); // Save the level to SaveLevel(filename); @@ -1140,7 +1140,7 @@ SqueezeLightmaps(0, -1); char filename[_MAX_PATH + 1]; - ddio_MakePath(filename, Base_directory, "LightSave.D3L", NULL); + ddio_MakePath(filename, Base_directory_write, "LightSave.D3L", NULL); // Save the level to disk SaveLevel(filename); --- a/editor/gameeditor.cpp +++ b/editor/gameeditor.cpp @@ -620,7 +620,7 @@ if (Temp_level_saved) { char filename[_MAX_PATH]; - ddio_MakePath(filename, Base_directory, "GameSave.D3L", NULL); // make explicit path + ddio_MakePath(filename, Base_directory_write, "GameSave.D3L", NULL); // make explicit path LoadLevel(filename); Temp_level_saved = 0; }