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.

149 lines
5.3 KiB

  1. //===== Copyright � 1996-2011, Valve Corporation, All rights reserved. ======//
  2. #ifndef PS3_SAVEUTIL_V2_H
  3. #define PS3_SAVEUTIL_V2_H
  4. //////////////////////////////////////////////////////////////////////////
  5. #include "tier1/utlbuffer.h"
  6. #include "common.h"
  7. #include "vstdlib/jobthread.h"
  8. #include <sysutil/sysutil_userinfo.h>
  9. #include <sysutil/sysutil_savedata.h>
  10. #include <cell/sysmodule.h>
  11. #include <sys/fs_external.h>
  12. #include <ps3/saverestore_ps3_api_ui.h>
  13. #include <vjobs_interface.h>
  14. //////////////////////////////////////////////////////////////////////////
  15. extern CPS3SaveRestoreAsyncStatus *g_pSaveUtilAsyncStatus;
  16. extern IPS3SaveSteamInfoProvider *g_pSteamInfoProvider;
  17. extern IThreadPool *g_pSaveUtilThreadPool;
  18. extern char const *g_pszSaveUtilContainerName;
  19. extern char const *g_pszSaveUtilSecureFileId;
  20. extern uint64 g_uiSteamCloudCryptoKey;
  21. #define VALVE_CONTAINER_FILE_STEAM "STEAMDAT.BIN"
  22. #define VALVE_CONTAINER_STRLEN 128
  23. #define VALVE_CONTAINER_FILENAME_LEN 64
  24. #define VALVE_CONTAINER_8_3_LEN 16
  25. #define VALVE_CONTAINER_COUNT 64
  26. #define VALVE_CONTAINER_FPARTS 2
  27. void SaveUtilV2_Initialize( CPS3SaveRestoreAsyncStatus *pAsync, IPS3SaveSteamInfoProvider *pSteamInfoProvider, int nKBRequired );
  28. void SaveUtilV2_Shutdown();
  29. bool SaveUtilV2_CanShutdown();
  30. void SaveUtilV2_GetFileInfoSync( CUtlVector< IPS3SaveRestoreToUI::PS3SaveGameInfo_t > &saveGameInfos, bool bFindAll );
  31. void SaveUtilV2_Write( CPS3SaveRestoreAsyncStatus *pAsync, const char *pSourcepath, const char *pScreenshotPath, const char *pComment );
  32. void SaveUtilV2_WriteAutosave( CPS3SaveRestoreAsyncStatus *pAsync,
  33. const char *pSourcePath, // eg "/dev_hdd1/tempsave/autosave.ps3.sav"
  34. const char *pComment, // the comment field for the new autosave.
  35. const unsigned int nMaxNumAutosaves );
  36. void SaveUtilV2_WriteCloudFile( CPS3SaveRestoreAsyncStatus *pAsync,
  37. const char *pSourcePath, // eg "/dev_hdd1/tempsave/autosave.ps3.sav"
  38. const unsigned int nMaxNumCloudFiles );
  39. void SaveUtilV2_WriteSteamInfo( CPS3SaveRestoreAsyncStatus *pAsync );
  40. void SaveUtilV2_Load( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename, const char *pDestFullPath );
  41. void SaveUtilV2_Delete( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename );
  42. //////////////////////////////////////////////////////////////////////////
  43. //
  44. // Helper definitions and declarations
  45. //
  46. #define SONY_SAVEUTIL_STAT_PARAMS CellSaveDataCBResult *cbResult, CellSaveDataStatGet *get, CellSaveDataStatSet *set
  47. #define SONY_SAVEUTIL_FILE_PARAMS CellSaveDataCBResult *cbResult, CellSaveDataFileGet *get, CellSaveDataFileSet *set
  48. #define SONY_SAVEUTIL_PARAMS cbResult, get, set
  49. class ISaveUtilV2Job : public CJob
  50. {
  51. public:
  52. ISaveUtilV2Job() { m_pfnDoDataFileCallback = 0; }
  53. public:
  54. static void csDataStatCallback( SONY_SAVEUTIL_STAT_PARAMS );
  55. static void csDataFileCallback( SONY_SAVEUTIL_FILE_PARAMS );
  56. public:
  57. virtual void DoDataStatCallback( SONY_SAVEUTIL_STAT_PARAMS ) = 0;
  58. void (ISaveUtilV2Job::*m_pfnDoDataFileCallback)( SONY_SAVEUTIL_FILE_PARAMS );
  59. template< typename T > inline void SetDataFileCallback( void (T::*pfnCallback)( SONY_SAVEUTIL_FILE_PARAMS ) ) { m_pfnDoDataFileCallback = reinterpret_cast< void (ISaveUtilV2Job::*)( SONY_SAVEUTIL_FILE_PARAMS ) >( pfnCallback ); }
  60. inline void SetDataFileCallbackFinalize() { m_pfnDoDataFileCallback = 0; }
  61. public:
  62. CellSaveDataSetBuf m_SaveDirInfo;
  63. CUtlBuffer m_bufSaveDirList;
  64. };
  65. bool SaveUtilV2_CanStartJob();
  66. void SaveUtilV2_EnqueueJob( CPS3SaveRestoreAsyncStatus *pAsync, ISaveUtilV2Job *pJob );
  67. JobStatus_t SaveUtilV2_JobDone( int nErrorCode );
  68. uint32 SaveUtilV2_ComputeBufferHash( void const *pvData, uint32 numBytes );
  69. //////////////////////////////////////////////////////////////////////////
  70. //
  71. // Container TOC
  72. //
  73. class CSaveUtilV2ContainerTOC
  74. {
  75. public:
  76. CSaveUtilV2ContainerTOC() : m_idxNewSaveName( 0 ) {}
  77. struct TocEntry_t
  78. {
  79. char m_chContainerName[VALVE_CONTAINER_8_3_LEN]; // 8.3 name inside container: 0000001A.SAV
  80. char m_chComment[VALVE_CONTAINER_STRLEN]; // description of file without needing to open file
  81. char m_chFile[VALVE_CONTAINER_FPARTS][VALVE_CONTAINER_FILENAME_LEN]; // names of the contained parts [sav+tga]
  82. uint32 m_numBytesFile[VALVE_CONTAINER_FPARTS]; // sizes of the parts inside container file [sav+tga]
  83. uint32 m_numBytesDecompressedFile[VALVE_CONTAINER_FPARTS]; // sizes of original decompressed parts [sav+tga], zero if uncompressed
  84. time_t m_timeModification; // timestamp of the container file
  85. };
  86. union TocStorageReserved_t
  87. {
  88. TocEntry_t m_entry;
  89. char m_chPadding[384];
  90. };
  91. CUtlVector< TocStorageReserved_t > m_arrEntries;
  92. CThreadFastMutex m_mtx;
  93. uint32 m_idxNewSaveName;
  94. enum Capacity_t
  95. {
  96. kStorageCapacity =
  97. sizeof(uint32) + // new save name
  98. sizeof(uint32) + // number of valid entries
  99. VALVE_CONTAINER_COUNT*sizeof(TocStorageReserved_t) // actual TOC entries
  100. };
  101. public:
  102. void SerializeIntoTocBuffer( void *pvBuffer );
  103. void SerializeFromTocBuffer( void *pvBuffer );
  104. void CopyInto( CSaveUtilV2ContainerTOC *pOther );
  105. int FindByEmbeddedFileName( char const *szFilename, int *pnPartIndex );
  106. };
  107. extern CSaveUtilV2ContainerTOC g_SaveUtilV2TOC;
  108. extern uint32 g_SaveUtilV2TOCVersion;
  109. class CSaveUtilVjobInstance : public VJobInstance
  110. {
  111. public:
  112. void Init();
  113. void Shutdown();
  114. };
  115. extern CSaveUtilVjobInstance g_saveUtilVjobInstance;
  116. #endif