| 1061 | } |
| 1062 | |
| 1063 | void SwapSaveState() |
| 1064 | { |
| 1065 | //-------------------------------------------------------------------------------------------- |
| 1066 | //Both files must exist |
| 1067 | //-------------------------------------------------------------------------------------------- |
| 1068 | |
| 1069 | if (lastSavestateMade.empty()) |
| 1070 | { |
| 1071 | FCEUI_DispMessage("Can't Undo",0); |
| 1072 | FCEUI_printf("Undo savestate was attempted but unsuccessful because there was not a recently used savestate.\n"); |
| 1073 | return; //If there is no last savestate, can't undo |
| 1074 | } |
| 1075 | string backup = GenerateBackupSaveStateFn(lastSavestateMade.c_str()); //Get filename of backup state |
| 1076 | if (!CheckFileExists(backup.c_str())) |
| 1077 | { |
| 1078 | FCEUI_DispMessage("Can't Undo",0); |
| 1079 | FCEUI_printf("Undo savestate was attempted but unsuccessful because there was not a backup of the last used savestate.\n"); |
| 1080 | return; //If no backup, can't undo |
| 1081 | } |
| 1082 | |
| 1083 | //-------------------------------------------------------------------------------------------- |
| 1084 | //So both exists, now swap the last savestate and its backup |
| 1085 | //-------------------------------------------------------------------------------------------- |
| 1086 | string temp = backup; //Put backup filename in temp |
| 1087 | temp.append("x"); //Add x |
| 1088 | |
| 1089 | rename(backup.c_str(),temp.c_str()); //rename backup file to temp file |
| 1090 | rename(lastSavestateMade.c_str(),backup.c_str()); //rename current as backup |
| 1091 | rename(temp.c_str(),lastSavestateMade.c_str()); //rename backup as current |
| 1092 | |
| 1093 | undoSS = true; //Just in case, if this was run, then there is definately a last savestate and backup |
| 1094 | if (redoSS) //This was a redo function, so if run again it will be an undo again |
| 1095 | redoSS = false; |
| 1096 | else //This was an undo function so next will be redo, so flag it |
| 1097 | redoSS = true; |
| 1098 | |
| 1099 | FCEUI_DispMessage("%s restored",0,backup.c_str()); |
| 1100 | FCEUI_printf("%s restored\n",backup.c_str()); |
| 1101 | } |
| 1102 | |
| 1103 | //------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 1104 | //************************************************************************* |
no test coverage detected