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.

243 lines
9.4 KiB

  1. //===== Copyright � 1996-2010, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: A convenient, clean interface for communicating between UI and
  4. // the PS3 save system.
  5. //
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #ifndef PS3_SAVEUIAPI_H
  9. #define PS3_SAVEUIAPI_H
  10. #include "threadtools.h"
  11. #include "ps3_pathinfo.h"
  12. class CUtlBuffer;
  13. enum eSaveOperationTag
  14. {
  15. kSAVE_TAG_UNKNOWN = 0,
  16. kSAVE_TAG_INITIALIZE,
  17. kSAVE_TAG_WRITE_STEAMINFO,
  18. kSAVE_TAG_WRITE_AUTOSAVE, // writing an autosave to the container
  19. kSAVE_TAG_READ_SAVE, // reading a save from the container
  20. kSAVE_TAG_WRITE_SAVE, // writing a manual save to the container
  21. kSAVE_TAG_READ_SCREENSHOT, // reading a screenshot from the container
  22. kSAVE_TAG_DELETE_SAVE, // deleting a save from the container
  23. };
  24. // this class will hold the result of an async operation.
  25. // poll JobDone() until it returns true, then you can
  26. // look at the other fields for what actually transpired.
  27. class CPS3SaveRestoreAsyncStatus
  28. {
  29. public:
  30. inline bool JobDone() { return !!m_bDone; }
  31. inline int GetSonyReturnValue(); // will return either an error from the enum below or one of these (defined by Sony):
  32. /*
  33. CELL_SAVEDATA_RET_OK
  34. success
  35. CELL_SAVEDATA_ERROR_CBRESULT
  36. Callback function returned an error
  37. CELL_SAVEDATA_ERROR_ACCESS_ERROR
  38. HDD access error
  39. CELL_SAVEDATA_ERROR_INTERNAL
  40. Fatal internal error
  41. CELL_SAVEDATA_ERROR_PARAM
  42. Error in parameter to be set to utility (application bug)
  43. CELL_SAVEDATA_ERROR_NOSPACE
  44. Insufficient free space (application bug: lack of free space must be judged and handled within the callback function)
  45. CELL_SAVEDATA_ERROR_BROKEN
  46. Save data corrupted (modification detected, etc.)
  47. CELL_SAVEDATA_ERROR_FAILURE
  48. Save/load of save data failed (file could not be found, etc.)
  49. CELL_SAVEDATA_ERROR_BUSY
  50. Save data utility function was called simultaneously
  51. CELL_SAVEDATA_ERROR_NOUSER
  52. Specified user does not exist
  53. CELL_SAVEDATA_ERROR_SIZEOVER
  54. Exceeds the maximum size of the saved data
  55. CELL_SAVEDATA_ERROR_NODATA
  56. Specified save data does not exist on the HDD
  57. CELL_SAVEDATA_ERROR_NOTSUPPORTED
  58. Called in an unsupported state
  59. */
  60. enum eSaveErrors // our own error types; not from Sony but formatted the same so as to look uniform.
  61. {
  62. CELL_SAVEDATA_ERROR_THREAD_WAS_BUSY = -11,
  63. CELL_SAVEDATA_ERROR_FILE_NOT_FOUND = -12, // you tried to load a file that wasn't in the container
  64. CELL_SAVEDATA_ERROR_WRONG_USER = -13, // tried to open or operate on a container belonging to a different user
  65. CELL_SAVEDATA_ERROR_NO_TOC = -14, // failed to read TOC
  66. CELL_SAVEDATA_ERROR_WRAPPER = -15, // a general failure somewhere in the wrapper classes.
  67. CELL_SAVEDATA_ERROR_NO_WORK_TO_DO = -16,
  68. CELL_SAVEDATA_WARNING_ASYNC_FAILSAFE = -17, // an operation completed but somehow forgot to trip the async object (so a failsafe triggered)
  69. };
  70. uint32 m_nCurrentOperationTag; // an arbitrary enum that you can set to whatever you like, except 0. Zero means "not doing anything."
  71. int m_nSonyRetValue;
  72. bool m_bUseSystemDialogs; ///< when true, says that we should have the OS pop up dialogs for error conditions, rather than letting the game handle them based on the return value here.
  73. CInterlockedInt m_bDone;
  74. uint32 m_uiAdditionalDetails;
  75. CPS3SaveRestoreAsyncStatus() : m_bDone(true), m_bUseSystemDialogs(false), m_nSonyRetValue(0), m_nCurrentOperationTag(kSAVE_TAG_UNKNOWN), m_uiAdditionalDetails( 0 )
  76. {};
  77. };
  78. inline int CPS3SaveRestoreAsyncStatus::GetSonyReturnValue()
  79. {
  80. return m_nSonyRetValue;
  81. }
  82. class IPS3SaveSteamInfoProvider
  83. {
  84. public:
  85. virtual CUtlBuffer * GetInitialLoadBuffer() = 0;
  86. virtual CUtlBuffer * GetSaveBufferForCommit() = 0;
  87. virtual CUtlBuffer * PrepareSaveBufferForCommit() = 0;
  88. };
  89. // the interface class
  90. class IPS3SaveRestoreToUI : public IAppSystem
  91. {
  92. public:
  93. // the maximum possible size of a COMMENT field (including the terminal zero)
  94. enum { PS3_SAVE_COMMENT_LENGTH = 128 };
  95. enum FileSecurity_t
  96. {
  97. kSECURE,
  98. kHACKABLE,
  99. kSYSTEM,
  100. };
  101. // information about one file in the container
  102. struct CPS3ContainerFileInfo
  103. {
  104. char fileName[64];
  105. char comment[PS3_SAVE_COMMENT_LENGTH];
  106. FileSecurity_t fileType;
  107. uint32 size; // in bytes
  108. time_t modtime; // modification time as a POSIX time_t
  109. CPS3ContainerFileInfo() { memset(fileName, 0, sizeof(fileName)); memset(comment, 0, sizeof(comment)); }
  110. };
  111. // the struct that gets written into by GetContainerInfo()
  112. struct CPS3ContainerFacts
  113. {
  114. int hddFreeSizeKB; // free size on disk IN KILOBYTES
  115. int sizeKB; // current size of container in kilobytes
  116. bool bOwnedByAnotherUser; // can't load if this is the case
  117. CUtlVectorConservative< CPS3ContainerFileInfo > files;
  118. };
  119. struct PS3SaveGameInfo_t
  120. {
  121. PS3SaveGameInfo_t() : m_nFileTime(0) {}
  122. CUtlString m_InternalName; // eg 0000005.SAV
  123. CUtlString m_Filename; // eg autosave.ps3.sav
  124. CUtlString m_ScreenshotFilename; // eg autosave.ps3.tga if one exists
  125. CUtlString m_Comment;
  126. time_t m_nFileTime;
  127. };
  128. virtual ~IPS3SaveRestoreToUI(){};
  129. public:
  130. /// You have to call this before doing any other save operation. In particular,
  131. /// there may be an error opening the container. Poll on Async, and when it's done,
  132. /// look in the return value to see if it succeeded, or if not, why not.
  133. /// When bCreateIfMissing is set, it will create a new container where none exists.
  134. virtual void Initialize( CPS3SaveRestoreAsyncStatus *pAsync, IPS3SaveSteamInfoProvider *pSteamInfoProvider, bool bCreateIfMissing, int nKBRequired ) = 0;
  135. // Save the given file into the container. (ie /dev_hdd1/tempsave/foo.ps3.sav will
  136. // be written into the container as foo.ps3.sav ). You can optionally specify a second
  137. // file to be written at the same time, eg a screenshot, because batching two writes
  138. // to happen at once is far far faster than having two batches one after another.
  139. // ALL game progress files must be
  140. // written as secure; for now, even the screenshots should be, as that puts the work
  141. // of CRC onto the operating system.
  142. virtual void Write( CPS3SaveRestoreAsyncStatus *pAsync, const char *pSourcepath, const char *pScreenshotPath, const char *pComment, FileSecurity_t nSecurity = kSECURE ) = 0;
  143. // A more complicated and intelligent form of save writing, specifically for the case of autosaves.
  144. // The source filename given (as an absolute path) will be written to "autosave.ps3.sav".
  145. // Meanwhile, the existing "autosave.ps3.sav" will be renamed "autosave01.ps3.sav",
  146. // any "autosave01.ps3.sav" will be renamed "autosave02.ps3.sav", and so on up to a maximum
  147. // number of autosaves N, plus the base autosave.ps3.sav. The highest "autosave%02d.ps3.sav"
  148. // will therefore have a number N. Excess autosaves with numbers >N will be deleted.
  149. // If you specify a ScreenshotExtension (such as "tga"), the same operation is performed
  150. // for every file above, where ."sav" is replaced with the given extension.
  151. virtual void WriteAutosave( CPS3SaveRestoreAsyncStatus *pAsync,
  152. const char *pSourcePath, // eg "/dev_hdd1/tempsave/autosave.ps3.sav"
  153. const char *pComment, // the comment field for the new autosave.
  154. const unsigned int nMaxNumAutosaves ) = 0; // should be at least 1; the highest numbered autosave will be N-1.
  155. // A way of writing clouded files into container, clouded files over
  156. // a certain age are purged from container
  157. virtual void WriteCloudFile( CPS3SaveRestoreAsyncStatus *pAsync,
  158. const char *pSourcePath,
  159. const unsigned int nMaxNumCloudFiles ) = 0; // should be at least 1; the highest numbered cloud file will be N-1.
  160. // Load a file from the container into the given directory.
  161. // give it a pointer to a CPS3SaveRestoreAsyncStatus struct that you have created and
  162. // intend to poll.
  163. virtual void Load( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename, const char *pDestFullPath ) = 0;
  164. // kill one or two files (eg, save and screenshot).
  165. // async will respond when done.
  166. virtual void Delete( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename, const char *pOtherFilename = NULL ) = 0;
  167. // synchronously retrieve information on the files in the container. Lacks some of the container-wide'
  168. // info of the above function, and may have slightly out of date information, but is a synchronous call
  169. // and returns precisely the structure needed by CBaseModPanel::GetSaveGameInfos().
  170. virtual void GetFileInfoSync( CUtlVector< PS3SaveGameInfo_t > &saveGameInfos, bool bFindAll ) = 0;
  171. // try to find Steam's schema file for the user and stuff it into the container.
  172. // returns false if it couldn't find the file locally (in which case you should
  173. // not wait for the async object to be "done", as the job wasn't initiated);
  174. // true if it found it locally and queued up an async job to write it.
  175. virtual void WriteSteamInfo( CPS3SaveRestoreAsyncStatus *pAsync ) = 0;
  176. // returns whether save thread is busy
  177. virtual bool IsSaveUtilBusy() = 0;
  178. // returns the m_nCurrentOperationTag field of the most recent async op to
  179. // have run, or kSAVE_TAG_UNKNOWN if none has been enqueued yet. This tag
  180. // changes the moment a job is made active and remains until the next job
  181. // starts.
  182. virtual uint32 GetCurrentOpTag() = 0;
  183. // returns the version of container, used to fire off events when container
  184. // contents changes.
  185. virtual uint32 GetContainerModificationVersion() = 0;
  186. // sets the cloud crypto key.
  187. virtual void SetCloudFileCryptoKey( uint64 uiCloudCryptoKey ) = 0;
  188. };
  189. #define IPS3SAVEUIAPI_VERSION_STRING "IPS3SAVEUIAPI_001"
  190. #endif