From 5834b66384ac24053bfa97150fe96e0afdb51fb1 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. At the moment, we work around this problem with things like the ddio module. If we make sure that we always use std::filesystem::paths, then we’ll be able to get rid of or simplify a lot of the ddio module. [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.h | 2 +- Descent3/game.cpp | 2 +- Descent3/gamesave.cpp | 8 ++++---- Descent3/init.cpp | 19 ++++++++----------- Descent3/mmItem.cpp | 2 +- Descent3/multi.cpp | 10 +++++----- Descent3/multi_dll_mgr.cpp | 8 ++++---- Descent3/multi_ui.cpp | 6 +++--- Descent3/pilot.cpp | 14 +++++++------- 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 | 28 ++++++++++++++-------------- 20 files changed, 73 insertions(+), 71 deletions(-) diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index d2eb2c3a1..baf35d4f7 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -567,7 +567,7 @@ bool InitGameModule(const char *name, module *mod) { char dll_name[_MAX_PATH * 2]; char tmp_dll_name[_MAX_PATH * 2]; // Make the hog filename - ddio_MakePath(lib_name, Base_directory, "netgames", name, NULL); + ddio_MakePath(lib_name, Base_directory.u8string().c_str(), "netgames", name, NULL); strcat(lib_name, ".d3m"); // Make the dll filename #if defined(WIN32) @@ -578,7 +578,7 @@ bool InitGameModule(const char *name, module *mod) { // Open the hog file if (!cf_OpenLibrary(lib_name)) { - ddio_MakePath(tmp_dll_name, Base_directory, "netgames", name, NULL); + ddio_MakePath(tmp_dll_name, Base_directory.u8string().c_str(), "netgames", name, NULL); strcat(tmp_dll_name, ".d3m"); Multi_game_dll_name[0] = '\0'; goto loaddll; diff --git a/Descent3/ambient.cpp b/Descent3/ambient.cpp index e0f861849..e00363171 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 d29a4c590..84042ac17 100644 --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -358,7 +358,7 @@ void DemoToggleRecording() { 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.u8string().c_str(), "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 @@ bool LoadDemoDialog() { char file[_MAX_PATH * 2]; - ddio_MakePath(file, Base_directory, "demo", NULL); + ddio_MakePath(file, Base_directory.u8string().c_str(), "demo", NULL); if (DoPathFileDialog(false, file, TXT_VIEWDEMO, "*.dem", PFDF_FILEMUSTEXIST)) { strcpy(Demo_fname, file); diff --git a/Descent3/descent.h b/Descent3/descent.h index 65e0fcd32..5e26b25bd 100644 --- a/Descent3/descent.h +++ b/Descent3/descent.h @@ -181,7 +181,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 6f25d3433..cc2db3439 100644 --- a/Descent3/game.cpp +++ b/Descent3/game.cpp @@ -1306,7 +1306,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 310ec0a50..7664c3488 100644 --- 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.u8string().c_str(), "savegame", filename, NULL); fp = fopen(pathname, "rb"); if (fp) { @@ -393,7 +393,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. @@ -545,7 +545,7 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data) mprintf(0, "savegame slot=%d\n", 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); @@ -588,7 +588,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/init.cpp b/Descent3/init.cpp index 1de7889be..070e36de1 100644 --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -1024,7 +1024,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; @@ -1407,8 +1407,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)); @@ -1417,16 +1416,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(); mprintf(0, "Using working directory of %s\n", 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); @@ -1989,7 +1986,7 @@ void SetupTempDirectory(void) { strcpy(Descent3_temp_directory, GameArgs[t_arg + 1]); } else { // initialize it to custom/cache - ddio_MakePath(Descent3_temp_directory, Base_directory, "custom", "cache", NULL); + ddio_MakePath(Descent3_temp_directory, Base_directory.u8string().c_str(), "custom", "cache", NULL); } // verify that temp directory exists @@ -2052,7 +2049,7 @@ void SetupTempDirectory(void) { exit(1); } // restore working dir - ddio_SetWorkingDir(Base_directory); + ddio_SetWorkingDir(Base_directory.u8string().c_str()); } void DeleteTempFiles(void) { @@ -2072,7 +2069,7 @@ void DeleteTempFiles(void) { } // restore directory - ddio_SetWorkingDir(Base_directory); + ddio_SetWorkingDir(Base_directory.u8string().c_str()); } /* 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 0ccb53baf..c0df036e6 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -8095,23 +8095,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: mprintf(0, "Unknown id (%d) passed to GetFileNameFromPlayerAndID()\n", id); diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index 6e874a694..b169187a7 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -526,7 +526,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; @@ -597,10 +597,10 @@ int LoadMultiDLL(const char *name) { if (MultiDLLHandle.handle) FreeMultiDLL(); - ddio_MakePath(dll_path_name, Base_directory, "online", "*.tmp", NULL); + ddio_MakePath(dll_path_name, Base_directory.u8string().c_str(), "online", "*.tmp", NULL); ddio_DeleteFile(dll_path_name); // Make the hog filename - ddio_MakePath(lib_name, Base_directory, "online", name, NULL); + ddio_MakePath(lib_name, Base_directory.u8string().c_str(), "online", name, NULL); strcat(lib_name, ".d3c"); // Make the dll filename #if defined(WIN32) @@ -611,7 +611,7 @@ int LoadMultiDLL(const char *name) { // Open the hog file if (!cf_OpenLibrary(lib_name)) { - ddio_MakePath(tmp_dll_name, Base_directory, "online", name, NULL); + ddio_MakePath(tmp_dll_name, Base_directory.u8string().c_str(), "online", name, NULL); strcat(tmp_dll_name, ".d3c"); Multi_conn_dll_name[0] = 0; goto loaddll; diff --git a/Descent3/multi_ui.cpp b/Descent3/multi_ui.cpp index 64013e94a..12cfbac32 100644 --- a/Descent3/multi_ui.cpp +++ b/Descent3/multi_ui.cpp @@ -443,7 +443,7 @@ int MainMultiplayerMenu() { char buffer[_MAX_PATH], fname[_MAX_PATH], fext[_MAX_PATH], fdir[_MAX_PATH]; char search[256]; - ddio_MakePath(search, Base_directory, "online", "*.d3c", NULL); + ddio_MakePath(search, Base_directory.u8string().c_str(), "online", "*.d3c", NULL); int dftidx = -1; dllcount = 0; @@ -1066,7 +1066,7 @@ void DoMultiAllowed(void) { void MultiDoConfigSave(void) { char file[_MAX_PATH * 2]; - ddio_MakePath(file, Base_directory, "custom", "settings", NULL); + ddio_MakePath(file, Base_directory.u8string().c_str(), "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 MultiDoConfigSave(void) { void MultiDoConfigLoad(void) { char file[_MAX_PATH * 2]; - ddio_MakePath(file, Base_directory, "custom", "settings", NULL); + ddio_MakePath(file, Base_directory.u8string().c_str(), "custom", "settings", NULL); if (DoPathFileDialog(false, file, TXT_MULTILOADSET, "*.mps", PFDF_FILEMUSTEXIST)) MultiLoadSettings(file); } diff --git a/Descent3/pilot.cpp b/Descent3/pilot.cpp index e3975a905..fa91aa7ac 100644 --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -1724,7 +1724,7 @@ bool PltDelete(pilot *Pilot) { Pilot->get_filename(pfilename); if (pfilename[0] != 0) { - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), pfilename, NULL); return (ddio_DeleteFile(pfilename) == 1); } else { Int3(); // this is odd @@ -1740,7 +1740,7 @@ bool PltDelete(pilot *Pilot) { strcpy(pfilename, pname); strcat(pfilename, PLTEXTENSION); - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), pfilename, NULL); return (ddio_DeleteFile(filename) == 1); } } @@ -1782,7 +1782,7 @@ void PltReadFile(pilot *Pilot, bool keyconfig, bool missiondata) { return; // open and process file - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), pfilename, NULL); try { file = cfopen(filename, "rb"); if (!file) @@ -1857,14 +1857,14 @@ char **PltGetPilots(int *count, char *ignore_filename, int display_default_confi switch (display_default_configs) { case 0: ASSERT(loop_count == 0); - ddio_MakePath(search, Base_directory, PLTWILDCARD, NULL); + ddio_MakePath(search, Base_directory.u8string().c_str(), PLTWILDCARD, NULL); break; case 1: - ddio_MakePath(search, Base_directory, (loop_count == 0) ? PLTWILDCARD : DPLTWILDCARD, NULL); + ddio_MakePath(search, Base_directory.u8string().c_str(), (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.u8string().c_str(), DPLTWILDCARD, NULL); break; default: Int3(); @@ -3930,7 +3930,7 @@ void _ReadOldPilotFile(pilot *Pilot, bool keyconfig, bool missiondata) { Pilot->get_filename(pfilename); // open and process file - ddio_MakePath(filename, Base_directory, pfilename, NULL); + ddio_MakePath(filename, Base_directory.u8string().c_str(), pfilename, NULL); CFILE *file = cfopen(filename, "rb"); if (!file) return; diff --git a/Descent3/pilot_class.cpp b/Descent3/pilot_class.cpp index a83fd2e40..26c6b24f6 100644 --- a/Descent3/pilot_class.cpp +++ b/Descent3/pilot_class.cpp @@ -422,7 +422,7 @@ int pilot::flush(bool new_file) { char real_filename[_MAX_PATH]; // open and process file - ddio_MakePath(real_filename, Base_directory, filename, NULL); + ddio_MakePath(real_filename, Base_directory.u8string().c_str(), filename, NULL); if (new_file && cfexist(real_filename)) { // the file already exists, we can't write out @@ -516,7 +516,7 @@ int pilot::read(bool skip_config, bool skip_mission_data) { char real_filename[_MAX_PATH]; // open and process file - ddio_MakePath(real_filename, Base_directory, filename, NULL); + ddio_MakePath(real_filename, Base_directory.u8string().c_str(), filename, NULL); if (!cfexist(real_filename)) { // the file already exists, we can't write out diff --git a/editor/MainFrm.cpp b/editor/MainFrm.cpp index 40393ab1d..867d470dc 100644 --- a/editor/MainFrm.cpp +++ b/editor/MainFrm.cpp @@ -1461,7 +1461,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 fb00324bf..7d91ec062 100644 --- a/editor/editor_lighting.cpp +++ b/editor/editor_lighting.cpp @@ -871,7 +871,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); @@ -1141,7 +1141,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 c85ede763..8fee5f33c 100644 --- a/editor/gameeditor.cpp +++ b/editor/gameeditor.cpp @@ -620,7 +620,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; } @@ -760,7 +760,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 1050dbd57..0487a2bbb 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -674,8 +674,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())) { + mprintf(0, "Warning: Base_directory is too long to fit in LocalD3Dir, so LocalD3Dir was truncated."); + } mprintf(1, "Local dir:%s\n", 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 253f90136..762dd5796 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -774,7 +774,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; @@ -1008,7 +1008,7 @@ int StartMultiplayerGameMenu() { #if (!(defined(OEM) || defined(DEMO))) dllcount = 0; char search[256]; - DLLddio_MakePath(search, DLLLocalD3Dir, "netgames", "*.d3m", NULL); + DLLddio_MakePath(search, DLLLocalD3Dir->u8string().c_str(), "netgames", "*.d3m", NULL); if (DLLddio_FindFileStart(search, buffer)) { do { buffer[strlen(buffer) - 4] = '\0'; // Strip out the extention @@ -1033,7 +1033,7 @@ int StartMultiplayerGameMenu() { #if (!(defined(OEM) || defined(DEMO))) msn_list *mi; - DLLddio_MakePath(search, DLLLocalD3Dir, "data", "levels", "*.msn", NULL); + DLLddio_MakePath(search, DLLLocalD3Dir->u8string().c_str(), "data", "levels", "*.msn", NULL); // DLLmprintf((0,search)); if (DLLddio_FindFileStart(search, buffer)) { if (DLLIsMissionMultiPlayable(buffer)) { @@ -1060,7 +1060,7 @@ int StartMultiplayerGameMenu() { DLLddio_FindFileClose(); // char mn3_path[_MAX_PATH*2]; - DLLddio_MakePath(search, DLLLocalD3Dir, "missions", "*.mn3", NULL); + DLLddio_MakePath(search, DLLLocalD3Dir->u8string().c_str(), "missions", "*.mn3", NULL); // DLLmprintf(0,search); if (DLLddio_FindFileStart(search, buffer)) { // DLLddio_MakePath(mn3_path,DLLLocalD3Dir,"missions",buffer,NULL); @@ -1127,7 +1127,7 @@ int StartMultiplayerGameMenu() { DLLNewUIWindowLoadBackgroundImage(main_wnd, "multimain.ogf"); DLLNewUIWindowOpen(main_wnd); char dftset[_MAX_PATH * 2]; - DLLddio_MakePath(dftset, DLLLocalD3Dir, "custom", "settings", "default.mps", NULL); + DLLddio_MakePath(dftset, DLLLocalD3Dir->u8string().c_str(), "custom", "settings", "default.mps", NULL); if (DLLMultiLoadSettings(dftset)) { DLLEditSetText(mission_name_edit, DLLNetgame->name); #if (!(defined(OEM) || defined(DEMO))) diff --git a/netcon/includes/mdllinit.h b/netcon/includes/mdllinit.h index 4367d77bd..79d50bf47 100644 --- a/netcon/includes/mdllinit.h +++ b/netcon/includes/mdllinit.h @@ -285,7 +285,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 971476cdc..e5455d53c 100644 --- a/netcon/mtclient/mtclient.cpp +++ b/netcon/mtclient/mtclient.cpp @@ -2149,7 +2149,7 @@ void CheckPXOForAnomalies() { // This is bad. It could be user error, but it could be something worse. FILE *errfile; char errfilepath[_MAX_PATH]; - DLLddio_MakePath(errfilepath, DLLLocalD3Dir, "pxo.err", NULL); + DLLddio_MakePath(errfilepath, DLLLocalD3Dir->u8string().c_str(), "pxo.err", NULL); errfile = fopen(errfilepath, "at"); if (errfile) { fprintf(errfile, "Dup TID: %s & %s / %s\n", DLLMPlayers[j].callsign, DLLMPlayers[i].callsign, @@ -2333,12 +2333,12 @@ int MTVersionCheck() { // Load the DLL and get it's version // Specify the correct path - DLLddio_MakePath(fulldllpath, DLLLocalD3Dir, "mtav.dll", NULL); + DLLddio_MakePath(fulldllpath, DLLLocalD3Dir->u8string().c_str(), "mtav.dll", NULL); if (!DLLmod_LoadModule(&MTAVDLLHandle, fulldllpath, MODF_LAZY)) { DLLmprintf(0, "Unable to load Mastertracker Auto version update DLL (mtav.dll)\n"); // Try restoring a backup of the DLL - DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL); - DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL); + DLLddio_MakePath(szolddll, DLLLocalD3Dir->u8string().c_str(), "mtav.dll", NULL); + DLLddio_MakePath(szbakdll, DLLLocalD3Dir->u8string().c_str(), "mtav.bak", NULL); CopyFile(szbakdll, szolddll, FALSE); return 0; } @@ -2347,8 +2347,8 @@ int MTVersionCheck() { DLLmprintf(0, "Unable to Find DLLAVInit() function in mtav.dll\n"); DLLmod_FreeModule(&MTAVDLLHandle); // Try restoring a backup of the DLL - DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL); - DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL); + DLLddio_MakePath(szolddll, DLLLocalD3Dir->u8string().c_str(), "mtav.dll", NULL); + DLLddio_MakePath(szbakdll, DLLLocalD3Dir->u8string().c_str(), "mtav.bak", NULL); CopyFile(szbakdll, szolddll, FALSE); return 0; } @@ -2357,8 +2357,8 @@ int MTVersionCheck() { DLLmprintf(0, "Unable to Find DLLAVGetVersion() function in mtav.dll\n"); DLLmod_FreeModule(&MTAVDLLHandle); // Try restoring a backup of the DLL - DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL); - DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL); + DLLddio_MakePath(szolddll, DLLLocalD3Dir->u8string().c_str(), "mtav.dll", NULL); + DLLddio_MakePath(szbakdll, DLLLocalD3Dir->u8string().c_str(), "mtav.bak", NULL); CopyFile(szbakdll, szolddll, FALSE); return 0; } @@ -2367,8 +2367,8 @@ int MTVersionCheck() { DLLmprintf(0, "Unable to Find DLLRunCheck() function in mtav.dll\n"); DLLmod_FreeModule(&MTAVDLLHandle); // Try restoring a backup of the DLL - DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL); - DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL); + DLLddio_MakePath(szolddll, DLLLocalD3Dir->u8string().c_str(), "mtav.dll", NULL); + DLLddio_MakePath(szbakdll, DLLLocalD3Dir->u8string().c_str(), "mtav.bak", NULL); CopyFile(szbakdll, szolddll, FALSE); return 0; } @@ -2393,8 +2393,8 @@ int MTVersionCheck() { if (MTUpdateURL[0]) { // We need to get a new DLL DLLmprintf(0, "Mastertracker says we need a new version, which is at %s.\n", MTUpdateURL); - sprintf(sznewdll, "%s\\newmtav.dll", DLLLocalD3Dir); - DLLddio_MakePath(sznewdll, DLLLocalD3Dir, "newmtav.dll", NULL); + sprintf(sznewdll, "%s\\newmtav.dll", DLLLocalD3Dir->u8string().c_str()); + DLLddio_MakePath(sznewdll, DLLLocalD3Dir->u8string().c_str(), "newmtav.dll", NULL); inetfile = new InetGetFile(MTUpdateURL, sznewdll); while (1) { DLLPollUI(); @@ -2407,8 +2407,8 @@ int MTVersionCheck() { if (inetfile->IsFileReceived()) { DLLmprintf(0, "Mastertracker update DLL received.\n"); DLLmod_FreeModule(&MTAVDLLHandle); - DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL); - DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL); + DLLddio_MakePath(szolddll, DLLLocalD3Dir->u8string().c_str(), "mtav.dll", NULL); + DLLddio_MakePath(szbakdll, DLLLocalD3Dir->u8string().c_str(), "mtav.bak", NULL); // We have the file, now backup & copy it and try to reload. CopyFile(szolddll, szbakdll, FALSE);