Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.9 KiB

  1. //===== Copyright � 1996-2011, Valve Corporation, All rights reserved. ======//
  2. #include "ps3_saveutil_v2.h"
  3. #include "memdbgon.h"
  4. class CSaveUtilV2Job_WriteSteamInfo : public ISaveUtilV2Job
  5. {
  6. public: // Job entry point
  7. virtual JobStatus_t DoExecute();
  8. protected: // Stat callback
  9. virtual void DoDataStatCallback( SONY_SAVEUTIL_STAT_PARAMS );
  10. protected: // Write Steam info
  11. void DoDataFile_WriteSteamInfo( SONY_SAVEUTIL_FILE_PARAMS );
  12. };
  13. //////////////////////////////////////////////////////////////////////////
  14. void SaveUtilV2_WriteSteamInfo( CPS3SaveRestoreAsyncStatus *pAsync )
  15. {
  16. if ( !SaveUtilV2_CanStartJob() )
  17. return;
  18. // Make sure that Steam info is prepared on the main thread
  19. if ( !g_pSteamInfoProvider->PrepareSaveBufferForCommit() )
  20. return;
  21. // Start the job
  22. CSaveUtilV2Job_WriteSteamInfo *pJob = new CSaveUtilV2Job_WriteSteamInfo;
  23. SaveUtilV2_EnqueueJob( pAsync, pJob );
  24. }
  25. //////////////////////////////////////////////////////////////////////////
  26. JobStatus_t CSaveUtilV2Job_WriteSteamInfo::DoExecute()
  27. {
  28. float flTimeStamp = Plat_FloatTime();
  29. Msg( "CSaveUtilV2Job_WriteSteamInfo @%.3f\n", flTimeStamp );
  30. // Call saveutil
  31. int retv = cellSaveDataAutoSave2(
  32. CELL_SAVEDATA_VERSION_CURRENT,
  33. g_pszSaveUtilContainerName,
  34. CELL_SAVEDATA_ERRDIALOG_ALWAYS,
  35. &m_SaveDirInfo,
  36. csDataStatCallback,
  37. csDataFileCallback,
  38. SYS_MEMORY_CONTAINER_ID_INVALID,
  39. this );
  40. float flEndTimeStamp = Plat_FloatTime();
  41. Msg( "CSaveUtilV2Job_WriteSteamInfo: cellSaveDataAutoSave2 returned %x @%.3f ( total time = %.3f sec )\n", retv, flEndTimeStamp, flEndTimeStamp - flTimeStamp );
  42. return SaveUtilV2_JobDone( retv );
  43. }
  44. void CSaveUtilV2Job_WriteSteamInfo::DoDataStatCallback( SONY_SAVEUTIL_STAT_PARAMS )
  45. {
  46. Msg( "CSaveUtilV2Job_WriteSteamInfo::DoDataStatCallback @%.3f\n", Plat_FloatTime() );
  47. SetDataFileCallback( &CSaveUtilV2Job_WriteSteamInfo::DoDataFile_WriteSteamInfo );
  48. cbResult->result = CELL_SAVEDATA_CBRESULT_OK_NEXT;
  49. }
  50. void CSaveUtilV2Job_WriteSteamInfo::DoDataFile_WriteSteamInfo( SONY_SAVEUTIL_FILE_PARAMS )
  51. {
  52. Msg( "CSaveUtilV2Job_WriteSteamInfo::DoDataFile_WriteSteamInfo @%.3f\n", Plat_FloatTime() );
  53. // Obtain steam buffer
  54. CUtlBuffer *pBuffer = g_pSteamInfoProvider->GetSaveBufferForCommit();
  55. if ( !pBuffer )
  56. {
  57. cbResult->result = CELL_SAVEDATA_CBRESULT_OK_LAST;
  58. return;
  59. }
  60. // Perform the write
  61. set->fileOperation = CELL_SAVEDATA_FILEOP_WRITE;
  62. set->fileBuf = pBuffer->Base();
  63. set->fileSize = set->fileBufSize = pBuffer->TellPut();
  64. set->fileName = VALVE_CONTAINER_FILE_STEAM;
  65. set->fileOffset = 0;
  66. set->fileType = CELL_SAVEDATA_FILETYPE_SECUREFILE;
  67. memcpy( set->secureFileId, g_pszSaveUtilSecureFileId, CELL_SAVEDATA_SECUREFILEID_SIZE );
  68. set->reserved = NULL;
  69. // final write
  70. SetDataFileCallbackFinalize();
  71. cbResult->result = CELL_SAVEDATA_CBRESULT_OK_NEXT;
  72. Msg( "CSaveUtilV2Job_WriteSteamInfo::DoDataFile_WriteSteamInfo will write %d bytes...\n", pBuffer->TellPut() );
  73. }