From 4bd7da72564e9bf10675768558fa9d466284dac1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 6 Dec 2005 20:44:39 +0000 Subject: [PATCH] Delete old files after writing, not before, to prevent data loss. (File writing makes efforts to try to avoid data loss if we crash while saving.) --- stepmania/src/NotesWriterSM.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stepmania/src/NotesWriterSM.cpp b/stepmania/src/NotesWriterSM.cpp index 4d3770cdd5..3cec6198dc 100644 --- a/stepmania/src/NotesWriterSM.cpp +++ b/stepmania/src/NotesWriterSM.cpp @@ -265,17 +265,7 @@ bool NotesWriterSM::WriteEditFileToMachine( const Song *pSong, Steps *pSteps ) { CString sDir = PROFILEMAN->GetProfileDir( ProfileSlot_Machine ) + EDIT_STEPS_SUBDIR; - /* If the file name of the edit has changed since the last save, then delete the old - * file before saving the new one. - */ - bool bFileNameChanged = - pSteps->GetSavedToDisk() && - pSteps->GetFilename() != GetEditFileName(pSong,pSteps); - if( bFileNameChanged ) - FILEMAN->Remove( pSteps->GetFilename() ); - CString sPath = sDir + GetEditFileName(pSong,pSteps); - pSteps->SetFilename( sPath ); /* Flush dir cache when writing steps, so the old size isn't cached. */ FILEMAN->FlushDirCache( Dirname(sPath) ); @@ -299,6 +289,16 @@ bool NotesWriterSM::WriteEditFileToMachine( const Song *pSong, Steps *pSteps ) return false; } + /* If the file name of the edit has changed since the last save, then delete the old + * file after saving the new one. If we delete it first, then we'll lose data on error. */ + bool bFileNameChanged = + pSteps->GetSavedToDisk() && + pSteps->GetFilename() != sPath; + + if( bFileNameChanged ) + FILEMAN->Remove( pSteps->GetFilename() ); + pSteps->SetFilename( sPath ); + return true; }