From 65c9065012fa3b82a84a786cf108c2ca27f064de Mon Sep 17 00:00:00 2001 From: Jason Yundt Date: Sat, 27 Jul 2024 10:56:02 -0400 Subject: [PATCH] Turn Base_directory into an std::filesystem::path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, Base_directory was a char array. In general, it’s better to use an std::filesystem::path to represent paths. Here’s why: • char arrays have a limited size. If a user creates a file or directory that has a very long path, then it might not be possible to store that path in a given char array. You can try to make the char array long enough to store the longest possible path, but future operating systems may increase that limit. With std::filesystem::paths, you don’t have to worry about path length limits. • char arrays cannot necessarily represent all paths. We try our best to use UTF-8 for all char arrays [1], but unfortunately, it’s possible to create a path that cannot be represent using UTF-8 [2]. With an std::filesystem::paths, stuff like that is less likely to happen because std::filesystem::path::value_type is platform-specific. • char arrays don’t have any built-in mechanisms for manipulating paths. Before this commit, the code would work around this problem in two different ways: 1. It would use Descent 3–specific functions that implement path operations on char arrays/pointers (for example, ddio_MakePath()). Once all paths use std::filesystem::path, we’ll be able to simplify the code by removing those functions. 2. It would temporarily convert Base_directory into an std::filesystem::path. This commit simplifies the code by removing those temporary conversions because they are no longer necessary. [1]: 7cd79025 (Merge pull request #494 from Jayman2000/encoding-improvements, 2024-07-20) [2]: --- Descent3/Game2DLL.cpp | 4 ++-- Descent3/ambient.cpp | 2 +- Descent3/demofile.cpp | 4 ++-- Descent3/descent.cpp | 2 +- Descent3/descent.h | 2 +- Descent3/game.cpp | 2 +- Descent3/gamesave.cpp | 8 ++++---- Descent3/gamespy.cpp | 2 +- Descent3/init.cpp | 15 ++++++--------- Descent3/mmItem.cpp | 2 +- Descent3/multi.cpp | 10 +++++----- Descent3/multi_dll_mgr.cpp | 8 ++++---- Descent3/multi_ui.cpp | 6 +++--- Descent3/pilot.cpp | 11 +++++------ Descent3/pilot_class.cpp | 4 ++-- editor/MainFrm.cpp | 2 +- editor/editor_lighting.cpp | 4 ++-- editor/gameeditor.cpp | 4 ++-- manage/manage.cpp | 9 +++++++-- netcon/includes/con_dll.h | 10 +++++----- netcon/includes/mdllinit.h | 2 +- netcon/mtclient/mtclient.cpp | 2 +- 22 files changed, 58 insertions(+), 57 deletions(-) diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index 3eafc2954..0bc4a98d4 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -565,7 +565,7 @@ bool InitGameModule(const char *name, module *mod) { std::filesystem::path dll_name; std::filesystem::path tmp_dll_name; // Make the hog filename - lib_name = std::filesystem::path(Base_directory) / "netgames" / name; + lib_name = Base_directory / "netgames" / name; lib_name.replace_extension(".d3m"); // Make the dll filename dll_name = name; @@ -573,7 +573,7 @@ bool InitGameModule(const char *name, module *mod) { // Open the hog file if (!cf_OpenLibrary(lib_name)) { - tmp_dll_name = std::filesystem::path(Base_directory) / "netgames" / name; + tmp_dll_name = Base_directory / "netgames" / name; tmp_dll_name.replace_extension(".d3m"); Multi_game_dll_name.clear(); goto loaddll; diff --git a/Descent3/ambient.cpp b/Descent3/ambient.cpp index ade9f295f..7819066d3 100644 --- a/Descent3/ambient.cpp +++ b/Descent3/ambient.cpp @@ -293,7 +293,7 @@ void WriteAmbientData() { CFILE *ofile; #ifndef NEWEDITOR - ddio_MakePath(filename, Base_directory, "data", "misc", AMBIENT_FILE_NAME, NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), "data", "misc", AMBIENT_FILE_NAME, NULL); #else ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL); #endif diff --git a/Descent3/demofile.cpp b/Descent3/demofile.cpp index 2942c208e..d5e33d05e 100644 --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -359,7 +359,7 @@ void DemoToggleRecording() { if (stricmp(szfile + (strlen(szfile) - 4), ".dem") != 0) { strcat(szfile, ".dem"); } - Demo_fname = std::filesystem::path(Base_directory) / "demo" / szfile; + Demo_fname = Base_directory / "demo" / szfile; LOG_INFO.printf("Saving demo to file: %s", Demo_fname.u8string().c_str()); // Try to create the file Demo_cfp = cfopen(Demo_fname, "wb"); @@ -1408,7 +1408,7 @@ bool LoadDemoDialog() { // return false; // #else - std::filesystem::path file = std::filesystem::path(Base_directory) / "demo"; + std::filesystem::path file = Base_directory / "demo"; if (DoPathFileDialog(false, file, TXT_VIEWDEMO, {"*.dem"}, PFDF_FILEMUSTEXIST)) { Demo_fname = file; diff --git a/Descent3/descent.cpp b/Descent3/descent.cpp index 80f223848..5910d155b 100644 --- a/Descent3/descent.cpp +++ b/Descent3/descent.cpp @@ -490,7 +490,7 @@ void Descent3() { }; for (auto const &intro : intros) { - PlayMovie(std::filesystem::path(Base_directory) / "movies" / intro); + PlayMovie(Base_directory / "movies" / intro); } } diff --git a/Descent3/descent.h b/Descent3/descent.h index 9ea4f976f..041926f84 100644 --- a/Descent3/descent.h +++ b/Descent3/descent.h @@ -182,7 +182,7 @@ extern bool Descent_overrided_intro; #define MSN_NAMELEN 32 // The "root" directory of the D3 file tree -extern char Base_directory[]; +extern std::filesystem::path Base_directory; // Variable to preserve current path. TODO: redundant? extern std::filesystem::path orig_pwd; diff --git a/Descent3/game.cpp b/Descent3/game.cpp index 14ad58c86..be6ecf6a3 100644 --- a/Descent3/game.cpp +++ b/Descent3/game.cpp @@ -1279,7 +1279,7 @@ void DoScreenshot() { count = 1; while (!done) { snprintf(str, sizeof(str), "Screenshot%.3d.png", count); - ddio_MakePath(filename, Base_directory, str, NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), str, NULL); infile = (CFILE *)cfopen(filename, "rb"); if (infile == NULL) { done = 1; diff --git a/Descent3/gamesave.cpp b/Descent3/gamesave.cpp index 7209d2925..314fb5d34 100644 --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -348,7 +348,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.u8string().c_str(), "savegame", filename, NULL); fp = fopen(pathname, "rb"); if (fp) { @@ -391,7 +391,7 @@ void SaveGameDialog() { #endif // setup paths. - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL); + ddio_MakePath(savegame_dir, Base_directory.u8string().c_str(), "savegame", NULL); // ddio_MakePath(pathname, savegame_dir, "*.sav", NULL); -unused // create savegame directory if it didn't exist before. @@ -543,7 +543,7 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data) LOG_DEBUG.printf("savegame slot=%d", id - SAVE_HOTSPOT_ID); - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL); + ddio_MakePath(savegame_dir, Base_directory.u8string().c_str(), "savegame", NULL); snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID)); ddio_MakePath(pathname, savegame_dir, filename, NULL); @@ -586,7 +586,7 @@ bool LoadGameDialog() { } // setup paths. - ddio_MakePath(savegame_dir, Base_directory, "savegame", NULL); + ddio_MakePath(savegame_dir, Base_directory.u8string().c_str(), "savegame", NULL); ddio_MakePath(pathname, savegame_dir, "*.sav", NULL); // create savegame directory if it didn't exist before. diff --git a/Descent3/gamespy.cpp b/Descent3/gamespy.cpp index 29d0f5474..7100d571e 100644 --- a/Descent3/gamespy.cpp +++ b/Descent3/gamespy.cpp @@ -124,7 +124,7 @@ int gspy_Init() { } // Read the config, resolve the name if needed and setup the server addresses - cfgpath = std::filesystem::path(Base_directory) / gspy_cfgfilename; + cfgpath = Base_directory / gspy_cfgfilename; gspy_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); diff --git a/Descent3/init.cpp b/Descent3/init.cpp index 2df70ff07..aa1431a73 100644 --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -1027,7 +1027,7 @@ static bool Title_bitmap_init = false; uint8_t Use_motion_blur = 0; // The "root" directory of the D3 file tree -char Base_directory[_MAX_PATH]; +std::filesystem::path Base_directory; extern int Min_allowed_frametime; @@ -1397,8 +1397,7 @@ void InitIOSystems(bool editor) { int dirarg = FindArg("-setdir"); int exedirarg = FindArg("-useexedir"); if (dirarg) { - strncpy(Base_directory, GameArgs[dirarg + 1], sizeof(Base_directory) - 1); - Base_directory[sizeof(Base_directory) - 1] = '\0'; + Base_directory = GameArgs[dirarg + 1]; } else if (exedirarg) { char exec_path[_MAX_PATH]; memset(exec_path, 0, sizeof(exec_path)); @@ -1407,16 +1406,14 @@ void InitIOSystems(bool editor) { Error("Failed to get executable path\n"); } else { std::filesystem::path executablePath(exec_path); - std::string baseDirectoryString = executablePath.parent_path().string(); - strncpy(Base_directory, baseDirectoryString.c_str(), sizeof(Base_directory) - 1); - Base_directory[sizeof(Base_directory) - 1] = '\0'; + Base_directory = executablePath.parent_path(); LOG_INFO << "Using working directory of " << Base_directory; } } else { - ddio_GetWorkingDir(Base_directory, sizeof(Base_directory)); + Base_directory = std::filesystem::current_path(); } - ddio_SetWorkingDir(Base_directory); + ddio_SetWorkingDir(Base_directory.u8string().c_str()); Descent->set_defer_handler(D3DeferHandler); @@ -2025,7 +2022,7 @@ void SetupTempDirectory(void) { exit(1); } // restore working dir - ddio_SetWorkingDir(Base_directory); + ddio_SetWorkingDir(Base_directory.u8string().c_str()); } void DeleteTempFiles() { diff --git a/Descent3/mmItem.cpp b/Descent3/mmItem.cpp index e5a692ef6..a211b59af 100644 --- a/Descent3/mmItem.cpp +++ b/Descent3/mmItem.cpp @@ -331,7 +331,7 @@ void mmInterface::Create() { static_menu_background = true; } else { char filename[_MAX_PATH]; - ddio_MakePath(filename, Base_directory, "movies", "mainmenu", NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), "movies", "mainmenu", NULL); m_movie = StartMovie(filename, true); if (!m_movie) //[ISB] Didn't find the menu movie? diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index 25b39c870..f1825e6b2 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -8010,23 +8010,23 @@ char *GetFileNameFromPlayerAndID(int16_t playernum, int16_t id) { 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.u8string().c_str(), "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.u8string().c_str(), "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.u8string().c_str(), "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.u8string().c_str(), "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.u8string().c_str(), "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL); break; default: LOG_FATAL.printf("Unknown id (%d) passed to GetFileNameFromPlayerAndID()", id); diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index 1dff4f69e..4655063c6 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -527,7 +527,7 @@ void GetMultiAPI(multi_api *api) { api->vp[2] = (int *)&Game_is_master_tracker_game; api->vp[3] = (int *)&Game_mode; api->vp[4] = (int *)NULL; // Current_pilot; no longer a struct - api->vp[5] = (int *)Base_directory; + api->vp[5] = (int *)&Base_directory; api->vp[6] = (int *)&MultiDLLGameStarting; api->vp[7] = (int *)MTPilotinfo; api->vp[8] = (int *)&Num_network_games_known; @@ -598,7 +598,7 @@ int LoadMultiDLL(const char *name) { if (MultiDLLHandle.handle) FreeMultiDLL(); - std::filesystem::path dll_path_name = std::filesystem::path(Base_directory) / "online"; + std::filesystem::path dll_path_name = Base_directory / "online"; ddio_DoForeachFile(dll_path_name, std::regex(".+\\.tmp"), [](const std::filesystem::path& path, ...) { std::error_code ec; std::filesystem::remove(path, ec); @@ -608,7 +608,7 @@ int LoadMultiDLL(const char *name) { }); // Make the hog filename - lib_name = std::filesystem::path(Base_directory) / "online" / name; + lib_name = Base_directory / "online" / name; lib_name.replace_extension(".d3c"); // Make the dll filename dll_name = name; @@ -616,7 +616,7 @@ int LoadMultiDLL(const char *name) { // Open the hog file if (!cf_OpenLibrary(lib_name)) { - tmp_dll_name = std::filesystem::path(Base_directory) / "online" / name; + tmp_dll_name = Base_directory / "online" / name; tmp_dll_name.replace_extension(".d3c"); Multi_conn_dll_name.clear(); goto loaddll; diff --git a/Descent3/multi_ui.cpp b/Descent3/multi_ui.cpp index facde1fbe..5a6bf2134 100644 --- a/Descent3/multi_ui.cpp +++ b/Descent3/multi_ui.cpp @@ -442,7 +442,7 @@ int MainMultiplayerMenu() { std::vector dllnames; - ddio_DoForeachFile(std::filesystem::path(Base_directory) / "online", std::regex(".*\\.d3c"), + ddio_DoForeachFile(Base_directory / "online", std::regex(".*\\.d3c"), [&dllnames](const std::filesystem::path &path) { std::string filename = path.stem().string(); @@ -989,7 +989,7 @@ void DoMultiAllowed(void) { } void MultiDoConfigSave() { - std::filesystem::path file = std::filesystem::path(Base_directory) / "custom" / "settings"; + std::filesystem::path file = Base_directory / "custom" / "settings"; if (DoPathFileDialog(true, file, TXT_MULTISAVESET, {"*.mps"}, 0)) { file.replace_extension(".mps"); MultiSaveSettings(file); @@ -997,7 +997,7 @@ void MultiDoConfigSave() { } void MultiDoConfigLoad() { - std::filesystem::path file = std::filesystem::path(Base_directory) / "custom" / "settings"; + std::filesystem::path file = Base_directory / "custom" / "settings"; if (DoPathFileDialog(false, file, TXT_MULTILOADSET, {"*.mps"}, PFDF_FILEMUSTEXIST)) MultiLoadSettings(file); } diff --git a/Descent3/pilot.cpp b/Descent3/pilot.cpp index e2191e8f5..d8db808e4 100644 --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -1581,7 +1581,7 @@ bool PltDelete(pilot *Pilot) { std::string pfilename = Pilot->get_filename(); std::error_code ec; if (!pfilename.empty()) { - return std::filesystem::remove(std::filesystem::path(Base_directory) / pfilename, ec); + return std::filesystem::remove(Base_directory / pfilename, ec); } else { Int3(); // this is odd @@ -1595,7 +1595,7 @@ bool PltDelete(pilot *Pilot) { PltMakeFNValid(pname); pfilename = std::string(pname) + PLTEXTENSION; - return std::filesystem::remove(std::filesystem::path(Base_directory) / pfilename, ec); + return std::filesystem::remove(Base_directory / pfilename, ec); } } @@ -1634,7 +1634,7 @@ void PltReadFile(pilot *Pilot, bool keyconfig, bool missiondata) { return; // open and process file - std::filesystem::path filename = std::filesystem::path(Base_directory) / pfilename; + std::filesystem::path filename = Base_directory / pfilename; try { file = cfopen(filename, "rb"); if (!file) @@ -1677,7 +1677,6 @@ std::vector PltGetPilots(std::string ignore_filename, int display_d // clear list PltClearList(); - std::filesystem::path search = std::filesystem::path(Base_directory); std::regex wildcard; std::vector result; @@ -1699,7 +1698,7 @@ std::vector PltGetPilots(std::string ignore_filename, int display_d break; } - ddio_DoForeachFile(search, wildcard, [&ignore_filename, &result](const std::filesystem::path &path) { + ddio_DoForeachFile(Base_directory, wildcard, [&ignore_filename, &result](const std::filesystem::path &path) { std::string pilot = path.filename().u8string(); if (!ignore_filename.empty() && stricmp(ignore_filename.c_str(), pilot.c_str()) == 0) { LOG_INFO.printf("Getting Pilots... found %s, but ignoring", pilot.c_str()); @@ -3275,7 +3274,7 @@ void _ReadOldPilotFile(pilot *Pilot, bool keyconfig, bool missiondata) { std::string pfilename = Pilot->get_filename(); // open and process file - std::filesystem::path filename = std::filesystem::path(Base_directory) / pfilename; + std::filesystem::path filename = Base_directory / pfilename; CFILE *file = cfopen(filename, "rb"); if (!file) return; diff --git a/Descent3/pilot_class.cpp b/Descent3/pilot_class.cpp index ad33cdfba..c1d91d246 100644 --- a/Descent3/pilot_class.cpp +++ b/Descent3/pilot_class.cpp @@ -415,7 +415,7 @@ int pilot::flush(bool new_file) { } CFILE *file; - std::filesystem::path real_filename = std::filesystem::path(Base_directory) / filename; + std::filesystem::path real_filename = Base_directory / filename; if (new_file && cfexist(real_filename)) { // the file already exists, we can't write out @@ -497,7 +497,7 @@ int pilot::read(bool skip_config, bool skip_mission_data) { } CFILE *file; - std::filesystem::path real_filename = std::filesystem::path(Base_directory) / filename; + std::filesystem::path real_filename = Base_directory / filename; if (!cfexist(real_filename)) { // the file already exists, we can't write out diff --git a/editor/MainFrm.cpp b/editor/MainFrm.cpp index c12cdf38f..2334e3da9 100644 --- a/editor/MainFrm.cpp +++ b/editor/MainFrm.cpp @@ -1460,7 +1460,7 @@ void InitCScripts() { CreateNewMine(); // Setup include directories for OSIRIS - ddio_MakePath(path, Base_directory, "data", "levels", NULL); + ddio_MakePath(path, Base_directory.u8string().c_str(), "data", "levels", NULL); } // Copied from winmain.cpp diff --git a/editor/editor_lighting.cpp b/editor/editor_lighting.cpp index 205cab82f..5f90fffd0 100644 --- a/editor/editor_lighting.cpp +++ b/editor/editor_lighting.cpp @@ -870,7 +870,7 @@ void DoRadiosityForRooms() { if (save_after_bsp) { char filename[_MAX_PATH]; - ddio_MakePath(filename, Base_directory, "BSPSave.D3L", NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), "BSPSave.D3L", NULL); // Save the level to SaveLevel(filename); @@ -1140,7 +1140,7 @@ void DoRadiosityForRooms() { SqueezeLightmaps(0, -1); char filename[_MAX_PATH + 1]; - ddio_MakePath(filename, Base_directory, "LightSave.D3L", NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), "LightSave.D3L", NULL); // Save the level to disk SaveLevel(filename); diff --git a/editor/gameeditor.cpp b/editor/gameeditor.cpp index 20cc0334a..d36268a33 100644 --- a/editor/gameeditor.cpp +++ b/editor/gameeditor.cpp @@ -611,7 +611,7 @@ void GameToEditor(bool set_viewer_from_player) { if (Temp_level_saved) { char filename[_MAX_PATH]; - ddio_MakePath(filename, Base_directory, "GameSave.D3L", NULL); // make explicit path + ddio_MakePath(filename, Base_directory.u8string().c_str(), "GameSave.D3L", NULL); // make explicit path LoadLevel(filename); Temp_level_saved = 0; } @@ -744,7 +744,7 @@ void EditorToGame() { // set game working directory bool set_size = false; ddio_GetWorkingDir(Editor_dir, sizeof(Editor_dir)); - ddio_SetWorkingDir(Base_directory); + ddio_SetWorkingDir(Base_directory.u8string().c_str()); Osiris_ResetAllTimers(); diff --git a/manage/manage.cpp b/manage/manage.cpp index ff2f60501..1829baddc 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -672,8 +672,13 @@ int mng_LoadTableFiles(int show_progress) { // This is for initting tables on STAND_ALONE, if the network is down, or if // the user doesn't want network support int mng_InitLocalTables() { - // Set the local table directory from the base directory - strcpy(LocalD3Dir, Base_directory); + // Set the local table directory from the base directory. + auto base_directory_string = Base_directory.u8string(); + strncpy(LocalD3Dir, base_directory_string.c_str(), sizeof LocalD3Dir); + LocalD3Dir[sizeof LocalD3Dir - 1] = '\0'; + if (strlen(LocalD3Dir) != strlen(base_directory_string.c_str())) { + LOG_WARNING << "Base_directory is too long to fit in LocalD3Dir, so LocalD3Dir was truncated."; + } LOG_INFO << "Local dir: " << LocalD3Dir; // Make the CFILE system first look at our local directories. If the goods aren't diff --git a/netcon/includes/con_dll.h b/netcon/includes/con_dll.h index 94c81df85..374217981 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -768,7 +768,7 @@ int DLLGame_mode; char *DLLTracker_id; int *DLLNum_directplay_games; netgame_info *DLLNetgame; -char *DLLLocalD3Dir; +std::filesystem::path *DLLLocalD3Dir; int *DLLMultiGameStarting; netplayer *DLLMNetPlayers; int MTWritingPilot, MTReadingPilot; @@ -998,7 +998,7 @@ int StartMultiplayerGameMenu() { DLLListRemoveAll(script_list); #if (!(defined(OEM) || defined(DEMO))) - DLLddio_DoForeachFile(std::filesystem::path(DLLLocalD3Dir) / "netgames", std::regex(".+\\.d3m"), + DLLddio_DoForeachFile(*DLLLocalD3Dir / "netgames", std::regex(".+\\.d3m"), [&dll_ui_items](const std::filesystem::path& path){ dll_ui_items.insert_or_assign( path.stem().u8string(), @@ -1018,8 +1018,8 @@ int StartMultiplayerGameMenu() { msn_list *mi; const std::vector> search_paths = { - {std::filesystem::path(DLLLocalD3Dir) / "data" / "levels", std::regex(".+\\.msn")}, - {std::filesystem::path(DLLLocalD3Dir) / "missions", std::regex(".+\\.mn3")} + {*DLLLocalD3Dir / "data" / "levels", std::regex(".+\\.msn")}, + {*DLLLocalD3Dir / "missions", std::regex(".+\\.mn3")} }; for (auto const &i : search_paths) { @@ -1074,7 +1074,7 @@ int StartMultiplayerGameMenu() { DLLNetgame->flags = NF_RANDOMIZE_RESPAWN; DLLNewUIWindowLoadBackgroundImage(main_wnd, "multimain.ogf"); DLLNewUIWindowOpen(main_wnd); - if (DLLMultiLoadSettings(std::filesystem::path(DLLLocalD3Dir) / "custom" / "settings" / "default.mps")) { + if (DLLMultiLoadSettings(*DLLLocalD3Dir / "custom" / "settings" / "default.mps")) { DLLEditSetText(mission_name_edit, DLLNetgame->name); #if (!(defined(OEM) || defined(DEMO))) p = DLLGetMissionName(DLLNetgame->mission); diff --git a/netcon/includes/mdllinit.h b/netcon/includes/mdllinit.h index 84de3e8ee..b563ff63d 100644 --- a/netcon/includes/mdllinit.h +++ b/netcon/includes/mdllinit.h @@ -286,7 +286,7 @@ DLLTracker_id = (char *)API.vp[1]; DLLGame_is_master_tracker_game = API.vp[2]; DLLGame_mode = *API.vp[3]; // DLLCurrent_pilot = (pilot *)API.vp[4]; -DLLLocalD3Dir = (char *)API.vp[5]; +DLLLocalD3Dir = (std::filesystem::path *)API.vp[5]; DLLMultiGameStarting = (int *)API.vp[6]; DLLMTPilotinfo = (vmt_descent3_struct *)API.vp[7]; DLLNum_network_games_known = API.vp[8]; diff --git a/netcon/mtclient/mtclient.cpp b/netcon/mtclient/mtclient.cpp index 39212f85a..dfdcfbf07 100644 --- a/netcon/mtclient/mtclient.cpp +++ b/netcon/mtclient/mtclient.cpp @@ -2132,7 +2132,7 @@ void CheckPXOForAnomalies() { if (stricmp(DLLMPlayers[i].tracker_id, DLLMPlayers[j].tracker_id) == 0) { // Ok, what we have here is multiple users with the same tracker ID. // This is bad. It could be user error, but it could be something worse. - std::filesystem::path errfilepath = std::filesystem::path(DLLLocalD3Dir) / "pxo.err"; + std::filesystem::path errfilepath = *DLLLocalD3Dir / "pxo.err"; FILE *errfile = fopen(errfilepath.u8string().c_str(), "at"); if (errfile) { fprintf(errfile, "Dup TID: %s & %s / %s\n", DLLMPlayers[j].callsign, DLLMPlayers[i].callsign,