allow reading whole files with GetFileContents

This commit is contained in:
Glenn Maynard
2005-05-20 00:12:43 +00:00
parent ffa3cd2b58
commit f37a3810d6
4 changed files with 15 additions and 7 deletions
+1 -1
View File
@@ -239,7 +239,7 @@ try_again:
while( GetExtension(sPath) == "redir" ) while( GetExtension(sPath) == "redir" )
{ {
CString sNewFileName; CString sNewFileName;
GetFileContents( sPath, sNewFileName ); GetFileContents( sPath, sNewFileName, true );
CString sRealPath; CString sRealPath;
FOREACHD_CONST( CString, data.vsDirSearchOrder, iter ) FOREACHD_CONST( CString, data.vsDirSearchOrder, iter )
+11 -3
View File
@@ -664,7 +664,7 @@ CString DerefRedir(const CString &_path)
} }
CString sNewFileName; CString sNewFileName;
GetFileContents( path, sNewFileName ); GetFileContents( path, sNewFileName, true );
/* Empty is invalid. */ /* Empty is invalid. */
if( sNewFileName == "" ) if( sNewFileName == "" )
@@ -692,7 +692,7 @@ CString DerefRedir(const CString &_path)
RageException::Throw( "Circular redirect '%s'", path.c_str() ); RageException::Throw( "Circular redirect '%s'", path.c_str() );
} }
bool GetFileContents( const CString &sPath, CString &sOut ) bool GetFileContents( const CString &sPath, CString &sOut, bool bOneLine )
{ {
/* Don't warn if the file doesn't exist, but do warn if it exists and fails to open. */ /* Don't warn if the file doesn't exist, but do warn if it exists and fails to open. */
if( !IsAFile(sPath) ) if( !IsAFile(sPath) )
@@ -706,13 +706,21 @@ bool GetFileContents( const CString &sPath, CString &sOut )
} }
CString sData; CString sData;
if( file.GetLine(sData) == -1 ) int iGot;
if( bOneLine )
iGot = file.GetLine( sData );
else
iGot = file.Read( sData, file.GetFileSize() );
if( iGot == -1 )
{ {
LOG->Warn( "GetFileContents(%s): %s", sPath.c_str(), file.GetError().c_str() ); LOG->Warn( "GetFileContents(%s): %s", sPath.c_str(), file.GetError().c_str() );
return false; return false;
} }
if( bOneLine )
StripCrnl( sData ); StripCrnl( sData );
sOut = sData; sOut = sData;
return true; return true;
} }
+1 -1
View File
@@ -309,7 +309,7 @@ void TrimRight(CString &str, const char *s = "\r\n\t ");
void StripCrnl(CString &s); void StripCrnl(CString &s);
CString DerefRedir( const CString &sPath ); CString DerefRedir( const CString &sPath );
bool GetFileContents( const CString &sPath, CString &sOut ); bool GetFileContents( const CString &sPath, CString &sOut, bool bOneLine = false );
class Regex { class Regex {
void *reg; void *reg;
+1 -1
View File
@@ -468,7 +468,7 @@ try_element_again:
else // bIsARedirect else // bIsARedirect
{ {
CString sNewFileName; CString sNewFileName;
GetFileContents( sPath, sNewFileName ); GetFileContents( sPath, sNewFileName, true );
CString sNewClassName, sNewFile; CString sNewClassName, sNewFile;
FileNameToClassAndElement(sNewFileName, sNewClassName, sNewFile); FileNameToClassAndElement(sNewFileName, sNewClassName, sNewFile);