void Dlg_GameLibrary::LoadAll() { mtx.lock(); FILE* pLoadIn = NULL; fopen_s(&pLoadIn, RA_MY_GAME_LIBRARY_FILENAME, "rb"); if (pLoadIn != NULL) { DWORD nCharsRead1 = 0; DWORD nCharsRead2 = 0; do { nCharsRead1 = 0; nCharsRead2 = 0; char fileBuf[2048]; char md5Buf[64]; ZeroMemory(fileBuf, 2048); ZeroMemory(md5Buf, 64); _ReadTil('\n', fileBuf, 2048, &nCharsRead1, pLoadIn); if (nCharsRead1 > 0) { _ReadTil('\n', md5Buf, 64, &nCharsRead2, pLoadIn); } if (fileBuf[0] != '\0' && md5Buf[0] != '\0' && nCharsRead1 > 0 && nCharsRead2 > 0) { fileBuf[nCharsRead1 - 1] = '\0'; md5Buf[nCharsRead2 - 1] = '\0'; // Add std::string file = fileBuf; std::string md5 = md5Buf; Results[file] = md5; } } while (nCharsRead1 > 0 && nCharsRead2 > 0); fclose(pLoadIn); } mtx.unlock(); }
void RA_RichPresenceInterpretter::ParseRichPresenceFile( const char* sFilename ) { m_formats.clear(); m_lookups.clear(); m_sDisplay.clear(); const char EndLine = '\n'; const char* LookupStr = "Lookup:"; const char* FormatStr = "Format:"; const char* FormatTypeStr = "FormatType="; const char* DisplayableStr = "Display:"; FILE* pFile = NULL; fopen_s( &pFile, sFilename, "r" ); if( pFile != NULL ) { DWORD nCharsRead = 0; char buffer[4096]; _ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile ); while( nCharsRead != 0 ) { if( strncmp( LookupStr, buffer, strlen( LookupStr ) ) == 0 ) { // Lookup type char* pBuf = buffer + ( strlen( LookupStr ) ); RA_Lookup newLookup( _ReadStringTil( EndLine, pBuf, TRUE ) ); while( nCharsRead != 0 && ( buffer[0] != EndLine ) ) { _ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile ); if( nCharsRead > 2 ) { char* pBuf = &buffer[0]; const char* pValue = _ReadStringTil( '=', pBuf, TRUE ); const char* pName = _ReadStringTil( EndLine, pBuf, TRUE ); int nBase = 10; if( pValue[0] == '0' && pValue[1] == 'x' ) nBase = 16; DataPos nVal = static_cast<DataPos>( strtol( pValue, NULL, nBase ) ); newLookup.AddLookupData( nVal, pName ); } } RA_LOG( "RP: Adding Lookup %s\n", newLookup.Description().c_str() ); m_lookups.push_back( newLookup ); } else if( strncmp( FormatStr, buffer, strlen( FormatStr ) ) == 0 ) { // char* pBuf = &buffer[0]; const char* pUnused = _ReadStringTil( ':', pBuf, TRUE ); std::string sDesc = _ReadStringTil( EndLine, pBuf, TRUE ); _ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile ); if( nCharsRead > 0 && strncmp( FormatTypeStr, buffer, strlen( FormatTypeStr ) ) == 0 ) { char* pBuf = &buffer[0]; const char* pUnused = _ReadStringTil( '=', pBuf, TRUE ); const char* pType = _ReadStringTil( EndLine, pBuf, TRUE ); RA_Leaderboard::FormatType nType; if( strcmp( pType, "SCORE" ) == 0 || strcmp( pType, "POINTS" ) == 0 ) { nType = RA_Leaderboard::Format_Score; } else if( strcmp( pType, "TIME" ) == 0 || strcmp( pType, "FRAMES" ) == 0 ) { nType = RA_Leaderboard::Format_TimeFrames; } else if( strcmp( pType, "SECS" ) == 0 ) { nType = RA_Leaderboard::Format_TimeSecs; } else if( strcmp( pType, "MILLISECS" ) == 0 ) { nType = RA_Leaderboard::Format_TimeMillisecs; } else if( strcmp( pType, "VALUE" ) == 0 ) { nType = RA_Leaderboard::Format_Value; } else { nType = RA_Leaderboard::Format_Other; } RA_LOG( "RP: Adding Formatter %s (%s)\n", sDesc.c_str(), pType ); m_formats.push_back( RA_Formattable( sDesc, nType ) ); } } else if( strncmp( DisplayableStr, buffer, strlen( DisplayableStr ) ) == 0 ) { _ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile ); char* pBuf = &buffer[0]; m_sDisplay = _ReadStringTil( '\n', pBuf, TRUE ); // Terminates \n instead } _ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile ); } fclose( pFile ); } }