From 79bc58aeddac7714c392aff1b088d20fb0ae9794 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 24 Aug 2002 07:57:28 +0000 Subject: [PATCH] Fix a bug in the m_sSongFileName optimization; add an assertion for it. --- stepmania/src/Song.cpp | 91 ++++++++++++++++++++++-------------------- stepmania/src/song.h | 2 + 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 8f0b1d0f84..1b0476d83a 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -267,53 +267,12 @@ CString Song::GetCacheFilePath() const * be a cache file. */ const CString &Song::GetSongFilePath() const { + ASSERT ( m_sSongFileName.GetLength() != 0 ); return m_sSongFileName; } -bool Song::LoadFromSongDir( CString sDir ) +bool Song::LoadWithoutCache( CString sDir ) { - LOG->Trace( "Song::LoadFromSongDir(%s)", sDir ); - - // make sure there is a trailing '\\' at the end of sDir - if( sDir.Right(1) != "\\" ) - sDir += "\\"; - - // save song dir - m_sSongDir = sDir; - - // save group name - CStringArray sDirectoryParts; - split( m_sSongDir, "\\", sDirectoryParts, false ); - m_sGroupName = sDirectoryParts[sDirectoryParts.GetSize()-3]; // second from last item - - { - /* Generated filename; this doesn't always point to a loadable file, - * but instead points to the place we should write changed files to. - * If we have an SM file in the directory, this should aways point to it. */ - CStringArray asFileNames; - GetDirListing( m_sSongDir+"*.sm", asFileNames ); - if( asFileNames.GetSize() > 0 ) - m_sSongFileName = m_sSongDir + asFileNames[0]; - else - m_sSongFileName = m_sSongDir + GetFullTitle() + ".sm"; - } - - // - // First look in the cache for this song (without loading NoteData) - // - int iDirHash = SONGINDEX->GetCacheHash(m_sSongDir); - if( GetHashForDirectory(m_sSongDir) == iDirHash ) // this cache is up to date - { - if( !DoesFileExist(GetCacheFilePath()) ) - goto load_without_cache; - - LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir, GetCacheFilePath() ); - LoadFromSMFile( GetCacheFilePath() ); - - return true; - } - -load_without_cache: // // There was no entry in the cache for this song. // Let's load it from a file, then write a cache entry. @@ -357,6 +316,52 @@ load_without_cache: // 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 ) +{ + LOG->Trace( "Song::LoadFromSongDir(%s)", sDir ); + + // make sure there is a trailing '\\' at the end of sDir + if( sDir.Right(1) != "\\" ) + sDir += "\\"; + + // save song dir + m_sSongDir = sDir; + + // save group name + CStringArray sDirectoryParts; + split( m_sSongDir, "\\", sDirectoryParts, false ); + m_sGroupName = sDirectoryParts[sDirectoryParts.GetSize()-3]; // second from last item + + // + // First look in the cache for this song (without loading NoteData) + // + int iDirHash = SONGINDEX->GetCacheHash(m_sSongDir); + if( GetHashForDirectory(m_sSongDir) == iDirHash && // this cache is up to date + DoesFileExist(GetCacheFilePath())) + { + LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir, GetCacheFilePath() ); + LoadFromSMFile( GetCacheFilePath() ); + } + else + { + if(!LoadWithoutCache(sDir)) + return false; + } + + { + /* Generated filename; this doesn't always point to a loadable file, + * but instead points to the place we should write changed files to. + * If we have an SM file in the directory, this should aways point to it. */ + CStringArray asFileNames; + GetDirListing( m_sSongDir+"*.sm", asFileNames ); + if( asFileNames.GetSize() > 0 ) + m_sSongFileName = m_sSongDir + asFileNames[0]; + else + m_sSongFileName = m_sSongDir + GetFullTitle() + ".sm"; + } return true; } diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 5c10819f38..e7c9bf394c 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -47,6 +47,8 @@ class Song public: Song(); ~Song(); + + bool LoadWithoutCache( CString sDir ); bool LoadFromSongDir( CString sDir ); // calls one of the loads below