bool CBaseGameStats::SaveToFileNOW( bool bForceSyncWrite /* = false */ ) { if ( !StatsTrackingIsFullyEnabled() ) return false; // this code path is only for old format stats. Products that use new format take a different path. if ( !gamestats->UseOldFormat() ) return false; CUtlBuffer buf; buf.PutShort( GAMESTATS_FILE_VERSION ); buf.Put( s_szPseudoUniqueID, 16 ); if( ShouldTrackStandardStats() ) m_BasicStats.SaveToBuffer( buf ); else buf.PutInt( GAMESTATS_STANDARD_NOT_SAVED ); gamestats->AppendCustomDataToSaveBuffer( buf ); char fullpath[ 512 ] = { 0 }; if ( filesystem->FileExists( GetStatSaveFileName(), GAMESTATS_PATHID ) ) { filesystem->RelativePathToFullPath( GetStatSaveFileName(), GAMESTATS_PATHID, fullpath, sizeof( fullpath ) ); } else { // filename is local to game dir for Steam, so we need to prepend game dir for regular file save char gamePath[256]; engine->GetGameDir( gamePath, 256 ); Q_StripTrailingSlash( gamePath ); Q_snprintf( fullpath, sizeof( fullpath ), "%s/%s", gamePath, GetStatSaveFileName() ); Q_strlower( fullpath ); Q_FixSlashes( fullpath ); } // StatsLog( "SaveToFileNOW '%s'\n", fullpath ); if( CBGSDriver.m_bShuttingDown || bForceSyncWrite ) //write synchronously { filesystem->WriteFile( fullpath, GAMESTATS_PATHID, buf ); StatsLog( "Shut down wrote to '%s'\n", fullpath ); } else { // Allocate memory for async system to use (and free afterward!!!) size_t nBufferSize = buf.TellPut(); void *pMem = malloc(nBufferSize); CUtlBuffer statsBuffer( pMem, nBufferSize ); statsBuffer.Put( buf.Base(), nBufferSize ); // Write data async filesystem->AsyncWrite( fullpath, statsBuffer.Base(), statsBuffer.TellPut(), true, false ); } return true; }
bool CBaseGameStats::UploadStatsFileNOW( void ) { if( !StatsTrackingIsFullyEnabled() ) return false; if ( !filesystem->FileExists( gamestats->GetStatSaveFileName(), GAMESTATS_PATHID ) ) { return false; } time_t curtime; VCRHook_Time( reinterpret_cast<long*>(&curtime) ); // For now always send updates after every time they run the engine!! #if 0 #if !defined( _DEBUG ) int elapsed = curtime - m_tLastUpload; if ( elapsed < ONE_DAY_IN_SECONDS ) return; #endif #endif CBGSDriver.m_tLastUpload = curtime; // Update the registry #ifndef SWDS IRegistry *reg = InstanceRegistry( "Steam" ); Assert( reg ); reg->WriteInt( GetStatUploadRegistryKeyName(), CBGSDriver.m_tLastUpload ); ReleaseInstancedRegistry( reg ); #endif CUtlBuffer buf; filesystem->ReadFile( GetStatSaveFileName(), GAMESTATS_PATHID, buf ); unsigned int uBlobSize = buf.TellPut(); if ( uBlobSize == 0 ) { return false; } const void *pvBlobData = ( const void * )buf.Base(); if( gamestatsuploader ) { return gamestatsuploader->UploadGameStats( "", 1, uBlobSize, pvBlobData ); } return false; }
bool CBaseGameStats::UploadStatsFileNOW( void ) { if( !StatsTrackingIsFullyEnabled() || !HaveValidData() || !gamestats->UseOldFormat() ) return false; if ( !filesystem->FileExists( gamestats->GetStatSaveFileName(), GAMESTATS_PATHID ) ) { return false; } int curtime = Plat_FloatTime(); CBGSDriver.m_tLastUpload = curtime; // Update the registry #ifndef SWDS IRegistry *reg = InstanceRegistry( "Steam" ); Assert( reg ); reg->WriteInt( GetStatUploadRegistryKeyName(), CBGSDriver.m_tLastUpload ); ReleaseInstancedRegistry( reg ); #endif CUtlBuffer buf; filesystem->ReadFile( GetStatSaveFileName(), GAMESTATS_PATHID, buf ); unsigned int uBlobSize = buf.TellPut(); if ( uBlobSize == 0 ) { return false; } const void *pvBlobData = ( const void * )buf.Base(); if( gamestatsuploader ) { return gamestatsuploader->UploadGameStats( "", 1, uBlobSize, pvBlobData ); } return false; }