diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index 959c1a121..fbf1867b2 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -573,7 +573,7 @@ bool InitGameModule(const char *name, module *mod) { // Open the hog file if (!cf_OpenLibrary(lib_name)) { - tmp_dll_name = cf_LocatePath(lib_name).u8string().c_str(); + tmp_dll_name = cf_LocatePath(lib_name); Multi_game_dll_name.clear(); goto loaddll; } diff --git a/Descent3/Inventory.cpp b/Descent3/Inventory.cpp index 4d34ff015..b573b2339 100644 --- a/Descent3/Inventory.cpp +++ b/Descent3/Inventory.cpp @@ -580,9 +580,7 @@ bool Inventory::AddCounterMeasure(int id, int aux_type, int aux_id, int flags, c newnode->iflags |= INVF_SELECTABLE | INVF_USEABLE | INVF_MISSIONITEM | INVF_TIMEOUTONSPEW; if (Weapons[id].icon_handle >= 0) { - newnode->icon_name = - mem_rmalloc(strlen(GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name) + 1); - strcpy(newnode->icon_name, GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name); + newnode->icon_name = mem_strdup(GameBitmaps[GameTextures[Weapons[id].icon_handle].bm_handle].name); } else { newnode->icon_name = nullptr; } @@ -647,8 +645,7 @@ bool Inventory::AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flag newnode->oid = oauxi; if (Object_info[oid].description) { - newnode->description = mem_rmalloc(strlen(Object_info[oid].description) + 1); - strcpy(newnode->description, Object_info[oid].description); + newnode->description = mem_strdup(Object_info[oid].description); } else { newnode->description = mem_rmalloc(); newnode->description[0] = 0; @@ -672,8 +669,7 @@ bool Inventory::AddObjectItem(int otype, int oid, int oauxt, int oauxi, int flag if (flags & INVAF_LEVELLAST) newnode->iflags |= INVAF_LEVELLAST; - newnode->icon_name = mem_rmalloc(strlen(Object_info[oid].icon_name) + 1); - strcpy(newnode->icon_name, Object_info[oid].icon_name); + newnode->icon_name = mem_strdup(Object_info[oid].icon_name); if (description) { newnode->name = mem_strdup(description); diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index 16a9e40e4..fd8a837ee 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -1684,8 +1684,7 @@ int ReadObject(CFILE *ifile, object *objp, int handle, int fileversion) { // Set the name if (tempname[0]) { - objp->name = mem_rmalloc(strlen(tempname) + 1); - strcpy(objp->name, tempname); + objp->name = mem_strdup(tempname); } // Update checksum @@ -2444,8 +2443,7 @@ int ReadRoom(CFILE *ifile, room *rp, int version) { char tempname[ROOM_NAME_LEN + 1]; cf_ReadString(tempname, sizeof(tempname), ifile); if (strlen(tempname)) { - rp->name = mem_rmalloc(strlen(tempname) + 1); - strcpy(rp->name, tempname); + rp->name = mem_strdup(tempname); } } @@ -3620,7 +3618,7 @@ bool LoadLevelInfo(const std::filesystem::path &filename, level_info &info) { bool found = false; if (!ifile) { - LOG_ERROR.printf("Failed to open mission file %s", filename.u8string().c_str()); + LOG_ERROR.printf("Failed to open mission file %s", PATH_TO_CSTR(filename)); return false; } diff --git a/Descent3/Mission.cpp b/Descent3/Mission.cpp index f5c601509..bd2fc1ab2 100644 --- a/Descent3/Mission.cpp +++ b/Descent3/Mission.cpp @@ -701,12 +701,12 @@ bool mn3_GetInfo(const std::filesystem::path &mn3file, tMissionInfo *msn); static inline bool IS_MN3_FILE(const std::filesystem::path &fname) { std::filesystem::path ext = fname.extension(); - return (stricmp((const char*)ext.u8string().c_str(), ".mn3") == 0); + return stricmp(PATH_TO_CSTR(ext), ".mn3") == 0; } static inline std::filesystem::path MN3_TO_MSN_NAME(const std::filesystem::path &mn3name) { std::filesystem::path fname = std::filesystem::path(mn3name).stem(); - if (stricmp((const char*)fname.u8string().c_str(), "d3_2") == 0) { + if (stricmp(PATH_TO_CSTR(fname), "d3_2") == 0) { fname = "d3"; } fname.replace_extension(".msn"); @@ -1166,9 +1166,9 @@ bool LoadMission(const char *mssn) { // set up current mission (movies are already set above) msn->cur_level = 1; msn->num_levels = numlevels; - msn->filename = mem_strdup((const char*)mission.u8string().c_str()); + msn->filename = mem_strdup(PATH_TO_CSTR(mission)); msn->game_state_flags = 0; - strcpy(Net_msn_URLs.msnname, (const char*)mission.u8string().c_str()); + strcpy(Net_msn_URLs.msnname, PATH_TO_CSTR(mission)); res = true; // everything is ok. // if error, print it out, else end. @@ -1238,7 +1238,7 @@ void LoadLevelText(const std::filesystem::path &level_filename) { pathname.replace_extension(".str"); char **goal_strings; - if (CreateStringTable((const char*)pathname.u8string().c_str(), &goal_strings, &n_strings)) { + if (CreateStringTable(PATH_TO_CSTR(pathname), &goal_strings, &n_strings)) { int n_goals = Level_goals.GetNumGoals(); ASSERT(n_strings == (n_goals * 3)); for (int i = 0; i < n_goals; i++) { @@ -1692,7 +1692,7 @@ bool GetMissionInfo(const std::filesystem::path &msnfile, tMissionInfo *msn) { } CFILE *fp = cfopen(msnfile, "rt"); if (!fp) { - LOG_WARNING.printf("Failed to open mission file %s in GetMissionInfo.", msnfile.u8string().c_str()); + LOG_WARNING.printf("Failed to open mission file %s in GetMissionInfo.", PATH_TO_CSTR(msnfile)); return false; } msn->multi = true; @@ -1791,17 +1791,17 @@ bool mn3_Open(const std::filesystem::path &mn3file) { std::filesystem::path filename = mn3file.stem(); std::filesystem::path voice_hog; - if ((stricmp((const char*)filename.u8string().c_str(), "d3") == 0) || (stricmp((const char*)filename.u8string().c_str(), "training") == 0)) { + if (stricmp(PATH_TO_CSTR(filename), "d3") == 0 || stricmp(PATH_TO_CSTR(filename), "training") == 0) { // Open audio hog file voice_hog = std::filesystem::path("missions") / "d3voice1.hog"; // Audio for levels 1-4 Mission_voice_hog_handle = cf_OpenLibrary(voice_hog); - } else if (stricmp((const char*)filename.u8string().c_str(), "d3_2") == 0) { + } else if (stricmp(PATH_TO_CSTR(filename), "d3_2") == 0) { // Open audio hog file voice_hog = std::filesystem::path("missions") / "d3voice2.hog"; // Audio for levels 5-17 Mission_voice_hog_handle = cf_OpenLibrary(voice_hog); } filename.replace_extension(".gam"); - mng_SetAddonTable((const char*)filename.u8string().c_str()); + mng_SetAddonTable(PATH_TO_CSTR(filename)); Current_mission.mn3_handle = mn3_handle; return true; } diff --git a/Descent3/OsirisLoadandBind.cpp b/Descent3/OsirisLoadandBind.cpp index 73f10fa48..a19ad879d 100644 --- a/Descent3/OsirisLoadandBind.cpp +++ b/Descent3/OsirisLoadandBind.cpp @@ -778,7 +778,7 @@ int Osiris_FindLoadedModule(const std::filesystem::path &module_name) { for (int i = 0; i < MAX_LOADED_MODULES; i++) { if (OSIRIS_loaded_modules[i].flags & OSIMF_INUSE) { if (OSIRIS_loaded_modules[i].module_name && - (stricmp(OSIRIS_loaded_modules[i].module_name, (const char*)real_name.u8string().c_str()) == 0)) { + stricmp(OSIRIS_loaded_modules[i].module_name, PATH_TO_CSTR(real_name)) == 0) { // we found a match return i; } @@ -890,7 +890,7 @@ int get_full_path_to_module(const std::filesystem::path &module_name, std::files adjusted_fname = module_name.filename(); // make sure filename/ext is all lowercase, requirement for Linux, doesn't hurt Windows - std::string p = (const char*)adjusted_fname.u8string().c_str(); + std::string p = PATH_TO_CSTR(adjusted_fname); std::transform(p.begin(), p.end(), p.begin(), [](unsigned char c) { return std::tolower(c); }); adjusted_fname = p; @@ -958,7 +958,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { // the module is already loaded OSIRIS_loaded_modules[loaded_id].reference_count++; LOG_DEBUG_IF(Show_osiris_debug) - .printf("OSIRIS: Level Module (%s) reference count increased to %d", module_name.u8string().c_str(), + .printf("OSIRIS: Level Module (%s) reference count increased to %d", PATH_TO_CSTR(module_name), OSIRIS_loaded_modules[loaded_id].reference_count); return loaded_id; } @@ -973,7 +973,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { if (loaded_id >= MAX_LOADED_MODULES) { // no slots available - LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): No available slots\n", module_name.u8string().c_str()); + LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): No available slots\n", PATH_TO_CSTR(module_name)); Int3(); return -4; } @@ -985,7 +985,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { switch (ret_val) { case -2: // the module does not exist - LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", module_name.u8string().c_str()); + LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", PATH_TO_CSTR(module_name)); return -1; break; case -1: @@ -993,8 +993,8 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { break; default: // the module was an extracted file - LOG_DEBUG.printf("OSIRIS: Found module (%s) in a temp file (%s)", basename.u8string().c_str(), - fullpath.u8string().c_str()); + LOG_DEBUG.printf("OSIRIS: Found module (%s) in a temp file (%s)", PATH_TO_CSTR(basename), + PATH_TO_CSTR(fullpath)); OSIRIS_loaded_modules[loaded_id].flags |= OSIMF_INTEMPDIR; OSIRIS_loaded_modules[loaded_id].extracted_id = ret_val; break; @@ -1003,7 +1003,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { // the module exists, now attempt to load it if (!mod_LoadModule(&OSIRIS_loaded_modules[loaded_id].mod, fullpath)) { // there was an error trying to load the module - LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): Unable to load module", module_name.u8string().c_str()); + LOG_FATAL.printf("OSIRIS: Osiris_LoadLevelModule(%s): Unable to load module", PATH_TO_CSTR(module_name)); Int3(); return -3; } @@ -1034,7 +1034,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { osm->SaveRestoreState = (SaveRestoreState_fp)mod_GetSymbol(mod, "SaveRestoreState", 8); osm->flags |= OSIMF_INUSE | OSIMF_LEVEL; - osm->module_name = mem_strdup((const char*)basename.u8string().c_str()); + osm->module_name = mem_strdup(PATH_TO_CSTR(basename)); osm->reference_count = 1; #ifdef OSIRISDEBUG @@ -1047,7 +1047,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { !osm->GetCOScriptList || !osm->CreateInstance || !osm->DestroyInstance || !osm->SaveRestoreState || !osm->CallInstanceEvent) { // there was an error importing a function - LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) couldn't import function.", (const char*)module_name.u8string().c_str()); + LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) couldn't import function.", PATH_TO_CSTR(module_name)); Int3(); osm->flags = 0; if (osm->module_name) @@ -1059,7 +1059,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { // check to see if there is a corresponding string table to load char stringtablename[_MAX_PATH]; - strcpy(stringtablename, (const char*)basename.u8string().c_str()); + strcpy(stringtablename, PATH_TO_CSTR(basename)); strcat(stringtablename, ".str"); if (cfexist(stringtablename)) { @@ -1067,7 +1067,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { bool ret = CreateStringTable(stringtablename, &osm->string_table, &osm->strings_loaded); if (!ret) { LOG_ERROR.printf("OSIRIS: Unable to load string table (%s) for (%s)", stringtablename, - basename.u8string().c_str()); + PATH_TO_CSTR(basename)); Int3(); osm->string_table = NULL; osm->strings_loaded = 0; @@ -1086,7 +1086,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { // when we get to this point we nearly have a loaded module, we just need to initialize it if (!osm->InitializeDLL(&Osiris_module_init)) { // there was an error initializing the module - LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) error initializing module.", basename.u8string().c_str()); + LOG_ERROR.printf("OSIRIS: Osiris_LoadLevelModule(%s) error initializing module.", PATH_TO_CSTR(basename)); if (osm->string_table) { DestroyStringTable(osm->string_table, osm->strings_loaded); } @@ -1129,7 +1129,7 @@ int Osiris_LoadLevelModule(const std::filesystem::path &module_name) { tOSIRISCurrentLevel.instance = OSIRIS_loaded_modules[loaded_id].CreateInstance(0); // level scripts always have id of 0 in a level dll - LOG_INFO.printf("OSIRIS: Level Module (%s) loaded successfully (%d custom handles)", basename.u8string().c_str(), + LOG_INFO.printf("OSIRIS: Level Module (%s) loaded successfully (%d custom handles)", PATH_TO_CSTR(basename), tOSIRISCurrentLevel.num_customs); Osiris_level_script_loaded = true; return loaded_id; @@ -1153,7 +1153,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { // the module is already loaded OSIRIS_loaded_modules[loaded_id].reference_count++; if (Show_osiris_debug) { - LOG_DEBUG.printf("OSIRIS: Game Module (%s) reference count increased to %d", module_name.u8string().c_str(), + LOG_DEBUG.printf("OSIRIS: Game Module (%s) reference count increased to %d", PATH_TO_CSTR(module_name), OSIRIS_loaded_modules[loaded_id].reference_count); } return loaded_id; @@ -1169,7 +1169,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { if (loaded_id >= MAX_LOADED_MODULES) { // no slots available - LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): No available slots", module_name.u8string().c_str()); + LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): No available slots", PATH_TO_CSTR(module_name)); Int3(); return -4; } @@ -1181,7 +1181,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { switch (ret_val) { case -2: // the module does not exist - LOG_WARNING.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", module_name.u8string().c_str()); + LOG_WARNING.printf("OSIRIS: Osiris_LoadLevelModule(%s): Module doesn't exist", PATH_TO_CSTR(module_name)); return -1; break; case -1: @@ -1189,7 +1189,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { break; default: // the module was an extracted file - LOG_INFO.printf("OSIRIS: Found module (%s) in a temp file", basename.u8string().c_str()); + LOG_INFO.printf("OSIRIS: Found module (%s) in a temp file", PATH_TO_CSTR(basename)); OSIRIS_loaded_modules[loaded_id].flags |= OSIMF_INTEMPDIR; OSIRIS_loaded_modules[loaded_id].extracted_id = ret_val; break; @@ -1198,7 +1198,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { // the module exists, now attempt to load it if (!mod_LoadModule(&OSIRIS_loaded_modules[loaded_id].mod, fullpath)) { // there was an error trying to load the module - LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): Unable to load module", module_name.u8string().c_str()); + LOG_FATAL.printf("OSIRIS: Osiris_LoadGameModule(%s): Unable to load module", PATH_TO_CSTR(module_name)); Int3(); return -3; } @@ -1227,7 +1227,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { osm->SaveRestoreState = (SaveRestoreState_fp)mod_GetSymbol(mod, "SaveRestoreState", 8); osm->flags |= OSIMF_INUSE; - osm->module_name = mem_strdup((const char*)basename.u8string().c_str()); + osm->module_name = mem_strdup(PATH_TO_CSTR(basename)); osm->reference_count = 1; #ifdef OSIRISDEBUG @@ -1239,7 +1239,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { if (!osm->InitializeDLL || !osm->ShutdownDLL || !osm->GetGOScriptID || !osm->CreateInstance || !osm->DestroyInstance || !osm->SaveRestoreState || !osm->CallInstanceEvent) { // there was an error importing a function - LOG_WARNING.printf("OSIRIS: Osiris_LoadGameModule(%s) couldn't import function.", basename.u8string().c_str()); + LOG_WARNING.printf("OSIRIS: Osiris_LoadGameModule(%s) couldn't import function.", PATH_TO_CSTR(basename)); Int3(); osm->flags = 0; if (osm->module_name) @@ -1251,7 +1251,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { // check to see if there is a corresponding string table to load char stringtablename[_MAX_PATH]; - strcpy(stringtablename, (const char*)basename.u8string().c_str()); + strcpy(stringtablename, PATH_TO_CSTR(basename)); strcat(stringtablename, ".str"); if (cfexist(stringtablename)) { @@ -1259,7 +1259,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { bool ret = CreateStringTable(stringtablename, &osm->string_table, &osm->strings_loaded); if (!ret) { LOG_FATAL.printf("OSIRIS: Unable to load string table (%s) for (%s)", stringtablename, - (const char*)basename.u8string().c_str()); + PATH_TO_CSTR(basename)); Int3(); osm->string_table = nullptr; osm->strings_loaded = 0; @@ -1277,7 +1277,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { // when we get to this point we nearly have a loaded module, we just need to initialize it if (!osm->InitializeDLL(&Osiris_module_init)) { // there was an error initializing the module - LOG_ERROR.printf("OSIRIS: Osiris_LoadGameModule(%s) error initializing module.", (const char*)basename.u8string().c_str()); + LOG_ERROR.printf("OSIRIS: Osiris_LoadGameModule(%s) error initializing module.", PATH_TO_CSTR(basename)); if (osm->string_table) { DestroyStringTable(osm->string_table, osm->strings_loaded); } @@ -1298,7 +1298,7 @@ int Osiris_LoadGameModule(const std::filesystem::path &module_name) { } // we have a successful module load - LOG_INFO.printf("OSIRIS: Game Module (%s) loaded successfully", basename.u8string().c_str()); + LOG_INFO.printf("OSIRIS: Game Module (%s) loaded successfully", PATH_TO_CSTR(basename)); return loaded_id; } @@ -3120,7 +3120,7 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) { if (temp_filename.empty()) { Int3(); } else { - std::string temp_realname = (const char*)std::filesystem::path(filename).stem().u8string().c_str(); + std::string temp_realname = PATH_TO_CSTR(std::filesystem::path(filename).stem()); // Lowercase for optimized search std::transform(temp_realname.begin(), temp_realname.end(), temp_realname.begin(), [](unsigned char c) { return std::tolower(c); }); @@ -3135,7 +3135,7 @@ int Osiris_ExtractScriptsFromHog(int library_handle, bool is_mission_hog) { t.temp_filename = temp_filename.filename(); OSIRIS_Extracted_scripts.insert_or_assign(temp_realname, t); - LOG_DEBUG.printf("Extracted %s as %s", temp_realname.c_str(), temp_filename.u8string().c_str()); + LOG_DEBUG.printf("Extracted %s as %s", temp_realname.c_str(), PATH_TO_CSTR(temp_filename)); } else { LOG_DEBUG.printf("Skipped %s (already extracted)", temp_realname.c_str()); } diff --git a/Descent3/TelComEffects.cpp b/Descent3/TelComEffects.cpp index 4483de2bf..4736dd1b1 100644 --- a/Descent3/TelComEffects.cpp +++ b/Descent3/TelComEffects.cpp @@ -1253,10 +1253,9 @@ bool CreateMovie(tceffect *tce, const char *filename) { tce->movieinfo.filename = NULL; tce->w = tce->h = 100; - tce->movieinfo.filename = mem_rmalloc(strlen(filename) + 1); + tce->movieinfo.filename = mem_strdup(filename); if (!tce->movieinfo.filename) return false; - strcpy(tce->movieinfo.filename, filename); tce->movieinfo.handle = StartMovie(filename); if (!tce->movieinfo.handle) return false; diff --git a/Descent3/ambient.cpp b/Descent3/ambient.cpp index de4260aec..cc8d2f0c0 100644 --- a/Descent3/ambient.cpp +++ b/Descent3/ambient.cpp @@ -294,7 +294,7 @@ void WriteAmbientData() { CFILE *ofile; #ifndef NEWEDITOR - ddio_MakePath(filename, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "data", "misc", AMBIENT_FILE_NAME, NULL); + ddio_MakePath(filename, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "data", "misc", AMBIENT_FILE_NAME, NULL); #else ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL); #endif diff --git a/Descent3/audiotaunts.cpp b/Descent3/audiotaunts.cpp index c7c211fa1..e98f39e14 100644 --- a/Descent3/audiotaunts.cpp +++ b/Descent3/audiotaunts.cpp @@ -133,7 +133,7 @@ bool taunt_PlayPlayerTaunt(int pnum, int index) { fullpath = LocalCustomSoundsDir / file; if (!cfexist(fullpath)) { - LOG_WARNING.printf("TAUNT: file %s doesn't exist (pnum=%d)", fullpath.u8string().c_str(), pnum); + LOG_WARNING.printf("TAUNT: file %s doesn't exist (pnum=%d)", PATH_TO_CSTR(fullpath), pnum); return false; } @@ -354,7 +354,7 @@ bool taunt_ImportWave(const char *wave_filename, const char *outputfilename) { goto error; } - if (!aenc_Compress((const char*)temp_filename.u8string().c_str(), (const char*)osftemp_filename.u8string().c_str(), NULL, &samples, &rate, &chan, NULL, NULL)) { + if (!aenc_Compress(PATH_TO_CSTR(temp_filename), PATH_TO_CSTR(osftemp_filename), NULL, &samples, &rate, &chan, NULL, NULL)) { // unable to compress LOG_WARNING << "Unable to compress"; ret = false; diff --git a/Descent3/cinematics.cpp b/Descent3/cinematics.cpp index 3d823172b..daadea5f4 100644 --- a/Descent3/cinematics.cpp +++ b/Descent3/cinematics.cpp @@ -72,7 +72,7 @@ bool PlayMovie(const std::filesystem::path &moviename) { std::filesystem::path filename = moviename; // check extension std::filesystem::path extension = moviename.extension(); - if (stricmp((const char*)extension.u8string().c_str(), ".mve") != 0 && stricmp((const char*)extension.u8string().c_str(), ".mv8") != 0) { + if (stricmp(PATH_TO_CSTR(extension), ".mve") != 0 && stricmp(PATH_TO_CSTR(extension), ".mv8") != 0) { // we need an extension filename.replace_extension(".mve"); } diff --git a/Descent3/d3movie.cpp b/Descent3/d3movie.cpp index a4a82ac31..c03a283c8 100644 --- a/Descent3/d3movie.cpp +++ b/Descent3/d3movie.cpp @@ -81,7 +81,7 @@ int mve_PlayMovie(const std::filesystem::path &pMovieName, oeApplication *pApp) return MVELIB_FILE_ERROR; } // open movie file. - FILE *hFile = fopen((const char*)real_name.u8string().c_str(), "rb"); + FILE *hFile = fopen(PATH_TO_CSTR(real_name), "rb"); if (hFile == nullptr) { LOG_ERROR << "MOVIE: Unable to open " << pMovieName; return MVELIB_FILE_ERROR; @@ -103,7 +103,7 @@ int mve_PlayMovie(const std::filesystem::path &pMovieName, oeApplication *pApp) MVESTREAM *mve = MVE_rmPrepMovie(hFile, -1, -1, 0); if (mve == nullptr) { - LOG_ERROR.printf("Failed to prepMovie %s", pMovieName.u8string().c_str()); + LOG_ERROR.printf("Failed to prepMovie %s", PATH_TO_CSTR(pMovieName)); fclose(hFile); mve_CloseSound(); return MVELIB_INIT_ERROR; @@ -323,10 +323,10 @@ intptr_t mve_SequenceStart(const char *mvename, void *fhandle, oeApplication *ap #ifndef NO_MOVIES // first, find that movie.. std::filesystem::path real_name = cf_LocatePath(std::filesystem::path("movies") / mvename); - fhandle = fopen((const char*)real_name.u8string().c_str(), "rb"); + fhandle = fopen(PATH_TO_CSTR(real_name), "rb"); if (fhandle == nullptr) { - LOG_WARNING.printf("MOVIE: Unable to open %s", (const char*)real_name.u8string().c_str()); + LOG_WARNING.printf("MOVIE: Unable to open %s", PATH_TO_CSTR(real_name)); return 0; } diff --git a/Descent3/dedicated_server.cpp b/Descent3/dedicated_server.cpp index 15e11b8fe..a27a18d05 100644 --- a/Descent3/dedicated_server.cpp +++ b/Descent3/dedicated_server.cpp @@ -336,7 +336,7 @@ int LoadServerConfigFile() { // open file if (!inf.Open(Netgame.server_config_name, "[server config file]", DedicatedServerLex)) { - PrintDedicatedMessage(TXT_DS_BADCONFIG, Netgame.server_config_name.u8string().c_str()); + PrintDedicatedMessage(TXT_DS_BADCONFIG, PATH_TO_CSTR(Netgame.server_config_name)); PrintDedicatedMessage("\n"); return 0; } diff --git a/Descent3/demofile.cpp b/Descent3/demofile.cpp index 46aed3f28..58d1800a1 100644 --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -401,7 +401,7 @@ void DemoWriteHeader() { ASSERT(Demo_flags == DF_RECORDING); // Start off with the signature - cf_WriteString(Demo_cfp, (const char *)szsig); + cf_WriteString(Demo_cfp, szsig); // Next is the version cf_WriteShort(Demo_cfp, GAMESAVE_VERSION); // Write the mission filename @@ -774,7 +774,7 @@ int DemoReadHeader() { // Now load the mission Osiris_DisableCreateEvents(); IsRestoredGame = true; - if (LoadMission((const char *)demo_mission)) { + if (LoadMission(demo_mission)) { mng_LoadAddonPages(); SetCurrentLevel(level_num); diff --git a/Descent3/game.cpp b/Descent3/game.cpp index 19bcf3b0b..e232f8628 100644 --- a/Descent3/game.cpp +++ b/Descent3/game.cpp @@ -969,7 +969,7 @@ void SetScreenMode(int sm, bool force_res_change) { } else { int t = FindArg("-ForceStateLimited"); if (t) { - StateLimited = (atoi((const char *)GameArgs[t + 1]) != 0); + StateLimited = (atoi(GameArgs[t + 1]) != 0); } if (rend_initted == -1) { @@ -1273,10 +1273,10 @@ void DoScreenshot() { screen_name << "screenshot-" << std::chrono::duration_cast(now).count() << ".png"; std::filesystem::path filename = screenshots_path / screen_name.str(); // Now save it - screenshot->saveAsPNG((const char*)filename.u8string().c_str()); + screenshot->saveAsPNG(PATH_TO_CSTR(filename)); if (Demo_flags != DF_PLAYBACK) { - AddHUDMessage(TXT_SCRNSHT, filename.filename().u8string().c_str()); + AddHUDMessage(TXT_SCRNSHT, PATH_TO_CSTR(filename.filename())); } StartTime(); diff --git a/Descent3/gamesave.cpp b/Descent3/gamesave.cpp index 589369144..0a739c193 100644 --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -345,7 +345,7 @@ void QuickSaveGame() { filename << "saveg" << std::setw(3) << std::setfill('0') << Quicksave_game_slot; std::filesystem::path pathname = cf_GetWritableBaseDirectory() / "savegame" / filename.str(); - FILE *fp = fopen((const char*)pathname.u8string().c_str(), "rb"); + FILE *fp = fopen(PATH_TO_CSTR(pathname), "rb"); if (fp) { // slot valid, save here. @@ -419,7 +419,7 @@ void SaveGameDialog() { occupied_slot[i] = false; - fp = fopen((const char*)pathname.u8string().c_str(), "rb"); + fp = fopen(PATH_TO_CSTR(pathname), "rb"); if (fp) { fclose(fp); @@ -542,7 +542,7 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data) LOG_DEBUG.printf("savegame slot=%d", id - SAVE_HOTSPOT_ID); - ddio_MakePath(savegame_dir, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "savegame", NULL); + ddio_MakePath(savegame_dir, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "savegame", NULL); snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID)); ddio_MakePath(pathname, savegame_dir, filename, NULL); @@ -615,7 +615,7 @@ bool LoadGameDialog() { occupied_slot[i] = false; - fp = fopen((const char*)pathname.u8string().c_str(), "rb"); + fp = fopen(PATH_TO_CSTR(pathname), "rb"); if (fp) { int bm_handle = -1; diff --git a/Descent3/gamesequence.cpp b/Descent3/gamesequence.cpp index c71beccd9..60d8add99 100644 --- a/Descent3/gamesequence.cpp +++ b/Descent3/gamesequence.cpp @@ -1311,7 +1311,7 @@ void CheckHogfile() { auto relative_path = std::filesystem::path("missions") / new_mn3; auto absolute_path = cf_LocatePath(relative_path); if (std::filesystem::exists(absolute_path)) { - mn3_Open(relative_path.u8string().c_str()); + mn3_Open(relative_path); mem_free(Current_mission.filename); Current_mission.filename = mem_strdup(new_mn3); } else { @@ -1330,7 +1330,7 @@ bool SimpleStartLevel(const std::filesystem::path& level_name) { Current_mission.num_levels = 1; Current_level = nullptr; - Current_mission.levels[0].filename = mem_strdup((const char*)level_name.u8string().c_str()); + Current_mission.levels[0].filename = mem_strdup(PATH_TO_CSTR(level_name)); InitMissionScript(); return true; diff --git a/Descent3/hotspotmap.cpp b/Descent3/hotspotmap.cpp index 8f605a40e..1f119fc0f 100644 --- a/Descent3/hotspotmap.cpp +++ b/Descent3/hotspotmap.cpp @@ -594,7 +594,7 @@ int menutga_alloc_file(const char *name, char *hsmap[1], int *w, int *h) { // Given a filename and a hotspotmap structure, it saves it to disk (.HSM) void menutga_SaveHotSpotMap(const std::filesystem::path &filename, hotspotmap_t *hsmap, windowmap_t *wndmap) { CFILE *file; - LOG_DEBUG.printf("Saving HotSpotMap %s", filename.u8string().c_str()); + LOG_DEBUG.printf("Saving HotSpotMap %s", PATH_TO_CSTR(filename)); file = (CFILE *)cfopen(filename, "wb"); if (!file) { Int3(); // get jeff! diff --git a/Descent3/init.cpp b/Descent3/init.cpp index 4db2b53d7..d59bc6434 100644 --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -1202,8 +1202,8 @@ void SaveGameSettings() { else Database->write("Default_pilot", " ", 2); - Database->write("GAME_base_directory", (const char*)config_base_directory.u8string().c_str(), - strlen((const char*)config_base_directory.u8string().c_str()) + 1); + Database->write("GAME_base_directory", PATH_TO_CSTR(config_base_directory), + strlen(PATH_TO_CSTR(config_base_directory)) + 1); } /* @@ -2001,7 +2001,7 @@ void SetupTempDirectory(void) { std::error_code ec; std::filesystem::create_directories(Descent3_temp_directory, ec); if (ec) { - Error("Could not create temporary directory: \"%s\"", Descent3_temp_directory.u8string().c_str()); + Error("Could not create temporary directory: \"%s\"", PATH_TO_CSTR(Descent3_temp_directory)); exit(1); } @@ -2010,7 +2010,7 @@ void SetupTempDirectory(void) { // verify that we can write to the temp directory if (tempfilename.empty()) { LOG_WARNING << "Unable to get temp file name"; - Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str()); + Error("Unable to set temporary directory to: \"%s\"", PATH_TO_CSTR(Descent3_temp_directory)); exit(1); } @@ -2019,7 +2019,7 @@ void SetupTempDirectory(void) { if (!file) { // unable to open file for writing LOG_WARNING << "Unable to open temp file name for writing"; - Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str()); + Error("Unable to set temporary directory to: \"%s\"", PATH_TO_CSTR(Descent3_temp_directory)); exit(1); } @@ -2032,7 +2032,7 @@ void SetupTempDirectory(void) { // unable to open file for reading LOG_WARNING << "Unable to open temp file name for reading"; std::filesystem::remove(tempfilename); - Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str()); + Error("Unable to set temporary directory to: \"%s\"", PATH_TO_CSTR(Descent3_temp_directory)); exit(1); } @@ -2041,7 +2041,7 @@ void SetupTempDirectory(void) { LOG_WARNING << "Temp file verify failed"; cfclose(file); std::filesystem::remove(tempfilename); - Error("Unable to set temporary directory to: \"%s\"", Descent3_temp_directory.u8string().c_str()); + Error("Unable to set temporary directory to: \"%s\"", PATH_TO_CSTR(Descent3_temp_directory)); exit(1); } @@ -2056,19 +2056,19 @@ void SetupTempDirectory(void) { if (!ddio_CreateLockFile(std::filesystem::path(Descent3_temp_directory))) { LOG_WARNING << "Lock file NOT created in temp dir " << Descent3_temp_directory; Error("Unable to set temporary directory to: \"%s\"\nUnable to create lock file", - Descent3_temp_directory.u8string().c_str()); + PATH_TO_CSTR(Descent3_temp_directory)); exit(1); } // restore working dir - ddio_SetWorkingDir((const char*)cf_GetWritableBaseDirectory().u8string().c_str()); + ddio_SetWorkingDir(PATH_TO_CSTR(cf_GetWritableBaseDirectory())); } void DeleteTempFiles() { ddio_DoForeachFile(Descent3_temp_directory, std::regex("d3[smocti].+\\.tmp"), [](const std::filesystem::path &path) { std::error_code ec; std::filesystem::remove(path, ec); - LOG_WARNING_IF(ec).printf("Unable to remove temporary file %s: %s\n", (const char*)path.u8string().c_str(), - (const char*)ec.message().c_str()); + LOG_WARNING_IF(ec).printf("Unable to remove temporary file %s: %s\n", PATH_TO_CSTR(path), + ec.message().c_str()); }); } diff --git a/Descent3/levelgoal.cpp b/Descent3/levelgoal.cpp index 4b157b1cc..eb4a2652d 100644 --- a/Descent3/levelgoal.cpp +++ b/Descent3/levelgoal.cpp @@ -289,8 +289,7 @@ bool lgoal::SetName(int handle, char *name) { if (m_name) mem_free(m_name); - m_name = mem_rmalloc(strlen(name) + 1); - strcpy(m_name, name); + m_name = mem_strdup(name); m_modified = 1; if (Game_mode & GM_MULTI && Netgame.local_role != LR_CLIENT) { @@ -321,9 +320,7 @@ bool lgoal::SetCompletionMessage(char *message) { if (m_completion_message) mem_free(m_completion_message); - m_completion_message = mem_rmalloc(strlen(message) + 1); - strcpy(m_completion_message, message); - + m_completion_message = mem_strdup(message); return true; } @@ -334,9 +331,7 @@ bool lgoal::SetItemName(char *iname) { if (m_item_name) mem_free(m_item_name); - m_item_name = mem_rmalloc(strlen(iname) + 1); - strcpy(m_item_name, iname); - + m_item_name = mem_strdup(iname); return true; } @@ -443,9 +438,7 @@ bool lgoal::SetDesc(char *desc) { if (m_desc) mem_free(m_desc); - m_desc = mem_rmalloc(strlen(desc) + 1); - strcpy(m_desc, desc); - + m_desc = mem_strdup(desc); return true; } diff --git a/Descent3/localization.cpp b/Descent3/localization.cpp index 711c7863b..6dfed522b 100644 --- a/Descent3/localization.cpp +++ b/Descent3/localization.cpp @@ -678,10 +678,9 @@ void GrowString::operator+=(char *str) { node->next = NULL; curr = node; } else { - root.string_data = mem_rmalloc(strlen(str) + 1); + root.string_data = mem_strdup(str); if (!root.string_data) return; - strcpy(root.string_data, str); root.next = NULL; } } diff --git a/Descent3/menu.cpp b/Descent3/menu.cpp index 817681d42..7180ade0c 100644 --- a/Descent3/menu.cpp +++ b/Descent3/menu.cpp @@ -1054,11 +1054,11 @@ static inline int count_missions(const std::vector &missi for (const auto &missions_directory : missions_directories) { ddio_DoForeachFile(missions_directory, std::regex(".*\\.mn3"), [&c](const std::filesystem::path &path) { - if (stricmp((const char*)path.filename().u8string().c_str(), "d3_2.mn3") == 0) + if (stricmp(PATH_TO_CSTR(path.filename()), "d3_2.mn3") == 0) return; - LOG_DEBUG.printf("Mission path: %s", (const char*)path.u8string().c_str()); + LOG_DEBUG.printf("Mission path: %s", PATH_TO_CSTR(path)); tMissionInfo msninfo{}; - GetMissionInfo((const char*)path.filename().u8string().c_str(), &msninfo); + GetMissionInfo(path.filename(), &msninfo); if (msninfo.name[0] && msninfo.single) { LOG_DEBUG.printf("Name: %s", msninfo.name); @@ -1066,7 +1066,7 @@ static inline int count_missions(const std::vector &missi if (!(c % 2)) DoWaitMessage(true); } else { - LOG_DEBUG.printf("Illegal or multiplayer mission: %s", path.u8string().c_str()); + LOG_DEBUG.printf("Illegal or multiplayer mission: %s", PATH_TO_CSTR(path)); } }); } @@ -1081,7 +1081,7 @@ static inline int generate_mission_listbox(newuiListBox *lb, std::vector= 0 && index < filelist.size()) { nameptr = filelist[index]; } - if (nameptr.empty() || !LoadMission((const char*)nameptr.u8string().c_str())) { + if (nameptr.empty() || !LoadMission(PATH_TO_CSTR(nameptr))) { DoMessageBox(TXT_ERROR, TXT_ERRLOADMSN, MSGBOX_OK); retval = false; } else { diff --git a/Descent3/mission_download.cpp b/Descent3/mission_download.cpp index f494abe96..2c515beb9 100644 --- a/Descent3/mission_download.cpp +++ b/Descent3/mission_download.cpp @@ -151,7 +151,7 @@ msn_urls Net_msn_URLs; extern char Proxy_server[200]; extern int16_t Proxy_port; -int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::filesystem::path &mn3name); +static int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::filesystem::path &mn3name); // Request a URL structure from a server containing a list of download locations // For the current mission being played @@ -322,7 +322,7 @@ bool msn_DownloadWithStatus(const char *url, const std::filesystem::path &filena return false; } std::filesystem::path download_file = std::filesystem::path(url_parts.back()); - if (stricmp((const char*)download_file.extension().u8string().c_str(), ".zip") == 0) { + if (stricmp(PATH_TO_CSTR(download_file.extension()), ".zip") == 0) { LOG_DEBUG << "We're downloading a zip file!!!"; file_is_zip = true; } @@ -430,7 +430,7 @@ bool msn_DownloadWithStatus(const char *url, const std::filesystem::path &filena if (file_is_zip) { // now we gotta handle the zip file - ret = msn_ExtractZipFile(qualfile.u8string().c_str(), filename); + ret = msn_ExtractZipFile(qualfile, filename); } else { ret = 1; } @@ -685,9 +685,9 @@ void _get_zipfilename(char *output, char *directory, char *zipfilename) { // return 0 on failure // return 1 on success -int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::filesystem::path &mn3name) { +static int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::filesystem::path &mn3name) { - LOG_DEBUG.printf("Extracting ZIP File (%s) to missions directory", zipfilename.u8string().c_str()); + LOG_DEBUG.printf("Extracting ZIP File (%s) to missions directory", PATH_TO_CSTR(zipfilename)); if (!cfexist(zipfilename)) { LOG_WARNING << "Zip file doesn't exist"; return 0; @@ -703,7 +703,7 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file ZIP zfile; zipentry *ze; - if (!zfile.OpenZip((const char*)zipfilename.u8string().c_str())) { + if (!zfile.OpenZip(PATH_TO_CSTR(zipfilename))) { LOG_WARNING << "Unable to open zip file"; return 0; } @@ -746,7 +746,7 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file snprintf(buffer, sizeof(buffer), "%s already exists. Overwrite?", output_filename); if (DoMessageBox("Confirm", buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { // delete the file - LOG_DEBUG.printf("Deleting %s", zipfilename.u8string().c_str()); + LOG_DEBUG.printf("Deleting %s", PATH_TO_CSTR(zipfilename)); if (!ddio_DeleteFile(output_filename)) { process_file = false; console.puts(GR_GREEN, "[Unable to Write] "); @@ -785,7 +785,7 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file console.puts(GR_GREEN, "CRC OK"); // check to see if we extracted our mn3 - if (CompareZipFileName(ze->name, (const char*)mn3name.u8string().c_str())) { + if (CompareZipFileName(ze->name, PATH_TO_CSTR(mn3name))) { found_mn3 = true; } } else { @@ -809,7 +809,7 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file if (DoMessageBox("Confirm", "Do you want to delete the zip file? It is no longer needed.", MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { // delete the file - LOG_DEBUG.printf("Deleting %s", zipfilename.u8string().c_str()); + LOG_DEBUG.printf("Deleting %s", PATH_TO_CSTR(zipfilename)); std::error_code ec; std::filesystem::remove(zipfilename); } diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index 5cc07f12b..f1487d7b1 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -7998,23 +7998,23 @@ char *GetFileNameFromPlayerAndID(int16_t playernum, int16_t id) { break; case NETFILE_ID_SHIP_TEX: if (NetPlayers[playernum].ship_logo[0]) - ddio_MakePath(rval, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "custom", "graphics", NetPlayers[playernum].ship_logo, NULL); + ddio_MakePath(rval, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "custom", "graphics", NetPlayers[playernum].ship_logo, NULL); break; case NETFILE_ID_VOICE_TAUNT1: if (NetPlayers[playernum].voice_taunt1[0]) - ddio_MakePath(rval, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL); + ddio_MakePath(rval, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "custom", "sounds", NetPlayers[playernum].voice_taunt1, NULL); break; case NETFILE_ID_VOICE_TAUNT2: if (NetPlayers[playernum].voice_taunt2[0]) - ddio_MakePath(rval, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL); + ddio_MakePath(rval, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "custom", "sounds", NetPlayers[playernum].voice_taunt2, NULL); break; case NETFILE_ID_VOICE_TAUNT3: if (NetPlayers[playernum].voice_taunt3[0]) - ddio_MakePath(rval, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL); + ddio_MakePath(rval, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "custom", "sounds", NetPlayers[playernum].voice_taunt3, NULL); break; case NETFILE_ID_VOICE_TAUNT4: if (NetPlayers[playernum].voice_taunt4[0]) - ddio_MakePath(rval, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "custom", "sounds", NetPlayers[playernum].voice_taunt4, NULL); + ddio_MakePath(rval, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "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 1ec0e14a4..8edd1d2a2 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -606,7 +606,7 @@ int LoadMultiDLL(const char *name) { std::error_code ec; std::filesystem::remove(path, ec); if (ec) { - LOG_ERROR.printf("Unable to remove temporary file %s: %s", path.u8string().c_str(), ec.message().c_str()); + LOG_ERROR.printf("Unable to remove temporary file %s: %s", PATH_TO_CSTR(path), ec.message().c_str()); } }); diff --git a/Descent3/newui_filedlg.cpp b/Descent3/newui_filedlg.cpp index 62679438a..222c5ec42 100644 --- a/Descent3/newui_filedlg.cpp +++ b/Descent3/newui_filedlg.cpp @@ -219,7 +219,7 @@ bool DoPathFileDialog(bool save_dialog, std::filesystem::path &path, const char sheet->NewGroup(nullptr, 0, 0); rootpathlistbox = sheet->AddListBox(60, 124, ID_ROOTPATH); for (auto const &root : ddio_GetSysRoots()) { - rootpathlistbox->AddItem((const char*)root.u8string().c_str()); + rootpathlistbox->AddItem(PATH_TO_CSTR(root)); } sheet->NewGroup(nullptr, 80, 0); @@ -237,7 +237,7 @@ bool DoPathFileDialog(bool save_dialog, std::filesystem::path &path, const char working_path = std::filesystem::canonical(path); UpdateFileList(listbox, working_path, wildcards); - strncpy(edits_filepath, (const char*)working_path.u8string().c_str(), _MAX_PATH - 1); + strncpy(edits_filepath, PATH_TO_CSTR(working_path), _MAX_PATH - 1); edits_filepath[_MAX_PATH - 1] = '\0'; std::string wildc1 = StringJoin(wildcards, ";"); @@ -275,7 +275,7 @@ bool DoPathFileDialog(bool save_dialog, std::filesystem::path &path, const char working_path = std::filesystem::canonical(working_path); UpdateFileList(listbox, working_path, wildcards); - strncpy(edits_filepath, (const char*)working_path.u8string().c_str(), _MAX_PATH - 1); + strncpy(edits_filepath, PATH_TO_CSTR(working_path), _MAX_PATH - 1); edits_filepath[_MAX_PATH - 1] = '\0'; } else { // File is chosen @@ -335,7 +335,7 @@ bool DoPathFileDialog(bool save_dialog, std::filesystem::path &path, const char UpdateFileList(listbox, working_path, wildcards); - strncpy(edits_filepath, (const char*)working_path.u8string().c_str(), _MAX_PATH - 1); + strncpy(edits_filepath, PATH_TO_CSTR(working_path), _MAX_PATH - 1); edits_filepath[_MAX_PATH - 1] = '\0'; } else { // double-click on a file @@ -362,7 +362,7 @@ bool DoPathFileDialog(bool save_dialog, std::filesystem::path &path, const char working_path = working_path.parent_path(); UpdateFileList(listbox, working_path, wildcards); - strncpy(edits_filepath, (const char*)working_path.u8string().c_str(), _MAX_PATH - 1); + strncpy(edits_filepath, PATH_TO_CSTR(working_path), _MAX_PATH - 1); edits_filepath[_MAX_PATH - 1] = '\0'; } break; case ID_WILDCARD: { @@ -400,7 +400,7 @@ bool DoPathFileDialog(bool save_dialog, std::filesystem::path &path, const char } if (ret) { - LOG_DEBUG.printf("Selected Filename: %s", path.u8string().c_str()); + LOG_DEBUG.printf("Selected Filename: %s", PATH_TO_CSTR(path)); } else { LOG_DEBUG << "Cancel!"; } @@ -433,8 +433,8 @@ void UpdateFileList(newuiListBox *lb, const std::filesystem::path &path, const s } if (std::filesystem::is_regular_file(dir_entry)) { for (const auto &wildcard : wildcards) { - if (stricmp((const char*)dir_entry.path().extension().u8string().c_str(), - (const char*)std::filesystem::path(wildcard).extension().u8string().c_str()) == 0) { + if (stricmp(PATH_TO_CSTR(dir_entry.path().extension()), + PATH_TO_CSTR(std::filesystem::path(wildcard).extension())) == 0) { files.push_back(dir_entry.path().filename()); } } @@ -442,7 +442,7 @@ void UpdateFileList(newuiListBox *lb, const std::filesystem::path &path, const s } } catch (std::exception &e) { DoMessageBox(TXT_ERROR, TXT_ERRPATHNOTVALID, MSGBOX_OK); - LOG_ERROR.printf("Error iterating directory %s: %s", (const char*)path.u8string().c_str(), e.what()); + LOG_ERROR.printf("Error iterating directory %s: %s", PATH_TO_CSTR(path), e.what()); } if (dirs.size() + files.size() == 0) { @@ -453,11 +453,11 @@ void UpdateFileList(newuiListBox *lb, const std::filesystem::path &path, const s char tempbuffer[_MAX_PATH + 1]; for (auto const &dir : dirs) { - snprintf(tempbuffer, sizeof(tempbuffer), " [%s]", (const char*)dir.u8string().c_str()); + snprintf(tempbuffer, sizeof(tempbuffer), " [%s]", PATH_TO_CSTR(dir)); lb->AddItem(tempbuffer); } for (auto const &file : files) { - lb->AddItem((const char*)file.u8string().c_str()); + lb->AddItem(PATH_TO_CSTR(file)); } FDlg_EnableWaitMessage(false); diff --git a/Descent3/pilot.cpp b/Descent3/pilot.cpp index 2a0448b52..3736d7402 100644 --- a/Descent3/pilot.cpp +++ b/Descent3/pilot.cpp @@ -1035,7 +1035,7 @@ void PilotSelect() { PilotListSelectChangeCallback(index); if (found_old) { - Current_pilot.set_filename((const char*)old_file.u8string().c_str()); + Current_pilot.set_filename(PATH_TO_CSTR(old_file)); PltReadFile(&Current_pilot, true, true); char pname[PILOT_STRING_SIZE]; @@ -1700,7 +1700,7 @@ std::vector PltGetPilots(std::string ignore_filename, int display_d } ddio_DoForeachFile(cf_GetWritableBaseDirectory(), wildcard, [&ignore_filename, &result](const std::filesystem::path &path) { - std::string pilot = (const char*)path.filename().u8string().c_str(); + std::string pilot = PATH_TO_CSTR(path.filename()); 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()); } else { @@ -1871,7 +1871,7 @@ tShipListInfo *lp_ship_info = nullptr; std::filesystem::path StripCRCFileName(const std::filesystem::path &src) { ASSERT(!src.empty()); - std::vector parts = StringSplit((const char*)src.u8string().c_str(), "_"); + std::vector parts = StringSplit(PATH_TO_CSTR(src), "_"); if (parts.size() < 2 || parts.back().size() != 8) { // this filename doesn't have a trailing CRC return src; @@ -1912,7 +1912,7 @@ bool CreateCRCFileName(const std::filesystem::path &src, std::filesystem::path & // now create the full filename - dest = src.parent_path() / ((const char*)(StripCRCFileName(src).stem().concat(hex_string).u8string().c_str())); + dest = src.parent_path() / StripCRCFileName(src).stem().concat(hex_string); dest.replace_extension(src.extension()); return true; @@ -1948,7 +1948,7 @@ bool CreateCRCFileName(const std::filesystem::path &src, std::filesystem::path & // Takes the graphics file at the given location and imports it into the custom\graphics dir as an scaled ogf // pathname = full path to source bitmap // newfile = on return true is the filename of the new bitmap -bool ImportGraphic(const char *pathname, char *newfile) { +static bool ImportGraphic(const char *pathname, char *newfile) { ASSERT(pathname); if (cfexist(pathname) != CFES_ON_DISK) { LOG_WARNING.printf("'%s' not found", pathname); @@ -2001,7 +2001,7 @@ bool ImportGraphic(const char *pathname, char *newfile) { // p contains the real filename // tempfilename contains old filename - bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE((const char*)tempfilename.u8string().c_str()), 0); + bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(PATH_TO_CSTR(tempfilename)), 0); if (bm_handle <= BAD_BITMAP_HANDLE) { LOG_WARNING << "Error reloading bitmap for rename"; std::filesystem::remove(tempfilename, ec); @@ -2018,7 +2018,7 @@ bool ImportGraphic(const char *pathname, char *newfile) { bm_FreeBitmap(bm_handle); std::filesystem::remove(tempfilename, ec); - strcpy(newfile, (const char*)p.u8string().c_str()); + strcpy(newfile, PATH_TO_CSTR(p)); return true; } @@ -2042,8 +2042,8 @@ bool UpdateGraphicsListbox(newuiListBox *lb, const std::filesystem::path &select int i = 1; // With "None" for (auto const &image : Custom_images) { - lb->AddItem((const char*)StripCRCFileName(image).u8string().c_str()); - if (stricmp((const char*)image.u8string().c_str(), (const char*)selected_name.filename().u8string().c_str()) == 0) { + lb->AddItem(PATH_TO_CSTR(StripCRCFileName(image))); + if (stricmp(PATH_TO_CSTR(image), PATH_TO_CSTR(selected_name.filename())) == 0) { lb->SetCurrentIndex(i); CustomCallBack(i); } @@ -2091,24 +2091,24 @@ void UpdateAudioTauntBoxes(newuiComboBox *audio1_list, newuiComboBox *audio2_lis int i = 0; for (const auto &taunt : Audio_taunts) { std::filesystem::path tfn = StripCRCFileName(taunt); - audio1_list->AddItem((const char*)tfn.u8string().c_str()); - audio2_list->AddItem((const char*)tfn.u8string().c_str()); - audio3_list->AddItem((const char*)tfn.u8string().c_str()); - audio4_list->AddItem((const char*)tfn.u8string().c_str()); + audio1_list->AddItem(PATH_TO_CSTR(tfn)); + audio2_list->AddItem(PATH_TO_CSTR(tfn)); + audio3_list->AddItem(PATH_TO_CSTR(tfn)); + audio4_list->AddItem(PATH_TO_CSTR(tfn)); - if (!stricmp(paudio1, (const char*)taunt.u8string().c_str())) { + if (!stricmp(paudio1, PATH_TO_CSTR(taunt))) { // set this as selected index for audio #1 audio1_list->SetCurrentIndex(i + 1); } - if (!stricmp(paudio2, (const char*)taunt.u8string().c_str())) { + if (!stricmp(paudio2, PATH_TO_CSTR(taunt))) { // set this as selected index for audio #2 audio2_list->SetCurrentIndex(i + 1); } - if (!stricmp(paudio3, (const char*)taunt.u8string().c_str())) { + if (!stricmp(paudio3, PATH_TO_CSTR(taunt))) { // set this as selected index for audio #1 audio3_list->SetCurrentIndex(i + 1); } - if (!stricmp(paudio4, (const char*)taunt.u8string().c_str())) { + if (!stricmp(paudio4, PATH_TO_CSTR(taunt))) { // set this as selected index for audio #2 audio4_list->SetCurrentIndex(i + 1); } @@ -2125,7 +2125,7 @@ void audio1changecallback(int index) { } else { index--; if (index < (int)Audio_taunts.size()) { - AudioTauntPilot->set_multiplayer_data(nullptr, (const char*)Audio_taunts[index].u8string().c_str()); + AudioTauntPilot->set_multiplayer_data(nullptr, PATH_TO_CSTR(Audio_taunts[index])); } } } @@ -2137,7 +2137,7 @@ void audio2changecallback(int index) { } else { index--; if (index < (int)Audio_taunts.size()) { - AudioTauntPilot->set_multiplayer_data(nullptr, nullptr, (const char*)Audio_taunts[index].u8string().c_str()); + AudioTauntPilot->set_multiplayer_data(nullptr, nullptr, PATH_TO_CSTR(Audio_taunts[index])); } } } @@ -2149,7 +2149,7 @@ void audio3changecallback(int index) { } else { index--; if (index < (int)Audio_taunts.size()) { - AudioTauntPilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, (const char*)Audio_taunts[index].u8string().c_str()); + AudioTauntPilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, PATH_TO_CSTR(Audio_taunts[index])); } } } @@ -2162,7 +2162,7 @@ void audio4changecallback(int index) { index--; if (index < (int)Audio_taunts.size()) { AudioTauntPilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, nullptr, - (const char*)Audio_taunts[index].u8string().c_str()); + PATH_TO_CSTR(Audio_taunts[index])); } } } @@ -2465,21 +2465,21 @@ bool PltSelectShip(pilot *Pilot) { int index; index = taunts_lists.taunt_a->GetCurrentIndex(); if (index > 0 && !Audio_taunts.empty()) { - Pilot->set_multiplayer_data(nullptr, (const char*)Audio_taunts[index - 1].u8string().c_str()); + Pilot->set_multiplayer_data(nullptr, PATH_TO_CSTR(Audio_taunts[index - 1])); } index = taunts_lists.taunt_b->GetCurrentIndex(); if (index > 0 && !Audio_taunts.empty()) { - Pilot->set_multiplayer_data(nullptr, nullptr, (const char*)Audio_taunts[index - 1].u8string().c_str()); + Pilot->set_multiplayer_data(nullptr, nullptr, PATH_TO_CSTR(Audio_taunts[index - 1])); } index = taunts_lists.taunt_c->GetCurrentIndex(); if (index > 0 && !Audio_taunts.empty()) { - Pilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, (const char*)Audio_taunts[index - 1].u8string().c_str()); + Pilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, PATH_TO_CSTR(Audio_taunts[index - 1])); } index = taunts_lists.taunt_d->GetCurrentIndex(); if (index > 0 && !Audio_taunts.empty()) { - Pilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, nullptr, (const char*)Audio_taunts[index - 1].u8string().c_str()); + Pilot->set_multiplayer_data(nullptr, nullptr, nullptr, nullptr, nullptr, PATH_TO_CSTR(Audio_taunts[index - 1])); } char audio1[PAGENAME_LEN], audio2[PAGENAME_LEN], audio3[PAGENAME_LEN], audio4[PAGENAME_LEN]; @@ -2504,7 +2504,7 @@ bool PltSelectShip(pilot *Pilot) { std::filesystem::path path; char newf[_MAX_FNAME]; if (DoPathFileDialog(false, path, TXT_CHOOSE, {"*.ogf", "*.tga", "*.pcx", "*.iff"}, PFDF_FILEMUSTEXIST)) { - if (ImportGraphic((const char*)path.u8string().c_str(), newf)) { + if (ImportGraphic(PATH_TO_CSTR(path), newf)) { // update the listbox if (!UpdateGraphicsListbox(custom_list, newf)) goto ship_id_err; @@ -2516,7 +2516,7 @@ bool PltSelectShip(pilot *Pilot) { case ID_GETANIM: { std::filesystem::path path; if (DoPathFileDialog(false, path, TXT_CHOOSE, {"*.ifl"}, PFDF_FILEMUSTEXIST)) { - int handle = AllocLoadIFLVClip(IGNORE_TABLE((const char*)path.u8string().c_str()), SMALL_TEXTURE, 1); + int handle = AllocLoadIFLVClip(IGNORE_TABLE(PATH_TO_CSTR(path)), SMALL_TEXTURE, 1); if (handle != -1) { // change the file extension @@ -2561,10 +2561,10 @@ bool PltSelectShip(pilot *Pilot) { int index = taunts_lists.taunt_a->GetCurrentIndex(); if (index > 0 && !Audio_taunts.empty()) { std::filesystem::path path = LocalCustomSoundsDir / Audio_taunts[index - 1]; - LOG_INFO.printf("Playing: %s", (const char*)path.u8string().c_str()); + LOG_INFO.printf("Playing: %s", PATH_TO_CSTR(path)); bool cenable = taunt_AreEnabled(); taunt_Enable(true); - taunt_PlayTauntFile((const char*)path.u8string().c_str()); + taunt_PlayTauntFile(path); taunt_Enable(cenable); } } break; @@ -2583,8 +2583,8 @@ bool PltSelectShip(pilot *Pilot) { std::filesystem::path tempfile = LocalCustomSoundsDir / filename; // import the sound - LOG_INFO.printf("Importing: '%s'->'%s'", (const char*)path.u8string().c_str(), (const char*)tempfile.u8string().c_str()); - if (taunt_ImportWave((const char*)path.u8string().c_str(), (const char*)tempfile.u8string().c_str())) { + LOG_INFO.printf("Importing: '%s'->'%s'", PATH_TO_CSTR(path), PATH_TO_CSTR(tempfile)); + if (taunt_ImportWave(PATH_TO_CSTR(path), PATH_TO_CSTR(tempfile))) { // success // check file size...make sure it isn't too big @@ -2708,7 +2708,7 @@ void CustomCallBack(int c) { select_bitmap = Custom_images[c - 1]; } - if (!strcmp(custom_texture, (const char*)select_bitmap.u8string().c_str())) + if (!strcmp(custom_texture, PATH_TO_CSTR(select_bitmap))) return; if (ship_pos.bm_handle > BAD_BITMAP_HANDLE) { @@ -2732,7 +2732,7 @@ void CustomCallBack(int c) { } else { if ((c - 1) < (int)Custom_images.size()) { select_bitmap = Custom_images[c - 1]; - strcpy(custom_texture, (const char*)select_bitmap.u8string().c_str()); + strcpy(custom_texture, PATH_TO_CSTR(select_bitmap)); } else { custom_texture[0] = '\0'; } @@ -2820,14 +2820,14 @@ void ShipSelectDeleteLogo(newuiListBox *lb) { char buffer[512]; snprintf(buffer, sizeof(buffer), TXT_PLTOKDEL, custom_logoname); if (DoMessageBox(TXT_PLTDELCONF, buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { - LOG_INFO.printf("Deleting pilot logo %s (%s)", custom_logoname, custom_filename.u8string().c_str()); + LOG_INFO.printf("Deleting pilot logo %s (%s)", custom_logoname, PATH_TO_CSTR(custom_filename)); std::error_code ec; if (std::filesystem::remove(LocalCustomGraphicsDir / custom_filename, ec)) { // Update the list box, select none UpdateGraphicsListbox(lb); } else { - LOG_FATAL.printf("Unable to delete file %s", custom_filename.u8string().c_str()); + LOG_FATAL.printf("Unable to delete file %s", PATH_TO_CSTR(custom_filename)); Int3(); } } @@ -2862,7 +2862,7 @@ void ShipSelectDeleteTaunt(pilot *Pilot, newuiComboBox *lb, tAudioTauntComboBoxe char buffer[512]; snprintf(buffer, sizeof(buffer), TXT_PLTOKDEL, custom_logoname); if (DoMessageBox(TXT_PLTDELCONF, buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { - LOG_INFO.printf("Deleting audio taunt %s (%s)", custom_logoname, custom_filename.u8string().c_str()); + LOG_INFO.printf("Deleting audio taunt %s (%s)", custom_logoname, PATH_TO_CSTR(custom_filename)); std::error_code ec; if (std::filesystem::remove(LocalCustomSoundsDir / custom_filename, ec)) { @@ -2870,7 +2870,7 @@ void ShipSelectDeleteTaunt(pilot *Pilot, newuiComboBox *lb, tAudioTauntComboBoxe UpdateAudioTauntBoxes(taunt_boxes->taunt_a, taunt_boxes->taunt_b, taunt_boxes->taunt_c, taunt_boxes->taunt_d, Pilot); } else { - LOG_FATAL.printf("Unable to delete file %s", custom_filename.u8string().c_str()); + LOG_FATAL.printf("Unable to delete file %s", PATH_TO_CSTR(custom_filename)); Int3(); } } diff --git a/Descent3/pilot_class.cpp b/Descent3/pilot_class.cpp index 59f101a3a..050670d47 100644 --- a/Descent3/pilot_class.cpp +++ b/Descent3/pilot_class.cpp @@ -419,7 +419,7 @@ int pilot::flush(bool new_file) { if (new_file && cfexist(real_filename)) { // the file already exists, we can't write out - LOG_WARNING.printf("PLTW: File (%s) exists, can't create", real_filename.u8string().c_str()); + LOG_WARNING.printf("PLTW: File (%s) exists, can't create", PATH_TO_CSTR(real_filename)); return PLTW_FILE_EXISTS; } @@ -428,7 +428,7 @@ int pilot::flush(bool new_file) { file = cfopen(real_filename, "wb"); if (!file) { - LOG_WARNING.printf("PLTW: File (%s) can't be opened", real_filename.u8string().c_str()); + LOG_WARNING.printf("PLTW: File (%s) can't be opened", PATH_TO_CSTR(real_filename)); return PLTW_FILE_CANTOPEN; } @@ -501,14 +501,14 @@ int pilot::read(bool skip_config, bool skip_mission_data) { if (!cfexist(real_filename)) { // the file already exists, we can't write out - LOG_WARNING.printf("PLTR: File (%s) does not exist", real_filename.u8string().c_str()); + LOG_WARNING.printf("PLTR: File (%s) does not exist", PATH_TO_CSTR(real_filename)); return PLTR_FILE_NOEXIST; } try { file = cfopen(real_filename, "rb"); if (!file) { - LOG_WARNING.printf("PLTR: File (%s) can't be opened", real_filename.u8string().c_str()); + LOG_WARNING.printf("PLTR: File (%s) can't be opened", PATH_TO_CSTR(real_filename)); return PLTR_FILE_CANTOPEN; } diff --git a/Descent3/subtitles.cpp b/Descent3/subtitles.cpp index 34d73cd34..35fd1db45 100644 --- a/Descent3/subtitles.cpp +++ b/Descent3/subtitles.cpp @@ -186,11 +186,9 @@ void SubtParseSubtitles(CFILE *file) { Subtitles[Num_subtitles].first_frame = first_frame; Subtitles[Num_subtitles].last_frame = last_frame; - Subtitles[Num_subtitles].msg = mem_rmalloc(strlen(p) + 1); + Subtitles[Num_subtitles].msg = mem_strdup(p); // be sure to free this later if (!Subtitles[Num_subtitles].msg) goto subt_parse_error; - strcpy(Subtitles[Num_subtitles].msg, p); // be sure to free this later - Num_subtitles++; PARSE_NEXT_LINE(); diff --git a/Descent3/vclip.cpp b/Descent3/vclip.cpp index d06c1d01d..3d65c8ff8 100644 --- a/Descent3/vclip.cpp +++ b/Descent3/vclip.cpp @@ -267,7 +267,7 @@ int SaveVClip(const std::filesystem::path& filename, int num) { // Now save each frame of this vclip for (int i = 0; i < vc->num_frames; i++) { if (bm_SaveBitmap(outfile, vc->frames[i]) != 1) { - LOG_ERROR.printf("Couldn't save frame %d of vclip %s!", i, filename.u8string().c_str()); + LOG_ERROR.printf("Couldn't save frame %d of vclip %s!", i, PATH_TO_CSTR(filename)); Int3(); cfclose(outfile); return 0; diff --git a/cfile/cfile.cpp b/cfile/cfile.cpp index 16183b16b..22e1016cb 100644 --- a/cfile/cfile.cpp +++ b/cfile/cfile.cpp @@ -137,7 +137,7 @@ std::filesystem::path cf_LocatePathCaseInsensitiveHelper(const std::filesystem:: auto const &it = std::filesystem::directory_iterator(search_path); auto found = std::find_if(it, end(it), [&search_file, &search_path, &result](const auto& dir_entry) { - return stricmp((const char*)dir_entry.path().filename().u8string().c_str(), (const char*)search_file.u8string().c_str()) == 0; + return stricmp(PATH_TO_CSTR(dir_entry.path().filename()), PATH_TO_CSTR(search_file)) == 0; }); if (found != end(it)) { @@ -244,7 +244,7 @@ int cf_OpenLibrary(const std::filesystem::path &libname) { // allocation library structure std::shared_ptr lib = std::make_shared(); lib->name = cf_LocatePath(libname); - fp = fopen((const char*)lib->name.u8string().c_str(), "rb"); + fp = fopen(PATH_TO_CSTR(lib->name), "rb"); if (fp == nullptr) { return 0; // CF_NO_FILE; } @@ -378,7 +378,7 @@ CFILE *cf_OpenFileInLibrary(const std::filesystem::path &filename, int libhandle do { i = (first + last) / 2; - c = stricmp((const char*)filename.u8string().c_str(), (const char*)lib->entries[i]->name); // compare to current + c = stricmp(PATH_TO_CSTR(filename), lib->entries[i]->name); // compare to current if (c == 0) { found = true; break; @@ -402,10 +402,10 @@ CFILE *cf_OpenFileInLibrary(const std::filesystem::path &filename, int libhandle fp = lib->file; lib->file = nullptr; } else { - fp = fopen((const char*)lib->name.u8string().c_str(), "rb"); + fp = fopen(PATH_TO_CSTR(lib->name), "rb"); if (!fp) { - LOG_ERROR.printf("Error opening library <%s> when opening file <%s>; errno=%d.", (const char*)lib->name.u8string().c_str(), - (const char*)filename.u8string().c_str(), errno); + LOG_ERROR.printf("Error opening library <%s> when opening file <%s>; errno=%d.", PATH_TO_CSTR(lib->name), + PATH_TO_CSTR(filename), errno); Int3(); return nullptr; } @@ -455,9 +455,9 @@ CFILE *open_file_in_lib(const char *filename) { fp = lib->file; lib->file = nullptr; } else { - fp = fopen((const char*)lib->name.u8string().c_str(), "rb"); + fp = fopen(PATH_TO_CSTR(lib->name), "rb"); if (!fp) { - LOG_ERROR.printf("Error opening library <%s> when opening file <%s>; errno=%d.", (const char*)lib->name.u8string().c_str(), + LOG_ERROR.printf("Error opening library <%s> when opening file <%s>; errno=%d.", PATH_TO_CSTR(lib->name), filename, errno); Int3(); return nullptr; @@ -509,7 +509,7 @@ CFILE *open_file_in_directory(const std::filesystem::path &filename, const char // if mode is "w", then open in text or binary as requested. If "r", always open in "rb" tmode[1] = (mode[0] == 'w') ? mode[1] : 'b'; // try to open file - fp = fopen((const char*)using_filename.u8string().c_str(), tmode); + fp = fopen(PATH_TO_CSTR(using_filename), tmode); if (!fp) { // File not found @@ -522,10 +522,9 @@ CFILE *open_file_in_directory(const std::filesystem::path &filename, const char cfile = mem_rmalloc(); if (!cfile) Error("Out of memory in open_file_in_directory()"); - cfile->name = mem_rmalloc((strlen((const char*)using_filename.u8string().c_str()) + 1)); + cfile->name = mem_strdup(PATH_TO_CSTR(using_filename)); if (!cfile->name) Error("Out of memory in open_file_in_directory()"); - strcpy(cfile->name, (const char*)using_filename.u8string().c_str()); cfile->file = fp; cfile->lib_handle = -1; cfile->size = ddio_GetFileLength(fp); @@ -562,7 +561,7 @@ CFILE *cfopen(const std::filesystem::path &filename, const char *mode) { // First look in the directories for this file's extension for (auto const &entry : extensions) { - if (!strnicmp((const char*)entry.first.u8string().c_str(), (const char*)ext.u8string().c_str(), _MAX_EXT)) { + if (!strnicmp(PATH_TO_CSTR(entry.first), PATH_TO_CSTR(ext), _MAX_EXT)) { // found ext cfile = open_file_in_directory(filename, mode, entry.second); if (cfile) { @@ -580,7 +579,7 @@ CFILE *cfopen(const std::filesystem::path &filename, const char *mode) { } } // Lastly, try the hog files - cfile = open_file_in_lib((const char*)filename.u8string().c_str()); + cfile = open_file_in_lib(PATH_TO_CSTR(filename)); got_file:; if (cfile) { if (mode[0] == 'w') @@ -893,7 +892,7 @@ void cf_WriteDouble(CFILE *cfp, double d) { // Throws an exception of type (cfile_error *) if the OS returns an error on read or write bool cf_CopyFile(const std::filesystem::path &dest, const std::filesystem::path &src, int copytime) { CFILE *infile, *outfile; - if (!stricmp((const char*)dest.u8string().c_str(), (const char*)src.u8string().c_str())) + if (!stricmp(PATH_TO_CSTR(dest), PATH_TO_CSTR(src))) return true; // don't copy files if they are the same infile = (CFILE *)cfopen(src, "rb"); if (!infile) @@ -1023,7 +1022,7 @@ int cf_DoForeachFileInLibrary(int handle, const std::filesystem::path &ext, // Iterate entries on found library int result = 0; for (const auto &item : search_library->entries) { - if (stricmp((const char*)std::filesystem::path(item->name).extension().u8string().c_str(), (const char*)ext.u8string().c_str()) == 0) { + if (stricmp(PATH_TO_CSTR(std::filesystem::path(item->name).extension()), PATH_TO_CSTR(ext)) == 0) { func(item->name); result++; } @@ -1035,7 +1034,7 @@ bool cf_IsFileInHog(const std::filesystem::path &filename, const std::filesystem std::shared_ptr lib = Libraries; while (lib) { - if (stricmp((const char*)lib->name.u8string().c_str(), (const char*)hogname.u8string().c_str()) == 0) { + if (stricmp(PATH_TO_CSTR(lib->name), PATH_TO_CSTR(hogname)) == 0) { // Now look for filename CFILE *cf; cf = cf_OpenFileInLibrary(filename, lib->handle); diff --git a/ddebug/windebug.cpp b/ddebug/windebug.cpp index 64434ba7d..526ff3b64 100644 --- a/ddebug/windebug.cpp +++ b/ddebug/windebug.cpp @@ -320,7 +320,7 @@ long WINAPI RecordExceptionInfo(PEXCEPTION_POINTERS data) { exit(1); } - HANDLE hDumpFile = CreateFile(dumFilePath.u8string().c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0); + HANDLE hDumpFile = CreateFile(PATH_TO_CSTR(dumFilePath), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0); if (hDumpFile == INVALID_HANDLE_VALUE) { OutrageMessageBox("Could not create crash dump file, error code: %x", GetLastError()); exit(1); @@ -332,7 +332,7 @@ long WINAPI RecordExceptionInfo(PEXCEPTION_POINTERS data) { exceptInfo.ClientPointers = TRUE; if (MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &exceptInfo, nullptr, nullptr)) { - OutrageMessageBox("Crash dump file written to: %s\nYou can attach it to a bug report.", dumFilePath.u8string().c_str()); + OutrageMessageBox("Crash dump file written to: %s\nYou can attach it to a bug report.", PATH_TO_CSTR(dumFilePath)); } else { OutrageMessageBox("Could not write crash dump file, error code: %x", GetLastError()); exit(1); diff --git a/ddio/file.cpp b/ddio/file.cpp index 4484a8a67..0e74d5995 100644 --- a/ddio/file.cpp +++ b/ddio/file.cpp @@ -170,9 +170,9 @@ std::filesystem::path ddio_GetTmpFileName(const std::filesystem::path &basedir, const int len = 10; const char *ext = ".tmp"; std::filesystem::path result; - size_t len_result = strlen((const char*)(basedir / prefix).u8string().c_str()); + size_t len_result = strlen(PATH_TO_CSTR(basedir / prefix)); char *random_name = (char *)mem_malloc(len_result + len + strlen(ext) + 1); - strncpy(random_name, (const char*)(basedir / prefix).u8string().c_str(), len_result); + strncpy(random_name, PATH_TO_CSTR(basedir / prefix), len_result); srand(D3::ChronoTimer::GetTimeMS()); diff --git a/ddio/lnxfile.cpp b/ddio/lnxfile.cpp index fee5ccce4..b05cef914 100644 --- a/ddio/lnxfile.cpp +++ b/ddio/lnxfile.cpp @@ -91,10 +91,10 @@ bool ddio_SetWorkingDir(const char *path) { return (chdir(path)) ? false : true; bool ddio_FileDiff(const std::filesystem::path &path1, const std::filesystem::path &path2) { struct stat abuf{}, bbuf{}; - if (stat((const char*)path1.u8string().c_str(), &abuf)) + if (stat(PATH_TO_CSTR(path1), &abuf)) Int3(); // error getting stat info - if (stat((const char*)path2.u8string().c_str(), &bbuf)) + if (stat(PATH_TO_CSTR(path2), &bbuf)) Int3(); // error getting stat info if ((abuf.st_size != bbuf.st_size) || (abuf.st_mtime != bbuf.st_mtime)) @@ -197,14 +197,14 @@ void ddio_SplitPath(const char *srcPath, char *path, char *filename, char *ext) void ddio_CopyFileTime(const std::filesystem::path &dest, const std::filesystem::path &src) { struct stat abuf{}; - if (stat((const char*)src.u8string().c_str(), &abuf)) + if (stat(PATH_TO_CSTR(src), &abuf)) Int3(); struct utimbuf bbuf{}; bbuf.actime = abuf.st_atime; bbuf.modtime = abuf.st_mtime; - if (utime((const char*)dest.u8string().c_str(), &bbuf)) + if (utime(PATH_TO_CSTR(dest), &bbuf)) Int3(); } diff --git a/ddio/winfile.cpp b/ddio/winfile.cpp index cc855402b..215932788 100644 --- a/ddio/winfile.cpp +++ b/ddio/winfile.cpp @@ -164,10 +164,10 @@ bool ddio_SetWorkingDir(const char *path) { return (SetCurrentDirectory(path)) ? bool ddio_FileDiff(const std::filesystem::path &path1, const std::filesystem::path &path2) { struct _stat abuf, bbuf; - if (_stat(path1.u8string().c_str(), &abuf)) + if (_stat(PATH_TO_CSTR(path1), &abuf)) Int3(); // error getting stat info - if (_stat(path2.u8string().c_str(), &bbuf)) + if (_stat(PATH_TO_CSTR(path2), &bbuf)) Int3(); // error getting stat info if ((abuf.st_size != bbuf.st_size) || (abuf.st_mtime != bbuf.st_mtime)) @@ -196,11 +196,11 @@ void ddio_CopyFileTime(const std::filesystem::path &dest, const std::filesystem: try_again:; - desthandle = CreateFile(dest.u8string().c_str(), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - srchandle = CreateFile(src.u8string().c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + desthandle = CreateFile(PATH_TO_CSTR(dest), GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + srchandle = CreateFile(PATH_TO_CSTR(src), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (desthandle == INVALID_HANDLE_VALUE || srchandle == INVALID_HANDLE_VALUE) { - LOG_WARNING.printf("Couldn't copy file time for %s! Error=%d", dest.u8string().c_str(), GetLastError()); + LOG_WARNING.printf("Couldn't copy file time for %s! Error=%d", PATH_TO_CSTR(dest), GetLastError()); if (desthandle != INVALID_HANDLE_VALUE) CloseHandle(desthandle); diff --git a/editor/BriefEdit.cpp b/editor/BriefEdit.cpp index d6aaf6186..3ea39e2f1 100644 --- a/editor/BriefEdit.cpp +++ b/editor/BriefEdit.cpp @@ -739,9 +739,8 @@ void BEAddTextEffect(TCTEXTDESC *desc, char *text, char *description, int id) { mem_free(befx->text); befx->text = NULL; } - befx->text = mem_rmalloc(strlen(text) + 1); + befx->text = mem_strdup(text); ASSERT(befx->text); - strcpy(befx->text, text); // Setup for items not set with caps if (!(dest->caps & TCTD_FONT)) { diff --git a/editor/DallasMainDlg.cpp b/editor/DallasMainDlg.cpp index b8e7de15a..131d6f5cc 100644 --- a/editor/DallasMainDlg.cpp +++ b/editor/DallasMainDlg.cpp @@ -4980,12 +4980,11 @@ int CDallasMainDlg::AddDoorToList(char *name) { return FALSE; int pos = m_DoorListSize; - m_DoorList[pos] = mem_rmalloc(strlen(name) + 1); + m_DoorList[pos] = mem_strdup(name); if (m_DoorList[pos] == NULL) { MessageBox("Out of memory in AddDoorToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_DoorList[pos], name); m_DoorListSize++; return TRUE; @@ -5018,12 +5017,11 @@ int CDallasMainDlg::AddObjectToList(char *name) { return FALSE; int pos = m_ObjectListSize; - m_ObjectList[pos] = mem_rmalloc(strlen(name) + 1); + m_ObjectList[pos] = mem_strdup(name); if (m_ObjectList[pos] == NULL) { MessageBox("Out of memory in AddObjectToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_ObjectList[pos], name); m_ObjectListSize++; return TRUE; @@ -5056,12 +5054,11 @@ int CDallasMainDlg::AddRoomToList(char *name) { return FALSE; int pos = m_RoomListSize; - m_RoomList[pos] = mem_rmalloc(strlen(name) + 1); + m_RoomList[pos] = mem_strdup(name); if (m_RoomList[pos] == NULL) { MessageBox("Out of memory in AddRoomToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_RoomList[pos], name); m_RoomListSize++; return TRUE; @@ -5094,12 +5091,11 @@ int CDallasMainDlg::AddTriggerToList(char *name) { return FALSE; int pos = m_TriggerListSize; - m_TriggerList[pos] = mem_rmalloc(strlen(name) + 1); + m_TriggerList[pos] = mem_strdup(name); if (m_TriggerList[pos] == NULL) { MessageBox("Out of memory in AddTriggerToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_TriggerList[pos], name); m_TriggerListSize++; return TRUE; @@ -5132,12 +5128,11 @@ int CDallasMainDlg::AddSoundToList(char *name) { return FALSE; int pos = m_SoundListSize; - m_SoundList[pos] = mem_rmalloc(strlen(name) + 1); + m_SoundList[pos] = mem_strdup(name); if (m_SoundList[pos] == NULL) { MessageBox("Out of memory in AddSoundToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_SoundList[pos], name); m_SoundListSize++; return TRUE; @@ -5170,12 +5165,11 @@ int CDallasMainDlg::AddTextureToList(char *name) { return FALSE; int pos = m_TextureListSize; - m_TextureList[pos] = mem_rmalloc(strlen(name) + 1); + m_TextureList[pos] = mem_strdup(name); if (m_TextureList[pos] == NULL) { MessageBox("Out of memory in AddTextureToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_TextureList[pos], name); m_TextureListSize++; return TRUE; @@ -5208,12 +5202,11 @@ int CDallasMainDlg::AddSpecnameToList(char *name) { return FALSE; int pos = m_SpecnameListSize; - m_SpecnameList[pos] = mem_rmalloc(strlen(name) + 1); + m_SpecnameList[pos] = mem_strdup(name); if (m_SpecnameList[pos] == NULL) { MessageBox("Out of memory in AddSpecnameToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_SpecnameList[pos], name); m_SpecnameListSize++; return TRUE; @@ -5246,12 +5239,11 @@ int CDallasMainDlg::AddPathToList(char *name) { return FALSE; int pos = m_PathListSize; - m_PathList[pos] = mem_rmalloc(strlen(name) + 1); + m_PathList[pos] = mem_strdup(name); if (m_PathList[pos] == NULL) { MessageBox("Out of memory in AddPathToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_PathList[pos], name); m_PathListSize++; return TRUE; @@ -5284,12 +5276,11 @@ int CDallasMainDlg::AddMatcenToList(char *name) { return FALSE; int pos = m_MatcenListSize; - m_MatcenList[pos] = mem_rmalloc(strlen(name) + 1); + m_MatcenList[pos] = mem_strdup(name); if (m_MatcenList[pos] == NULL) { MessageBox("Out of memory in AddMatcenToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_MatcenList[pos], name); m_MatcenListSize++; return TRUE; @@ -5322,12 +5313,11 @@ int CDallasMainDlg::AddGoalToList(char *name) { return FALSE; int pos = m_GoalListSize; - m_GoalList[pos] = mem_rmalloc(strlen(name) + 1); + m_GoalList[pos] = mem_strdup(name); if (m_GoalList[pos] == NULL) { MessageBox("Out of memory in AddGoalToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_GoalList[pos], name); m_GoalListSize++; return TRUE; @@ -5360,12 +5350,11 @@ int CDallasMainDlg::AddStrmAudioToList(char *name) { return FALSE; int pos = m_StrmAudioListSize; - m_StrmAudioList[pos] = mem_rmalloc(strlen(name) + 1); + m_StrmAudioList[pos] = mem_strdup(name); if (m_StrmAudioList[pos] == NULL) { MessageBox("Out of memory in AddStrmAudioToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_StrmAudioList[pos], name); m_StrmAudioListSize++; return TRUE; @@ -5398,12 +5387,11 @@ int CDallasMainDlg::AddMessageNameToList(char *name) { return FALSE; int pos = m_MessageNameListSize; - m_MessageNameList[pos] = mem_rmalloc(strlen(name) + 1); + m_MessageNameList[pos] = mem_strdup(name); if (m_MessageNameList[pos] == NULL) { MessageBox("Out of memory in AddMessageNameToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION); return FALSE; } - strcpy(m_MessageNameList[pos], name); m_MessageNameListSize++; return TRUE; @@ -5512,13 +5500,11 @@ int CDallasMainDlg::AddUserTypeValue(char *utype_name, char *value_name) { // Store the new value at the current position tEnumValueEntry *value_entry = &entry->values[j]; value_entry->value = new_value; - value_entry->name = mem_rmalloc(strlen(value_name) + 1); + value_entry->name = mem_strdup(value_name); if (value_entry->name == NULL) { MessageBox("ERROR: Out of mem in AddUserTypeValue()!", "Error!"); return (-1); } - strcpy(value_entry->name, value_name); - entry->num_values++; SetModified(TRUE); @@ -5582,12 +5568,11 @@ int CDallasMainDlg::ChangeValueName(char *utype_name, char *old_name, char *new_ mem_free(value_entry->name); // Add the new name - value_entry->name = mem_rmalloc(strlen(new_name) + 1); + value_entry->name = mem_strdup(new_name); if (value_entry->name == NULL) { MessageBox("ERROR: Out of mem in ChangeValueName()!", "Error!"); return FALSE; } - strcpy(value_entry->name, new_name); SetModified(TRUE); return TRUE; @@ -6185,13 +6170,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* done = 1; else if (m_NumFunctionCategories < MAX_CATEGORIES) { if (GetFunctionCategoryID(line) == INVALID_CATEGORY) { // don't add duplicate categories - m_FunctionCategories[m_NumFunctionCategories] = mem_rmalloc(strlen(line) + 1); + m_FunctionCategories[m_NumFunctionCategories] = mem_strdup(line); if (m_FunctionCategories[m_NumFunctionCategories] == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(m_FunctionCategories[m_NumFunctionCategories], line); m_NumFunctionCategories++; if (m_NumFunctionCategories == MAX_CATEGORIES) MessageBox("Warning: The Maximum Category limit has been reached!", "Warning!"); @@ -6222,13 +6206,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* enum_entry = NULL; } else { enum_entry = &m_EnumDatabase[m_NumEnums++]; - enum_entry->name = mem_rmalloc(strlen(enum_name) + 1); + enum_entry->name = mem_strdup(enum_name); if (enum_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(enum_entry->name, enum_name); enum_entry->num_values = 0; enum_entry->is_user_type = TRUE; enum_entry->max_values = atoi(max_value_text); @@ -6240,13 +6223,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* // Add the default (-1:None) value tEnumValueEntry *value_entry; value_entry = &enum_entry->values[enum_entry->num_values++]; - value_entry->name = mem_rmalloc(strlen(USERTYPE_NONE) + 1); + value_entry->name = mem_strdup(USERTYPE_NONE); if (value_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(value_entry->name, USERTYPE_NONE); value_entry->value = -1; } } else if (strncmp(line, TAG_ENUM, strlen(TAG_ENUM)) == 0) { // Parse an enumeration block @@ -6266,13 +6248,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* enum_entry = NULL; } else { enum_entry = &m_EnumDatabase[m_NumEnums++]; - enum_entry->name = mem_rmalloc(strlen(enum_name) + 1); + enum_entry->name = mem_strdup(enum_name); if (enum_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(enum_entry->name, enum_name); enum_entry->num_values = 0; enum_entry->is_user_type = FALSE; enum_entry->max_values = 0; @@ -6313,13 +6294,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* value_entry = NULL; } else { value_entry = &enum_entry->values[enum_entry->num_values++]; - value_entry->name = mem_rmalloc(strlen(enum_value_name) + 1); + value_entry->name = mem_strdup(enum_value_name); if (value_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(value_entry->name, enum_value_name); value_entry->value = enum_value; } } @@ -6345,13 +6325,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* flag_entry = NULL; } else { flag_entry = &m_FlagDatabase[m_NumFlags++]; - flag_entry->name = mem_rmalloc(strlen(flag_name) + 1); + flag_entry->name = mem_strdup(flag_name); if (flag_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(flag_entry->name, flag_name); flag_entry->num_values = 0; } @@ -6390,13 +6369,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* value_entry = NULL; } else { value_entry = &flag_entry->values[flag_entry->num_values++]; - value_entry->name = mem_rmalloc(strlen(flag_value_name) + 1); + value_entry->name = mem_strdup(flag_value_name); if (value_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(value_entry->name, flag_value_name); value_entry->value = flag_value; } } @@ -6439,13 +6417,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* RemoveTrailingWhitespace(linebuf); line = SkipInitialWhitespace(linebuf); - action->desc = mem_rmalloc(strlen(line) + 1); + action->desc = mem_strdup(line); if (action->desc == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(action->desc, line); // Read action function cf_ReadString(linebuf, sizeof(linebuf), ifile); @@ -6455,13 +6432,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* RemoveTrailingWhitespace(linebuf); line = SkipInitialWhitespace(linebuf); - action->func = mem_rmalloc(strlen(line) + 1); + action->func = mem_strdup(line); if (action->func == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(action->func, line); // Read help bool done = 0; @@ -6487,13 +6463,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* if (!done) FunctionFileParseError(UEOF_ERR, linenum, filename); - action->help = mem_rmalloc(strlen(helpbuf) + 1); + action->help = mem_strdup(helpbuf); if (action->help == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(action->help, helpbuf); } else if (strncmp(line, TAG_QUERY, strlen(TAG_QUERY)) == 0) { // Parse Query block if (m_NumQueries >= MAX_QUERIES) { MessageBox("ERROR: The Maximum Query limit has been exceeded!\n\nParsing must stop immediately.", "ERROR!"); @@ -6528,13 +6503,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* RemoveTrailingWhitespace(linebuf); line = SkipInitialWhitespace(linebuf); - query->desc = mem_rmalloc(strlen(line) + 1); + query->desc = mem_strdup(line); if (query->desc == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(query->desc, line); // Read action function cf_ReadString(linebuf, sizeof(linebuf), ifile); @@ -6544,13 +6518,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* RemoveTrailingWhitespace(linebuf); line = SkipInitialWhitespace(linebuf); - query->func = mem_rmalloc(strlen(line) + 1); + query->func = mem_strdup(line); if (query->func == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(query->func, line); // Read help bool done = 0; @@ -6576,13 +6549,12 @@ void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE* if (!done) FunctionFileParseError(UEOF_ERR, linenum, filename); - query->help = mem_rmalloc(strlen(helpbuf) + 1); + query->help = mem_strdup(helpbuf); if (query->help == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(ifile); return; } - strcpy(query->help, helpbuf); } } @@ -6772,12 +6744,11 @@ bool CDallasMainDlg::ValidateActionNode(HTREEITEM node, int linenum) child_node=m_ScriptTree.GetChildItem(node); // Make a copy of description (so null chars can be added) - desc_copy=mem_rmalloc(strlen(desc)+1); + desc_copy=mem_strdup(desc); if(desc_copy==NULL) { MessageBox("ERROR: Out of memory in ValidateActionNode()!","Out of Memory Error!",MB_OK|MB_ICONEXCLAMATION); return FALSE; } - strcpy(desc_copy,desc); // Parse the description, adding default parameter nodes appropriately int j=0; @@ -7047,12 +7018,11 @@ bool CDallasMainDlg::ValidateQueryNode(HTREEITEM node, int linenum) child_node=m_ScriptTree.GetChildItem(node); // Make a copy of description (so null chars can be added) - desc_copy=mem_rmalloc(strlen(desc)+1); + desc_copy=mem_strdup(desc); if(desc_copy==NULL) { MessageBox("ERROR: Out of memory in ValidateQueryNode()!","Out of Memory Error!",MB_OK|MB_ICONEXCLAMATION); return FALSE; } - strcpy(desc_copy,desc); // Parse the description, adding default parameter nodes appropriately int j=0; @@ -7848,13 +7818,12 @@ int CDallasMainDlg::ParseSourceScript(char *filename) { value_entry = NULL; } else { value_entry = &enum_entry->values[enum_entry->num_values++]; - value_entry->name = mem_rmalloc(strlen(enum_value_name) + 1); + value_entry->name = mem_strdup(enum_value_name); if (value_entry->name == NULL) { FunctionFileParseError(NO_MEM_ERR, linenum, filename); cfclose(infile); return FALSE; } - strcpy(value_entry->name, enum_value_name); value_entry->value = enum_value; } } @@ -9466,14 +9435,13 @@ int CDallasMainDlg::ParseCustomScriptFile(char *filename, bool show_errors /*=TR // Store this line if (m_NumCustomScriptLines < m_MaxNumCustomScriptLines) { - m_CustomScriptLines[m_NumCustomScriptLines] = mem_rmalloc(strlen(linebuf) + 1); + m_CustomScriptLines[m_NumCustomScriptLines] = mem_strdup(linebuf); if (m_CustomScriptLines[m_NumCustomScriptLines] == NULL) { MessageBox("ERROR: Ran out of memory parsing custom script block", "Custom Script Parse Error", MB_OK | MB_ICONEXCLAMATION); cfclose(infile); return FALSE; } - strcpy(m_CustomScriptLines[m_NumCustomScriptLines], linebuf); m_NumCustomScriptLines++; } else { MessageBox("ERROR: The maximum custom script block line limit has been exceeded.\n\nThe excess lines will " @@ -13726,12 +13694,11 @@ void CDallasMainDlg::AddActionParameterNodes(HTREEITEM action_node) if(desc==NULL) return; // Make a copy of description (so null chars can be added) - desc_copy=mem_rmalloc(strlen(desc)+1); + desc_copy=mem_strdup(desc); if(desc_copy==NULL) { MessageBox("ERROR: Out of memory adding action parameter node!","Out of Memory Error!",MB_OK|MB_ICONEXCLAMATION); return; } - strcpy(desc_copy,desc); // Parse the description, adding default parameter nodes appropriately j=0; @@ -13846,12 +13813,11 @@ void CDallasMainDlg::AddQueryParameterNodes(HTREEITEM query_node) if(desc==NULL) return; // Make a copy of description (so null chars can be added) - desc_copy=mem_rmalloc(strlen(desc)+1); + desc_copy=mem_strdup(desc); if(desc_copy==NULL) { MessageBox("ERROR: Out of memory adding query parameter node!","Out of Memory Error!",MB_OK|MB_ICONEXCLAMATION); return; } - strcpy(desc_copy,desc); // Parse the description, adding default parameter nodes appropriately j=0; diff --git a/editor/LightingDialog.cpp b/editor/LightingDialog.cpp index ce264aeaa..494f3c464 100644 --- a/editor/LightingDialog.cpp +++ b/editor/LightingDialog.cpp @@ -1625,9 +1625,9 @@ void ResaveVClip(const char *name) { void ResaveAllBitmaps() { ddio_DoForeachFile(std::filesystem::path(LocalD3Dir) / "data" / "graphics", std::regex(".+\\.ogf"), - [](const std::filesystem::path &path) { ResaveBitmap(path.filename().u8string().c_str()); }); + [](const std::filesystem::path &path) { ResaveBitmap(PATH_TO_CSTR(path.filename())); }); ddio_DoForeachFile(std::filesystem::path(LocalD3Dir) / "data" / "graphics", std::regex(".+\\.oaf"), - [](const std::filesystem::path &path) { ResaveVClip(path.filename().u8string().c_str()); }); + [](const std::filesystem::path &path) { ResaveVClip(PATH_TO_CSTR(path.filename())); }); } void CLightingDialog::OnVolumeLights() { diff --git a/editor/MainFrm.cpp b/editor/MainFrm.cpp index f2997a818..60892982b 100644 --- a/editor/MainFrm.cpp +++ b/editor/MainFrm.cpp @@ -1460,7 +1460,7 @@ void InitCScripts() { CreateNewMine(); // Setup include directories for OSIRIS - ddio_MakePath(path, cf_GetWritableBaseDirectory().u8string().c_str(), "data", "levels", NULL); + ddio_MakePath(path, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "data", "levels", NULL); } // Copied from winmain.cpp @@ -2017,11 +2017,11 @@ void CMainFrame::OnImportBitmap() { mprintf(0, "Making a copy of this bitmap/anim locally...\n"); if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), GameBitmaps[bm_handle].name); + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[bm_handle].name); bm_SaveFileBitmap(filename, bm_handle); bm_FreeBitmap(bm_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), GameVClips[bm_handle].name); + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[bm_handle].name); SaveVClip(filename, bm_handle); FreeVClip(bm_handle); } @@ -3169,12 +3169,11 @@ void CMainFrame::OnHotspotTga() { return; } - buffer = mem_rmalloc(strlen(tga_path.GetBuffer(1)) + 1); + buffer = mem_strdup(tga_path.GetBuffer(1)); if (!buffer) { Int3(); // find Jeff return; } - strcpy(buffer, tga_path.GetBuffer(1)); if (menutga_ConvertTGAtoHSM(buffer)) OutrageMessageBox("HotSpot Map Extracted"); @@ -3186,7 +3185,7 @@ void CMainFrame::OnHotspotTga() { } if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), GameBitmaps[bm_handle].name); + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[bm_handle].name); bm_SaveFileBitmap(filename, bm_handle); bm_FreeBitmap(bm_handle); } diff --git a/editor/MegacellDialog.cpp b/editor/MegacellDialog.cpp index bbc8dc4e4..b17a13306 100644 --- a/editor/MegacellDialog.cpp +++ b/editor/MegacellDialog.cpp @@ -1201,7 +1201,7 @@ void CMegacellDialog::OnImportTiny() { strcpy(GameBitmaps[bm_handle].name, filename); // Save this textures image locally - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); mprintf(0, "Saving bitmap %s from megacell!\n", GameBitmaps[bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); @@ -1327,7 +1327,7 @@ void CMegacellDialog::OnImportSky() { strcpy(GameBitmaps[bm_handle].name, filename); // Save this textures image locally - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); mprintf(0, "Saving bitmap %s from megacell!\n", GameBitmaps[bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); @@ -1449,7 +1449,7 @@ void CMegacellDialog::OnImportSkyBand() { strcpy(GameBitmaps[bm_handle].name, filename); // Save this textures image locally - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); mprintf(0, "Saving bitmap %s from megacell!\n", GameBitmaps[bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); diff --git a/editor/ObjCScript.cpp b/editor/ObjCScript.cpp index ccf75dd89..732ec9915 100644 --- a/editor/ObjCScript.cpp +++ b/editor/ObjCScript.cpp @@ -137,6 +137,8 @@ #define MAX_SCRIPT_LINE_SIZE 800 +static void GenerateScriptListFromFile(const char *fname); + // script name for current level char Level_script_name[MAX_SCRFILENAME]; @@ -238,13 +240,7 @@ char *LoadScript(const char *filename) { mem_free(tmp_script); cfclose(file); - - source = mem_rmalloc(strlen(temp.GetBuffer(1)) + 1); - if (!source) - return false; - strcpy(source, temp.GetBuffer(1)); - - return source; + return mem_strdup(temp.GetBuffer(1)); } void SaveScript(const char *filename, char *script) { @@ -696,10 +692,10 @@ void GenerateScriptListFromAllFiles(int mask) { // compile all script files and place into script list. ddio_DoForeachFile(dir, std::regex(".+\\.scr"), [&mask](const std::filesystem::path& path){ std::filesystem::path file = path.filename(); - if (!stricmp(file.u8string().c_str(), DEFAULT_SCRIPT_NAME) && (mask & DEFAULT_SCRIPT_MASK)) - GenerateScriptListFromFile(file.u8string().c_str()); - else if ((mask & CUSTOM_SCRIPT_MASK) && stricmp(file.u8string().c_str(), DEFAULT_SCRIPT_NAME)) - GenerateScriptListFromFile(file.u8string().c_str()); + if (!stricmp(PATH_TO_CSTR(file), DEFAULT_SCRIPT_NAME) && (mask & DEFAULT_SCRIPT_MASK)) + GenerateScriptListFromFile(PATH_TO_CSTR(file)); + else if ((mask & CUSTOM_SCRIPT_MASK) && stricmp(PATH_TO_CSTR(file), DEFAULT_SCRIPT_NAME)) + GenerateScriptListFromFile(PATH_TO_CSTR(file)); }); } diff --git a/editor/ObjCScript.h b/editor/ObjCScript.h index 5efef4b26..99870af02 100644 --- a/editor/ObjCScript.h +++ b/editor/ObjCScript.h @@ -178,9 +178,6 @@ char *AddEventBlockToScript(char *script, const char *evtname, const char *scrip // generates script list from all script files. void GenerateScriptListFromAllFiles(int mask = ALL_SCRIPT_MASK); -// generates script list from one file -void GenerateScriptListFromFile(const char *fname); - // This function generates ScriptWizard comment header information for script files // if it doesn't already have it. This should be called whenever a script file is loaded and compiled // via script wizard. diff --git a/editor/ObjectDialog.cpp b/editor/ObjectDialog.cpp index 2fc420dc0..ed56ba6cc 100644 --- a/editor/ObjectDialog.cpp +++ b/editor/ObjectDialog.cpp @@ -1160,8 +1160,7 @@ void CObjectDialog::OnObjectSwapButton() { int o_index = ObjCreate(Object_info[d_id].type, d_id, room, &pos, &orient, parent); if (temp_name[0] != '\0') { - Objects[o_index].name = mem_rmalloc(strlen(temp_name) + 1); - strcpy(Objects[o_index].name, temp_name); + Objects[o_index].name = mem_strdup(temp_name); } } } diff --git a/editor/OrphanRemoveDlg.cpp b/editor/OrphanRemoveDlg.cpp index 32a939512..51dd850cf 100644 --- a/editor/OrphanRemoveDlg.cpp +++ b/editor/OrphanRemoveDlg.cpp @@ -359,7 +359,7 @@ const char *orphan_ignore[] = { "monster.str", "mtclient.str", "tanarchy.str"}; int num_orphan_ignore = std::size(orphan_ignore); -bool IsFileUsed(const char *filename) { +static bool IsFileUsed(const char *filename) { bool found = false; for (int i = 0; i < num_orphan_ignore; i++) { @@ -426,8 +426,8 @@ void COrphanRemoveDlg::OnSelchangeDirectory() { ddio_DoForeachFile(fullpath, std::regex(".+"), [this, &num_files, &total_filesize, &data, &stats](const std::filesystem::path &path) { - if (!IsFileUsed(path.filename().u8string().c_str())) { - m_List.AddString(path.filename().u8string().c_str()); + if (!IsFileUsed(PATH_TO_CSTR(path.filename()))) { + m_List.AddString(PATH_TO_CSTR(path.filename())); num_files++; total_filesize += filelen(path.filename(), path.parent_path()); sprintf(data, "Num Files: %d\r\nSize: %dK", num_files, total_filesize / 1024); diff --git a/editor/Read3ds.cpp b/editor/Read3ds.cpp index 3bca25ba3..d4d03481c 100644 --- a/editor/Read3ds.cpp +++ b/editor/Read3ds.cpp @@ -371,11 +371,10 @@ skip_combine:; } ASSERT(rp->name == NULL); - rp->name = mem_rmalloc(strlen(roomname) + 1); - strcpy(rp->name, roomname); + rp->name = mem_strdup(roomname); // Save it out to disk (locally) - ddio_MakePath(name, LocalRoomsDir.u8string().c_str(), roomname, NULL); + ddio_MakePath(name, PATH_TO_CSTR(LocalRoomsDir), roomname, NULL); SaveRoom(ROOMNUM(rp), name); } diff --git a/editor/ScriptLevelInterface.cpp b/editor/ScriptLevelInterface.cpp index ef7714c86..c6b3d6c04 100644 --- a/editor/ScriptLevelInterface.cpp +++ b/editor/ScriptLevelInterface.cpp @@ -616,7 +616,7 @@ void CScriptLevelInterface::UpdateScriptListWithLevels() { // ok we have a d3l, look to see if there is a script available for it gamefile.replace_extension(".cpp"); if (std::filesystem::is_regular_file(std::filesystem::path(LocalScriptDir) / gamefile)) { - combo->AddString(gamefile.u8string().c_str()); + combo->AddString(PATH_TO_CSTR(gamefile)); } } } @@ -669,7 +669,7 @@ void CScriptLevelInterface::UpdateScriptListWithScripts() { if (m_ShowNonCheckedOut) { ddio_DoForeachFile(std::filesystem::path(LocalScriptDir), std::regex(".+\\.cpp"), [&combo](const std::filesystem::path& path){ - combo->AddString(path.filename().u8string().c_str()); + combo->AddString(PATH_TO_CSTR(path.filename())); }); } else { diff --git a/editor/ScriptWizard.cpp b/editor/ScriptWizard.cpp index 545bcca9b..a8ea71dd3 100644 --- a/editor/ScriptWizard.cpp +++ b/editor/ScriptWizard.cpp @@ -165,7 +165,7 @@ BOOL CScriptWizard::OnInitDialog() { std::filesystem::path dir = std::filesystem::path(LocalLevelsDir); ddio_DoForeachFile(dir, std::regex(".+\\.scr"), [&modcbox](const std::filesystem::path& path){ std::filesystem::path file = path.filename(); - modcbox->AddString(file.u8string().c_str()); + modcbox->AddString(PATH_TO_CSTR(file)); }); modcbox->SelectString(-1, LEVEL_SCRIPT_NAME); diff --git a/editor/TableManage.cpp b/editor/TableManage.cpp index 3772e1a92..e164b79e0 100644 --- a/editor/TableManage.cpp +++ b/editor/TableManage.cpp @@ -394,9 +394,8 @@ void GenericPageList::SaveSelected(CEdit *description) { // Get Copy of new Description text description->GetWindowText(new_descrip); - new_text = mem_rmalloc(strlen(new_descrip.GetBuffer(0)) + 1); + new_text = mem_strdup(new_descrip.GetBuffer(0)); ASSERT(new_text); // out of memory! - sprintf(new_text, "%s", new_descrip.GetBuffer(0)); // Check if new description is empty, if it is, make it NULL if (strlen(new_text) == 0 || stricmp(new_text, NO_DESCRIPTION_STRING) == 0) { diff --git a/editor/TextureGrWnd.cpp b/editor/TextureGrWnd.cpp index cc808aeed..e86b9b301 100644 --- a/editor/TextureGrWnd.cpp +++ b/editor/TextureGrWnd.cpp @@ -1548,8 +1548,7 @@ BOOL CTextureGrWnd::OnCommand(WPARAM wParam, LPARAM lParam) { } if (strlen(tempname)) { - curobj->name = mem_rmalloc(strlen(tempname) + 1); - strcpy(curobj->name, tempname); + curobj->name = mem_strdup(tempname); } World_changed = 1; diff --git a/editor/WorldObjectsGenericDialog.cpp b/editor/WorldObjectsGenericDialog.cpp index 03bbe5d75..935f8a767 100644 --- a/editor/WorldObjectsGenericDialog.cpp +++ b/editor/WorldObjectsGenericDialog.cpp @@ -654,7 +654,7 @@ void CWorldObjectsGenericDialog::OnGenericAddNew() { ddio_SplitPath(filename, dir, fname, ext); std::filesystem::path tmp = ChangePolyModelName(filename); - strcpy(cur_name, tmp.u8string().c_str()); + strcpy(cur_name, PATH_TO_CSTR(tmp)); if ((FindPolyModelName(fname)) != -1) { OutrageMessageBox("You must rename your model to something else because there is already a model with that name!"); @@ -1007,7 +1007,7 @@ void CWorldObjectsGenericDialog::OnGenericChangeModel() { return; std::filesystem::path tmp = ChangePolyModelName(filename); - strcpy(curname, tmp.u8string().c_str()); + strcpy(curname, PATH_TO_CSTR(tmp)); ddio_SplitPath(filename, dir, fname, ext); @@ -1049,7 +1049,7 @@ void CWorldObjectsGenericDialog::OnGenericChangeModel() { } // Finally, save a local copy of the model - sprintf(curname, "%s\\%s", LocalModelsDir.u8string().c_str(), Poly_models[img_handle].name); + sprintf(curname, "%s\\%s", PATH_TO_CSTR(LocalModelsDir), Poly_models[img_handle].name); cf_CopyFile(curname, filename); UpdateDialog(); diff --git a/editor/WorldObjectsPlayerDialog.cpp b/editor/WorldObjectsPlayerDialog.cpp index 0120a0eb8..aa6c6c739 100644 --- a/editor/WorldObjectsPlayerDialog.cpp +++ b/editor/WorldObjectsPlayerDialog.cpp @@ -976,7 +976,7 @@ void CWorldObjectsPlayerDialog::OnPshipCockpit() { sprintf(Ships[D3EditState.current_ship].cockpit_name, "%s%s", curname, ext); // Finally, save a local copy of the inf file. - sprintf(curname, "%s\\%s", LocalMiscDir.u8string().c_str(), Ships[D3EditState.current_ship].cockpit_name); + sprintf(curname, "%s\\%s", PATH_TO_CSTR(LocalMiscDir), Ships[D3EditState.current_ship].cockpit_name); cf_CopyFile(curname, filename); UpdateDialog(); diff --git a/editor/WorldTexturesDialog.cpp b/editor/WorldTexturesDialog.cpp index e58731253..bbbc3e376 100644 --- a/editor/WorldTexturesDialog.cpp +++ b/editor/WorldTexturesDialog.cpp @@ -458,11 +458,11 @@ void CWorldTexturesDialog::OnWtexdlgAddnew() { mprintf(0, "Making a copy of this bitmap/anim locally...\n"); if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[GameTextures[tex_handle].bm_handle].name); SaveVClip(filename, GameTextures[tex_handle].bm_handle); } @@ -1332,11 +1332,11 @@ void CWorldTexturesDialog::OnLoadBitmap() { mprintf(0, "Making a copy of this bitmap locally...\n"); if (anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[GameTextures[n].bm_handle].name); SaveVClip(filename, GameTextures[n].bm_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[n].bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[n].bm_handle); } @@ -1691,7 +1691,7 @@ int CWorldTexturesDialog::LoadITLFile(char *filename, int type) { for (i = 0; i < total; i++) { tex_handle = tex_list[i]; - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); } @@ -1846,11 +1846,11 @@ void CWorldTexturesDialog::OnAddNewSmall() { mprintf(0, "Making a copy of this bitmap/anim locally...\n"); if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[GameTextures[tex_handle].bm_handle].name); SaveVClip(filename, GameTextures[tex_handle].bm_handle); } @@ -1937,11 +1937,11 @@ void CWorldTexturesDialog::OnAddNewTiny() { mprintf(0, "Making a copy of this bitmap/anim locally...\n"); if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[GameTextures[tex_handle].bm_handle].name); SaveVClip(filename, GameTextures[tex_handle].bm_handle); } @@ -2551,11 +2551,11 @@ void CWorldTexturesDialog::OnAddNewHuge() { mprintf(0, "Making a copy of this bitmap/anim locally...\n"); if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[GameTextures[tex_handle].bm_handle].name); bm_SaveFileBitmap(filename, GameTextures[tex_handle].bm_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[GameTextures[tex_handle].bm_handle].name); SaveVClip(filename, GameTextures[tex_handle].bm_handle); } diff --git a/editor/WorldWeaponsDialog.cpp b/editor/WorldWeaponsDialog.cpp index 70333d881..3735e3676 100644 --- a/editor/WorldWeaponsDialog.cpp +++ b/editor/WorldWeaponsDialog.cpp @@ -486,11 +486,11 @@ void CWorldWeaponsDialog::OnAddWeapon() { mprintf(0, "Making a copy of this bitmap/anim locally...\n"); if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[Weapons[weapon_handle].hud_image_handle].name); bm_SaveFileBitmap(filename, Weapons[weapon_handle].hud_image_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[Weapons[weapon_handle].hud_image_handle].name); SaveVClip(filename, Weapons[weapon_handle].hud_image_handle); } @@ -539,11 +539,11 @@ void CWorldWeaponsDialog::OnAddWeapon() { if (!model) { if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[Weapons[weapon_handle].fire_image_handle].name); bm_SaveFileBitmap(filename, Weapons[weapon_handle].fire_image_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[Weapons[weapon_handle].fire_image_handle].name); SaveVClip(filename, Weapons[weapon_handle].fire_image_handle); } @@ -1414,11 +1414,11 @@ void CWorldWeaponsDialog::OnLoadWeaponDischarge() { if (!model) { if (!anim) { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameBitmaps[Weapons[n].fire_image_handle].name); bm_SaveFileBitmap(filename, Weapons[n].fire_image_handle); } else { - sprintf(filename, "%s\\%s", LocalManageGraphicsDir.u8string().c_str(), + sprintf(filename, "%s\\%s", PATH_TO_CSTR(LocalManageGraphicsDir), GameVClips[Weapons[n].fire_image_handle].name); SaveVClip(filename, Weapons[n].fire_image_handle); } diff --git a/editor/editorView.cpp b/editor/editorView.cpp index ef7b253da..0d1188487 100644 --- a/editor/editorView.cpp +++ b/editor/editorView.cpp @@ -1269,8 +1269,7 @@ try_again:; } if (strlen(tempname)) { - Curroomp->name = mem_rmalloc(strlen(tempname) + 1); - strcpy(Curroomp->name, tempname); + Curroomp->name = mem_strdup(tempname); } World_changed = 1; diff --git a/editor/editor_lighting.cpp b/editor/editor_lighting.cpp index 108e934f3..e33c985e5 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, cf_GetWritableBaseDirectory().u8string().c_str(), "BSPSave.D3L", NULL); + ddio_MakePath(filename, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "BSPSave.D3L", NULL); // Save the level to SaveLevel(filename); @@ -1137,7 +1137,7 @@ void DoRadiosityForRooms() { SqueezeLightmaps(0, -1); char filename[_MAX_PATH + 1]; - ddio_MakePath(filename, cf_GetWritableBaseDirectory().u8string().c_str(), "LightSave.D3L", NULL); + ddio_MakePath(filename, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "LightSave.D3L", NULL); // Save the level to disk SaveLevel(filename); diff --git a/editor/gameeditor.cpp b/editor/gameeditor.cpp index a4c09d24a..a818a3aa6 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, cf_GetWritableBaseDirectory().u8string().c_str(), "GameSave.D3L", NULL); // make explicit path + ddio_MakePath(filename, PATH_TO_CSTR(cf_GetWritableBaseDirectory()), "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(cf_GetWritableBaseDirectory().u8string().c_str()); + ddio_SetWorkingDir(PATH_TO_CSTR(cf_GetWritableBaseDirectory())); Osiris_ResetAllTimers(); diff --git a/editor/roomkeypaddialog.cpp b/editor/roomkeypaddialog.cpp index 7bbda7644..0b0317035 100644 --- a/editor/roomkeypaddialog.cpp +++ b/editor/roomkeypaddialog.cpp @@ -437,8 +437,7 @@ void CRoomKeypadDialog::OnLoadRoom() { } ASSERT(Rooms[n].name == NULL); - Rooms[n].name = mem_rmalloc(strlen(roomname) + 1); - strcpy(Rooms[n].name, roomname); + Rooms[n].name = mem_strdup(roomname); D3EditState.current_room = n; diff --git a/lib/pstypes.h b/lib/pstypes.h index 978dad26e..ba9d5d279 100644 --- a/lib/pstypes.h +++ b/lib/pstypes.h @@ -40,4 +40,12 @@ #endif #endif +/* + * g++ -std=c++17: fs::path::u8string() returns std::string + * g++ -std=c++20: fs::path::u8string() returns std::u8string + * But there are no practical APIs to even deal with char8_t, so just + * wing it with the char representation. + */ +#define PATH_TO_CSTR(/*std::filesystem::path*/ p) reinterpret_cast((p).u8string().c_str()) + #endif diff --git a/linux/lnxdata.cpp b/linux/lnxdata.cpp index 8e38c0786..f24681025 100644 --- a/linux/lnxdata.cpp +++ b/linux/lnxdata.cpp @@ -77,7 +77,7 @@ oeLnxAppDatabase::oeLnxAppDatabase() { } std::filesystem::path fileName = prefPath / REGISTRY_FILENAME; - database = new CRegistry((const char*)fileName.u8string().c_str()); + database = new CRegistry(PATH_TO_CSTR(fileName)); database->Import(); create_record("Version"); } diff --git a/logger/log.cpp b/logger/log.cpp index 5e8b77c36..0fbf38300 100644 --- a/logger/log.cpp +++ b/logger/log.cpp @@ -33,7 +33,7 @@ void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console) { std::filesystem::path log_file = "Descent3.log"; static plog::ColorConsoleAppender consoleAppender; - static plog::RollingFileAppender fileAppender((const char*)log_file.u8string().c_str()); + static plog::RollingFileAppender fileAppender(PATH_TO_CSTR(log_file)); #ifdef WIN32 static plog::DebugOutputAppender debugAppender; diff --git a/logger/log.h b/logger/log.h index 0d5b6cfc4..f167dfd37 100644 --- a/logger/log.h +++ b/logger/log.h @@ -20,6 +20,7 @@ // This is interface header for chosen logger library. Currently, this is plog. #include +#include "pstypes.h" /* In case of swapping to another solution here should be redefined following macros: diff --git a/manage/manage.cpp b/manage/manage.cpp index 8155162bc..97211828b 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -714,8 +714,8 @@ int mng_InitLocalTables() { #endif if (Network_up) { - ddio_MakePath(LocalTableFilename, (const char*)LocalTableDir.u8string().c_str(), LOCAL_TABLE, NULL); - ddio_MakePath(LocalTempTableFilename, (const char*)LocalTableDir.u8string().c_str(), TEMP_LOCAL_TABLE, NULL); + ddio_MakePath(LocalTableFilename, PATH_TO_CSTR(LocalTableDir), LOCAL_TABLE, NULL); + ddio_MakePath(LocalTempTableFilename, PATH_TO_CSTR(LocalTableDir), TEMP_LOCAL_TABLE, NULL); } else { strcpy(LocalTableFilename, LOCAL_TABLE); strcpy(LocalTempTableFilename, TEMP_LOCAL_TABLE); @@ -747,11 +747,11 @@ int mng_InitNetTables() { NetMusicDir = netdir / "data" / "music"; NetVoiceDir = netdir / "data" / "voice"; TableLockFilename = NetTableDir / "table.lok"; - ddio_MakePath(BackupLockFilename, (const char*)NetTableDir.u8string().c_str(), "tablelok.bak", NULL); - ddio_MakePath(BackupTableFilename, (const char*)NetTableDir.u8string().c_str(), "table.bak", NULL); - ddio_MakePath(TableFilename, (const char*)NetTableDir.u8string().c_str(), NET_TABLE, NULL); - ddio_MakePath(TempTableLockFilename, (const char*)NetTableDir.u8string().c_str(), "lock.tmp", NULL); - ddio_MakePath(TempTableFilename, (const char*)NetTableDir.u8string().c_str(), TEMP_NET_TABLE, NULL); + ddio_MakePath(BackupLockFilename, PATH_TO_CSTR(NetTableDir), "tablelok.bak", NULL); + ddio_MakePath(BackupTableFilename, PATH_TO_CSTR(NetTableDir), "table.bak", NULL); + ddio_MakePath(TableFilename, PATH_TO_CSTR(NetTableDir), NET_TABLE, NULL); + ddio_MakePath(TempTableLockFilename, PATH_TO_CSTR(NetTableDir), "lock.tmp", NULL); + ddio_MakePath(TempTableFilename, PATH_TO_CSTR(NetTableDir), TEMP_NET_TABLE, NULL); LockerFile = NetTableDir / "locker"; VersionFile = NetTableDir / "TableVersion"; @@ -878,7 +878,7 @@ void mng_BackupTableFile() { TableTimeThreshold.dwLowDateTime = 0; } else { WIN32_FIND_DATA filedata; - HANDLE filehandle = FindFirstFile(str.u8string().c_str(), &filedata); + HANDLE filehandle = FindFirstFile(PATH_TO_CSTR(str), &filedata); if (filehandle == INVALID_HANDLE_VALUE) { Error("Couldn't open net table file for some reason!"); return; @@ -1573,7 +1573,7 @@ void mng_TransferPages() { snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); goto done; } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { + if (rename(TempTableLockFilename, PATH_TO_CSTR(TableLockFilename))) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); goto done; @@ -1860,13 +1860,13 @@ bool InLockList(mngs_Pagelock *pl) { int GetPrimType(const std::filesystem::path &name) { int primtype; std::filesystem::path ext = name.extension(); - if (!stricmp(".oof", (const char*)ext.u8string().c_str())) + if (!stricmp(".oof", PATH_TO_CSTR(ext))) primtype = PRIMTYPE_OOF; - else if (!stricmp(".ogf", (const char*)ext.u8string().c_str())) + else if (!stricmp(".ogf", PATH_TO_CSTR(ext))) primtype = PRIMTYPE_OGF; - else if (!stricmp(".oaf", (const char*)ext.u8string().c_str())) + else if (!stricmp(".oaf", PATH_TO_CSTR(ext))) primtype = PRIMTYPE_OAF; - else if (!stricmp(".wav", (const char*)ext.u8string().c_str())) + else if (!stricmp(".wav", PATH_TO_CSTR(ext))) primtype = PRIMTYPE_WAV; else primtype = PRIMTYPE_FILE; @@ -1879,7 +1879,7 @@ void BuildOldFilesForDirectory(const std::filesystem::path& path, FILETIME thres HANDLE filehandle; WIN32_FIND_DATA filedata; std::filesystem::path newpath = path / "*.*"; - filehandle = FindFirstFile(newpath.u8string().c_str(), &filedata); + filehandle = FindFirstFile(PATH_TO_CSTR(newpath), &filedata); bool go_ahead = true; if (filehandle == INVALID_HANDLE_VALUE) go_ahead = false; diff --git a/manage/pagelock.cpp b/manage/pagelock.cpp index 4c6c70f2a..f2bbef5f3 100644 --- a/manage/pagelock.cpp +++ b/manage/pagelock.cpp @@ -524,7 +524,7 @@ int mng_ReplacePagelock(char *name, mngs_Pagelock *pl) { cfclose(infile); cfclose(outfile); - if (!SwitcherooFiles((const char*)TableLockFilename.u8string().c_str(), TempTableLockFilename)) { + if (!SwitcherooFiles(PATH_TO_CSTR(TableLockFilename), TempTableLockFilename)) { Int3(); return 0; } @@ -532,7 +532,7 @@ int mng_ReplacePagelock(char *name, mngs_Pagelock *pl) { // Log this change #ifndef RELEASE std::filesystem::path pathstr = std::filesystem::path(NetD3Dir) / "TableLog"; - FILE *logfile = fopen((const char*)pathstr.u8string().c_str(), "at"); + FILE *logfile = fopen(PATH_TO_CSTR(pathstr), "at"); if (logfile) { char str[255 + 32]; char date[255]; @@ -590,7 +590,7 @@ int mng_DeletePagelock(char *name, int pagetype) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); return (0); } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { + if (rename(TempTableLockFilename, PATH_TO_CSTR(TableLockFilename))) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); return (0); @@ -644,7 +644,7 @@ int mng_DeletePagelockSeries(char *names[], int num, int pagetype) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); return (0); } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { + if (rename(TempTableLockFilename, PATH_TO_CSTR(TableLockFilename))) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); return (0); @@ -781,7 +781,7 @@ int mng_UnlockPagelockSeries(const char *names[], int *pagetypes, int num) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); return (0); } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { + if (rename(TempTableLockFilename, PATH_TO_CSTR(TableLockFilename))) { snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); return (0); diff --git a/model/polymodel.cpp b/model/polymodel.cpp index 420fb7df2..bda2027c3 100644 --- a/model/polymodel.cpp +++ b/model/polymodel.cpp @@ -2122,12 +2122,12 @@ int LoadPolyModel(const std::filesystem::path &filename, int pageable) { } // if this is an oof instead of a pof, flag it as such - if (!stricmp(".oof", (const char*)filename.extension().u8string().c_str())) { + if (!stricmp(".oof", PATH_TO_CSTR(filename.extension()))) { Poly_models[polynum].new_style = 1; } else Poly_models[polynum].new_style = 0; - strcpy(Poly_models[polynum].name, (const char*)name.u8string().c_str()); + strcpy(Poly_models[polynum].name, PATH_TO_CSTR(name)); int ret = 0; if (!pageable) @@ -2228,7 +2228,7 @@ std::filesystem::path ChangePolyModelName(const std::filesystem::path &src) { // or index of polymodel with name int FindPolyModelName(const std::filesystem::path &name) { for (int i = 0; i < MAX_POLY_MODELS; i++) { - if (Poly_models[i].used && !stricmp((const char*)Poly_models[i].name, (const char*)name.u8string().c_str())) { + if (Poly_models[i].used && !stricmp(Poly_models[i].name, PATH_TO_CSTR(name))) { return i; } } diff --git a/module/module.cpp b/module/module.cpp index da12376ed..21fc8d987 100644 --- a/module/module.cpp +++ b/module/module.cpp @@ -110,7 +110,7 @@ int ModLastError = MODERR_NOERROR; std::filesystem::path mod_GetRealModuleName(const std::filesystem::path &mod_filename) { std::filesystem::path filename = mod_filename; - std::string ext = (const char*)mod_filename.extension().u8string().c_str(); + std::string ext = PATH_TO_CSTR(mod_filename.extension()); if (ext.empty()) { filename.replace_extension(MODULE_EXT); @@ -152,7 +152,7 @@ bool mod_LoadModule(module *handle, const std::filesystem::path &imodfilename, i handle->handle = nullptr; std::filesystem::path modfilename = mod_GetRealModuleName(imodfilename); #if defined(WIN32) - handle->handle = LoadLibrary(modfilename.u8string().c_str()); + handle->handle = LoadLibrary(PATH_TO_CSTR(modfilename)); if (!handle->handle) { // There was an error loading the module DWORD err = GetLastError(); @@ -180,7 +180,7 @@ bool mod_LoadModule(module *handle, const std::filesystem::path &imodfilename, i f |= RTLD_NOW; if (flags & MODF_GLOBAL) f |= RTLD_GLOBAL; - handle->handle = dlopen((const char*)modfilename.u8string().c_str(), f); + handle->handle = dlopen(PATH_TO_CSTR(modfilename), f); if (!handle->handle) { // ok we couldn't find the given name...try other ways std::filesystem::path parent_path = modfilename.parent_path().filename(); @@ -193,10 +193,10 @@ bool mod_LoadModule(module *handle, const std::filesystem::path &imodfilename, i } // ok we have a different filename - LOG_DEBUG.printf("MOD: Attempting to open %s instead of %s", new_filename.u8string().c_str(), - modfilename.u8string().c_str()); + LOG_DEBUG.printf("MOD: Attempting to open %s instead of %s", PATH_TO_CSTR(new_filename), + PATH_TO_CSTR(modfilename)); modfilename = parent_path / new_filename; - handle->handle = dlopen((const char*)modfilename.u8string().c_str(), f); + handle->handle = dlopen(PATH_TO_CSTR(modfilename), f); if (!handle->handle) { LOG_ERROR.printf("Module Load Err: %s", dlerror()); ModLastError = MODERR_MODNOTFOUND; diff --git a/netcon/includes/con_dll.h b/netcon/includes/con_dll.h index edf67e576..fcfd8182a 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -1181,8 +1181,8 @@ int StartMultiplayerGameMenu() { for (const auto &netgames_directory : DLLcf_LocateMultiplePaths("netgames")) { DLLddio_DoForeachFile(netgames_directory, std::regex(".+\\.d3m"), [&dll_ui_items](const std::filesystem::path& path){ - dll_ui_items.insert_or_assign((const char*)path.stem().u8string().c_str(), - DLLCreateNewUITextItem((const char*)path.stem().u8string().c_str(), UICOL_LISTBOX_LO, -1) + dll_ui_items.insert_or_assign(PATH_TO_CSTR(path.stem()), + DLLCreateNewUITextItem(PATH_TO_CSTR(path.stem()), UICOL_LISTBOX_LO, -1) ); } ); } @@ -1209,12 +1209,12 @@ int StartMultiplayerGameMenu() { for (auto const &i : search_paths) { DLLddio_DoForeachFile(i.first, i.second, [&mi, &list_1](const std::filesystem::path &path) { std::filesystem::path mission_name = path.filename(); - if (DLLIsMissionMultiPlayable((const char*)mission_name.u8string().c_str()) && - (stricmp("d3_2.mn3", (const char*)mission_name.u8string().c_str()) != 0)) { - DLLmprintf(0, "Found a mission: %s\n", (const char*)mission_name.u8string().c_str()); + if (DLLIsMissionMultiPlayable(PATH_TO_CSTR(mission_name)) && + stricmp("d3_2.mn3", PATH_TO_CSTR(mission_name)) != 0) { + DLLmprintf(0, "Found a mission: %s\n", PATH_TO_CSTR(mission_name)); mi = (msn_list *)DLLmem_malloc(sizeof(msn_list)); - strcpy(mi->msn_name, DLLGetMissionName((const char*)mission_name.u8string().c_str())); - strcpy(mi->msn_file, (const char*)mission_name.u8string().c_str()); + strcpy(mi->msn_name, DLLGetMissionName(PATH_TO_CSTR(mission_name))); + strcpy(mi->msn_file, PATH_TO_CSTR(mission_name)); mi->ti = DLLCreateNewUITextItem(mi->msn_name, UICOL_LISTBOX_LO, -1); AddMsnItem(mi); DLLListAddItem(list_1, mi->ti); diff --git a/netcon/mtclient/mtclient.cpp b/netcon/mtclient/mtclient.cpp index 84035c5d3..047ee9d78 100644 --- a/netcon/mtclient/mtclient.cpp +++ b/netcon/mtclient/mtclient.cpp @@ -2126,7 +2126,7 @@ void CheckPXOForAnomalies() { // 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 = DLLcf_GetWritableBaseDirectory() / "pxo.err"; - FILE *errfile = fopen((const char*)errfilepath.u8string().c_str(), "at"); + FILE *errfile = fopen(PATH_TO_CSTR(errfilepath), "at"); if (errfile) { fprintf(errfile, "Dup TID: %s & %s / %s\n", DLLMPlayers[j].callsign, DLLMPlayers[i].callsign, DLLMPlayers[i].tracker_id); diff --git a/stream_audio/osfarchive.cpp b/stream_audio/osfarchive.cpp index d902eb5b7..55f40294c 100644 --- a/stream_audio/osfarchive.cpp +++ b/stream_audio/osfarchive.cpp @@ -99,7 +99,7 @@ bool OSFArchive::Open(const std::filesystem::path &filename, bool write) { cfseek(m_fp, -OSF_HDR_SIZE, SEEK_END); cf_ReadBytes((uint8_t *)tag, strlen(OSF_TAG), m_fp); if (strcmp(OSF_TAG, tag) != 0) { - LOG_WARNING.printf("Illegal OSF file format for %s.", filename.u8string().c_str()); + LOG_WARNING.printf("Illegal OSF file format for %s.", PATH_TO_CSTR(filename)); cfclose(m_fp); m_fp = NULL; return false; @@ -122,7 +122,7 @@ bool OSFArchive::Open(const std::filesystem::path &filename, bool write) { // read in aux header based off of type. m_hdr.digi.measure = (uint32_t)cf_ReadInt(m_fp); } else { - LOG_WARNING.printf("Unsupported OSF file type in %s!", filename.u8string().c_str()); + LOG_WARNING.printf("Unsupported OSF file type in %s!", PATH_TO_CSTR(filename)); cfclose(m_fp); m_fp = NULL; return false; @@ -133,7 +133,7 @@ bool OSFArchive::Open(const std::filesystem::path &filename, bool write) { cfseek(m_fp, -OSF_HDR_TITLE_OFS, SEEK_END); if (!cf_ReadBytes((uint8_t *)m_name, OSF_HDR_TITLE_LEN, m_fp)) { - LOG_WARNING.printf("Stream title not found for %s.", filename.u8string().c_str()); + LOG_WARNING.printf("Stream title not found for %s.", PATH_TO_CSTR(filename)); cfclose(m_fp); m_fp = NULL; return false;