static bool HashFile( RageFileBasic &f, unsigned char buf_hash[20], int iHash ) { hash_state hash; int iRet = hash_descriptor[iHash].init( &hash ); ASSERT_M( iRet == CRYPT_OK, error_to_string(iRet) ); RString s; while( !f.AtEOF() ) { s.erase(); if( f.Read(s, 1024*4) == -1 ) { LOG->Warn( "Error reading %s: %s", f.GetDisplayPath().c_str(), f.GetError().c_str() ); hash_descriptor[iHash].done( &hash, buf_hash ); return false; } iRet = hash_descriptor[iHash].process( &hash, (const unsigned char *) s.data(), s.size() ); ASSERT_M( iRet == CRYPT_OK, error_to_string(iRet) ); } iRet = hash_descriptor[iHash].done( &hash, buf_hash ); ASSERT_M( iRet == CRYPT_OK, error_to_string(iRet) ); return true; }
bool IniFile::ReadFile( RageFileBasic &f ) { RString keyname; while( 1 ) { RString line; /* Read lines until we reach a line that doesn't end in a backslash */ while( true ) { RString s; switch( f.GetLine(s) ) { case -1: m_sError = f.GetError(); return false; case 0: return true; /* eof */ } utf8_remove_bom( s ); line += s; if( line.empty() || line[line.size()-1] != '\\' ) break; line.erase( line.end()-1 ); } if( line.size() == 0 ) continue; if( line[0] == '#' ) continue; /* comment */ if( line.size() > 1 && line[0] == '/' && line[1] == '/' ) continue; /* comment */ if( line[0] == '[' && line[line.size()-1] == ']' ) { /* New section. */ keyname = line.substr(1, line.size()-2); } else { /* New value. */ size_t iEqualIndex = line.find("="); if( iEqualIndex != string::npos ) { RString valuename = line.Left( (int) iEqualIndex ); RString value = line.Right( line.size()-valuename.size()-1 ); Trim( valuename ); if( keyname.size() && valuename.size() ) SetValue( keyname, valuename, value ); } } } }
void FileReading::ReadBytes( RageFileBasic &f, void *buf, int size, RString &sError ) { if( sError.size() != 0 ) return; int ret = f.Read( buf, size ); if( ret == -1 ) sError = f.GetError(); else if( ret < size ) sError = "Unexpected end of file"; }
void FileReading::Seek( RageFileBasic &f, int iOffset, RString &sError ) { if( sError.size() != 0 ) return; int iGot = f.Seek( iOffset ); if( iGot == iOffset ) return; if( iGot == -1 ) sError = f.GetError(); else if( iGot < iOffset ) sError = "Unexpected end of file"; }
RString FileReading::ReadString( RageFileBasic &f, int size, RString &sError ) { if( sError.size() != 0 ) return RString(); RString sBuf; int ret = f.Read( sBuf, size ); if( ret == -1 ) sError = f.GetError(); else if( ret < size ) sError = "Unexpected end of file"; return sBuf; }
bool XmlFileUtil::LoadFromFileShowErrors( XNode &xml, RageFileBasic &f ) { RString sError; RString s; if( f.Read( s ) == -1 ) sError = f.GetError(); else Load( &xml, s, sError ); if( sError.empty() ) return true; RString sWarning = ssprintf( "XML: LoadFromFile failed: %s", sError.c_str() ); LuaHelpers::ReportScriptError(sWarning, "XML_PARSE_ERROR"); return false; }
bool IniFile::ReadFile( RageFileBasic &f ) { CString keyname; while( 1 ) { CString line; switch( f.GetLine(line) ) { case -1: m_sError = f.GetError(); return false; case 0: return true; /* eof */ } utf8_remove_bom( line ); if( line.size() == 0 ) continue; if( line[0] == '#' ) continue; /* comment */ if( line.size() > 1 && line[0] == '/' && line[1] == '/' ) continue; /* comment */ if( line[0] == '[' && line[line.length()-1] == ']' ) { /* New section. */ keyname = line.substr(1, line.size()-2); } else //if a value { int iEqualIndex = line.find("="); if( iEqualIndex != -1 ) { CString valuename = line.Left(iEqualIndex); CString value = line.Right(line.length()-valuename.length()-1); if( keyname.size() && valuename.size() ) SetValue(keyname,valuename,value); } } } }
bool XNode::LoadFromFile( RageFileBasic &f ) { PARSEINFO pi; CString s; if( f.Read( s ) == -1 ) { pi.error_occur = true; pi.error_pointer = NULL; pi.error_code = PIE_READ_ERROR; pi.error_string = f.GetError(); goto error; } this->Load( s, &pi ); if( pi.error_occur ) goto error; return true; error: CString sWarning = ssprintf( "XML: LoadFromFile failed: %s", pi.error_string.c_str() ); LOG->Warn( sWarning ); Dialog::OK( sWarning, "XML_PARSE_ERROR" ); return false; }