diff --git a/TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp b/TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp index 9212ae21c..1428e36aa 100644 --- a/TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp +++ b/TheForceEngine/TFE_FrontEndUI/frontEndUi.cpp @@ -1711,8 +1711,8 @@ namespace TFE_FrontEndUI ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); char textBuffer[TFE_MAX_PATH]; - sprintf(textBuffer, "Game: Dark Forces\nTime: %s\nLevel: %s\nMods: %s\n", s_saveDir[s_selectedSave - listOffset].dateTime, - s_saveDir[s_selectedSave - listOffset].levelName, s_saveDir[s_selectedSave - listOffset].modNames); + sprintf(textBuffer, "Game: Dark Forces\nTime: %s\nLevel: %s\nMods: %s\nFileName: %s\n", s_saveDir[s_selectedSave - listOffset].dateTime, + s_saveDir[s_selectedSave - listOffset].levelName, s_saveDir[s_selectedSave - listOffset].modNames, s_saveDir[s_selectedSave - listOffset].fileName); ImGui::InputTextMultiline("##Info", textBuffer, strlen(textBuffer) + 1, size, ImGuiInputTextFlags_ReadOnly); ImGui::PopFont(); @@ -1775,12 +1775,13 @@ namespace TFE_FrontEndUI bool shouldExit = false; if (save) { + // New Save Created if (s_selectedSave == 0) { s_selectedSaveSlot = (s32)s_saveDir.size(); // If no quicksave exists, skip over it when generating the name. const s32 saveIndex = s_selectedSaveSlot + (s_hasQuicksave ? 0 : 1); - TFE_SaveSystem::getSaveFilenameFromIndex(saveIndex, s_fileName); + TFE_SaveSystem::getSaveFilename(s_fileName, saveIndex); s_newSaveName[0] = 0; openSaveNameEditPopup(s_newSaveName); diff --git a/TheForceEngine/TFE_Game/saveSystem.cpp b/TheForceEngine/TFE_Game/saveSystem.cpp index 2e59d1e76..e9ef8387e 100644 --- a/TheForceEngine/TFE_Game/saveSystem.cpp +++ b/TheForceEngine/TFE_Game/saveSystem.cpp @@ -27,6 +27,8 @@ namespace TFE_SaveSystem SVER_CUR = SVER_REPLAY }; + const int TFE_MAX_SAVES = 1024; + static SaveRequest s_req = SF_REQ_NONE; static char s_reqFilename[TFE_MAX_PATH]; static char s_reqSavename[TFE_MAX_PATH]; @@ -388,4 +390,37 @@ namespace TFE_SaveSystem lastState = 0; } } + + void getSaveFilename(char* filename, s32 index) + { + char saveFilePath[TFE_MAX_PATH]; + TFE_SaveSystem::getSaveFilenameFromIndex(index, filename); + sprintf(saveFilePath, "%s%s", s_gameSavePath, filename); + + // If the file doesn't exist or we are overwriting, use the saveFilePath - ex: save015.tfe + if (!FileUtil::exists(saveFilePath)) + { + filename = saveFilePath; + return; + } + else + { + // If the file already exists you must have deleted an older one so lets find the right index + // Ex: save000.tfe save001.tfe save003.tfe (skipped 2) or you have custom save names. + for (int i = 0; i < TFE_MAX_SAVES; i++) + { + TFE_SaveSystem::getSaveFilenameFromIndex(i, filename); + sprintf(saveFilePath, "%s%s", s_gameSavePath, filename); + + if (!FileUtil::exists(saveFilePath)) + { + filename = saveFilePath; + return; + } + } + } + + TFE_System::logWrite(LOG_MSG, "SaveSystem", "Unable to create a save file after %d attempts", TFE_MAX_SAVES); + assert(0); + } } \ No newline at end of file diff --git a/TheForceEngine/TFE_Game/saveSystem.h b/TheForceEngine/TFE_Game/saveSystem.h index 4a647fdcf..e890568e6 100644 --- a/TheForceEngine/TFE_Game/saveSystem.h +++ b/TheForceEngine/TFE_Game/saveSystem.h @@ -49,7 +49,7 @@ namespace TFE_SaveSystem const char* loadRequestFilename(); const char* saveRequestFilename(); - void getSaveFilenameFromIndex(s32 index, char* name); - + void getSaveFilename(char* filename, s32 index); void populateSaveDirectory(std::vector& dir); + } \ No newline at end of file