From 4e6d7160278ccb360bcc01a6fc51992f7cee6e01 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 17 May 2005 02:20:43 +0000 Subject: [PATCH] GetRedirContents -> GetFileContents --- stepmania/src/NoteSkinManager.cpp | 3 ++- stepmania/src/RageUtil.cpp | 29 +++++++++++++---------- stepmania/src/RageUtil.h | 4 ++-- stepmania/src/ThemeManager.cpp | 3 ++- stepmania/src/arch/Sound/ALSA9Helpers.cpp | 5 ++-- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index 68e91ad01a..3a26add9e8 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -238,7 +238,8 @@ try_again: while( GetExtension(sPath) == "redir" ) { - CString sNewFileName = GetRedirContents(sPath); + CString sNewFileName; + GetFileContents( sPath, sNewFileName ); CString sRealPath; FOREACHD_CONST( CString, data.vsDirSearchOrder, iter ) diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 12c9f83dde..75cb06975f 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -663,7 +663,8 @@ CString DerefRedir(const CString &_path) return path; } - CString sNewFileName = GetRedirContents( path ); + CString sNewFileName; + GetFileContents( path, sNewFileName ); /* Empty is invalid. */ if( sNewFileName == "" ) @@ -691,25 +692,29 @@ CString DerefRedir(const CString &_path) RageException::Throw( "Circular redirect '%s'", path.c_str() ); } -/* XXX: This can be used to read one line from any file; rename it. */ -CString GetRedirContents(const CString &path) +bool GetFileContents( const CString &sPath, CString &sOut ) { + /* Don't warn if the file doesn't exist, but do warn if it exists and fails to open. */ + if( !IsAFile(sPath) ) + return false; + RageFile file; - if( !file.Open(path) ) + if( !file.Open(sPath) ) { - LOG->Warn( "GetRedirContents(%s): %s", path.c_str(), file.GetError().c_str() ); - return ""; + LOG->Warn( "GetFileContents(%s): %s", sPath.c_str(), file.GetError().c_str() ); + return false; } - CString sNewFileName; - if( file.GetLine( sNewFileName ) == -1 ) + CString sData; + if( file.GetLine(sData) == -1 ) { - LOG->Warn( "GetRedirContents(%s): %s", path.c_str(), file.GetError().c_str() ); - return ""; + LOG->Warn( "GetFileContents(%s): %s", sPath.c_str(), file.GetError().c_str() ); + return false; } - StripCrnl(sNewFileName); - return sNewFileName; + StripCrnl( sData ); + sOut = sData; + return true; } #if 1 diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index def793d45f..4f20cc7667 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -308,8 +308,8 @@ void TrimLeft(CString &str, const char *s = "\r\n\t "); void TrimRight(CString &str, const char *s = "\r\n\t "); void StripCrnl(CString &s); -CString DerefRedir(const CString &path); -CString GetRedirContents(const CString &path); +CString DerefRedir( const CString &sPath ); +bool GetFileContents( const CString &sPath, CString &sOut ); class Regex { void *reg; diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 8ae17a85a6..325b5ed263 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -467,7 +467,8 @@ try_element_again: } else // bIsARedirect { - CString sNewFileName = GetRedirContents(sPath); + CString sNewFileName; + GetFileContents( sPath, sNewFileName ); CString sNewClassName, sNewFile; FileNameToClassAndElement(sNewFileName, sNewClassName, sNewFile); diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.cpp b/stepmania/src/arch/Sound/ALSA9Helpers.cpp index ec9fb8c68a..92d1edc2bc 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.cpp +++ b/stepmania/src/arch/Sound/ALSA9Helpers.cpp @@ -169,8 +169,9 @@ void Alsa9Buf::GetSoundCardDebugInfo() if( DoesFileExist("/proc/asound/version") ) { - const CString ver = GetRedirContents("/proc/asound/version"); - LOG->Info( "ALSA: %s", ver.c_str() ); + CString sVersion; + GetFileContents( "/proc/asound/version", sVersion ); + LOG->Info( "ALSA: %s", sVersion.c_str() ); } InitializeErrorHandler();