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.

205 lines
7.1 KiB

  1. //===== Copyright � 1996-2011, Valve Corporation, All rights reserved. ======//
  2. #include "ps3_saveutil_v2.h"
  3. #include "memdbgon.h"
  4. // the interface class
  5. class CPS3SaveRestoreToUI : public CTier2AppSystem< IPS3SaveRestoreToUI >
  6. {
  7. public: // IAppSystem
  8. virtual bool Connect( CreateInterfaceFn factory );
  9. virtual void Disconnect();
  10. virtual void *QueryInterface( const char *pInterfaceName );
  11. virtual InitReturnVal_t Init();
  12. virtual void Shutdown();
  13. public: // IPS3SaveRestoreToUI
  14. /// You have to call this before doing any other save operation. In particular,
  15. /// there may be an error opening the container. Poll on Async, and when it's done,
  16. /// look in the return value to see if it succeeded, or if not, why not.
  17. /// When bCreateIfMissing is set, it will create a new container where none exists.
  18. virtual void Initialize( CPS3SaveRestoreAsyncStatus *pAsync, IPS3SaveSteamInfoProvider *pSteamInfoProvider, bool bCreateIfMissing, int nKBRequired )
  19. {
  20. SaveUtilV2_Initialize( pAsync, pSteamInfoProvider, nKBRequired );
  21. }
  22. // Save the given file into the container. (ie /dev_hdd1/tempsave/foo.ps3.sav will
  23. // be written into the container as foo.ps3.sav ). You can optionally specify a second
  24. // file to be written at the same time, eg a screenshot, because batching two writes
  25. // to happen at once is far far faster than having two batches one after another.
  26. // ALL game progress files must be
  27. // written as secure; for now, even the screenshots should be, as that puts the work
  28. // of CRC onto the operating system.
  29. virtual void Write( CPS3SaveRestoreAsyncStatus *pAsync, const char *pSourcepath, const char *pScreenshotPath, const char *pComment, FileSecurity_t nSecurity = kSECURE )
  30. {
  31. SaveUtilV2_Write( pAsync, pSourcepath, pScreenshotPath, pComment );
  32. }
  33. // A more complicated and intelligent form of save writing, specifically for the case of autosaves.
  34. // The source filename given (as an absolute path) will be written to "autosave.ps3.sav".
  35. // Meanwhile, the existing "autosave.ps3.sav" will be renamed "autosave01.ps3.sav",
  36. // any "autosave01.ps3.sav" will be renamed "autosave02.ps3.sav", and so on up to a maximum
  37. // number of autosaves N, plus the base autosave.ps3.sav. The highest "autosave%02d.ps3.sav"
  38. // will therefore have a number N. Excess autosaves with numbers >N will be deleted.
  39. // If you specify a ScreenshotExtension (such as "tga"), the same operation is performed
  40. // for every file above, where ."sav" is replaced with the given extension.
  41. virtual void WriteAutosave( CPS3SaveRestoreAsyncStatus *pAsync,
  42. const char *pSourcePath, // eg "/dev_hdd1/tempsave/autosave.ps3.sav"
  43. const char *pComment, // the comment field for the new autosave.
  44. const unsigned int nMaxNumAutosaves ) // should be at least 1; the highest numbered autosave will be N-1.
  45. {
  46. SaveUtilV2_WriteAutosave( pAsync, pSourcePath, pComment, nMaxNumAutosaves );
  47. }
  48. // A way of writing clouded files into container, clouded files over
  49. // a certain age are purged from container
  50. virtual void WriteCloudFile( CPS3SaveRestoreAsyncStatus *pAsync,
  51. const char *pSourcePath,
  52. const unsigned int nMaxNumCloudFiles ) // should be at least 1; the highest numbered cloud file will be N-1.
  53. {
  54. SaveUtilV2_WriteCloudFile( pAsync, pSourcePath, nMaxNumCloudFiles );
  55. }
  56. // Load a file from the container into the given directory.
  57. // give it a pointer to a CPS3SaveRestoreAsyncStatus struct that you have created and
  58. // intend to poll.
  59. virtual void Load( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename, const char *pDestFullPath )
  60. {
  61. SaveUtilV2_Load( pAsync, pFilename, pDestFullPath );
  62. }
  63. // kill one or two files (eg, save and screenshot).
  64. // async will respond when done.
  65. virtual void Delete( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename, const char *pOtherFilename = NULL )
  66. {
  67. SaveUtilV2_Delete( pAsync, pFilename );
  68. }
  69. // synchronously retrieve information on the files in the container. Lacks some of the container-wide'
  70. // info of the above function, and may have slightly out of date information, but is a synchronous call
  71. // and returns precisely the structure needed by CBaseModPanel::GetSaveGameInfos().
  72. virtual void GetFileInfoSync( CUtlVector< PS3SaveGameInfo_t > &saveGameInfos, bool bFindAll )
  73. {
  74. SaveUtilV2_GetFileInfoSync( saveGameInfos, bFindAll );
  75. }
  76. // try to find Steam's schema file for the user and stuff it into the container.
  77. // returns false if it couldn't find the file locally (in which case you should
  78. // not wait for the async object to be "done", as the job wasn't initiated);
  79. // true if it found it locally and queued up an async job to write it.
  80. virtual void WriteSteamInfo( CPS3SaveRestoreAsyncStatus *pAsync )
  81. {
  82. SaveUtilV2_WriteSteamInfo( pAsync );
  83. }
  84. // returns whether save thread is busy
  85. virtual bool IsSaveUtilBusy()
  86. {
  87. return !!g_pSaveUtilAsyncStatus;
  88. }
  89. // returns the m_nCurrentOperationTag field of the most recent async op to
  90. // have run, or kSAVE_TAG_UNKNOWN if none has been enqueued yet. This tag
  91. // changes the moment a job is made active and remains until the next job
  92. // starts.
  93. virtual uint32 GetCurrentOpTag()
  94. {
  95. CPS3SaveRestoreAsyncStatus *pAsync = g_pSaveUtilAsyncStatus;
  96. if ( pAsync )
  97. return pAsync->m_nCurrentOperationTag;
  98. else
  99. return kSAVE_TAG_UNKNOWN;
  100. }
  101. // returns the version of container, used to fire off events when container
  102. // contents changes.
  103. virtual uint32 GetContainerModificationVersion()
  104. {
  105. return g_SaveUtilV2TOCVersion;
  106. }
  107. // sets the cloud crypto key.
  108. virtual void SetCloudFileCryptoKey( uint64 uiCloudCryptoKey )
  109. {
  110. g_uiSteamCloudCryptoKey = uiCloudCryptoKey;
  111. }
  112. };
  113. //////////////////////////////////////////////////////////////////////////
  114. CPS3SaveRestoreToUI g_PS3SaveToUI;
  115. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CPS3SaveRestoreToUI, IPS3SaveRestoreToUI,
  116. IPS3SAVEUIAPI_VERSION_STRING, g_PS3SaveToUI );
  117. static CreateInterfaceFn s_pfnDelegateFactory;
  118. static void * InternalFactory( const char *pName, int *pReturnCode )
  119. {
  120. if ( pReturnCode )
  121. {
  122. *pReturnCode = IFACE_OK;
  123. }
  124. // Try to get interface via delegate
  125. if ( void *pInterface = s_pfnDelegateFactory ? s_pfnDelegateFactory( pName, pReturnCode ) : NULL )
  126. {
  127. return pInterface;
  128. }
  129. // Try to get internal interface
  130. if ( void *pInterface = Sys_GetFactoryThis()( pName, pReturnCode ) )
  131. {
  132. return pInterface;
  133. }
  134. // Failed
  135. if ( pReturnCode )
  136. {
  137. *pReturnCode = IFACE_FAILED;
  138. }
  139. return NULL;
  140. }
  141. bool CPS3SaveRestoreToUI::Connect( CreateInterfaceFn factory )
  142. {
  143. Assert( !s_pfnDelegateFactory );
  144. s_pfnDelegateFactory = factory;
  145. CreateInterfaceFn ourFactory = InternalFactory;
  146. ConnectTier1Libraries( &ourFactory, 1 );
  147. ConnectTier2Libraries( &ourFactory, 1 );
  148. s_pfnDelegateFactory = NULL;
  149. return true;
  150. }
  151. void CPS3SaveRestoreToUI::Disconnect()
  152. {
  153. DisconnectTier2Libraries();
  154. DisconnectTier1Libraries();
  155. }
  156. void * CPS3SaveRestoreToUI::QueryInterface( const char *pInterfaceName )
  157. {
  158. if ( !Q_stricmp( pInterfaceName, IPS3SAVEUIAPI_VERSION_STRING ) )
  159. return static_cast< IPS3SaveRestoreToUI * >( this );
  160. return NULL;
  161. }
  162. InitReturnVal_t CPS3SaveRestoreToUI::Init()
  163. {
  164. return INIT_OK;
  165. }
  166. void CPS3SaveRestoreToUI::Shutdown()
  167. {
  168. return;
  169. }