diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index 959c1a121..7fbce3ac8 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -287,8 +287,8 @@ void GetGameAPI(game_api *api) { api->fp[149] = (int *)ui_HideCursor; api->fp[150] = (int *)GameFrame; api->fp[151] = (int *)PrintDedicatedMessage; - api->fp[152] = (int *)ddio_MakePath; - api->fp[153] = (int *)ddio_SplitPath; + api->fp[152] = (int *)nullptr; // ddio_MakePath; + api->fp[153] = (int *)nullptr; // ddio_SplitPath; api->fp[154] = (int *)D3W_Play2dSound; api->fp[155] = (int *)D3W_TouchSound; api->fp[156] = (int *)dDatabaseRead1; diff --git a/Descent3/OsirisLoadandBind.cpp b/Descent3/OsirisLoadandBind.cpp index 73f10fa48..97b64a845 100644 --- a/Descent3/OsirisLoadandBind.cpp +++ b/Descent3/OsirisLoadandBind.cpp @@ -908,7 +908,7 @@ int get_full_path_to_module(const std::filesystem::path &module_name, std::files int exist = cfexist(modfilename); switch (exist) { case CFES_ON_DISK: - fullpath = std::filesystem::path(LocalScriptDir) / modfilename; + fullpath = LocalScriptDir / modfilename; return -1; break; case CFES_IN_LIBRARY: { diff --git a/Descent3/ambient.cpp b/Descent3/ambient.cpp index de4260aec..1879c4d6a 100644 --- a/Descent3/ambient.cpp +++ b/Descent3/ambient.cpp @@ -290,13 +290,13 @@ extern char D3HogDir[_MAX_PATH * 2]; // Writes data from the ambient sound data file void WriteAmbientData() { - char filename[_MAX_PATH]; + std::filesystem::path filename; CFILE *ofile; #ifndef NEWEDITOR - ddio_MakePath(filename, (const char*)cf_GetWritableBaseDirectory().u8string().c_str(), "data", "misc", AMBIENT_FILE_NAME, NULL); + filename = cf_GetWritableBaseDirectory() / "data" / "misc" / AMBIENT_FILE_NAME; #else - ddio_MakePath(filename, D3HogDir, "data", "misc", AMBIENT_FILE_NAME, NULL); + filename = D3HogDir / "data" / "misc" / AMBIENT_FILE_NAME; #endif ofile = cfopen(filename, "wb"); diff --git a/Descent3/gamefile.cpp b/Descent3/gamefile.cpp index a28a165f3..53e79320e 100644 --- a/Descent3/gamefile.cpp +++ b/Descent3/gamefile.cpp @@ -106,7 +106,7 @@ int GetPrevGamefile(int n) { } // Searches thru all gamefiles for a specific name, returns -1 if not found // or index of gamefile with name -int FindGamefileName(char *name) { +int FindGamefileName(const char *name) { int i; ASSERT(name != NULL); diff --git a/Descent3/gamefile.h b/Descent3/gamefile.h index 0073c248f..9cc8cb9e5 100644 --- a/Descent3/gamefile.h +++ b/Descent3/gamefile.h @@ -50,6 +50,6 @@ int GetPrevGamefile(int n); // Searches thru all gamefile for a specific name, returns -1 if not found // or index of gamefile with name -int FindGamefileName(char *name); +int FindGamefileName(const char *name); #endif diff --git a/Descent3/gamesave.cpp b/Descent3/gamesave.cpp index 589369144..68a97d49b 100644 --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -531,8 +531,6 @@ void __cdecl LoadGameDialogCB(newuiTiledWindow *wnd, void *data) if (id < (SAVE_HOTSPOT_ID + N_SAVE_SLOTS) && id != cb_data->cur_slot) { // new bitmap to be displayed! char filename[PSFILENAME_LEN + 1]; - char pathname[_MAX_PATH]; - char savegame_dir[_MAX_PATH]; char desc[GAMESAVE_DESCLEN + 1]; int bm_handle; @@ -542,9 +540,8 @@ 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); snprintf(filename, sizeof(filename), "saveg00%d", (id - SAVE_HOTSPOT_ID)); - ddio_MakePath(pathname, savegame_dir, filename, NULL); + std::filesystem::path pathname = cf_GetWritableBaseDirectory() / "savegame" / filename; if (GetGameStateInfo(pathname, desc, &bm_handle)) { if (bm_handle > 0) { diff --git a/Descent3/localization.cpp b/Descent3/localization.cpp index 711c7863b..a568f4409 100644 --- a/Descent3/localization.cpp +++ b/Descent3/localization.cpp @@ -84,14 +84,15 @@ * $NoKeywords: $ */ +#include #include #include #include #include +#include +#include #include "cfile.h" -#include "ddio.h" -#include "descent.h" #include "game.h" #include "localization.h" #include "log.h" @@ -235,29 +236,12 @@ const char *GetStringFromTable(int index) { return String_table[index]; } -void FixFilenameCase(const char *filename, char *newfile) { - char path[_MAX_PATH], file[_MAX_FNAME], ext[_MAX_EXT]; - ddio_SplitPath(filename, path, file, ext); - - char *p; - - p = file; - while (*p) { - *p = tolower(*p); - p++; - }; - p = ext; - while (*p) { - *p = tolower(*p); - p++; - }; - - strcat(file, ext); - - if (strlen(path) > 0) - ddio_MakePath(newfile, path, file, NULL); - else - strcpy(newfile, file); +std::filesystem::path FixFilenameCase(const std::filesystem::path &filename) { + std::string local_file = filename.filename().u8string(); + + std::transform(local_file.begin(), local_file.end(), local_file.begin(), + [](unsigned char c){ return std::tolower(c); }); + return filename.parent_path() / local_file; } // Given a filename, pointer to a char * array and a pointer to an int, @@ -273,11 +257,9 @@ bool CreateStringTable(const char *filename, char ***table, int *size) { *size = 0; return false; } - CFILE *file; - char fname[_MAX_PATH]; - FixFilenameCase(filename, fname); - file = cfopen(fname, "rt"); + std::filesystem::path fname = FixFilenameCase(filename); + CFILE *file = cfopen(fname, "rt"); if (!file) { if (table) *table = NULL; @@ -450,8 +432,7 @@ int GetTotalStringCount(void) { while (String_table_list[findex]) { // open the file up - char fname[_MAX_PATH]; - FixFilenameCase(String_table_list[findex], fname); + std::filesystem::path fname = FixFilenameCase(String_table_list[findex]); file = cfopen(fname, "rt"); if (!file) return 0; @@ -475,10 +456,8 @@ int LoadStringFile(const char *filename, int starting_offset) { if (!filename) return 0; - CFILE *file; - char fname[_MAX_PATH]; - FixFilenameCase(filename, fname); - file = cfopen(fname, "rt"); + std::filesystem::path fname = FixFilenameCase(filename); + CFILE *file = cfopen(fname, "rt"); if (!file) return 0; diff --git a/Descent3/mission_download.cpp b/Descent3/mission_download.cpp index f494abe96..c5773b94c 100644 --- a/Descent3/mission_download.cpp +++ b/Descent3/mission_download.cpp @@ -119,8 +119,9 @@ */ #include -#include +#include #include +#include #include "mem.h" #include "args.h" @@ -673,16 +674,6 @@ char *msn_SecondsToString(int time_sec) { return fmttime; } -void _get_zipfilename(char *output, char *directory, char *zipfilename) { - char *s = strrchr(zipfilename, '/'); - if (s) - s++; - else - s = zipfilename; - - ddio_MakePath(output, directory, s, NULL); -} - // return 0 on failure // return 1 on success int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::filesystem::path &mn3name) { @@ -693,11 +684,9 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file return 0; } - char mission_directory[_MAX_PATH]; - char output_filename[_MAX_PATH]; char buffer[256 + 32]; - ddio_MakePath(mission_directory, LocalD3Dir, "missions", NULL); + std::filesystem::path mission_directory = std::filesystem::path(LocalD3Dir) / "missions"; // now go through the zip file and extract all the files out that we can ZIP zfile; @@ -740,14 +729,15 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file console.puts(GR_GREEN, buffer); // create the filename for this file - _get_zipfilename(output_filename, mission_directory, ze->name); + std::filesystem::path output_filename = mission_directory / ze->name; if (cfexist(output_filename)) { - snprintf(buffer, sizeof(buffer), "%s already exists. Overwrite?", output_filename); + snprintf(buffer, sizeof(buffer), "%s already exists. Overwrite?", output_filename.u8string().c_str()); if (DoMessageBox("Confirm", buffer, MSGBOX_YESNO, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL)) { // delete the file LOG_DEBUG.printf("Deleting %s", zipfilename.u8string().c_str()); - if (!ddio_DeleteFile(output_filename)) { + std::error_code ec; + if (!std::filesystem::remove(output_filename, ec)) { process_file = false; console.puts(GR_GREEN, "[Unable to Write] "); } else { @@ -765,7 +755,7 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file DoUIFrame(); rend_Flip(); - int ret = zfile.ExtractFile(ze, output_filename); + int ret = zfile.ExtractFile(ze, output_filename.u8string().c_str()); if (ret < 0) { if (ret == -9) { LOG_WARNING << " Error writing to file"; @@ -776,7 +766,8 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file } console.puts(GR_GREEN, buffer); if (cfexist(output_filename)) { - ddio_DeleteFile(output_filename); + std::error_code ec; + std::filesystem::remove(output_filename, ec); } } else { // check the CRC @@ -790,7 +781,8 @@ int msn_ExtractZipFile(const std::filesystem::path &zipfilename, const std::file } } else { console.puts(GR_GREEN, "CRC FAIL!"); - ddio_DeleteFile(output_filename); + std::error_code ec; + std::filesystem::remove(output_filename, ec); } } } diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index 5cc07f12b..224678df7 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -1644,6 +1644,8 @@ #include #include +#include +#include #include "chrono_timer.h" #include "pserror.h" @@ -1656,6 +1658,7 @@ #include "init.h" #include "hud.h" #include "log.h" +#include "pstring.h" #include "robotfire.h" #include "ship.h" #include "descent.h" @@ -1812,7 +1815,14 @@ void SendDataChunk(int playernum); void DenyFile(int playernum, int filenum, int file_who); void MultiDoFileCancelled(uint8_t *data); void MultiDoCustomPlayerData(uint8_t *data); -char *GetFileNameFromPlayerAndID(int16_t playernum, int16_t id); + +/** + * Return filename for player's customizable data (logo and taunts) + * @param playernum requested player id + * @param id requested resource id + * @return filename or empty path if no such resource for requested player + */ +std::filesystem::path GetFileNameFromPlayerAndID(uint16_t playernum, uint16_t id); // Multiplayer position flags #define MPF_AFTERBURNER 1 // Afterburner is on @@ -7530,23 +7540,22 @@ void MultiAskForFile(uint16_t file_id, uint16_t file_who, uint16_t who) { return; } // Check to see if this file exists already - char *p = GetFileNameFromPlayerAndID(file_who, file_id); - if (*p) { - if (CFES_ON_DISK == cfexist(p)) { + std::filesystem::path p = GetFileNameFromPlayerAndID(file_who, file_id); + if (!p.empty()) { + if (cfexist(p) == CFES_ON_DISK) { char szcrc[_MAX_PATH]; - char path[_MAX_PATH]; - char ext[_MAX_PATH]; - char file[_MAX_PATH]; - ddio_SplitPath(p, path, file, ext); - snprintf(szcrc, sizeof(szcrc), "_%.8x", cf_GetfileCRC(p)); - // See if the the CRC is already in the filename - if (strnicmp(szcrc, file + (strlen(file) - 9), 9) != 0) { - LOG_WARNING.printf("Bad CRC on file %s! It must be corrupt! File will not be used, and is being deleted!", p); - ddio_DeleteFile(p); + std::vector parts = StringSplit(p.stem().u8string(), "_"); + snprintf(szcrc, sizeof(szcrc), "%.8x", cf_GetfileCRC(p)); + // See if the CRC is already in the filename + if (stricmp(szcrc, parts.back().c_str()) != 0) { + LOG_WARNING.printf("Bad CRC on file %s! It must be corrupt! File will not be used, and is being deleted!", + p.u8string().c_str()); + std::error_code ec; + std::filesystem::remove(p, ec); } else { // Hey hey, we already have this file - LOG_DEBUG.printf("Using existing file: %s", p); + LOG_DEBUG << "Using existing file: " << p; DoNextPlayerFile(file_who); return; } @@ -7593,15 +7602,14 @@ void MultiDoFileReq(uint8_t *data) { // FIXME!! Figure out what file to open CFILE *cfp; // char filename[_MAX_PATH]; - char filewithpath[_MAX_PATH * 2]; - strcpy(filewithpath, GetFileNameFromPlayerAndID(filewho, filenum)); - if (filewithpath[0] == 0) { - LOG_DEBUG.printf("Got a file request for a file that doesn't exist (%s).", filewithpath); + std::filesystem::path filewithpath = GetFileNameFromPlayerAndID(filewho, filenum); + if (filewithpath.empty()) { + LOG_DEBUG.printf("Got a file request for a file that doesn't exist (%s).", filewithpath.u8string().c_str()); DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who); } else { cfp = cfopen(filewithpath, "rb"); if (!cfp) { - LOG_WARNING.printf("Couldn't open a file (%s) for transfer.", filewithpath); + LOG_WARNING.printf("Couldn't open a file (%s) for transfer.", filewithpath.u8string().c_str()); DenyFile(playernum, filenum, NetPlayers[playernum].file_xfer_who); return; // We couldn't create the file, so cancel the attempt to transfer it. @@ -7700,14 +7708,12 @@ void MultiDoFileData(uint8_t *data) { // Find out if this is the first packet of this file. if so, create and open the file if (NetPlayers[playernum].file_xfer_pos == 0) { LOG_DEBUG << "Creating file..."; - CFILE *cfp; // char filename[_MAX_PATH]; - char filewithpath[_MAX_PATH * 2]; - strcpy(filewithpath, GetFileNameFromPlayerAndID(playernum, file_id)); + std::filesystem::path filewithpath = GetFileNameFromPlayerAndID(playernum, file_id); - cfp = cfopen(filewithpath, "wb"); + CFILE *cfp = cfopen(filewithpath, "wb"); if (!cfp) { - LOG_WARNING.printf("Can't create file %s", filewithpath); + LOG_WARNING << "Can't create file " << filewithpath; // We couldn't create the file, so cancel the attempt to transfer it. MultiCancelFile(playernum, file_id, NetPlayers[playernum].file_xfer_who); return; @@ -7949,14 +7955,14 @@ void MultiDoCustomPlayerData(uint8_t *data) { return; LOG_DEBUG << "Got custom data in MultiDoCustomPlayerData()"; NetPlayers[playernum].custom_file_seq = NETFILE_ID_SHIP_TEX; // First in the sequence of files we will request - int16_t logo_len = MultiGetUshort(data, &count); + uint16_t logo_len = MultiGetUshort(data, &count); memcpy(NetPlayers[playernum].ship_logo, data + count, logo_len); count += logo_len; LOG_DEBUG.printf("%s uses custom ship logo %s", Players[playernum].callsign, NetPlayers[playernum].ship_logo); for (int t = 0; t < 4; t++) { char *filename; - int16_t vt_len; + uint16_t vt_len; switch (t) { case 0: @@ -7979,17 +7985,15 @@ void MultiDoCustomPlayerData(uint8_t *data) { } } -char *GetFileNameFromPlayerAndID(int16_t playernum, int16_t id) { - static char rval[_MAX_PATH * 2]; - - rval[0] = '\0'; +std::filesystem::path GetFileNameFromPlayerAndID(uint16_t playernum, uint16_t id) { + std::filesystem::path rval; if (playernum >= MAX_NET_PLAYERS) { - LOG_WARNING.printf("Invalid playernum (%d) passed to GetFileNameFromPlayerAndID()", playernum); + LOG_WARNING.printf("Invalid playernum (%d) passed to function", playernum); return rval; } if (id > NETFILE_ID_LAST_FILE) { - LOG_WARNING.printf("Invalid file id (%d) passed to GetFileNameFromPlayerAndID()", id); + LOG_WARNING.printf("Invalid file id (%d) passed to function", id); return rval; } switch (id) { @@ -7998,38 +8002,36 @@ 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); + rval = cf_GetWritableBaseDirectory() / "custom" / "graphics" / NetPlayers[playernum].ship_logo; 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); + rval = cf_GetWritableBaseDirectory() / "custom" / "sounds" / NetPlayers[playernum].voice_taunt1; 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); + rval = cf_GetWritableBaseDirectory() / "custom" / "sounds" / NetPlayers[playernum].voice_taunt2; 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); + rval = cf_GetWritableBaseDirectory() / "custom" / "sounds" / NetPlayers[playernum].voice_taunt3; 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); + rval = cf_GetWritableBaseDirectory() / "custom" / "sounds" / NetPlayers[playernum].voice_taunt4; break; default: - LOG_FATAL.printf("Unknown id (%d) passed to GetFileNameFromPlayerAndID()", id); + LOG_FATAL.printf("Unknown id (%d) passed to function", id); Int3(); break; } - if (*rval) { - CFILE *cfp; - cfp = cfopen(rval, "rb"); + if (!rval.empty()) { + CFILE *cfp = cfopen(rval, "rb"); if (!cfp) { LOG_WARNING.printf("Multiplayer file xfer File does not exist, not using file %d for player %d!", id, playernum); - // rval[0] = '\0'; } else if (32768 < cfilelength(cfp)) { LOG_WARNING.printf("Multiplayer file xfer File to long, not using file %d for player %d!", id, playernum); - rval[0] = '\0'; + rval.clear(); } if (cfp) cfclose(cfp); @@ -8332,7 +8334,7 @@ void MultiDoAiWeaponFlags(uint8_t *data) { int flags; int wb_index; - int16_t obj_num = Server_object_list[MultiGetUshort(data, &count)]; + uint16_t obj_num = Server_object_list[MultiGetUshort(data, &count)]; flags = MultiGetInt(data, &count); wb_index = MultiGetByte(data, &count); if (obj_num == 65535) { diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index 1ec0e14a4..83e24bb10 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -432,7 +432,7 @@ void GetMultiAPI(multi_api *api) { api->fp[32] = (int *)MultiStartClient; api->fp[33] = (int *)rend_GetRenderState; api->fp[34] = (int *)LoadMission; - api->fp[35] = (int *)ddio_MakePath; + api->fp[35] = (int *)nullptr; // ddio_MakePath; api->fp[36] = (int *)nullptr; // ddio_FindFileStart; api->fp[37] = (int *)nullptr; // ddio_FindFileClose; api->fp[38] = (int *)nullptr; // ddio_FindNextFile; @@ -440,7 +440,7 @@ void GetMultiAPI(multi_api *api) { api->fp[40] = (int *)ShowProgressScreen; api->fp[41] = (int *)SearchForLocalGamesTCP; api->fp[42] = (int *)nw_GetHostAddressFromNumbers; - api->fp[43] = (int *)NULL; // nw_GetProtocolType; + api->fp[43] = (int *)nullptr; // nw_GetProtocolType; api->fp[44] = (int *)HotSpotCreate; api->fp[45] = (int *)PollUI; api->fp[46] = (int *)GetMissionName; diff --git a/Descent3/multisafe_server.cpp b/Descent3/multisafe_server.cpp index b3791b1f0..360bc3075 100644 --- a/Descent3/multisafe_server.cpp +++ b/Descent3/multisafe_server.cpp @@ -33,8 +33,8 @@ #define GET_AND_VERIFY_OBJECT(o) \ { \ - o = VerifyMSafeObject(MultiGetUshort(data, &count)); \ - if (o == OBJECT_HANDLE_NONE) \ + (o) = VerifyMSafeObject(MultiGetUshort(data, &count)); \ + if ((o) == OBJECT_HANDLE_NONE) \ return; \ } diff --git a/Descent3/object_external.h b/Descent3/object_external.h index 07c4d3a8b..b1573f6d7 100644 --- a/Descent3/object_external.h +++ b/Descent3/object_external.h @@ -153,7 +153,7 @@ #define OBJECT_HANDLE_BAD 0 // Use this handle when you want a handle that will never be a valid object -#define OBJECT_HANDLE_NONE -1 +#define OBJECT_HANDLE_NONE (-1) // Object types #define OBJ_NONE 255 // unused object diff --git a/editor/BriefManage.cpp b/editor/BriefManage.cpp index 661cc6093..c540d7b9d 100644 --- a/editor/BriefManage.cpp +++ b/editor/BriefManage.cpp @@ -60,7 +60,7 @@ END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBriefManage message handlers -bool AddNewGameFile(char *fullpath, char *directory); +bool AddNewGameFile(const std::filesystem::path &fullpath, const std::filesystem::path &directory); bool CheckInGamefile(char *tempbuffer, bool show_ok_confirmation); void CBriefManage::OnAdd() { if (!Network_up) { diff --git a/editor/CustDefaultScriptSelect.cpp b/editor/CustDefaultScriptSelect.cpp index 0e70e3fba..c7eff87de 100644 --- a/editor/CustDefaultScriptSelect.cpp +++ b/editor/CustDefaultScriptSelect.cpp @@ -19,11 +19,12 @@ // CustDefaultScriptSelect.cpp : implementation file // +#include + #include "stdafx.h" #include "editor.h" #include "CustDefaultScriptSelect.h" #include "manage.h" -#include "ddio.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -72,15 +73,15 @@ void CCustDefaultScriptSelect::OnBrowse() { CString filter = "D3 Compiled Scripts (*.dll)|*.dll||"; char filename[_MAX_PATH]; - char pathname[_MAX_PATH], name[_MAX_PATH]; - strcpy(pathname, LocalScriptDir); + char pathname[_MAX_PATH]; + strncpy(pathname, LocalScriptDir.u8string().c_str(), _MAX_PATH); if (!OpenFileDialog(this, (LPCTSTR)filter, filename, pathname, sizeof(pathname))) return; - ddio_SplitPath(filename, NULL, name, NULL); + std::filesystem::path name = std::filesystem::path(filename).stem(); - m_Module = name; + m_Module = name.u8string().c_str(); UpdateData(false); } diff --git a/editor/DallasMainDlg.cpp b/editor/DallasMainDlg.cpp index b8e7de15a..e160ee408 100644 --- a/editor/DallasMainDlg.cpp +++ b/editor/DallasMainDlg.cpp @@ -307,14 +307,14 @@ #include "stdafx.h" -#include -#include +#include +#include +#include #include #include "pserror.h" #include "cfile.h" #include "mem.h" -#include "mono.h" #include "ddio.h" #include "manage.h" #include "object.h" @@ -362,7 +362,7 @@ CFILE *CurrentOutputFile; int CurrentTabLevel; // Writes out text to CurrentFile -void OutToFile(char *format, ...) { +void OutToFile(const char *format, ...) { char buffer[1024]; if (CurrentOutputFile == NULL) @@ -671,7 +671,7 @@ void CDallasMainDlg::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized) { // Saves all data void CDallasMainDlg::OnSaveButton() { CString temp_str; - char fullpath[_MAX_PATH]; + std::filesystem::path fullpath; #ifndef NEWEDITOR // Make sure we're in the editor @@ -692,8 +692,9 @@ void CDallasMainDlg::OnSaveButton() { CreateMsgTableFile(m_ScriptMessagesFilename.GetBuffer(0)); // Get the full DLL path, and delete the DLL - ddio_MakePath(fullpath, LocalScriptDir, m_ScriptDLLFilename.GetBuffer(0), NULL); - ddio_DeleteFile(fullpath); + fullpath = LocalScriptDir / m_ScriptDLLFilename.GetBuffer(0); + std::error_code ec; + std::filesystem::remove(fullpath, ec); // Attempt to compile it and create the dll CompilerOutputText = ""; @@ -705,8 +706,8 @@ void CDallasMainDlg::OnSaveButton() { ScriptCompile(&ci); // Check to see if the DLL has been created - ddio_MakePath(fullpath, LocalScriptDir, m_ScriptDLLFilename.GetBuffer(0), NULL); - if (_access(fullpath, 0x00) == -1) { + fullpath = LocalScriptDir / m_ScriptDLLFilename.GetBuffer(0); + if (!std::filesystem::exists(fullpath)) { MessageBox("The compile failed. See output for error details.", "Compiler Error"); } @@ -1601,7 +1602,7 @@ void CDallasMainDlg::OnMenuSelectionOfTypeDelete(UINT nID) { } // Displays a deletion prompt -int CDallasMainDlg::DeletePrompt(char *msg) { +int CDallasMainDlg::DeletePrompt(const char *msg) { CString title = "Deletion Prompt"; return (MessageBox(msg, title.GetBuffer(0), MB_YESNO | MB_ICONQUESTION)); } @@ -1814,7 +1815,7 @@ void CDallasMainDlg::ClearTree(void) { } // Obtains the string name for an event type -char *CDallasMainDlg::GetEventTypeString(int type) { +const char *CDallasMainDlg::GetEventTypeString(int type) { for (int j = 0; event_info[j].type >= 0; j++) if (event_info[j].type == type) return (event_info[j].name); @@ -1841,7 +1842,7 @@ void CDallasMainDlg::UpdateTreeText(HTREEITEM parent) { } // Obtains the in-code DEFINE name for an event type -char *CDallasMainDlg::GetEventCodeName(int type) { +const char *CDallasMainDlg::GetEventCodeName(int type) { for (int j = 0; event_info[j].type >= 0; j++) if (event_info[j].type == type) return (event_info[j].code_name); @@ -1850,7 +1851,7 @@ char *CDallasMainDlg::GetEventCodeName(int type) { } // Obtains the data line for an event type -char *CDallasMainDlg::GetEventDataLine(int type) { +const char *CDallasMainDlg::GetEventDataLine(int type) { for (int j = 0; event_info[j].type >= 0; j++) if (event_info[j].type == type) return (event_info[j].data_line); @@ -2066,7 +2067,7 @@ bool CDallasMainDlg::CanAppendElseToNode(HTREEITEM node) { } // Obtains the string name for an expression operator type -char *CDallasMainDlg::GetExpressionOperatorTypeString(int type) { +const char *CDallasMainDlg::GetExpressionOperatorTypeString(int type) { for (int j = 0; expop_info[j].type >= 0; j++) if (expop_info[j].type == type) return (expop_info[j].name); @@ -2075,7 +2076,7 @@ char *CDallasMainDlg::GetExpressionOperatorTypeString(int type) { } // Obtains the string name for an expression operator type -char *CDallasMainDlg::GetExpressionOperatorCodeName(int type) { +const char *CDallasMainDlg::GetExpressionOperatorCodeName(int type) { for (int j = 0; expop_info[j].type >= 0; j++) if (expop_info[j].type == type) return (expop_info[j].code_name); @@ -2084,7 +2085,7 @@ char *CDallasMainDlg::GetExpressionOperatorCodeName(int type) { } // Obtains the string name for a literal -char *CDallasMainDlg::GetLiteralName(int type) { +const char *CDallasMainDlg::GetLiteralName(int type) { for (int j = 0; param_menu_item[j].type >= 0; j++) if (param_menu_item[j].type == type) return (param_menu_item[j].name); @@ -3291,7 +3292,7 @@ HTREEITEM CDallasMainDlg::AddNodeToTree(HTREEITEM parent, HTREEITEM insertbefore tvi.mask = TVIF_TEXT; // FormatTreeText(node_text,new_data_node); // tvi.pszText=node_text.GetBuffer(0); - tvi.pszText = ""; + tvi.pszText = const_cast(""); // Get the previous child node for "insert before" if (insertbefore != TVI_FIRST && insertbefore != TVI_LAST && insertbefore != TVI_SORT) { @@ -3847,7 +3848,7 @@ void CDallasMainDlg::ClearMessageList(void) { } // Adds a message to the list -bool CDallasMainDlg::AddToMessageList(char *name, char *message) { +bool CDallasMainDlg::AddToMessageList(char *name, const char *message) { tMessageListEntry *empty_slot; int index; @@ -4827,7 +4828,7 @@ int CDallasMainDlg::AddNameToListFromTreeNode(HTREEITEM node, bool show_notspec_ } // Displays the invalid special parameter warning message -void CDallasMainDlg::InvSpecParamMsg(int scriptID, char *type_name) { +void CDallasMainDlg::InvSpecParamMsg(int scriptID, const char *type_name) { CString msg, title; if (type_name == NULL) @@ -4840,7 +4841,7 @@ void CDallasMainDlg::InvSpecParamMsg(int scriptID, char *type_name) { } // Displays the NOT SPECIFIED indexed value warning message -void CDallasMainDlg::IndValNotSpecMsg(int scriptID, char *type_name) { +void CDallasMainDlg::IndValNotSpecMsg(int scriptID, const char *type_name) { CString msg, title; if (type_name == NULL) @@ -4852,7 +4853,7 @@ void CDallasMainDlg::IndValNotSpecMsg(int scriptID, char *type_name) { } // Displays the invalid indexed value warning message -void CDallasMainDlg::InvIndValMsg(int scriptID, char *type_name, int index, char *name) { +void CDallasMainDlg::InvIndValMsg(int scriptID, const char *type_name, int index, const char *name) { CString msg, title; if (type_name == NULL || name == NULL) @@ -4866,7 +4867,7 @@ void CDallasMainDlg::InvIndValMsg(int scriptID, char *type_name, int index, char } // Displays the invalid indexed value prompt -int CDallasMainDlg::InvIndValPrompt(int scriptID, char *type_name, int index, char *name, int new_index) { +int CDallasMainDlg::InvIndValPrompt(int scriptID, const char *type_name, int index, const char *name, int new_index) { CString msg, title; if (type_name == NULL || name == NULL) @@ -4880,7 +4881,7 @@ int CDallasMainDlg::InvIndValPrompt(int scriptID, char *type_name, int index, ch } // Displays the invalid indexed value name warning message -void CDallasMainDlg::InvNameIndValMsg(int scriptID, char *type_name, int index, char *name, char *new_name) { +void CDallasMainDlg::InvNameIndValMsg(int scriptID, const char *type_name, int index, const char *name, const char *new_name) { CString msg, title; if (type_name == NULL || name == NULL || new_name == NULL) @@ -4894,7 +4895,7 @@ void CDallasMainDlg::InvNameIndValMsg(int scriptID, char *type_name, int index, } // Displays the invalid indexed value name prompt -int CDallasMainDlg::InvNameIndValPrompt(int scriptID, char *type_name, int index, char *name, char *new_name, +int CDallasMainDlg::InvNameIndValPrompt(int scriptID, const char *type_name, int index, const char *name, const char *new_name, int new_index) { CString msg, title; @@ -5638,7 +5639,7 @@ void CDallasMainDlg::ClearEnumDatabase(void) { } // Returns the DB slot matching the given enum type name -int CDallasMainDlg::GetEnumID(char *name) { +int CDallasMainDlg::GetEnumID(const char *name) { int i; if (name == NULL) @@ -5668,7 +5669,7 @@ char *CDallasMainDlg::GetEnumValueName(char *name, int value) { // Obtains the value bound to an enum value name, // Returns TRUE if value was found, FALSE otherwise -bool CDallasMainDlg::GetEnumValue(char *name, char *value_name, int &value) { +bool CDallasMainDlg::GetEnumValue(const char *name, const char *value_name, int &value) { int DBslot, j; DBslot = GetEnumID(name); @@ -6048,7 +6049,7 @@ char *CDallasMainDlg::GetActionHelp(int ID) { } // Returns a pointer to the action function name -char *CDallasMainDlg::GetActionFunc(int ID) { +const char *CDallasMainDlg::GetActionFunc(int ID) { if (ID == DO_NOTHING_ID) return DO_NOTHING_STRING; @@ -6090,7 +6091,7 @@ char *CDallasMainDlg::GetQueryHelp(int ID) { } // Returns a pointer to the query function name -char *CDallasMainDlg::GetQueryFunc(int ID) { +const char *CDallasMainDlg::GetQueryFunc(int ID) { if (ID < 0 || ID >= m_NumQueries) return INVALID_FUNCTION_NAME; @@ -6138,15 +6139,14 @@ int CDallasMainDlg::GetQueryReturnType(int ID, CString &name) { } // Parses the given text file, adding categories, actions, and queries, as it finds them -void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*/) { +void CDallasMainDlg::ParseFunctionFile(const char *filename, bool show_errors /*=TRUE*/) { CFILE *ifile; char linebuf[2048]; char *line; char helpbuf[2048]; int linenum; - char fullpath[_MAX_PATH]; - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; ifile = cfopen(fullpath, "rt"); if (ifile == NULL) { @@ -7160,7 +7160,7 @@ void CDallasMainDlg::FillActionMenu(CMenu *action_menu, int command_offset) { // Fills up the given menu with the categories of queries // NOTE: Command ID's of menu items start at the given command_offset void CDallasMainDlg::FillQueryMenu(CMenu *query_menu, int command_offset, int valid_return_type, - char *valid_return_name) { + const char *valid_return_name) { int j, k, queries_added; int query_ret_type; CString query_ret_name; @@ -7702,14 +7702,13 @@ void CDallasMainDlg::ScriptFileParseError(int error_code, int linenum, int scrip // Reads in the script source file and calls the various parsers for the // Appropriate sections -int CDallasMainDlg::ParseSourceScript(char *filename) { +int CDallasMainDlg::ParseSourceScript(const char *filename) { CFILE *infile; char linebuf[2048]; char tempbuf[256]; char *line; int linenum; int valid_lines_read, version; - char fullpath[_MAX_PATH]; int rc; HTREEITEM last_node_added, current_parent, returned_node; @@ -7719,7 +7718,7 @@ int CDallasMainDlg::ParseSourceScript(char *filename) { CurrentParsingFilename = m_ScriptFilename; - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; // Try to open the file for loading infile = cfopen(fullpath, "rt"); @@ -9222,7 +9221,7 @@ HTREEITEM CDallasMainDlg::ParseScriptNodeLine_v1U(char *line, int linenum, HTREE } // Handle Special Parse Errors (Invalid Named Values) -void CDallasMainDlg::SpecialScriptFileParseError(int linenum, int script_ID, char *type_name, const char *name) { +void CDallasMainDlg::SpecialScriptFileParseError(int linenum, int script_ID, const char *type_name, const char *name) { CString err_msg; if (name == NULL || type_name == NULL) @@ -9256,15 +9255,13 @@ bool CDallasMainDlg::ValidateFunctionNode(HTREEITEM node, int linenum) { } // Reads in the message list from a file -int CDallasMainDlg::ParseMsgTableFile(char *filename) { +int CDallasMainDlg::ParseMsgTableFile(const char *filename) { CFILE *infile; char filebuffer[MAX_MSG_FILE_BUFFER_LEN]; char *line, *msg_start; int line_num; bool next_msgid_found; - char fullpath[_MAX_PATH]; - - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; // Try to open the file for loading infile = cfopen(fullpath, "rt"); @@ -9395,16 +9392,15 @@ int CDallasMainDlg::CountCustomScriptLines(CFILE *infile) { } // Reads in and stores all the lines in the custom script block -int CDallasMainDlg::ParseCustomScriptFile(char *filename, bool show_errors /*=TRUE*/) { +int CDallasMainDlg::ParseCustomScriptFile(const char *filename, bool show_errors /*=TRUE*/) { CFILE *infile; char linebuf[2048]; char *line; int linenum; - char fullpath[_MAX_PATH]; CurrentParsingFilename = m_ScriptFilename; - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; // Try to open the file for loading infile = cfopen(fullpath, "rt"); @@ -9526,14 +9522,13 @@ void CDallasMainDlg::WriteCustomScriptBlock(void) { ///////////////////////////////////////////////////////////////////////////// // Writes message list to file -int CDallasMainDlg::CreateMsgTableFile(char *filename) { +int CDallasMainDlg::CreateMsgTableFile(const char *filename) { CFILE *outfile; CString buffer; int count, j; tMessageListEntry *msg_data; - char fullpath[_MAX_PATH]; - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; // Try to open the file for writing outfile = cfopen(fullpath, "wt"); @@ -9590,7 +9585,6 @@ void CDallasMainDlg::TabOver(void) { // Create the source script CPP file int CDallasMainDlg::CreateScriptFile(char *filename) { - char fullpath[_MAX_PATH]; int j, counter, num_CO_scripts; // Fill the name lists (and check for any invalid/not selected fields) @@ -9608,11 +9602,11 @@ int CDallasMainDlg::CreateScriptFile(char *filename) { BuildScriptGroupingList(); // Open the file for writing - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; CurrentOutputFile = cfopen(fullpath, "wt"); if (CurrentOutputFile == NULL) { CString msg, title; - msg.Format("ERROR: Unable to open %s for output.", fullpath); + msg.Format("ERROR: Unable to open %s for output.", fullpath.u8string().c_str()); title.Format("Script Save Error!"); MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION); return FALSE; @@ -14459,7 +14453,7 @@ HTREEITEM CDallasMainDlg::CreateDefaultActionStatementNode(HTREEITEM parent) { // Create default parameter node, and assigns it an appropriate default value // based upon the parameter type HTREEITEM CDallasMainDlg::CreateDefaultParameterNode(HTREEITEM parent, HTREEITEM insert_before, int param_type, - char *name, char *def_value /*=NULL*/) { + const char *name, const char *def_value /*=NULL*/) { tTreeNodeData node_data; if (parent == NULL || insert_before == NULL || name == NULL) diff --git a/editor/DallasMainDlg.h b/editor/DallasMainDlg.h index 2ee0cd755..5eee10add 100644 --- a/editor/DallasMainDlg.h +++ b/editor/DallasMainDlg.h @@ -362,11 +362,11 @@ struct tMessageListEntry { // Struct for storing expression operator information struct ExpOpInfoItem { - int type; // expression operator (see above) - char *name; // the displayed name - char *menu_name; // the menu name - char *code_name; // DEFINE string to identify event in code - int op_type; // whether it is a binary or comparison op + int type; // expression operator (see above) + const char *name; // the displayed name + const char *menu_name; // the menu name + const char *code_name; // DEFINE string to identify event in code + int op_type; // whether it is a binary or comparison op }; // Script Owner Types @@ -425,11 +425,11 @@ struct ExpOpInfoItem { // Struct for storing event information struct EventInfoItem { - int type; // event type (see above) - char *name; // the displayed name - char *code_name; // DEFINE string to identify event in code - char *data_line; // The line for this event's data struct - int flags; // owner and various flags + int type; // event type (see above) + const char *name; // the displayed name + const char *code_name; // DEFINE string to identify event in code + const char *data_line; // The line for this event's data struct + int flags; // owner and various flags }; // Constants for masking what events go with what owner @@ -448,8 +448,8 @@ struct EventInfoItem { // Struct for easily creating literal menu struct ParamMenuItem { - int type; // the type of literal (parameter type) - char *name; // menu name of the literal + int type; // the type of literal (parameter type) + const char *name; // menu name of the literal }; // Nested Types @@ -1092,13 +1092,16 @@ class CDallasMainDlg : public CDialog { void SetTreeNodeImage(HTREEITEM node); // Sets the image for a node (based on node data) - char *GetEventTypeString(int type); - char *GetEventCodeName(int type); - char *GetEventDataLine(int type); + const char *GetEventTypeString(int type); + + const char *GetEventCodeName(int type); + + const char *GetEventDataLine(int type); void GetLogicalOperatorTypeString(int type, CString &string); - char *GetExpressionOperatorTypeString(int type); - char *GetExpressionOperatorCodeName(int type); - char *GetLiteralName(int type); + + const char *GetExpressionOperatorTypeString(int type); + const char *GetExpressionOperatorCodeName(int type); + const char *GetLiteralName(int type); bool ScriptHasAnIt(HTREEITEM script_node); bool ScriptHasAMe(HTREEITEM script_node); @@ -1131,7 +1134,7 @@ class CDallasMainDlg : public CDialog { tTreeNodeData *GetNearestFunctionNode(HTREEITEM node); void DisplayFloatingPopupMenu(HTREEITEM node, POINT &pt); - int DeletePrompt(char *msg); + int DeletePrompt(const char *msg); void ConfirmAfterDelete(HTREEITEM parent); void HighlightAllScripts(void); // Highlights scripts according to public owner data @@ -1146,7 +1149,7 @@ class CDallasMainDlg : public CDialog { /////////////////////////////////// void InitMessageList(void); // initializes the message list void ClearMessageList(void); // clears the message list - bool AddToMessageList(char *name, char *message); // adds a message to the list + bool AddToMessageList(char *name, const char *message); // adds a message to the list char *FindMessageInList(char *name); // returns a message matching given name int DeleteMessageListEntry(char *name); // Deletes a message entry tMessageListEntry *GetEmptyMessageListEntry(void); // returns an available entry slot @@ -1160,12 +1163,12 @@ class CDallasMainDlg : public CDialog { int AddNameToListFromTreeNode(HTREEITEM node, bool show_notspec_warnings); // Funcs for displaying Indexed value messages - void InvSpecParamMsg(int scriptID, char *type_name); - void IndValNotSpecMsg(int scriptID, char *type_name); - void InvIndValMsg(int scriptID, char *type_name, int index, char *name); - int InvIndValPrompt(int scriptID, char *type_name, int index, char *name, int new_index); - void InvNameIndValMsg(int scriptID, char *type_name, int index, char *name, char *new_name); - int InvNameIndValPrompt(int scriptID, char *type_name, int index, char *name, char *new_name, int new_index); + void InvSpecParamMsg(int scriptID, const char *type_name); + void IndValNotSpecMsg(int scriptID, const char *type_name); + void InvIndValMsg(int scriptID, const char *type_name, int index, const char *name); + int InvIndValPrompt(int scriptID, const char *type_name, int index, const char *name, int new_index); + void InvNameIndValMsg(int scriptID, const char *type_name, int index, const char *name, const char *new_name); + int InvNameIndValPrompt(int scriptID, const char *type_name, int index, const char *name, const char *new_name, int new_index); // Funcs for displaying object messages void InvObjMsg(int scriptID, int handle, char *name); @@ -1224,10 +1227,10 @@ class CDallasMainDlg : public CDialog { /////////////////////////////////////// void InitEnumDatabase(void); // Initializes the enum DB for use void ClearEnumDatabase(void); // Clears any allocated data for the enums - int GetEnumID(char *name); // Returns the DB slot matching the given enum type name + int GetEnumID(const char *name); // Returns the DB slot matching the given enum type name char *GetEnumValueName(char *name, int value); // Returns the name bound to an enum value - bool GetEnumValue(char *name, char *value_name, int &value); // obtains value for given value name + bool GetEnumValue(const char *name, const char *value_name, int &value); // obtains value for given value name int FillEnumTypesMenu(CMenu *enum_menu, int command_offset, char *valid_name); int FillEnumValuesMenu(CMenu *enum_menu, int command_offset, char *enum_name); @@ -1251,15 +1254,15 @@ class CDallasMainDlg : public CDialog { /////////////////////////////////////// void InitFunctionDatabases(void); // Initialize the Action and Query Database Arrays void ClearFunctionDatabases(void); // Frees up any allocated memory - void ParseFunctionFile(char *filename, + void ParseFunctionFile(const char *filename, bool show_errors = TRUE); // Parses a file, and adds any Actions and Querys to the database char *GetActionDesc(int ID); // Returns the Action description char *GetActionHelp(int ID); // Returns the Action help text - char *GetActionFunc(int ID); // Returns the Action function name + const char *GetActionFunc(int ID); // Returns the Action function name int GetActionFuncID(char *func_name); // Searches action list for action matching given function name char *GetQueryDesc(int ID); // Returns the Query description char *GetQueryHelp(int ID); // Returns the Query help text - char *GetQueryFunc(int ID); // Returns the Query function name + const char *GetQueryFunc(int ID); // Returns the Query function name int GetQueryFuncID(char *func_name); // Searches query list for query matching given function name int GetQueryReturnType(int ID, CString &name); // Returns the Query's return type (parameter type) int GetFunctionCategoryID(char *catname); // Matches an integer ID to a given category name @@ -1272,7 +1275,7 @@ class CDallasMainDlg : public CDialog { bool ValidateActionNode(HTREEITEM node, int linenum); bool ValidateQueryNode(HTREEITEM node, int linenum); void FillActionMenu(CMenu *action_menu, int command_offset); - void FillQueryMenu(CMenu *query_menu, int command_offset, int valid_return_type, char *valid_return_name); + void FillQueryMenu(CMenu *query_menu, int command_offset, int valid_return_type, const char *valid_return_name); bool ConformParamNode(HTREEITEM parent_node, HTREEITEM ¶m_node, int type, char *name, char *def_value = NULL); int ParseNthParam(HTREEITEM func_node, int n, CString &name_text, CString &default_text, CString &range_text); @@ -1298,15 +1301,15 @@ class CDallasMainDlg : public CDialog { /////////////////////////////////// // Source File Parsing Functions /////////////////////////////////// - int ParseSourceScript(char *filename); // does high-level parsing of CPP file - int ParseMsgTableFile(char *filename); // reads in the message list from a file + int ParseSourceScript(const char *filename); // does high-level parsing of CPP file + int ParseMsgTableFile(const char *filename); // reads in the message list from a file HTREEITEM ParseScriptNodeLine_v0(char *line, int linenum, HTREEITEM parent, bool &skip_all_children, HTREEITEM insert_before = TVI_LAST); HTREEITEM ParseScriptNodeLine_v1U(char *line, int linenum, HTREEITEM parent, bool &skip_all_children, int version, HTREEITEM insert_before = TVI_LAST); void ScriptFileParseError(int error_code, int linenum, int script_ID, const char *name); - void SpecialScriptFileParseError(int linenum, int script_ID, char *type_name, const char *name); + void SpecialScriptFileParseError(int linenum, int script_ID, const char *type_name, const char *name); bool ValidateFunctionNode(HTREEITEM node, int linenum); /////////////////////////////////// @@ -1315,13 +1318,13 @@ class CDallasMainDlg : public CDialog { void InitCustomScriptStorage(void); void ClearCustomScriptStorage(void); int CountCustomScriptLines(CFILE *infile); - int ParseCustomScriptFile(char *filename, bool show_errors = TRUE); + int ParseCustomScriptFile(const char *filename, bool show_errors = TRUE); void WriteCustomScriptBlock(void); /////////////////////////////////// // Source File Creation Functions /////////////////////////////////// - int CreateMsgTableFile(char *filename); // writes message list to file + int CreateMsgTableFile(const char *filename); // writes message list to file void TabOver(void); // writes series of tabs int CreateScriptFile(char *filename); // creates the new script file void CreateLevelEventCases(tScriptOwnerGroup *owner_group); @@ -1431,8 +1434,8 @@ class CDallasMainDlg : public CDialog { HTREEITEM CreateDefaultConditionalStatementSubtree(HTREEITEM parent, int type, int query_id = -1); HTREEITEM CreateDefaultExpressionOperatorNode(HTREEITEM parent, int type); HTREEITEM CreateDefaultActionStatementNode(HTREEITEM parent); - HTREEITEM CreateDefaultParameterNode(HTREEITEM parent, HTREEITEM insert_before, int param_type, char *name, - char *def_value = NULL); + HTREEITEM CreateDefaultParameterNode(HTREEITEM parent, HTREEITEM insert_before, int param_type, const char *name, + const char *def_value = NULL); HTREEITEM CreateDefaultClipboardNode(void); /////////////////////////////////// diff --git a/editor/ObjCScript.cpp b/editor/ObjCScript.cpp index ccf75dd89..f40695f40 100644 --- a/editor/ObjCScript.cpp +++ b/editor/ObjCScript.cpp @@ -149,7 +149,7 @@ tScriptName Script_names[MAX_SCRIPTS]; #define MAX_SCREVTS 15 // INCREMENT MAX_SCREVTS in ObjCScript when you add a new event! -char *Script_evt_names[MAX_SCREVTS] = { +const char *Script_evt_names[MAX_SCREVTS] = { "EVT_AI_FRAME", "EVT_AI_NOTIFY", "EVT_AI_INIT", "EVT_CREATED", "EVT_COLLIDE", "EVT_DAMAGED", "EVT_INTERVAL", "EVT_DESTROY", "EVT_USE", @@ -183,13 +183,8 @@ char *GotoScriptInText(char *text, const char *script); int GenerateScriptParamInfo(int id, const char *script_text); bool NewScript(const char *filename) { - char path[_MAX_PATH]; - CFILE *file; - - ddio_MakePath(path, LocalLevelsDir, filename, NULL); - // create the file - file = cfopen(path, "wt"); + CFILE *file = cfopen(LocalLevelsDir / filename, "wt"); if (!file) return false; @@ -202,7 +197,6 @@ bool NewScript(const char *filename) { // Returns true on success char *LoadScript(const char *filename) { char *source; - char file_path[256]; CFILE *file; CString temp; int size; @@ -210,7 +204,7 @@ char *LoadScript(const char *filename) { memset(buffer, 0, MAX_SCRIPT_LINE_SIZE); - ddio_MakePath(file_path, LocalLevelsDir, filename, NULL); + std::filesystem::path file_path = LocalLevelsDir / filename; // mprintf(0,"Loading script from %s\n",file_path); if (!cfexist(file_path)) { return false; @@ -248,12 +242,7 @@ char *LoadScript(const char *filename) { } void SaveScript(const char *filename, char *script) { - CFILE *file; - char file_path[256]; - - ddio_MakePath(file_path, LocalLevelsDir, filename, NULL); - - file = cfopen(file_path, "wt"); + CFILE *file = cfopen(LocalLevelsDir / filename, "wt"); cf_WriteString(file, script); // mprintf(0,"Saving script to %s\n",file_path); cfclose(file); @@ -294,12 +283,8 @@ bool CompileScript(tD3XProgram *program, char *script) { } void SaveScriptCode(const char *filename, tD3XProgram *program) { - CFILE *file; - char file_path[256]; - // write out default script program - ddio_MakePath(file_path, LocalLevelsDir, filename, NULL); - file = cfopen(file_path, "wb"); + CFILE *file = cfopen(LocalLevelsDir / filename, "wb"); // D3XSaveProgram(file, program); // LGT: function undefined mprintf(0, "Saving %s.\n", filename); cfclose(file); diff --git a/editor/ObjCScript.h b/editor/ObjCScript.h index 5efef4b26..b028e2590 100644 --- a/editor/ObjCScript.h +++ b/editor/ObjCScript.h @@ -148,7 +148,7 @@ extern char *Level_script_source; extern tScriptName Script_names[]; // Script event names -extern char *Script_evt_names[]; +extern const char *Script_evt_names[]; extern uint16_t Script_evt_ids[]; bool NewScript(const char *filename); diff --git a/editor/QuickCompile.cpp b/editor/QuickCompile.cpp index 39cbc21b6..834d4dcd8 100644 --- a/editor/QuickCompile.cpp +++ b/editor/QuickCompile.cpp @@ -35,6 +35,8 @@ // QuickCompile.cpp : implementation file // +#include + #include "stdafx.h" #include "editor.h" #include "QuickCompile.h" @@ -110,10 +112,10 @@ BOOL CQuickCompile::OnInitDialog() { wnd->EnableWindow(false); if (cfexist(filename)) { - char full_path[_MAX_PATH]; - ddio_MakePath(full_path, LocalScriptDir, compiled_filename, NULL); + std::filesystem::path full_path = LocalScriptDir / compiled_filename; if (cfexist(full_path)) { - ddio_DeleteFile(full_path); + std::error_code ec; + std::filesystem::remove(full_path, ec); } if (!isours) { diff --git a/editor/ScriptCompilerAPI.cpp b/editor/ScriptCompilerAPI.cpp index 8fb33737c..58f4d7eca 100644 --- a/editor/ScriptCompilerAPI.cpp +++ b/editor/ScriptCompilerAPI.cpp @@ -203,7 +203,7 @@ int ScriptCompile(tCompilerInfo *ci) { cline += ci->source_filename; cline += "\""; cline += " -dir "; - cline += LocalScriptDir; + cline += LocalScriptDir.u8string().c_str(); if (ci->script_type == ST_LEVEL) cline += " -level"; switch (Warning_level) { @@ -338,7 +338,7 @@ bool ScriptCreateEmptyScript(char *filename, uint8_t script_type) { #define O(x) outputtofile x CFILE *CurrentFile; -void outputtofile(char *format, ...) { +void outputtofile(const char *format, ...) { char buffer[1024]; va_list marker; va_start(marker, format); @@ -348,8 +348,7 @@ void outputtofile(char *format, ...) { } bool ScriptCreateEmptyLevelScript(char *filename) { - char fullpath[_MAX_PATH]; - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; CurrentFile = cfopen(fullpath, "wt"); if (!CurrentFile) return false; @@ -552,8 +551,7 @@ bool ScriptCreateEmptyLevelScript(char *filename) { } bool ScriptCreateEmptyGameScript(char *filename) { - char fullpath[_MAX_PATH]; - ddio_MakePath(fullpath, LocalScriptDir, filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / filename; CurrentFile = cfopen(fullpath, "wt"); if (!CurrentFile) return false; diff --git a/editor/ScriptLevelInterface.cpp b/editor/ScriptLevelInterface.cpp index ef7714c86..d06c3b32b 100644 --- a/editor/ScriptLevelInterface.cpp +++ b/editor/ScriptLevelInterface.cpp @@ -142,7 +142,7 @@ static char THIS_FILE[] = __FILE__; #endif -bool AddNewGameFile(char *fullpath, char *directory); +bool AddNewGameFile(const std::filesystem::path &fullpath, const std::filesystem::path &directory); bool DeleteGamefile(char *tempbuffer); bool CheckInGamefile(char *tempbuffer, bool giveok); bool CheckOutGamefile(char *tempbuffer, bool show_ok_confirmation, bool report_who_has_locked = true); @@ -325,15 +325,15 @@ void CScriptLevelInterface::OnCompile() { "Congratulations! It looks like a dll was successfully created. I\ndon't see the DLL in the manage " "system, so\nwould you like me to add it into the manage system for you?(HIGHLY recommended)"); if (MessageBox(buffer, "Congratulations", MB_YESNO) == IDYES) { - ddio_MakePath(buffer, LocalScriptDir, filename, NULL); - if (!cfexist(buffer)) { + std::filesystem::path full_path = LocalScriptDir / filename; + if (!cfexist(full_path)) { sprintf(buffer, "I can't seem to find %s in your data\\scripts directory...Sorry,\nbut I can't automatically add it " "for you.\nYou'll have to manually add %s into the manage system.", filename, filename); MessageBox(buffer, "Uh Oh!", MB_OK); } else { - if (AddNewGameFile(buffer, "scripts")) { + if (AddNewGameFile(full_path, "scripts")) { sprintf(buffer, "%s has been added into the manage system. Don't forget to check it in to make sure it stays in " "the\nmanage system!", @@ -361,7 +361,7 @@ void CScriptLevelInterface::OnEditscript() { if (!combo) return; - char tempbuf[_MAX_PATH], fullpath[_MAX_PATH]; + char tempbuf[_MAX_PATH]; int index = combo->GetCurSel(); combo->GetLBText(index, tempbuf); @@ -371,9 +371,9 @@ void CScriptLevelInterface::OnEditscript() { MessageBox("This file is NOT checked out, you'll lose all changes on your\nnext data update!", "Warning", MB_OK); } - ddio_MakePath(fullpath, LocalScriptDir, tempbuf, NULL); + std::filesystem::path fullpath = LocalScriptDir / tempbuf; if (!cfexist(fullpath)) { - sprintf(tempbuf, "Weird, I couldn't find %s to open...", fullpath); + sprintf(tempbuf, "Weird, I couldn't find %s to open...", fullpath.u8string().c_str()); MessageBox(tempbuf, "Error", MB_OK); return; } @@ -384,9 +384,9 @@ void CScriptLevelInterface::OnEditscript() { sei.fMask = SEE_MASK_NOCLOSEPROCESS; sei.hwnd = m_hWnd; sei.lpVerb = "open"; - sei.lpFile = fullpath; + sei.lpFile = fullpath.u8string().c_str(); sei.lpParameters = NULL; - sei.lpDirectory = LocalScriptDir; + sei.lpDirectory = LocalScriptDir.u8string().c_str(); sei.nShow = SW_NORMAL; // int res = (int)ShellExecute(m_hWnd,"open",fullpath,NULL,LocalScriptDir,0); @@ -841,8 +841,7 @@ void CScriptLevelInterface::OnCreatescript() { sprintf(buffer, "Do you want to add\n%s\nto the network?", filename); if (cfexist(filename) && MessageBox(buffer, "Add to Data", MB_YESNO) == IDYES) { - ddio_MakePath(buffer, LocalScriptDir, filename, NULL); - AddNewGameFile(buffer, "scripts"); + AddNewGameFile(LocalScriptDir / filename, "scripts"); UpdateDialog(); added_to_network = true; } @@ -870,8 +869,7 @@ void CScriptLevelInterface::OnCreatescript() { ddio_SplitPath(filename, NULL, dllname, NULL); strcat(dllname, ".dll"); if (cfexist(dllname) && added_to_network) { - ddio_MakePath(buffer, LocalScriptDir, dllname, NULL); - AddNewGameFile(buffer, "scripts"); + AddNewGameFile(LocalScriptDir / dllname, "scripts"); UpdateDialog(); } @@ -1017,9 +1015,7 @@ bool DeleteGamefile(char *tempbuffer) { return true; } -bool AddNewGameFile(char *fullpath, char *directory) { - char cur_name[100]; - char pathname[100], name[100], extension[100]; +bool AddNewGameFile(const std::filesystem::path &fullpath, const std::filesystem::path &directory) { int gamefile_handle; if (!Network_up) { @@ -1027,28 +1023,27 @@ bool AddNewGameFile(char *fullpath, char *directory) { } // Okay, we selected a file. Lets do what needs to be done here. - ddio_SplitPath(fullpath, pathname, name, extension); - sprintf(cur_name, "%s%s", name, extension); + std::filesystem::path cur_name = fullpath.filename(); - if ((FindGamefileName(cur_name)) != -1) { + if ((FindGamefileName(cur_name.u8string().c_str())) != -1) { OutrageMessageBox("There is already a file with that name. Rename the file and then try to add it."); return false; } gamefile_handle = AllocGamefile(); - strcpy(Gamefiles[gamefile_handle].name, cur_name); - strcpy(Gamefiles[gamefile_handle].dir_name, directory); + strcpy(Gamefiles[gamefile_handle].name, cur_name.u8string().c_str()); + strcpy(Gamefiles[gamefile_handle].dir_name, directory.u8string().c_str()); // Finally, save a local copy of the model/anim and alloc a tracklock mprintf(0, "Making a copy of this file locally...\n"); char destname[100]; ddio_MakePath(destname, LocalD3Dir, "data", directory, Gamefiles[gamefile_handle].name, NULL); - if (stricmp(destname, fullpath)) // only copy if they are different + if (stricmp(destname, fullpath.u8string().c_str())) // only copy if they are different cf_CopyFile(destname, fullpath); - mng_AllocTrackLock(cur_name, PAGETYPE_GAMEFILE); + mng_AllocTrackLock(cur_name.u8string().c_str(), PAGETYPE_GAMEFILE); return true; } @@ -2301,26 +2296,23 @@ typedef void(DLLFUNCCALL *ShutdownDLL_fp)(void); // returns true if the given .cpp/.dll file is out of sync (or non-existant). Working directory // doesn't necessarily have to be set to data\scripts. -bool IsScriptOutofSync(char *name) { +bool IsScriptOutofSync(const std::filesystem::path &name) { bool out_of_sync = false; InitializeDLL_fp initdll; ShutdownDLL_fp shutdowndll; module mod; - char filename[_MAX_PATH], ext[_MAX_EXT]; - char path[_MAX_PATH]; - - ddio_SplitPath(name, NULL, filename, ext); + std::filesystem::path filename = name.stem(); Osiris_module_init.string_count = 0; Osiris_module_init.string_table = NULL; Osiris_module_init.module_is_static = false; Osiris_module_init.module_identifier = 0; - Osiris_module_init.script_identifier = filename; + Osiris_module_init.script_identifier = filename.u8string().c_str(); - strcat(filename, ".dll"); - ddio_MakePath(path, LocalScriptDir, filename, NULL); - mprintf(0, " Checking %s...", filename); + filename.replace_extension(".dll"); + std::filesystem::path path = LocalScriptDir / filename; + mprintf(0, " Checking %s...", filename.u8string().c_str()); if (mod_LoadModule(&mod, path)) { initdll = (InitializeDLL_fp)mod_GetSymbol(&mod, "InitializeDLL", 4); diff --git a/editor/ScriptLevelInterface.h b/editor/ScriptLevelInterface.h index 44d1e9935..e35bcc21a 100644 --- a/editor/ScriptLevelInterface.h +++ b/editor/ScriptLevelInterface.h @@ -63,12 +63,8 @@ * $NoKeywords: $ */ -#if !defined(AFX_SCRIPTLEVELINTERFACE_H__7CFE839C_90E9_11D2_AB2B_006008BF0B09__INCLUDED_) -#define AFX_SCRIPTLEVELINTERFACE_H__7CFE839C_90E9_11D2_AB2B_006008BF0B09__INCLUDED_ - -#if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 + // ScriptLevelInterface.h : header file // @@ -155,7 +151,7 @@ int AreScriptsOutofDate(void); // dir MUST be set to data\scripts before calling this function bool IsScriptOutofDate(char *name); +bool IsScriptOutofSync(const std::filesystem::path &name); + //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_SCRIPTLEVELINTERFACE_H__7CFE839C_90E9_11D2_AB2B_006008BF0B09__INCLUDED_) diff --git a/editor/ScriptMassCompile.cpp b/editor/ScriptMassCompile.cpp index 843c5980c..711d45dc4 100644 --- a/editor/ScriptMassCompile.cpp +++ b/editor/ScriptMassCompile.cpp @@ -60,19 +60,21 @@ // ScriptMassCompile.cpp : implementation file // +#include +#include +#include + #include "stdafx.h" #include "editor.h" +#include "ScriptLevelInterface.h" #include "ScriptMassCompile.h" #include "cfile.h" #include "gamefile.h" #include "gamefilepage.h" #include "AppDatabase.h" #include "Descent.h" -#include "mono.h" #include "ddio.h" #include "ScriptCompilerAPI.h" -#include -#include #include "mem.h" #include "pserror.h" @@ -86,7 +88,7 @@ static char THIS_FILE[] = __FILE__; // CScriptMassCompile dialog CString MassScriptEditContent; CEdit *MassScriptEdit; -void writeline(char *format, ...); +void writeline(const char *format, ...); CScriptMassCompile::CScriptMassCompile(CWnd *pParent /*=NULL*/) : CDialog(CScriptMassCompile::IDD, pParent) { //{{AFX_DATA_INIT(CScriptMassCompile) @@ -203,7 +205,7 @@ void CScriptMassCompile::OnOK() { CDialog::OnOK(); } -void writeline(char *format, ...) { +void writeline(const char *format, ...) { char buffer[2048]; va_list marker; va_start(marker, format); @@ -321,7 +323,7 @@ BOOL CScriptMassCompile::OnInitDialog() { return TRUE; } -void CScriptMassCompile::SetStepText(int step, char *format, ...) { +void CScriptMassCompile::SetStepText(int step, const char *format, ...) { if (step < 1 || step > 4) return; @@ -490,19 +492,20 @@ void masscompilercallback(char *str) { Descent->defer(); } -bool CScriptMassCompile::Step3(char *filename, bool islevel) { +bool CScriptMassCompile::Step3(const char *filename, bool islevel) { tCompilerInfo ci; ci.callback = masscompilercallback; ci.script_type = (islevel) ? ST_LEVEL : ST_GAME; strcpy(ci.source_filename, filename); strcat(ci.source_filename, ".cpp"); - char compiled_filename[_MAX_PATH], full_path[_MAX_PATH]; + char compiled_filename[_MAX_PATH]; strcpy(compiled_filename, filename); strcat(compiled_filename, ".dll"); - ddio_MakePath(full_path, LocalScriptDir, compiled_filename, NULL); + std::filesystem::path full_path = LocalScriptDir / compiled_filename; if (cfexist(full_path)) { - ddio_DeleteFile(full_path); + std::error_code ec; + std::filesystem::remove(full_path, ec); } writeline("===START COMPILE==="); @@ -525,7 +528,7 @@ bool CScriptMassCompile::Step3(char *filename, bool islevel) { } bool CheckInGamefile(char *tempbuffer, bool giveok); -bool AddNewGameFile(char *fullpath, char *directory); +bool AddNewGameFile(const std::filesystem::path &fullpath, const std::filesystem::path &directory); bool CScriptMassCompile::Step4(char *filename) { if (!Network_up) { SetStepText(4, "Skipping, Network 'Down'"); @@ -600,8 +603,7 @@ bool CScriptMassCompile::Step4(char *filename) { if (j >= MAX_GAMEFILES) { // compiled file doesn't exist, we'll need to add it writeline("Step 4: Attempting to add %s to manage system", compiled_filename); - char fullpath[_MAX_PATH]; - ddio_MakePath(fullpath, LocalScriptDir, compiled_filename, NULL); + std::filesystem::path fullpath = LocalScriptDir / compiled_filename; bool ret = AddNewGameFile(fullpath, "scripts"); if (!ret) { writeline("Step 4: Unable to add %s to manage system", compiled_filename); @@ -676,9 +678,8 @@ void CScriptMassCompile::OnOodscripts() { if (!list) return; - char old_dir[_MAX_PATH]; - ddio_GetWorkingDir(old_dir, _MAX_PATH); - ddio_SetWorkingDir(LocalScriptDir); + std::filesystem::path old_dir = std::filesystem::current_path(); + std::filesystem::current_path(LocalScriptDir); char filename[_MAX_PATH]; int count = list->GetCount(); @@ -695,9 +696,9 @@ void CScriptMassCompile::OnOodscripts() { } } - ddio_SetWorkingDir(old_dir); + std::filesystem::current_path(old_dir); } -bool IsScriptOutofSync(char *name); + void CScriptMassCompile::OnOosscripts() { CCheckListBox *list = (CCheckListBox *)GetDlgItem(IDC_LIST); if (!list) diff --git a/editor/ScriptMassCompile.h b/editor/ScriptMassCompile.h index 83e778988..f6bb0fb4d 100644 --- a/editor/ScriptMassCompile.h +++ b/editor/ScriptMassCompile.h @@ -73,10 +73,10 @@ class CScriptMassCompile : public CDialog { public: CScriptMassCompile(CWnd *pParent = NULL); // standard constructor - void SetStepText(int step, char *format, ...); + void SetStepText(int step, const char *format, ...); bool Step1(char *filename); bool Step2(char *filename); - bool Step3(char *filename, bool islevel); + bool Step3(const char *filename, bool islevel); bool Step4(char *filename); void BuildList(void); diff --git a/editor/ScriptSyncDialog.cpp b/editor/ScriptSyncDialog.cpp index ec8071fc7..74c93ed8f 100644 --- a/editor/ScriptSyncDialog.cpp +++ b/editor/ScriptSyncDialog.cpp @@ -39,7 +39,7 @@ static char THIS_FILE[] = __FILE__; #endif -bool ManageFindFirst(char *buffer, char *wildcard); +bool ManageFindFirst(char *buffer, const char *wildcard); bool ManageFindNext(char *buffer); void ManageFindClose(void); @@ -50,7 +50,7 @@ uint8_t DetermineScriptType(char *filename); bool IsScriptOutofDate(char *name); // returns true if the given .cpp/.dll file is out of sync (or non-existant). Working directory // doesn't necessarily have to be set to data\scripts. -bool IsScriptOutofSync(char *name); +bool IsScriptOutofSync(const std::filesystem::path &name); ///////////////////////////////////////////////////////////////////////////// // CScriptSyncDialog dialog @@ -206,7 +206,7 @@ class tManageFindIn { }; tManageFindIn ManageFindInData; -bool ManageFindFirst(char *buffer, char *wildcard) { +bool ManageFindFirst(char *buffer, const char *wildcard) { if (ManageFindInData.searching) ManageFindClose(); @@ -267,8 +267,8 @@ BOOL CScriptSyncDialog::OnInitDialog() { m_Files = NULL; m_FillingIn = true; m_ErrorCount = 0; - ddio_GetWorkingDir(old_dir, _MAX_PATH); - ddio_SetWorkingDir(LocalScriptDir); + old_dir = std::filesystem::current_path(); + std::filesystem::current_path(LocalScriptDir); m_List.Initialize(); BuildList(); @@ -477,5 +477,5 @@ void CScriptSyncDialog::OnDestroy() { if (m_Files) { mem_free(m_Files); } - ddio_SetWorkingDir(old_dir); + std::filesystem::current_path(old_dir); } diff --git a/editor/ScriptSyncDialog.h b/editor/ScriptSyncDialog.h index 3c1bd0661..addd8f1d8 100644 --- a/editor/ScriptSyncDialog.h +++ b/editor/ScriptSyncDialog.h @@ -16,12 +16,10 @@ * along with this program. If not, see . */ -#if !defined(AFX_SCRIPTSYNCDIALOG_H__9C4083C0_CB58_11D2_AB2B_006008BF0B09__INCLUDED_) -#define AFX_SCRIPTSYNCDIALOG_H__9C4083C0_CB58_11D2_AB2B_006008BF0B09__INCLUDED_ - -#if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 + +#include + // ScriptSyncDialog.h : header file // @@ -92,7 +90,7 @@ class CScriptSyncDialog : public CDialog { bool m_InStuff; int m_Index; bool m_Done; - char old_dir[_MAX_PATH]; + std::filesystem::path old_dir; bool m_FillingIn; int m_ErrorCount; int m_HasCompiler; @@ -124,5 +122,3 @@ class CScriptSyncDialog : public CDialog { //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_SCRIPTSYNCDIALOG_H__9C4083C0_CB58_11D2_AB2B_006008BF0B09__INCLUDED_) diff --git a/editor/WorldObjectsDoorDialog.cpp b/editor/WorldObjectsDoorDialog.cpp index 720210548..cb9b92876 100644 --- a/editor/WorldObjectsDoorDialog.cpp +++ b/editor/WorldObjectsDoorDialog.cpp @@ -120,7 +120,6 @@ #include "manage.h" #include "doorpage.h" #include "mono.h" -#include "vclip.h" #include "polymodel.h" #include "door.h" #include "ddio.h" @@ -972,7 +971,7 @@ void CWorldObjectsDoorDialog::OnBrowse() { char filename[_MAX_PATH]; char pathname[_MAX_PATH], name[_MAX_PATH]; - strcpy(pathname, LocalScriptDir); + strcpy(pathname, LocalScriptDir.u8string().c_str()); if (!OpenFileDialog(this, (LPCTSTR)filter, filename, pathname, sizeof(pathname))) return; diff --git a/editor/WorldObjectsGenericDialog.cpp b/editor/WorldObjectsGenericDialog.cpp index 03bbe5d75..670112e3c 100644 --- a/editor/WorldObjectsGenericDialog.cpp +++ b/editor/WorldObjectsGenericDialog.cpp @@ -1467,7 +1467,7 @@ void CWorldObjectsGenericDialog::OnSelScript() { char filename[_MAX_PATH]; char pathname[_MAX_PATH], name[_MAX_PATH]; - strcpy(pathname, LocalScriptDir); + strcpy(pathname, LocalScriptDir.u8string().c_str()); if (!OpenFileDialog(this, (LPCTSTR)filter, filename, pathname, sizeof(pathname))) return; diff --git a/editor/editorDoc.cpp b/editor/editorDoc.cpp index fdfa8f50e..f4a532467 100644 --- a/editor/editorDoc.cpp +++ b/editor/editorDoc.cpp @@ -70,6 +70,9 @@ // editorDoc.cpp : implementation of the CEditorDoc class // +#include +#include + #include "stdafx.h" #include "editor.h" #include "SrvrItem.h" // ADDED FOR OLE SUPPORT @@ -78,8 +81,6 @@ #include "keypaddialog.h" #include "MainFrm.h" -#include - #include "d3edit.h" #include "mono.h" #include "game.h" @@ -98,11 +99,8 @@ static char THIS_FILE[] = __FILE__; // Function to copy a Dallas script file int CopyScriptFile(char *old_file, char *new_file) { - char old_fullpath[_MAX_PATH]; - char new_fullpath[_MAX_PATH]; - - ddio_MakePath(old_fullpath, LocalScriptDir, old_file, NULL); - ddio_MakePath(new_fullpath, LocalScriptDir, new_file, NULL); + std::filesystem::path old_fullpath = LocalScriptDir / old_file; + std::filesystem::path new_fullpath = LocalScriptDir / new_file; return (cf_CopyFile(new_fullpath, old_fullpath)); } @@ -188,13 +186,10 @@ BOOL CEditorDoc::OnNewDocument() { theApp.main_doc = this; // Remove any "Untitled" dallas script files - char fullpath[_MAX_PATH]; - ddio_MakePath(fullpath, LocalScriptDir, "Untitled.cpp", NULL); - ddio_DeleteFile(fullpath); - ddio_MakePath(fullpath, LocalScriptDir, "Untitled.dll", NULL); - ddio_DeleteFile(fullpath); - ddio_MakePath(fullpath, LocalScriptDir, "Untitled.msg", NULL); - ddio_DeleteFile(fullpath); + std::error_code ec; + std::filesystem::remove(LocalScriptDir / "Untitled.cpp", ec); + std::filesystem::remove(LocalScriptDir / "Untitled.dll", ec); + std::filesystem::remove(LocalScriptDir / "Untitled.msg", ec); return TRUE; } diff --git a/lib/manage.h b/lib/manage.h index 2319d2bfa..7da08eed1 100644 --- a/lib/manage.h +++ b/lib/manage.h @@ -105,11 +105,11 @@ extern int Starting_editor, Loading_locals, Loading_addon_table; extern char LocalD3Dir[]; extern char NetD3Dir[]; -extern char TableFilename[]; +extern std::filesystem::path TableFilename; extern std::filesystem::path TableLockFilename; -extern char LocalTableFilename[]; -extern char LocalTempTableFilename[]; -extern char LocalLevelsDir[]; +extern std::filesystem::path LocalTableFilename; +extern std::filesystem::path LocalTempTableFilename; +extern std::filesystem::path LocalLevelsDir; extern std::filesystem::path ManageGraphicsDir; extern std::filesystem::path LocalManageGraphicsDir; extern std::filesystem::path LocalModelsDir; @@ -123,16 +123,16 @@ extern std::filesystem::path NetMiscDir; extern std::filesystem::path LocalMiscDir; extern std::filesystem::path NetMusicDir; extern std::filesystem::path LocalMusicDir; -extern char NetScriptDir[]; -extern char LocalScriptDir[]; +extern std::filesystem::path NetScriptDir; +extern std::filesystem::path LocalScriptDir; extern std::filesystem::path NetArtDir; extern std::filesystem::path LocalArtDir; extern std::filesystem::path LocalCustomGraphicsDir; extern std::filesystem::path LocalCustomSoundsDir; -extern char TempTableFilename[]; -extern char TempTableLockFilename[]; +extern std::filesystem::path TempTableFilename; +extern std::filesystem::path TempTableLockFilename; extern char ErrorString[INFO_STRING_LEN]; extern char InfoString[INFO_STRING_LEN]; extern char TableUser[]; @@ -218,7 +218,7 @@ int mng_FindTrackLock(char *name, int pagetype); // Searches through global array of tracklocks and returns first free one // returns -1 if none free -int mng_AllocTrackLock(char *name, int pagetype); +int mng_AllocTrackLock(const char *name, int pagetype); // Frees a tracklock void mng_FreeTrackLock(int n); @@ -233,7 +233,7 @@ int mng_RenamePage(char *oldname, char *newname, int pagetype); // Removes a file, then renames another file to be the removed file. Get it? // Returns 1 on success, else 0 on fail -int SwitcherooFiles(const char *name, char *tempname); +int SwitcherooFiles(const std::filesystem::path &name, const std::filesystem::path &tempname); // Returns true if the passed in pagelock is in the LockList, else false bool InLockList(mngs_Pagelock *pl); diff --git a/manage/manage.cpp b/manage/manage.cpp index 8155162bc..2fc9b40b5 100644 --- a/manage/manage.cpp +++ b/manage/manage.cpp @@ -470,19 +470,18 @@ int Old_table_method = 0; void mng_WriteNewUnknownPage(CFILE *outfile); // This is for levels -char LocalLevelsDir[TABLE_NAME_LEN]; +std::filesystem::path LocalLevelsDir; // This is for pages -std::filesystem::path TableLockFilename; -char TableFilename[TABLE_NAME_LEN]; -char TempTableLockFilename[TABLE_NAME_LEN], TempTableFilename[TABLE_NAME_LEN]; -char LocalTableFilename[TABLE_NAME_LEN], LocalTempTableFilename[TABLE_NAME_LEN]; -char BackupTableFilename[TABLE_NAME_LEN], BackupLockFilename[TABLE_NAME_LEN]; +std::filesystem::path TableLockFilename, TableFilename; +std::filesystem::path TempTableLockFilename, TempTableFilename; +std::filesystem::path LocalTableFilename, LocalTempTableFilename; +std::filesystem::path BackupTableFilename, BackupLockFilename; std::filesystem::path ManageGraphicsDir, LocalManageGraphicsDir; std::filesystem::path LocalModelsDir, NetModelsDir; std::filesystem::path LocalSoundsDir, NetSoundsDir; std::filesystem::path LocalRoomsDir, NetRoomsDir; std::filesystem::path LocalBriefingDir, NetBriefingDir; -char LocalScriptDir[TABLE_NAME_LEN], NetScriptDir[TABLE_NAME_LEN]; +std::filesystem::path LocalScriptDir, NetScriptDir; std::filesystem::path LocalMiscDir, NetMiscDir; std::filesystem::path LocalArtDir, NetArtDir; std::filesystem::path LocalMusicDir, NetMusicDir; @@ -533,7 +532,6 @@ void mng_BackupTableFile(); // returns 1 if network is up, 0 if down int mng_IsNetworkUp() { - char dir[100]; if (Stand_alone) return 0; @@ -542,18 +540,18 @@ int mng_IsNetworkUp() { Database->read("net directory", net_dir, &dirlen); if (net_dir[0] == 0) return 0; - ddio_MakePath(dir, net_dir, "data", NULL); + std::filesystem::path dir = std::filesystem::path(net_dir) / "data"; std::error_code ec; std::filesystem::create_directories(dir, ec); if (!ec) { - char old_dir[100]; - ddio_GetWorkingDir(old_dir, 100); - if (!ddio_SetWorkingDir(dir)) + std::filesystem::path old_dir = std::filesystem::current_path(); + std::filesystem::current_path(dir, ec); + if (ec) return 0; // network down else { - ddio_SetWorkingDir(old_dir); // restore directory - return 1; // directory is already there + std::filesystem::current_path(old_dir); // restore directory + return 1; // directory is already there } } @@ -671,9 +669,9 @@ int mng_LoadTableFiles(int show_progress) { int mng_InitLocalTables() { // Set the local table directory from the base directory. auto writable_base_directory_string = cf_GetWritableBaseDirectory().u8string(); - strncpy(LocalD3Dir, (const char*)writable_base_directory_string.c_str(), sizeof LocalD3Dir); + strncpy(LocalD3Dir, (const char *)writable_base_directory_string.c_str(), sizeof LocalD3Dir); LocalD3Dir[sizeof LocalD3Dir - 1] = '\0'; - if (strlen(LocalD3Dir) != strlen((const char*)writable_base_directory_string.c_str())) { + if (strlen(LocalD3Dir) != strlen((const char *)writable_base_directory_string.c_str())) { LOG_WARNING << "cf_GetWritableBaseDirectory() is too long to fit in LocalD3Dir, so LocalD3Dir was truncated."; } LOG_INFO << "Local dir: " << LocalD3Dir; @@ -690,12 +688,12 @@ int mng_InitLocalTables() { LocalCustomGraphicsDir = cf_GetWritableBaseDirectory() / "custom" / "graphics"; LocalRoomsDir = localdir / "data" / "rooms"; LocalBriefingDir = localdir / "data" / "briefings"; - ddio_MakePath(LocalScriptDir, LocalD3Dir, "data", "scripts", NULL); + LocalScriptDir = localdir / "data" / "scripts"; LocalMiscDir = localdir / "data" / "misc"; LocalArtDir = localdir / "data" / "art"; LocalMusicDir = localdir / "data" / "music"; LocalVoiceDir = localdir / "data" / "voice"; - ddio_MakePath(LocalLevelsDir, LocalD3Dir, "data", "levels", NULL); + LocalLevelsDir = localdir / "data" / "levels"; cf_SetSearchPath(LocalD3Dir); #ifndef RELEASE cf_SetSearchPath(LocalLevelsDir); @@ -714,11 +712,11 @@ 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); + LocalTableFilename = LocalTableDir / LOCAL_TABLE; + LocalTempTableFilename = LocalTableDir / TEMP_LOCAL_TABLE; } else { - strcpy(LocalTableFilename, LOCAL_TABLE); - strcpy(LocalTempTableFilename, TEMP_LOCAL_TABLE); + LocalTableFilename = LOCAL_TABLE; + LocalTempTableFilename = TEMP_LOCAL_TABLE; } return 1; @@ -739,7 +737,7 @@ int mng_InitNetTables() { NetSoundsDir = netdir / "data" / "sounds"; NetRoomsDir = netdir / "data" / "rooms"; NetBriefingDir = netdir / "data" / "briefings"; - ddio_MakePath(NetScriptDir, NetD3Dir, "data", "scripts", NULL); + NetScriptDir = netdir / "data" / "scripts"; NetMiscDir = netdir / "data" / "misc"; ManageGraphicsDir = netdir / "data" / "graphics"; NetTableDir = netdir / "data" / "tables"; @@ -747,11 +745,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); + BackupLockFilename = NetTableDir / "tablelok.bak"; + BackupTableFilename = NetTableDir / "table.bak"; + TableFilename = NetTableDir / NET_TABLE; + TempTableLockFilename = NetTableDir / "lock.tmp"; + TempTableFilename = NetTableDir / TEMP_NET_TABLE; LockerFile = NetTableDir / "locker"; VersionFile = NetTableDir / "TableVersion"; @@ -794,7 +792,7 @@ void mng_CheckToCreateLocalTables() { CFILE *outfile; if (!Network_up) { - strcpy(TableFilename, NET_TABLE); + TableFilename = NET_TABLE; LOG_DEBUG << "table filename = " << TableFilename; return; } @@ -820,7 +818,6 @@ void mng_InitLocalDirectories() { std::filesystem::create_directories(dir / "custom" / "settings", ec); std::filesystem::create_directories(dir / "savegame", ec); - cf_SetSearchPath(LocalCustomGraphicsDir); cf_SetSearchPath(LocalCustomSoundsDir); @@ -933,7 +930,7 @@ int mng_FindTrackLock(char *name, int pagetype) { // Searches through global array of tracklocks and returns first free one // Sets the tracklock to be named "name" and its type "pagetype" // returns -1 if none free -int mng_AllocTrackLock(char *name, int pagetype) { +int mng_AllocTrackLock(const char *name, int pagetype) { int i; for (i = 0; i < MAX_TRACKLOCKS; i++) if (GlobalTrackLocks[i].used == 0) { @@ -1237,8 +1234,8 @@ int mng_LoadNetPages(int show_progress) { } else infile = cfopen(TableFilename, "rb"); if (!infile) { - LOG_ERROR.printf("Couldn't open table file (%s) to read pages!\n", TableFilename); - Error("Cannot open table file <%s>", TableFilename); + LOG_ERROR.printf("Couldn't open table file (%s) to read pages!\n", TableFilename.u8string().c_str()); + Error("Cannot open table file <%s>", TableFilename.u8string().c_str()); return 0; } if (show_progress) { @@ -1368,7 +1365,7 @@ int mng_LoadLocalPages() { LOG_INFO << "Overlaying local pages..."; infile = cfopen(LocalTableFilename, "rb"); if (!infile) { - LOG_WARNING.printf("Couldn't open local table file (%s) to read pages!", LocalTableFilename); + LOG_WARNING.printf("Couldn't open local table file (%s) to read pages!", LocalTableFilename.u8string().c_str()); return 1; } Loading_locals = 1; @@ -1422,7 +1419,7 @@ int mng_LoadLocalPages() { #define MAX_TRIES 10000 // Removes a file, then renames another file to be the removed file. Get it? // Returns 1 on success, else 0 on fail -int SwitcherooFiles(const char *name, char *tempname) { +int SwitcherooFiles(const std::filesystem::path &name, const std::filesystem::path &tempname) { /*// If we're changing the net table file, make a backup first! if ((!stricmp (name,TableFilename))) { @@ -1430,7 +1427,8 @@ int SwitcherooFiles(const char *name, char *tempname) { cf_CopyFile (BackupLockFilename,TableLockFilename); }*/ int num_tries = 0; - while (!ddio_DeleteFile(name) && num_tries < MAX_TRIES) { + std::error_code ec; + while (!std::filesystem::remove(name, ec) && num_tries < MAX_TRIES) { D3::ChronoTimer::SleepMS(100); num_tries++; } @@ -1441,7 +1439,11 @@ int SwitcherooFiles(const char *name, char *tempname) { return (0); } num_tries = 0; - while ((rename(tempname, name)) && num_tries <= MAX_TRIES) { + while (num_tries <= MAX_TRIES) { + std::filesystem::rename(tempname, name, ec); + if (!ec) { + break; + } D3::ChronoTimer::SleepMS(100); num_tries++; } @@ -1459,6 +1461,7 @@ void mng_TransferPages() { CFILE *infile, *outfile; int pagetype; int num_tracklocks = 0; + std::error_code ec; LOG_INFO << "Transferring pages, please wait..."; if (!mng_MakeLocker()) return; @@ -1569,12 +1572,14 @@ void mng_TransferPages() { cfclose(infile); cfclose(outfile); - if (remove(TableLockFilename)) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); + if (std::filesystem::remove(TableLockFilename, ec)) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file: %s", ec.message().c_str()); goto done; } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); + + std::filesystem::rename(TempTableLockFilename, TableLockFilename, ec); + if (ec) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file: %s", ec.message().c_str()); goto done; } @@ -1860,13 +1865,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", (const char *)ext.u8string().c_str())) primtype = PRIMTYPE_OOF; - else if (!stricmp(".ogf", (const char*)ext.u8string().c_str())) + else if (!stricmp(".ogf", (const char *)ext.u8string().c_str())) primtype = PRIMTYPE_OGF; - else if (!stricmp(".oaf", (const char*)ext.u8string().c_str())) + else if (!stricmp(".oaf", (const char *)ext.u8string().c_str())) primtype = PRIMTYPE_OAF; - else if (!stricmp(".wav", (const char*)ext.u8string().c_str())) + else if (!stricmp(".wav", (const char *)ext.u8string().c_str())) primtype = PRIMTYPE_WAV; else primtype = PRIMTYPE_FILE; @@ -1875,7 +1880,7 @@ int GetPrimType(const std::filesystem::path &name) { #if defined(WIN32) // Builds a list of old files in a path -void BuildOldFilesForDirectory(const std::filesystem::path& path, FILETIME threshold) { +void BuildOldFilesForDirectory(const std::filesystem::path &path, FILETIME threshold) { HANDLE filehandle; WIN32_FIND_DATA filedata; std::filesystem::path newpath = path / "*.*"; @@ -2365,7 +2370,7 @@ void mng_ReadPhysicsChunk(physics_info *phys_info, CFILE *infile) { phys_info->full_rotthrust = cf_ReadFloat(infile); phys_info->num_bounces = cf_ReadInt(infile); phys_info->velocity.z() = cf_ReadFloat(infile); - phys_info->rotvel = { cf_ReadFloat(infile), cf_ReadFloat(infile), cf_ReadFloat(infile) }; + phys_info->rotvel = {cf_ReadFloat(infile), cf_ReadFloat(infile), cf_ReadFloat(infile)}; phys_info->wiggle_amplitude = cf_ReadFloat(infile); phys_info->wiggles_per_sec = cf_ReadFloat(infile); phys_info->coeff_restitution = cf_ReadFloat(infile); @@ -2735,8 +2740,7 @@ bool mng_SetAddonTable(const char *name) { return false; strcpy(AddOnDataTables[Num_addon_tables].AddOnTableFilename, name); - AddOnDataTables[Num_addon_tables].Addon_tracklocks = - mem_rmalloc(MAX_ADDON_TRACKLOCKS); + AddOnDataTables[Num_addon_tables].Addon_tracklocks = mem_rmalloc(MAX_ADDON_TRACKLOCKS); AddOnDataTables[Num_addon_tables].Num_addon_tracklocks = 0; ASSERT(AddOnDataTables[Num_addon_tables].Addon_tracklocks); memset(AddOnDataTables[Num_addon_tables].Addon_tracklocks, 0, MAX_ADDON_TRACKLOCKS * sizeof(mngs_track_lock)); @@ -2862,8 +2866,9 @@ void mng_CompileAddonPages(void) { // this is it! LOG_INFO.printf("Compiling: %s[%s] to %d", AddOnDataTables[tf].Addon_tracklocks[i].name, - (curr_tablefile == 1) ? TableFilename : AddOnDataTables[curr_tablefile - 2].AddOnTableFilename, - page_pos); + (curr_tablefile == 1) ? TableFilename.u8string().c_str() + : AddOnDataTables[curr_tablefile - 2].AddOnTableFilename, + page_pos); ASSERT(AddOnDataTables[tf].Addon_tracklocks[i].stack_filepos == 0); AddOnDataTables[tf].Addon_tracklocks[i].stack_filepos = page_pos; found_page = true; diff --git a/manage/pagelock.cpp b/manage/pagelock.cpp index 4c6c70f2a..a5759e7ee 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(TableLockFilename, TempTableLockFilename)) { Int3(); return 0; } @@ -590,8 +590,10 @@ 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())) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); + std::error_code ec; + std::filesystem::rename(TempTableLockFilename, TableLockFilename, ec); + if (ec) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file: %s", ec.message().c_str()); return (0); } @@ -603,6 +605,7 @@ int mng_DeletePagelockSeries(char *names[], int num, int pagetype) { CFILE *infile, *outfile; int done = 0; mngs_Pagelock temp_pl; + std::error_code ec; infile = (CFILE *)cfopen(TableLockFilename, "rb"); if (!infile) { @@ -640,12 +643,14 @@ int mng_DeletePagelockSeries(char *names[], int num, int pagetype) { cfclose(infile); cfclose(outfile); - if (remove(TableLockFilename)) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); + if (std::filesystem::remove(TableLockFilename, ec)) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file: %s", ec.message().c_str()); return (0); } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); + + std::filesystem::rename(TempTableLockFilename, TableLockFilename, ec); + if (ec) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file: %s", ec.message().c_str()); return (0); } @@ -729,6 +734,7 @@ int mng_UnlockPagelockSeries(const char *names[], int *pagetypes, int num) { int done = 0; mngs_Pagelock temp_pl; int total = 0; + std::error_code ec; infile = (CFILE *)cfopen(TableLockFilename, "rb"); if (!infile) { @@ -777,12 +783,14 @@ int mng_UnlockPagelockSeries(const char *names[], int *pagetypes, int num) { LOG_DEBUG.printf("Unlocked %d pages\n", total); - if (remove(TableLockFilename)) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file - errno %d", errno); + if (std::filesystem::remove(TableLockFilename)) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem deleting the temp file: %s", ec.message().c_str()); return (0); } - if (rename(TempTableLockFilename, (const char*)TableLockFilename.u8string().c_str())) { - snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file - errno %d", errno); + + std::filesystem::rename(TempTableLockFilename, TableLockFilename, ec); + if (ec) { + snprintf(ErrorString, sizeof(ErrorString), "There was a problem renaming the temp file: %s", ec.message().c_str()); return (0); } diff --git a/misc/pstring.cpp b/misc/pstring.cpp index 53a120cdf..973fb92c2 100644 --- a/misc/pstring.cpp +++ b/misc/pstring.cpp @@ -71,7 +71,7 @@ std::size_t CleanupStr(char *dest, const char *src, std::size_t destlen) { end++; // Set output size to minimum of trimmed string length and buffer size minus 1 - out_size = (end - src) < destlen - 1 ? (end - src) : destlen - 1; + out_size = static_cast(end - src) < destlen - 1 ? (end - src) : destlen - 1; // Copy trimmed string and add null terminator std::memcpy(dest, src, out_size); @@ -84,7 +84,7 @@ std::string StringJoin(const std::vector &strs, const std::string & if (strs.empty()) return ""; std::vector res; - for (int i = 0; i < strs.size() - 1; ++i) { + for (size_t i = 0; i < strs.size() - 1; ++i) { for (auto const &c : strs[i]) { res.push_back(c); } diff --git a/netcon/includes/con_dll.h b/netcon/includes/con_dll.h index edf67e576..b20a25f40 100644 --- a/netcon/includes/con_dll.h +++ b/netcon/includes/con_dll.h @@ -447,9 +447,6 @@ rend_GetRenderState_fp DLLrend_GetRenderState; typedef bool (*LoadMission_fp)(char *msn); LoadMission_fp DLLLoadMission; -typedef void (*ddio_MakePath_fp)(char *newPath, const char *absolutePathHeader, const char *subDir, ...); -ddio_MakePath_fp DLLddio_MakePath; - // typedef void( *MultiStartServer_fp) (int playing,char *scriptname,int dedicated_num_teams=-1); typedef void (*MultiStartServer_fp)(int playing, char *scriptname, int dedicated_num_teams); MultiStartServer_fp DLLMultiStartServerFP; @@ -904,7 +901,7 @@ void CommonDLLInit(int *api_func) { DLLMultiStartClient = (MultiStartClient_fp)API.fp[32]; DLLrend_GetRenderState = (rend_GetRenderState_fp)API.fp[33]; DLLLoadMission = (LoadMission_fp)API.fp[34]; - DLLddio_MakePath = (ddio_MakePath_fp)API.fp[35]; + // DLLddio_MakePath = (ddio_MakePath_fp)API.fp[35]; // unused // DLLddio_FindFileStart = (ddio_FindFileStart_fp)API.fp[36]; // unused // DLLddio_FindFileClose = (ddio_FindFileClose_fp)API.fp[37]; // unused // DLLddio_FindNextFile = (ddio_FindNextFile_fp)API.fp[38]; // unused diff --git a/netgames/anarchy/anarchy.cpp b/netgames/anarchy/anarchy.cpp index 54f9a00a8..7a4906172 100644 --- a/netgames/anarchy/anarchy.cpp +++ b/netgames/anarchy/anarchy.cpp @@ -50,15 +50,15 @@ * $NoKeywords: $ */ -#include -#include -#include +#include +#include +#include +#include + #include "idmfc.h" #include "Anarchy.h" #include "anarchystr.h" -#include - IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; @@ -78,7 +78,7 @@ static bool display_my_welcome = false; static void DisplayHUDScores(struct tHUDItem *hitem); static void DisplayScores(void); static void DisplayWelcomeMessage(int player_num); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); static void SwitchHUDColor(int i); static void SwitchAnarchyScores(int i); static const char *GetString(int d); @@ -546,7 +546,7 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -709,21 +709,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "Anarchy" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/coop/coop.cpp b/netgames/coop/coop.cpp index f055e2edd..9e376acd1 100644 --- a/netgames/coop/coop.cpp +++ b/netgames/coop/coop.cpp @@ -99,15 +99,15 @@ * $NoKeywords: $ */ -#include -#include -#include +#include +#include +#include +#include + #include "idmfc.h" #include "coop.h" #include "coopstr.h" -#include - IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; static player *dPlayers; @@ -631,7 +631,7 @@ void DisplayHUDScores(struct tHUDItem *hitem) { DLLgrtext_SetFont(old_font); } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { /* CFILE *file; DLLOpenCFILE(&file,filename,"wt"); @@ -709,21 +709,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "D3Coop" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/coop/coop.h b/netgames/coop/coop.h index 4c2c36480..def377f51 100644 --- a/netgames/coop/coop.h +++ b/netgames/coop/coop.h @@ -73,7 +73,7 @@ void OnPlayerConnect(int player_num); void OnServerGameCreated(void); void OnClientLevelStart(void); void OnGameStateRequest(int player_num); -void SaveStatsToFile(char *filename); +void SaveStatsToFile(const std::filesystem::path &filename); void OnSaveStatsToFile(void); void OnLevelEndSaveStatsToFile(void); void OnDisconnectSaveStatsToFile(void); diff --git a/netgames/ctf/ctf.cpp b/netgames/ctf/ctf.cpp index c3b1779ce..ad061937a 100644 --- a/netgames/ctf/ctf.cpp +++ b/netgames/ctf/ctf.cpp @@ -84,8 +84,9 @@ * $NoKeywords: $ */ +#include + #include "gamedll_header.h" -#include #include "idmfc.h" #include "ctf.h" @@ -238,7 +239,7 @@ const char *GetString(int d) { else return StringTable[d]; } -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); static void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size); static void ShowStatBitmap(int precord_num, int column_num, int x, int y, int w, int h, uint8_t alpha_to_use); @@ -1380,7 +1381,7 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -1604,21 +1605,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "CTF" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/dmfc/dmfcbase.cpp b/netgames/dmfc/dmfcbase.cpp index dbd9773e0..84c2f00e4 100644 --- a/netgames/dmfc/dmfcbase.cpp +++ b/netgames/dmfc/dmfcbase.cpp @@ -467,15 +467,19 @@ * $NoKeywords: $ */ +#include +#include +#include +#include +#include +#include +#include + #include "gamedll_header.h" #include "DMFC.h" #include "dmfcinternal.h" #include "dmfcinputcommands.h" -#include -#include -#include - char **DMFCStringTable; int DMFCStringTableSize = 0; const char *_DMFCErrorString = "DMFC Missing String"; @@ -935,8 +939,8 @@ void DMFCBase::LoadFunctions(int *api_func) { DLLHideCursor = (ui_HideCursor_fp)API.fp[149]; DLLGameFrame = (GameFrame_fp)API.fp[150]; DPrintf = (DPrintf_fp)API.fp[151]; - DLLddio_MakePath = (ddio_MakePath_fp)API.fp[152]; - DLLddio_SplitPath = (ddio_SplitPath_fp)API.fp[153]; + // DLLddio_MakePath = (ddio_MakePath_fp)API.fp[152]; + // DLLddio_SplitPath = (ddio_SplitPath_fp)API.fp[153]; DLLPlay2dSound = (Play2dSound_fp)API.fp[154]; DLLTouchSound = (TouchSound_fp)API.fp[155]; DatabaseRead1 = (dDatabaseRead_fp1)API.fp[156]; @@ -3852,103 +3856,22 @@ void DMFCBase::EnableAutoSaveDisconnect(bool enable) { DISABLE_FLAGS(m_iProtectedFlags, DMFC_PRF_AUTOSAVEDISC); } -// DMFCBase::GenerateStatFilename -// -// Given the following information it will return a full path to what -// the recommended filename to save stats to should be. -// root = Multiplayer DLL Name (filename will start with this) -// end_of_level = pass true if this is the end of a level stats -void DMFCBase::GenerateStatFilename(char *filename, const char *root, bool end_of_level) { +std::filesystem::path DMFCBase::GenerateStatFilename(const char *root, bool end_of_level) { int level = Current_mission->cur_level; char *name = Netgame->name; - struct tm *newtime; - time_t long_time; - time(&long_time); - newtime = localtime(&long_time); - - char fname[256]; - char timestr[100]; - char day[8], month[8]; - - switch (newtime->tm_wday) { - case 0: - strcpy(day, DTXT_SUNDAY); - break; - case 1: - strcpy(day, DTXT_MONDAY); - break; - case 2: - strcpy(day, DTXT_TUESDAY); - break; - case 3: - strcpy(day, DTXT_WEDNESDAY); - break; - case 4: - strcpy(day, DTXT_THURSDAY); - break; - case 5: - strcpy(day, DTXT_FRIDAY); - break; - case 6: - strcpy(day, DTXT_SATURDAY); - break; - } - - switch (newtime->tm_mon) { - case 0: - strcpy(month, DTXT_JANUARY); - break; - case 1: - strcpy(month, DTXT_FEBRUARY); - break; - case 2: - strcpy(month, DTXT_MARCH); - break; - case 3: - strcpy(month, DTXT_APRIL); - break; - case 4: - strcpy(month, DTXT_MAY); - break; - case 5: - strcpy(month, DTXT_JUNE); - break; - case 6: - strcpy(month, DTXT_JULY); - break; - case 7: - strcpy(month, DTXT_AUGUST); - break; - case 8: - strcpy(month, DTXT_SEPTEMBER); - break; - case 9: - strcpy(month, DTXT_OCTOBER); - break; - case 10: - strcpy(month, DTXT_NOVEMBER); - break; - case 11: - strcpy(month, DTXT_DECEMBER); - break; - } - - snprintf(timestr, sizeof(timestr), "%s._%s._%d_%d_%02d%02d", day, month, newtime->tm_mday, newtime->tm_year + 1900, - newtime->tm_hour, newtime->tm_min); - snprintf(fname, sizeof(fname), "%s_%s_%d_%s%s.stats", root, name, level, (end_of_level) ? DTXT_ENDOFLEVELCONCAT : "", - timestr); + const auto now = std::chrono::system_clock::now(); + auto in_time_t = std::chrono::system_clock::to_time_t(now); + std::stringstream ss; + ss << root << "_" << name << "_" << level << "_" << (end_of_level ? DTXT_ENDOFLEVELCONCAT : "") + << std::put_time(std::localtime(&in_time_t), "%Y_%m_%d_%H%M") << ".stats"; + std::string fname = ss.str(); // remove all spaces (convert to _) - char *p = fname; - while ((*p)) { - if (*p == ' ') - *p = '_'; - p++; - } + std::replace(fname.begin(), fname.end(), ' ', '_'); // build the path info here - DLLddio_MakePath(filename, LocalD3Dir, "netgames", fname, NULL); + return std::filesystem::path(LocalD3Dir) / "netgames" / fname; } // DMFCBase::IsPlayerObserver @@ -4683,7 +4606,7 @@ MenuItem *DMFCBase::CreateMenuItem(const char *title, char type, uint8_t flags, return NULL; } -void ParseHostsFile(char *filename, tHostsNode **root) { +void ParseHostsFile(const std::filesystem::path &filename, tHostsNode **root) { CFILE *file; DLLOpenCFILE(&file, filename, "rt"); @@ -4835,15 +4758,12 @@ void ParseHostsFile(char *filename, tHostsNode **root) { // // Reads in the hosts.allow and hosts.deny files (if available) void DMFCBase::ReadInHostsAllowDeny(void) { - char allow_fn[_MAX_PATH], deny_fn[_MAX_PATH]; - bool allow_exist, deny_exist; - // build the path info here - DLLddio_MakePath(allow_fn, LocalD3Dir, "netgames", "hosts.allow", NULL); - DLLddio_MakePath(deny_fn, LocalD3Dir, "netgames", "hosts.deny", NULL); + std::filesystem::path allow_fn = std::filesystem::path(LocalD3Dir) / "netgames" / "hosts.allow"; + std::filesystem::path deny_fn = std::filesystem::path(LocalD3Dir) / "netgames" / "hosts.deny"; - allow_exist = (bool)(DLLcfexist(allow_fn) != 0); - deny_exist = (bool)(DLLcfexist(deny_fn) != 0); + bool allow_exist = (bool)(DLLcfexist(allow_fn) != 0); + bool deny_exist = (bool)(DLLcfexist(deny_fn) != 0); m_DenyList = NULL; m_AllowList = NULL; @@ -4909,7 +4829,7 @@ bool DMFCBase::IsPlayerAlive(int pnum) { // Loads up the startup script and sets variables accordingly void DMFCBase::ParseStartupScript(void) { CFILE *file; - char path[_MAX_PATH]; + std::filesystem::path path; char buffer[256]; int size; bool ok_to_read; @@ -4918,11 +4838,11 @@ void DMFCBase::ParseStartupScript(void) { if ((autoexec_arg = DLLFindArg("-autoexec", 1)) != 0) { // a specific autoexec.dmfc file was specified, use that - strcpy(path, GetGameArg(autoexec_arg + 1)); - mprintf(0, "Override AUTOEXEC.DMFC to %s\n", path); + path = GetGameArg(autoexec_arg + 1); + mprintf(0, "Override AUTOEXEC.DMFC to %s\n", path.u8string().c_str()); } else { // use the default autoexec.dmfc - DLLddio_MakePath(path, LocalD3Dir, "netgames", "autoexec.dmfc", NULL); + path = std::filesystem::path(LocalD3Dir) / "netgames" / "autoexec.dmfc"; } DLLOpenCFILE(&file, path, "rt"); diff --git a/netgames/dmfc/dmfcfunctions.cpp b/netgames/dmfc/dmfcfunctions.cpp index 409e68a41..e0a612543 100644 --- a/netgames/dmfc/dmfcfunctions.cpp +++ b/netgames/dmfc/dmfcfunctions.cpp @@ -290,8 +290,6 @@ void (*DLLHideCursor)(void); void (*DLLGameFrame)(void); void (*DPrintf)(const char *format, ...); void (*DLLassert)(int, const char *, const char *, int); -void (*DLLddio_SplitPath)(const char *srcPath, char *path, char *filename, char *ext); -void (*DLLddio_MakePath)(char *newPath, const char *absolutePathHeader, const char *subDir, ...); int (*DLLPlay2dSound)(int sound_index, float volume); void (*DLLTouchSound)(int sound_index); bool (*DatabaseRead1)(const char *label, char *entry, int *entrylen); diff --git a/netgames/dmfc/dmfcinterface.cpp b/netgames/dmfc/dmfcinterface.cpp index 617dd3f2a..101932394 100644 --- a/netgames/dmfc/dmfcinterface.cpp +++ b/netgames/dmfc/dmfcinterface.cpp @@ -927,9 +927,9 @@ void DLLFUNCCALL IDMFC_EnableAutoSaveDisconnect(IDMFC *instance, bool enable) { instance->EnableAutoSaveDisconnect(enable); } -void DLLFUNCCALL IDMFC_GenerateStatFilename(IDMFC *instance, char *filename, const char *root, bool end_of_level) { +std::filesystem::path DLLFUNCCALL IDMFC_GenerateStatFilename(IDMFC *instance, const char *root, bool end_of_level) { assert(instance != NULL); - instance->GenerateStatFilename(filename, root, end_of_level); + return instance->GenerateStatFilename(root, end_of_level); } bool DLLFUNCCALL IDMFC_IsPlayerObserver(IDMFC *instance, int pnum) { diff --git a/netgames/dmfc/dmfcinternal.h b/netgames/dmfc/dmfcinternal.h index 45a68b08c..5ff855ae4 100644 --- a/netgames/dmfc/dmfcinternal.h +++ b/netgames/dmfc/dmfcinternal.h @@ -252,9 +252,11 @@ #ifndef __DMFC_INTERNAL_H #define __DMFC_INTERNAL_H -#include -#include -#include +#include +#include +#include +#include + #include "idmfc.h" #include "DMFC.h" #include "gamedll_header.h" @@ -1633,7 +1635,7 @@ class DMFCBase : public IDMFC { // the recommended filename to save stats to should be. // root = Multiplayer DLL Name (filename will start with this) // end_of_level = pass true if this is the end of a level stats - void GenerateStatFilename(char *filename, const char *root, bool end_of_level); + std::filesystem::path GenerateStatFilename(const char *root, bool end_of_level); // DMFCBase::IsPlayerObserver // diff --git a/netgames/entropy/EntropyBase.cpp b/netgames/entropy/EntropyBase.cpp index 996dfeea9..01e8cf4cf 100644 --- a/netgames/entropy/EntropyBase.cpp +++ b/netgames/entropy/EntropyBase.cpp @@ -95,8 +95,10 @@ * $NoKeywords: $ */ +#include +#include + #include "gamedll_header.h" //included by all mods, it includes all needed headers, etc. -#include #include "idmfc.h" //dmfc! (required) #include "Entropy.h" #include "Entropystr.h" //our string table for Entropy @@ -189,7 +191,7 @@ static int snd_virus_pickup = -1; static void DisplayHUDScores(struct tHUDItem *hitem); static void DisplayWelcomeMessage(int player_num); static void SortTeamScores(int *sortedindex, int *scores); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); static void OnLabSpewTimer(void); void RemoveVirusFromPlayer(int player_num, bool remove_all); static bool ScanForLaboratory(int team, int *newlab); @@ -1394,7 +1396,7 @@ void OnControlMessage(uint8_t msg, int from_pnum) { } } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -1593,21 +1595,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "Entropy" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/hoard/hoard.cpp b/netgames/hoard/hoard.cpp index 2149f7152..8930ed3ed 100644 --- a/netgames/hoard/hoard.cpp +++ b/netgames/hoard/hoard.cpp @@ -63,15 +63,16 @@ * $NoKeywords: $ */ +#include +#include +#include + #include "gamedll_header.h" -#include #include "idmfc.h" #include "Hoard.h" #include "hoardstr.h" #include "hoardaux.h" -#include - IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; static object *dObjects = NULL; @@ -130,7 +131,7 @@ static void DisplayWelcomeMessage(int player_num); static void DoBallsEffect(int i, int count); static void ReceiveHoardInv(uint8_t *data); static void SendHoardInv(int playernum); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); static void ReceiveGameConfig(uint8_t *data); static void OnClientPlayerEntersGame(int player_num); @@ -1024,7 +1025,7 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -1199,21 +1200,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "Hoard" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/hyperanarchy/hyperanarchy.cpp b/netgames/hyperanarchy/hyperanarchy.cpp index 11dac65e4..9df5b6ccc 100644 --- a/netgames/hyperanarchy/hyperanarchy.cpp +++ b/netgames/hyperanarchy/hyperanarchy.cpp @@ -53,12 +53,15 @@ * $NoKeywords: $ */ -#include -#include +#include +#include +#include + #include "gamedll_header.h" #include "idmfc.h" #include "HyperAnarchy.h" #include "hyperstr.h" + IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; static object *dObjects; @@ -152,7 +155,7 @@ static int FindHyperObjectNum(void); // if no one does. static int FindHyperOrbInInventory(void); static void ResetTimer(void); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); void DetermineScore(int precord_num, int column_num, char *buffer, int buffer_size) { player_record *pr = DMFCBase->GetPlayerRecord(precord_num); @@ -903,7 +906,7 @@ void OnClientPlayerDisconnect(int player_num) { DMFCBase->OnClientPlayerDisconnect(player_num); } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -1071,21 +1074,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "Hyper" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/includes/gamedll_header.h b/netgames/includes/gamedll_header.h index 90dd15148..1f0be2a59 100644 --- a/netgames/includes/gamedll_header.h +++ b/netgames/includes/gamedll_header.h @@ -831,21 +831,6 @@ DMFCDLLOUT(SliderSetSelectChangeCallbackWData_fp DLLSliderSetSelectChangeCallbac typedef void (*DPrintf_fp)(const char *fmt, ...); DMFCDLLOUT(DPrintf_fp DPrintf;) -// Split a pathname into its component parts -// The path in splitpath is in the *LOCAL* file system's syntax -typedef void (*ddio_SplitPath_fp)(const char *srcPath, char *path, char *filename, char *ext); -DMFCDLLOUT(ddio_SplitPath_fp DLLddio_SplitPath;) - -// Constructs a path in the local file system's syntax -// builtPath: stores the constructed path -// absolutePathHeader: absolute path on which the sub directories will be appended -// (specified in local file system syntax) -// subdir: the first subdirectory -// takes a variable number of additional subdirectories which will be concatenated on to the path -// the last argument in the list of sub dirs *MUST* be NULL to terminate the list -typedef void (*ddio_MakePath_fp)(char *newPath, const char *absolutePathHeader, const char *subDir, ...); -DMFCDLLOUT(ddio_MakePath_fp DLLddio_MakePath;) - // Plays a 2d sound // typedef int (*Play2dSound_fp)(int sound_index, float volume =MAX_GAME_VOLUME/2); typedef int (*Play2dSound_fp)(int sound_index, float volume); diff --git a/netgames/includes/idmfc.h b/netgames/includes/idmfc.h index 3db486697..0fa7491a1 100644 --- a/netgames/includes/idmfc.h +++ b/netgames/includes/idmfc.h @@ -139,9 +139,10 @@ #ifndef __IDMFC_H_ #define __IDMFC_H_ -#include -#include -#include +#include +#include +#include + #include "gamedll_header.h" #include "DMFC.h" #include "controls.h" @@ -1189,13 +1190,14 @@ class IDMFC : public IObject { // Disables/Enables the autosaving of game stats to file on disconnect from the game virtual void EnableAutoSaveDisconnect(bool enable) = 0; - // DMFCBase::GenerateStatFilename - // - // Given the following information it will return a full path to what - // the recommended filename to save stats to should be. - // root = Multiplayer DLL Name (filename will start with this) - // end_of_level = pass true if this is the end of a level stats - virtual void GenerateStatFilename(char *filename, const char *root, bool end_of_level) = 0; + /** + * Given the following information it will return a full path to what + * the recommended filename to save stats to should be. + * @param root Multiplayer DLL Name (filename will start with this) + * @param end_of_level pass true if this is the end of a level stats + * @return + */ + virtual std::filesystem::path GenerateStatFilename(const char *root, bool end_of_level) = 0; // DMFCBase::IsPlayerObserver // @@ -1922,7 +1924,7 @@ DLLEXPORT void DLLFUNCCALL IDMFC_EnableStatisticalMessages(IDMFC *instance, bool DLLEXPORT void DLLFUNCCALL IDMFC_EnableOnScreenMenu(IDMFC *instance, bool turn_on); DLLEXPORT void DLLFUNCCALL IDMFC_EnableAutoSaveLevelEnd(IDMFC *instance, bool enable); DLLEXPORT void DLLFUNCCALL IDMFC_EnableAutoSaveDisconnect(IDMFC *instance, bool enable); -DLLEXPORT void DLLFUNCCALL IDMFC_GenerateStatFilename(IDMFC *instance, char *filename, const char *root, +DLLEXPORT std::filesystem::path DLLFUNCCALL IDMFC_GenerateStatFilename(IDMFC *instance, const char *root, bool end_of_level); DLLEXPORT bool DLLFUNCCALL IDMFC_IsPlayerObserver(IDMFC *instance, int pnum); DLLEXPORT void DLLFUNCCALL IDMFC_EnableOnScreenMenuBackground(IDMFC *instance, bool enable); diff --git a/netgames/monsterball/monsterball.cpp b/netgames/monsterball/monsterball.cpp index e5e6c571d..f532b8dac 100644 --- a/netgames/monsterball/monsterball.cpp +++ b/netgames/monsterball/monsterball.cpp @@ -162,16 +162,16 @@ * $NoKeywords: $ */ +#include #include +#include +#include #include "gamedll_header.h" #include "idmfc.h" #include "monsterball.h" -#include #include "monsterstr.h" -#include - IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; static room *dRooms; @@ -295,7 +295,7 @@ static void OnTimerScoreKill(void); static void OnTimerKill(void); static void OnTimerRegen(void); static void OnTimerRegenKill(void); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); static void SortPlayerSlots(int *sorted_list, int count); static void SendLastHitInfo(void); static void GetLastHitInfo(uint8_t *data); @@ -1429,7 +1429,7 @@ void OnPrintScores(int level) { } } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -1635,21 +1635,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "MonsterBall" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/roboanarchy/roboanarchy.cpp b/netgames/roboanarchy/roboanarchy.cpp index e49f1b074..0f1f9aff8 100644 --- a/netgames/roboanarchy/roboanarchy.cpp +++ b/netgames/roboanarchy/roboanarchy.cpp @@ -47,15 +47,15 @@ * $NoKeywords: $ */ -#include -#include -#include +#include +#include +#include +#include + #include "idmfc.h" #include "roboAnarchy.h" #include "roboanarchystr.h" -#include - IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; @@ -75,7 +75,7 @@ static bool display_my_welcome = false; static void DisplayHUDScores(struct tHUDItem *hitem); static void DisplayScores(void); static void DisplayWelcomeMessage(int player_num); -static void SaveStatsToFile(char *filename); +static void SaveStatsToFile(const std::filesystem::path &filename); static void SwitchHUDColor(int i); static void SwitchAnarchyScores(int i); @@ -541,7 +541,7 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -704,21 +704,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "Anarchy" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/netgames/tanarchy/tanarchy.cpp b/netgames/tanarchy/tanarchy.cpp index 26080e2ff..fe015680e 100644 --- a/netgames/tanarchy/tanarchy.cpp +++ b/netgames/tanarchy/tanarchy.cpp @@ -76,11 +76,14 @@ * $NoKeywords: $ */ +#include +#include + #include "gamedll_header.h" -#include #include "idmfc.h" #include "tanDMFC.h" #include "tanarchystr.h" + IDMFC *DMFCBase = NULL; static IDmfcStats *dstat = NULL; static player *dPlayers; @@ -618,7 +621,7 @@ void OnPLRInterval(void) { quick_exit:; } -void SaveStatsToFile(char *filename) { +void SaveStatsToFile(const std::filesystem::path &filename) { CFILE *file; DLLOpenCFILE(&file, filename, "wt"); if (!file) { @@ -815,21 +818,18 @@ void SaveStatsToFile(char *filename) { } #define ROOTFILENAME "Team Anarchy" -void OnSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } -void OnLevelEndSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, true); +void OnLevelEndSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, true); SaveStatsToFile(filename); } -void OnDisconnectSaveStatsToFile(void) { - char filename[256]; - DMFCBase->GenerateStatFilename(filename, ROOTFILENAME, false); +void OnDisconnectSaveStatsToFile() { + std::filesystem::path filename = DMFCBase->GenerateStatFilename(ROOTFILENAME, false); SaveStatsToFile(filename); } diff --git a/scripts/osiris_common.h b/scripts/osiris_common.h index c6a53f2f4..2313e10c4 100644 --- a/scripts/osiris_common.h +++ b/scripts/osiris_common.h @@ -334,7 +334,9 @@ #ifndef __OSIRIS_COMMON_H_ #define __OSIRIS_COMMON_H_ +#include #include +#include #include "vecmat_external.h" #include "aistruct_external.h" @@ -986,7 +988,7 @@ struct tOSIRISModuleInit { // count is 0....only when the level ends. // this is for Game modules ONLY. - char *script_identifier; // Contains a unique script identifier (string), which + const char *script_identifier; // Contains a unique script identifier (string), which // can be used for the OMMS system. While this pointer // will always be valid during the lifetime of the module // DO NOT ALTER THE STRING IT POINTS TO. @@ -1230,8 +1232,8 @@ struct msafe_struct { uint8_t pulse_offset; // Objects/Players - uint32_t objhandle; - uint32_t ithandle; + int32_t objhandle; + int32_t ithandle; float shields, energy; int16_t start_tick; int16_t end_tick;