CopyThread.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Installer *
  23. * *
  24. * $Archive:: /Commando/Code/Installer/CopyThread.h $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 1/10/02 6:34p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef _COPY_THREAD_H
  36. #define _COPY_THREAD_H
  37. // Includes.
  38. #include "Thread.h"
  39. #include "Win.h"
  40. #include "WWString.h"
  41. #include "WideString.h"
  42. // Class to implement a worker thread that will execute the file copying process.
  43. // NOTE: Thread usage will ensure that copying does not stall the copy dialog.
  44. class CopyThreadClass : public ThreadClass
  45. {
  46. public:
  47. enum StatusEnum {
  48. STATUS_OK,
  49. STATUS_RETRY = STATUS_OK,
  50. STATUS_ERROR,
  51. STATUS_QUIT,
  52. STATUS_SUCCESS,
  53. STATUS_ABORTED,
  54. STATUS_FAILURE
  55. };
  56. CopyThreadClass (__int64 bytestocopy);
  57. ~CopyThreadClass();
  58. void Thread_Function();
  59. bool Can_Abort (bool lock);
  60. void Set_Abort (bool abort);
  61. bool Get_Abort (bool canabort);
  62. bool Is_Aborting() {return (IsAborting);}
  63. void Add_Bytes_Copied (unsigned bytecount);
  64. float Get_Fraction_Complete();
  65. void Set_Target_Path (const WideStringClass &targetpath);
  66. WCHAR *Get_Target_Path (WideStringClass &targetpath);
  67. void Set_Status_Message (const WideStringClass &targetpath);
  68. WCHAR *Get_Status_Message (WideStringClass &targetpath);
  69. void Set_Error_Message (const WideStringClass &errormessage);
  70. WCHAR *Get_Error_Message (WideStringClass &errormessage);
  71. void Set_Status (StatusEnum status);
  72. StatusEnum Get_Status();
  73. bool Retry();
  74. DynamicVectorClass <StringClass> &Get_Subdirectory_Log() {return (SubdirectoryLog);}
  75. DynamicVectorClass <StringClass> &Get_Filename_Log() {return (FilenameLog);}
  76. static bool Replace_File (const FILETIME &sourcefiletime, DWORD sourcefilesize, const WideStringClass &targetpathname);
  77. static bool Replace_File (const WideStringClass &sourcepathname, const WideStringClass &targetpathname);
  78. static CopyThreadClass *_ActiveCopyThread;
  79. protected:
  80. void Copy_Directory (const WideStringClass &sourcepath, const WideStringClass &targetpath);
  81. void Copy_File (const WideStringClass &sourcepathname, const WideStringClass &targetpathname);
  82. __int64 BytesToCopy;
  83. bool IsAborting;
  84. // NOTE: Do not access the following variables directly. Instead use the Set/Get()
  85. // functions because they are protected by critical sections.
  86. bool Abort;
  87. bool CanAbort;
  88. __int64 BytesCopied; // Bytes copied so far.
  89. WideStringClass TargetPath;
  90. WideStringClass StatusMessage;
  91. WideStringClass ErrorMessage;
  92. StatusEnum Status;
  93. FastCriticalSectionClass::LockClass *AbortLock;
  94. FastCriticalSectionClass SectionAbort;
  95. FastCriticalSectionClass SectionBytesCopied;
  96. FastCriticalSectionClass SectionTargetPath;
  97. FastCriticalSectionClass SectionStatusMessage;
  98. FastCriticalSectionClass SectionErrorMessage;
  99. FastCriticalSectionClass SectionStatus;
  100. DynamicVectorClass <StringClass> SubdirectoryLog;
  101. DynamicVectorClass <StringClass> FilenameLog;
  102. };
  103. #endif // COPY_THREAD_H