From 098eb864305af935566ac8dcae62c0162e9b50f5 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 4 Jun 2005 19:01:13 +0000 Subject: [PATCH] Don't search recursively for backgrounds. Recursing picks up backgrounds from group-specific dirs when it shouldn't. --- stepmania/src/BackgroundUtil.cpp | 83 ++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/stepmania/src/BackgroundUtil.cpp b/stepmania/src/BackgroundUtil.cpp index 389defe58f..981153ab4c 100644 --- a/stepmania/src/BackgroundUtil.cpp +++ b/stepmania/src/BackgroundUtil.cpp @@ -178,55 +178,64 @@ void BackgroundUtil::GetGlobalRandomMovies( const Song *pSong, const CString &sM vsPathsOut.clear(); vsNamesOut.clear(); - set ssFilterToFileNames; - if( pSong && !pSong->m_sGenre.empty() ) - GetFilterToFileNames( RANDOMMOVIES_DIR, pSong, ssFilterToFileNames ); - - vector vsDirsToTry; - if( pSong ) + // Check for an exact match + if( !sMatch.empty() ) { - ASSERT( !pSong->m_sGroupName.empty() ); - vsDirsToTry.push_back( RANDOMMOVIES_DIR+pSong->m_sGroupName+"/" ); - } - vsDirsToTry.push_back( RANDOMMOVIES_DIR ); - - FOREACH_CONST( CString, vsDirsToTry, sDir ) - { - if( sMatch.empty() ) - { - GetDirListingRecursive( *sDir, "*.avi", vsPathsOut ); - GetDirListingRecursive( *sDir, "*.mpg", vsPathsOut ); - GetDirListingRecursive( *sDir, "*.mpeg", vsPathsOut ); - } + GetDirListing( RANDOMMOVIES_DIR+sMatch, vsPathsOut, false, true ); + if( !vsPathsOut.empty() ) + goto found_files; else - { - GetDirListing( RANDOMMOVIES_DIR+sMatch, vsPathsOut, false, true ); - } + LOG->Warn( "Background missing: %s", sMatch.c_str() ); + } - if( !ssFilterToFileNames.empty() ) + // + // Search for the most appropriate background + // + { + set ssFilterToFileNames; + if( pSong && !pSong->m_sGenre.empty() ) + GetFilterToFileNames( RANDOMMOVIES_DIR, pSong, ssFilterToFileNames ); + + vector vsDirsToTry; + if( pSong ) { - for( unsigned i=0; im_sGroupName.empty() ); + vsDirsToTry.push_back( RANDOMMOVIES_DIR+pSong->m_sGroupName+"/" ); + } + vsDirsToTry.push_back( RANDOMMOVIES_DIR ); + + FOREACH_CONST( CString, vsDirsToTry, sDir ) + { + GetDirListing( *sDir+"*.avi", vsPathsOut, false, true ); + GetDirListing( *sDir+"*.mpg", vsPathsOut, false, true ); + GetDirListing( *sDir+"*.mpeg", vsPathsOut, false, true ); + + if( !ssFilterToFileNames.empty() ) { - CString sBasename = Basename( vsPathsOut[i] ); - bool bFound = ssFilterToFileNames.find(sBasename) != ssFilterToFileNames.end(); - if( !bFound ) + for( unsigned i=0; iRight( s->size() - RANDOMMOVIES_DIR.size() - 1 ); - vsNamesOut.push_back( sName ); + if( !vsPathsOut.empty() ) + goto found_files; } - - if( !vsPathsOut.empty() ) - break; } +found_files: + + FOREACH_CONST( CString, vsPathsOut, s ) + { + CString sName = s->Right( s->size() - RANDOMMOVIES_DIR.size() - 1 ); + vsNamesOut.push_back( sName ); + } StripCvs( vsPathsOut, vsNamesOut ); }