BackgroundUtil: replace goto with helper function

This commit is contained in:
Devin J. Pohly
2013-01-25 15:45:01 -05:00
parent 7769142ec0
commit e840ac9a6c
+41 -27
View File
@@ -279,33 +279,31 @@ void BackgroundUtil::GetGlobalBGAnimations( const Song *pSong, const RString &sM
StripCvsAndSvn( vsPathsOut, vsNamesOut ); StripCvsAndSvn( vsPathsOut, vsNamesOut );
} }
void BackgroundUtil::GetGlobalRandomMovies( namespace {
const Song *pSong, /**
const RString &sMatch, * @brief Fetches the appropriate path(s) for global random movies.
vector<RString> &vsPathsOut, */
vector<RString> &vsNamesOut, void GetGlobalRandomMoviePaths(
bool bTryInsideOfSongGroupAndGenreFirst, const Song *pSong,
bool bTryInsideOfSongGroupFirst ) const RString &sMatch,
{ vector<RString> &vsPathsOut,
vsPathsOut.clear(); bool bTryInsideOfSongGroupAndGenreFirst,
vsNamesOut.clear(); bool bTryInsideOfSongGroupFirst )
// Check for an exact match
if( !sMatch.empty() )
{ {
GetDirListing( SONG_MOVIES_DIR+pSong->m_sGroupName+"/"+sMatch, vsPathsOut, false, true ); // search in SongMovies/SongGroupName/ first // Check for an exact match
GetDirListing( SONG_MOVIES_DIR+sMatch, vsPathsOut, false, true ); if( !sMatch.empty() )
GetDirListing( RANDOMMOVIES_DIR+sMatch, vsPathsOut, false, true ); {
if( !vsPathsOut.empty() ) GetDirListing( SONG_MOVIES_DIR+pSong->m_sGroupName+"/"+sMatch, vsPathsOut, false, true ); // search in SongMovies/SongGroupName/ first
goto found_files; GetDirListing( SONG_MOVIES_DIR+sMatch, vsPathsOut, false, true );
GetDirListing( RANDOMMOVIES_DIR+sMatch, vsPathsOut, false, true );
if( vsPathsOut.empty() && sMatch != NO_SONG_BG_FILE )
{
LOG->Warn( "Background missing: %s", sMatch.c_str() );
}
return;
}
if( sMatch != NO_SONG_BG_FILE ) // Search for the most appropriate background
LOG->Warn( "Background missing: %s", sMatch.c_str() );
return;
}
// Search for the most appropriate background
{
set<RString> ssFileNameWhitelist; set<RString> ssFileNameWhitelist;
if( bTryInsideOfSongGroupAndGenreFirst && pSong && !pSong->m_sGenre.empty() ) if( bTryInsideOfSongGroupAndGenreFirst && pSong && !pSong->m_sGenre.empty() )
GetFilterToFileNames( RANDOMMOVIES_DIR, pSong, ssFileNameWhitelist ); GetFilterToFileNames( RANDOMMOVIES_DIR, pSong, ssFileNameWhitelist );
@@ -342,11 +340,27 @@ void BackgroundUtil::GetGlobalRandomMovies(
} }
if( !vsPathsOut.empty() ) if( !vsPathsOut.empty() )
goto found_files; {
// Return only the first directory found
return;
}
} }
} }
found_files: }
void BackgroundUtil::GetGlobalRandomMovies(
const Song *pSong,
const RString &sMatch,
vector<RString> &vsPathsOut,
vector<RString> &vsNamesOut,
bool bTryInsideOfSongGroupAndGenreFirst,
bool bTryInsideOfSongGroupFirst )
{
vsPathsOut.clear();
vsNamesOut.clear();
GetGlobalRandomMoviePaths( pSong, sMatch, vsPathsOut, bTryInsideOfSongGroupAndGenreFirst, bTryInsideOfSongGroupFirst );
FOREACH_CONST( RString, vsPathsOut, s ) FOREACH_CONST( RString, vsPathsOut, s )
{ {