From a811c1cfeac178d0186737a011e886410025c6e9 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Fri, 31 Jul 2009 12:39:31 +0000 Subject: When renaming old savefiles for Nippon Safes, don't assert if a file that matches the pattern game.* and is not a savefile is found in the savepath. svn-id: r42958 --- engines/parallaction/saveload.cpp | 44 +++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'engines') diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index e42b7df16b..d95decfd4f 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -420,33 +420,40 @@ void SaveLoad_ns::getGamePartProgress(bool *complete, int size) { complete[2] = s.contains("dough"); } -void SaveLoad_ns::renameOldSavefiles() { - Common::StringList oldFilenames = _saveFileMan->listSavefiles("game.*"); - - if (oldFilenames.size() == 0) { - // there are no old savefiles: nothing to do - return; - } - +static bool askRenameOldSavefiles() { GUI::MessageDialog dialog0( "ScummVM found that you have old savefiles for Nippon Safes that should be renamed.\n" "The old names are no longer supported, so you will not be able to load your games if you don't convert them.\n\n" "Press OK to convert them now, otherwise you will be asked next time.\n", "OK", "Cancel"); - int choice = dialog0.runModal(); - if (choice == 0) { - // user pressed cancel - return; - } + return (dialog0.runModal() != 0); +} +void SaveLoad_ns::renameOldSavefiles() { + Common::StringList oldFilenames = _saveFileMan->listSavefiles("game.*"); + uint numOldSaves = oldFilenames.size(); + + bool rename = false; uint success = 0, id; Common::String oldName, newName; for (uint i = 0; i < oldFilenames.size(); ++i) { oldName = oldFilenames[i]; int e = sscanf(oldName.c_str(), "game.%u", &id); - assert(e == 1); - newName = genSaveFileName(id); + if (e != 1) { + // this wasn't a savefile, so adjust numOldSaves accordingly + --numOldSaves; + continue; + } + + if (!rename) { + rename = askRenameOldSavefiles(); + } + if (!rename) { + // return immediately if the user doesn't want to rename the files + return; + } + newName = genSaveFileName(id); if (_saveFileMan->renameSavefile(oldName, newName)) { success++; } else { @@ -455,8 +462,13 @@ void SaveLoad_ns::renameOldSavefiles() { } } + if (numOldSaves == 0) { + // there were no old savefiles: nothing to notify + return; + } + char msg[200]; - if (success == oldFilenames.size()) { + if (success == numOldSaves) { sprintf(msg, "ScummVM successfully converted all your savefiles."); } else { sprintf(msg, -- cgit v1.2.3