From 3211748947d5a07553bcd5f33713c6a1d7f742dd Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 31 Oct 2003 09:07:30 +0000 Subject: [PATCH] fix "edited steps disappear after leaving editor, re-appear after restart" --- stepmania/src/Song.cpp | 61 ++++++++++++++++++++---------------------- stepmania/src/song.h | 3 +-- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 26b3cec777..e58d649da7 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -360,35 +360,7 @@ NotesLoader *Song::MakeLoader( CString sDir ) const * pull in into Song.h, which is heavily used. */ static set BlacklistedImages; -bool Song::LoadWithoutCache( CString sDir ) -{ - // - // There was no entry in the cache for this song, or it was out of date. - // Let's load it from a file, then write a cache entry. - // - - NotesLoader *ld = MakeLoader( sDir ); - if(!ld) - { - LOG->Warn( "Couldn't find any SM, DWI, BMS, or KSF files in '%s'. This is not a valid song directory.", sDir.c_str() ); - return false; - } - - bool success = ld->LoadFromDir( sDir, *this ); - BlacklistedImages = ld->GetBlacklistedImages(); - delete ld; - - if(!success) - return false; - - TidyUpData(); - - // save a cache file so we don't have to parse it all over again next time - SaveToCacheFile(); - return true; -} - -bool Song::LoadFromSongDir( CString sDir ) +bool Song::LoadFromSongDir( CString sDir, bool bAllowCache ) { // LOG->Trace( "Song::LoadFromSongDir(%s)", sDir.c_str() ); ASSERT( sDir != "" ); @@ -411,7 +383,8 @@ bool Song::LoadFromSongDir( CString sDir ) // First look in the cache for this song (without loading NoteData) // unsigned uDirHash = SONGINDEX->GetCacheHash(m_sSongDir); - if( GetHashForDirectory(m_sSongDir) == uDirHash && // this cache is up to date + if( bAllowCache && + GetHashForDirectory(m_sSongDir) == uDirHash && // this cache is up to date DoesFileExist(GetCacheFilePath())) { // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); @@ -420,8 +393,29 @@ bool Song::LoadFromSongDir( CString sDir ) } else { - if(!LoadWithoutCache(m_sSongDir)) + // + // There was no entry in the cache for this song, or it was out of date. + // Let's load it from a file, then write a cache entry. + // + + NotesLoader *ld = MakeLoader( sDir ); + if(!ld) + { + LOG->Warn( "Couldn't find any SM, DWI, BMS, or KSF files in '%s'. This is not a valid song directory.", sDir.c_str() ); return false; + } + + bool success = ld->LoadFromDir( sDir, *this ); + BlacklistedImages = ld->GetBlacklistedImages(); + delete ld; + + if(!success) + return false; + + TidyUpData(); + + // save a cache file so we don't have to parse it all over again next time + SaveToCacheFile(); } /* Load the cached banners, if it's not loaded already. */ @@ -489,7 +483,10 @@ void Song::RevertFromDisk() /* Erase all existing data. */ Reset(); - LoadFromSongDir( dir ); + + // Don't load from cache, or else we'll get an old version + // if they've saved in the editor. + LoadFromSongDir( dir, false ); if( GAMESTATE->m_pCurSong == this ) { diff --git a/stepmania/src/song.h b/stepmania/src/song.h index b8aaf655fd..bb2f8027e1 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -76,10 +76,9 @@ public: ~Song(); void Reset(); - bool LoadWithoutCache( CString sDir ); NotesLoader *MakeLoader( CString sDir ) const; - bool LoadFromSongDir( CString sDir ); + bool LoadFromSongDir( CString sDir, bool bAllowCache = true ); void RevertFromDisk(); void TidyUpData(); // call after loading to clean up invalid data