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.

117 lines
3.8 KiB

  1. //===== Copyright � 1996-2011, Valve Corporation, All rights reserved. ======//
  2. #include "ps3_saveutil_v2.h"
  3. #include "memdbgon.h"
  4. class CSaveUtilV2Job_Delete : public ISaveUtilV2Job
  5. {
  6. public: // Job entry point
  7. virtual JobStatus_t DoExecute();
  8. public: // Data resolved from the main thread
  9. CSaveUtilV2ContainerTOC::TocEntry_t *m_pTocEntry;
  10. int m_nTocEntryIndex;
  11. protected: // Stat callback
  12. virtual void DoDataStatCallback( SONY_SAVEUTIL_STAT_PARAMS );
  13. protected: // Delete the file and update TOC
  14. void DoDataFile_Delete( SONY_SAVEUTIL_FILE_PARAMS );
  15. void DoDataFile_UpdateTOC( SONY_SAVEUTIL_FILE_PARAMS );
  16. };
  17. //////////////////////////////////////////////////////////////////////////
  18. void SaveUtilV2_Delete( CPS3SaveRestoreAsyncStatus *pAsync, const char *pFilename )
  19. {
  20. if ( !SaveUtilV2_CanStartJob() )
  21. return;
  22. // Find the file that the caller wants
  23. int k = g_SaveUtilV2TOC.FindByEmbeddedFileName( pFilename, NULL );
  24. if ( ( k < 0 ) || ( k >= g_SaveUtilV2TOC.m_arrEntries.Count() ) )
  25. {
  26. pAsync->m_nSonyRetValue = CELL_SAVEDATA_ERROR_FAILURE;
  27. pAsync->m_bDone = 1;
  28. Warning( "ERROR: SaveUtilV2_Delete: attempted to delete file '%s' which doesn't exist in container!\n", pFilename );
  29. return;
  30. }
  31. // Start the job
  32. CSaveUtilV2Job_Delete *pJob = new CSaveUtilV2Job_Delete;
  33. // It is safe to hold this pointer into the TOC for the duration of this job
  34. // Only jobs update TOC and this is the current job, main thread accesses TOC for read only
  35. pJob->m_pTocEntry = &g_SaveUtilV2TOC.m_arrEntries[k].m_entry;
  36. pJob->m_nTocEntryIndex = k;
  37. SaveUtilV2_EnqueueJob( pAsync, pJob );
  38. }
  39. //////////////////////////////////////////////////////////////////////////
  40. JobStatus_t CSaveUtilV2Job_Delete::DoExecute()
  41. {
  42. float flTimeStamp = Plat_FloatTime();
  43. Msg( "CSaveUtilV2Job_Delete @%.3f\n", flTimeStamp );
  44. // Call saveutil
  45. int retv = cellSaveDataAutoSave2(
  46. CELL_SAVEDATA_VERSION_CURRENT,
  47. g_pszSaveUtilContainerName,
  48. g_pSaveUtilAsyncStatus->m_bUseSystemDialogs ? CELL_SAVEDATA_ERRDIALOG_ALWAYS : CELL_SAVEDATA_ERRDIALOG_NONE,
  49. &m_SaveDirInfo,
  50. csDataStatCallback,
  51. csDataFileCallback,
  52. SYS_MEMORY_CONTAINER_ID_INVALID,
  53. this );
  54. float flEndTimeStamp = Plat_FloatTime();
  55. Msg( "CSaveUtilV2Job_Delete: cellSaveDataAutoSave2 returned %x @%.3f ( total time = %.3f sec )\n", retv, flEndTimeStamp, flEndTimeStamp - flTimeStamp );
  56. ++ g_SaveUtilV2TOCVersion;
  57. return SaveUtilV2_JobDone( retv );
  58. }
  59. void CSaveUtilV2Job_Delete::DoDataStatCallback( SONY_SAVEUTIL_STAT_PARAMS )
  60. {
  61. Msg( "CSaveUtilV2Job_Delete::DoDataStatCallback @%.3f\n", Plat_FloatTime() );
  62. SetDataFileCallback( &CSaveUtilV2Job_Delete::DoDataFile_Delete );
  63. cbResult->result = CELL_SAVEDATA_CBRESULT_OK_NEXT;
  64. }
  65. void CSaveUtilV2Job_Delete::DoDataFile_Delete( SONY_SAVEUTIL_FILE_PARAMS )
  66. {
  67. Msg( "CSaveUtilV2Job_Delete::DoDataFile_Delete @%.3f\n", Plat_FloatTime() );
  68. // Perform the delete
  69. set->fileOperation = CELL_SAVEDATA_FILEOP_DELETE;
  70. set->fileBuf = NULL;
  71. set->fileSize = set->fileBufSize = 0;
  72. set->fileName = m_pTocEntry->m_chContainerName;
  73. set->fileOffset = 0;
  74. set->fileType = CELL_SAVEDATA_FILETYPE_SECUREFILE;
  75. memcpy( set->secureFileId, g_pszSaveUtilSecureFileId, CELL_SAVEDATA_SECUREFILEID_SIZE );
  76. set->reserved = NULL;
  77. // final write
  78. SetDataFileCallback( &CSaveUtilV2Job_Delete::DoDataFile_UpdateTOC );
  79. cbResult->result = CELL_SAVEDATA_CBRESULT_OK_NEXT;
  80. Msg( "CSaveUtilV2Job_Delete::DoDataFile_Delete will delete '%s'...\n", m_pTocEntry->m_chContainerName );
  81. }
  82. void CSaveUtilV2Job_Delete::DoDataFile_UpdateTOC( SONY_SAVEUTIL_FILE_PARAMS )
  83. {
  84. Msg( "CSaveUtilV2Job_Delete::DoDataFile_UpdateTOC @%.3f\n", Plat_FloatTime() );
  85. // Update TOC since we successfully deleted the file
  86. {
  87. AUTO_LOCK( g_SaveUtilV2TOC.m_mtx );
  88. // Deleting an entry doesn't reallocate the memory
  89. g_SaveUtilV2TOC.m_arrEntries.Remove( m_nTocEntryIndex );
  90. }
  91. cbResult->result = CELL_SAVEDATA_CBRESULT_OK_LAST;
  92. }