void PictureMetaEngine::removeSaveState(const char *target, int slot) const { // Slot 0 can't be deleted, it's for restarting the game(s) if (slot == 0) return; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::String filename = Picture::PictureEngine::getSavegameFilename(target, slot); saveFileMan->removeSavefile(filename.c_str()); Common::StringArray filenames; Common::String pattern = target; pattern += ".???"; filenames = saveFileMan->listSavefiles(pattern.c_str()); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); // Rename every slot greater than the deleted slot, // Also do not rename quicksaves. if (slotNum > slot && slotNum < 990) { // FIXME: Our savefile renaming done here is inconsitent with what we do in // GUI_v2::deleteMenu. While here we rename every slot with a greater equal // number of the deleted slot to deleted slot, deleted slot + 1 etc., // we only rename the following slots in GUI_v2::deleteMenu until a slot // is missing. saveFileMan->renameSavefile(file->c_str(), filename.c_str()); filename = Picture::PictureEngine::getSavegameFilename(target, ++slot); } } }
TestExitStatus SaveGametests::testRenamingSavefile() { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); // Open a file for renaming if (!writeDataToFile("tBedSomeWeirdName.0", "Rename me!")) { Testsuite::logDetailedPrintf("Writing data to savefile failed\n"); return kTestFailed; } // Rename it saveFileMan->renameSavefile("tBedSomeWeirdName.0", "tBedSomeCoolName.0"); // Verify if it contains the same data if (!readAndVerifyData("tBedSomeCoolName.0", "Rename me!")) { Testsuite::logDetailedPrintf("Renaming savefile failed\n"); return kTestFailed; } return kTestPassed; }
void ToltecsMetaEngine::removeSaveState(const char *target, int slot) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::String filename = Toltecs::ToltecsEngine::getSavegameFilename(target, slot); saveFileMan->removeSavefile(filename.c_str()); Common::StringArray filenames; Common::String pattern = target; pattern += ".###"; filenames = saveFileMan->listSavefiles(pattern.c_str()); Common::sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) { // Obtain the last 3 digits of the filename, since they correspond to the save slot int slotNum = atoi(file->c_str() + file->size() - 3); // Rename every slot greater than the deleted slot, if (slotNum > slot) { saveFileMan->renameSavefile(file->c_str(), filename.c_str()); filename = Toltecs::ToltecsEngine::getSavegameFilename(target, ++slot); } } }