Win32 - backup - expand numbering to 999, add condition for 999 overflow

This commit is contained in:
adelikat 2008-12-22 20:55:16 +00:00
parent 29ed7c2f71
commit da3a3af4dd
1 changed files with 22 additions and 4 deletions

View File

@ -2075,19 +2075,22 @@ void MakeBackup(bool dispMessage)
stringstream stream;
int x; //Temp variable for string manip
bool exist = false; //Used to test if filename exists
bool overflow = false; //Used for special situation when backup numbering exceeds limit
currentFn = curMovieFilename; //Get current moviefilename
backupFn = curMovieFilename; //Make backup filename the same as current moviefilename
x = backupFn.find_last_of("."); //Find file extension
backupFn = backupFn.substr(0,x); //Remove extension
tempFn = backupFn; //Store the filename at this point
for (unsigned int backNum=0;backNum<256;backNum++) //256 = arbituary limit to backup files
for (unsigned int backNum=0;backNum<999;backNum++) //999 = arbituary limit to backup files
{
stream.str(""); //Clear stream
if (backNum > 9)
if (backNum > 99)
stream << "-" << backNum; //assign backNum to stream
else if (backNum <=99 && backNum >= 10)
stream << "-0"; //Make it 010, etc if two digits
else
stream << "-0" << backNum; //Make it 01, etc if single digit
stream << "-00" << backNum; //Make it 001, etc if single digit
backupFn.append(stream.str()); //add number to bak filename
backupFn.append(".bak"); //add extension
@ -2096,7 +2099,16 @@ void MakeBackup(bool dispMessage)
if (!exist)
break; //Yeah yeah, I should use a do loop or something
else
{
backupFn = tempFn; //Before we loop again, reset the filename
if (backNum == 999) //If 999 exists, we have overflowed, let's handle that
{
backupFn.append("-001.bak"); //We are going to simply overwrite 001.bak
overflow = true; //Flag that we have exceeded limit
break; //Just in case
}
}
}
MovieData md = currMovieData; //Get current movie data
@ -2106,7 +2118,13 @@ void MakeBackup(bool dispMessage)
//TODO, decide if fstream successfully opened the file and print error message if it doesn't
if (dispMessage) FCEUI_DispMessage("%s created",backupFn.c_str()); //Inform user it told to
if (dispMessage) //If we should inform the user
{
if (overflow)
FCEUI_DispMessage("Overwriting %s",backupFn.c_str()); //Inform user of overflow
else
FCEUI_DispMessage("%s created",backupFn.c_str()); //Inform user of backup filename
}
}
bool CheckFileExists(const char* filename)