Team Fortress 2 Source Code as on 22/4/2020
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.

79 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #ifndef CL_RECORDINGSESSIONBLOCK_H
  5. #define CL_RECORDINGSESSIONBLOCK_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //----------------------------------------------------------------------------------------
  10. #include "baserecordingsessionblock.h"
  11. #include "engine/http.h"
  12. //----------------------------------------------------------------------------------------
  13. class CClientRecordingSessionBlock : public CBaseRecordingSessionBlock
  14. {
  15. typedef CBaseRecordingSessionBlock BaseClass;
  16. public:
  17. CClientRecordingSessionBlock( IReplayContext *pContext );
  18. bool NeedsUpdate() const;
  19. bool ShouldDownloadNow() const;
  20. bool DownloadedSuccessfully() const;
  21. int GetNumDownloadAttempts() const { return m_nDownloadAttempts; }
  22. virtual bool Read( KeyValues *pIn );
  23. virtual void Write( KeyValues *pOut );
  24. virtual void OnDelete();
  25. // Resets the download status to be "ready for download" if the # of download attempts
  26. // is under 3. Returns false if reset failed, otherwise true.
  27. bool AttemptToResetForDownload();
  28. // Checks data against the block's md5 digest
  29. bool ValidateData( const void *pData, int nSize, unsigned char *pOutHash = NULL ) const;
  30. enum DownloadStatus_t
  31. {
  32. DOWNLOADSTATUS_ABORTED, // Download was aborted for some reason
  33. DOWNLOADSTATUS_ERROR, // Refer to m_nError for more detail
  34. DOWNLOADSTATUS_WAITING, // Waiting for the file to be ready on the server
  35. DOWNLOADSTATUS_READYTODOWNLOAD, // File is ready to be downloaded
  36. DOWNLOADSTATUS_CONNECTING, // Connecting to file server
  37. DOWNLOADSTATUS_DOWNLOADING, // Currently downloading
  38. DOWNLOADSTATUS_DOWNLOADED, // Successfully downloaded file
  39. MAX_DOWNLOADSTATUS
  40. };
  41. // Persistent:
  42. DownloadStatus_t m_nDownloadStatus;
  43. uint32 m_uBytesDownloaded;
  44. bool m_bDataInvalid; // Hash didn't match data?
  45. HTTPError_t m_nHttpError;
  46. private:
  47. // Non-persistent:
  48. int m_nDownloadAttempts; // Should be modified via AttemptToResetForDownload()
  49. };
  50. //----------------------------------------------------------------------------------------
  51. inline CClientRecordingSessionBlock *CL_CastBlock( IReplaySerializeable *pBlock )
  52. {
  53. return static_cast< CClientRecordingSessionBlock * >( pBlock );
  54. }
  55. inline const CClientRecordingSessionBlock *CL_CastBlock( const IReplaySerializeable *pBlock )
  56. {
  57. return static_cast< const CClientRecordingSessionBlock * >( pBlock );
  58. }
  59. //----------------------------------------------------------------------------------------
  60. #endif // CL_RECORDINGSESSIONBLOCK_H