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.

91 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=======================================================================================//
  4. #ifndef SV_FILESERVERCLEANUP_H
  5. #define SV_FILESERVERCLEANUP_H
  6. #ifdef _WIN32
  7. #pragma once
  8. #endif
  9. //----------------------------------------------------------------------------------------
  10. #include "basethinker.h"
  11. #include "spew.h"
  12. #include "sv_basejob.h"
  13. //----------------------------------------------------------------------------------------
  14. bool SV_DoFileserverCleanup( bool bForceCleanAll, ISpewer *pSpewer/*=g_pDefaultSpewer*/ );
  15. CBaseJob *SV_CreateDeleteFileJob();
  16. //----------------------------------------------------------------------------------------
  17. class IFileserverCleanerJob
  18. {
  19. public:
  20. virtual ~IFileserverCleanerJob() {}
  21. virtual void AddFileForDelete( const char *pFilename ) = 0;
  22. virtual int GetNumFilesDeleted() const = 0;
  23. };
  24. IFileserverCleanerJob *SV_CastJobToIFileserverCleanerJob( CBaseJob *pJob );
  25. //----------------------------------------------------------------------------------------
  26. class CFileserverCleaner : public CBaseThinker
  27. {
  28. public:
  29. CFileserverCleaner();
  30. void MarkFileForDelete( const char *pFilename );
  31. int GetNumFilesDeleted() const { return m_nNumFilesDeleted; }
  32. bool HasFilesQueuedForDelete() const { return m_pCleanerJob != NULL; }
  33. void BlockForCompletion();
  34. void DoCleanAsynchronous( bool bPrintResult = false, ISpewer *pSpewer = g_pDefaultSpewer );
  35. private:
  36. void Clear();
  37. void PrintResult();
  38. virtual void Think();
  39. virtual float GetNextThinkTime() const;
  40. CBaseJob *m_pCleanerJob;
  41. bool m_bRunning;
  42. bool m_bPrintResult;
  43. int m_nNumFilesDeleted;
  44. ISpewer *m_pSpewer;
  45. };
  46. //----------------------------------------------------------------------------------------
  47. class CLocalFileDeleterJob : public CBaseJob,
  48. public IFileserverCleanerJob
  49. {
  50. public:
  51. CLocalFileDeleterJob();
  52. virtual void AddFileForDelete( const char *pFilename );
  53. virtual int GetNumFilesDeleted() const { return m_nNumDeleted; }
  54. enum DeleteError_t
  55. {
  56. ERROR_FILE_DOES_NOT_EXIST,
  57. };
  58. private:
  59. virtual JobStatus_t DoExecute();
  60. CUtlStringList m_vecFiles;
  61. int m_nNumDeleted;
  62. };
  63. CLocalFileDeleterJob *SV_CreateLocalFileDeleterJob();
  64. //----------------------------------------------------------------------------------------
  65. #endif // SV_FILESERVERCLEANUP_H