From 9fb1994b47efefc71710ce9cd63bfd33f2815860 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 23 May 2008 22:48:14 +0000 Subject: [PATCH] support change: read PreferredSongs.txt all at once (easier to read multiple files); always clear empty groups; simplify --- stepmania/src/SongManager.cpp | 46 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 90c42ee035..ac7b9c6bc9 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1401,17 +1401,18 @@ void SongManager::UpdatePreferredSort() { m_vPreferredSongSort.clear(); + vector asLines; RString sFile = THEME->GetPathO( "SongManager", "PreferredSongs.txt" ); - RageFile file; - if( !file.Open( sFile ) ) + GetFileContents( sFile, asLines ); + if( asLines.empty() ) return; vector vpSongs; - RString sLine; - while( file.GetLine(sLine) ) + FOREACH( RString, asLines, s ) { - bool bSectionDivider = sLine.find("---") != RString::npos; + RString sLine = *s; + bool bSectionDivider = sLine.find("---") == 0; if( bSectionDivider ) { if( !vpSongs.empty() ) @@ -1419,15 +1420,16 @@ void SongManager::UpdatePreferredSort() m_vPreferredSongSort.push_back( vpSongs ); vpSongs.clear(); } + continue; } - else - { - Song *pSong = NULL; - if( !sLine.empty() ) - pSong = FindSong( sLine ); - if( pSong && !(UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE) ) - vpSongs.push_back( pSong ); - } + + Song *pSong = FindSong( sLine ); + if( pSong == NULL ) + continue; + if( UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE ) + continue; + + vpSongs.push_back( pSong ); } if( !vpSongs.empty() ) @@ -1460,16 +1462,16 @@ void SongManager::UpdatePreferredSort() } m_vPreferredSongSort.push_back( vpUnlockSongs ); - - // prune empty groups - for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- ) - if( m_vPreferredSongSort[i].empty() ) - m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i ); - - FOREACH( SongPointerVector, m_vPreferredSongSort, i ) - FOREACH( Song*, *i, j ) - ASSERT( *j ); } + + // prune empty groups + for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- ) + if( m_vPreferredSongSort[i].empty() ) + m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i ); + + FOREACH( SongPointerVector, m_vPreferredSongSort, i ) + FOREACH( Song*, *i, j ) + ASSERT( *j ); } {