From 38aec56633779a280b9fa9adc3fe7212bfe5cc0f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 3 Feb 2007 02:32:57 +0000 Subject: [PATCH] add paranoid BackUpAllSongSaves --- stepmania/src/Song.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index dae9a8cd01..4513349840 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -29,6 +29,7 @@ #include "LyricsLoader.h" +#include #include #include @@ -38,6 +39,7 @@ const float DEFAULT_MUSIC_SAMPLE_LENGTH = 12.f; static Preference g_fLongVerSongSeconds( "LongVerSongSeconds", 60*2.5f ); static Preference g_fMarathonVerSongSeconds( "MarathonVerSongSeconds", 60*5.f ); +static Preference g_BackUpAllSongSaves( "BackUpAllSongSaves", false ); Song::Song() { @@ -836,6 +838,27 @@ bool Song::SaveToSMFile( RString sPath, bool bSavingCache ) if( !NotesWriterSM::Write(sPath, *this, vpStepsToSave, bSavingCache) ) return false; + if( !bSavingCache && g_BackUpAllSongSaves.Get() ) + { + RString sExt = GetExtension( sPath ); + RString sBackupFile = SetExtension( sPath, "" ); + + time_t cur_time; + time( &cur_time ); + struct tm now; + localtime_r( &cur_time, &now ); + + sBackupFile += ssprintf( "-%04i-%02i-%02i--%02i-%02i-%02i", + 1900+now.tm_year, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec ); + sBackupFile = SetExtension( sBackupFile, sExt ); + sBackupFile += ssprintf( ".old" ); + + if( FileCopy(sPath, sBackupFile) ) + LOG->Trace( "Backed up %s to %s", sPath.c_str(), sBackupFile.c_str() ); + else + LOG->Trace( "Failed to back up %s to %s", sPath.c_str(), sBackupFile.c_str() ); + } + if( !bSavingCache ) { /* Mark these steps saved to disk. */