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" )
{
CString sNewFileName;
GetFileContents( sPath, sNewFileName );
GetFileContents( sPath, sNewFileName, true );
CString sRealPath;
FOREACHD_CONST( CString, data.vsDirSearchOrder, iter )
+12 -4
View File
@@ -664,7 +664,7 @@ CString DerefRedir(const CString &_path)
}
CString sNewFileName;
GetFileContents( path, sNewFileName );
GetFileContents( path, sNewFileName, true );
/* Empty is invalid. */
if( sNewFileName == "" )
@@ -692,7 +692,7 @@ CString DerefRedir(const CString &_path)
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. */
if( !IsAFile(sPath) )
@@ -706,13 +706,21 @@ bool GetFileContents( const CString &sPath, CString &sOut )
}
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() );
return false;
}
if( bOneLine )
StripCrnl( sData );
StripCrnl( sData );
sOut = sData;
return true;
}
+1 -1
View File
@@ -309,7 +309,7 @@ void TrimRight(CString &str, const char *s = "\r\n\t ");
void StripCrnl(CString &s);
CString DerefRedir( const CString &sPath );
bool GetFileContents( const CString &sPath, CString &sOut );
bool GetFileContents( const CString &sPath, CString &sOut, bool bOneLine = false );
class Regex {
void *reg;
+1 -1
View File
@@ -468,7 +468,7 @@ try_element_again:
else // bIsARedirect
{
CString sNewFileName;
GetFileContents( sPath, sNewFileName );
GetFileContents( sPath, sNewFileName, true );
CString sNewClassName, sNewFile;
FileNameToClassAndElement(sNewFileName, sNewClassName, sNewFile);