CopyParam.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Common.h"
  5. #include "CopyParam.h"
  6. //---------------------------------------------------------------------------
  7. __fastcall TCopyParamType::TCopyParamType()
  8. {
  9. Default();
  10. }
  11. //---------------------------------------------------------------------------
  12. __fastcall TCopyParamType::TCopyParamType(const TCopyParamType & Source)
  13. {
  14. Assign(&Source);
  15. }
  16. //---------------------------------------------------------------------------
  17. __fastcall TCopyParamType::~TCopyParamType()
  18. {
  19. }
  20. //---------------------------------------------------------------------------
  21. void __fastcall TCopyParamType::Default()
  22. {
  23. FileNameCase = ncNoChange;
  24. PreserveReadOnly = true;
  25. PreserveTime = true;
  26. Rights.Number = TRights::rfDefault;
  27. PreserveRights = false; // Was True until #106
  28. AsciiFileMask.Masks = "*.*html; *.htm; *.txt; *.php*; *.cgi; *.c; *.cpp; *.h; *.pas; "
  29. "*.bas; *.tex; *.pl; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml";
  30. TransferMode = tmAutomatic;
  31. AddXToDirectories = true;
  32. ResumeSupport = rsSmart;
  33. ResumeThreshold = 100 * 1024; // (100 kB)
  34. ReplaceInvalidChars = true;
  35. LocalInvalidChars = "/\\:*?\"<>|";
  36. CalculateSize = true;
  37. FileMask = "*.*";
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TCopyParamType::Assign(const TCopyParamType * Source)
  41. {
  42. assert(Source != NULL);
  43. #define COPY(Prop) Prop = Source->Prop
  44. COPY(FileNameCase);
  45. COPY(PreserveReadOnly);
  46. COPY(PreserveTime);
  47. COPY(Rights);
  48. COPY(AsciiFileMask);
  49. COPY(TransferMode);
  50. COPY(AddXToDirectories);
  51. COPY(PreserveRights);
  52. COPY(ResumeSupport);
  53. COPY(ResumeThreshold);
  54. COPY(ReplaceInvalidChars);
  55. COPY(LocalInvalidChars);
  56. COPY(CalculateSize);
  57. COPY(FileMask);
  58. #undef COPY
  59. }
  60. //---------------------------------------------------------------------------
  61. TCopyParamType & __fastcall TCopyParamType::operator =(const TCopyParamType & rhp)
  62. {
  63. Assign(&rhp);
  64. return *this;
  65. }
  66. //---------------------------------------------------------------------------
  67. AnsiString __fastcall TCopyParamType::ValidLocalFileName(AnsiString FileName) const
  68. {
  69. char * InvalidChar;
  70. while ((InvalidChar = strpbrk(FileName.c_str(), LocalInvalidChars.c_str())) != NULL)
  71. {
  72. FileName[InvalidChar - FileName.c_str() + 1] = '_';
  73. }
  74. return FileName;
  75. }
  76. //---------------------------------------------------------------------------
  77. AnsiString __fastcall TCopyParamType::ChangeFileName(AnsiString FileName,
  78. TOperationSide Side, bool FirstLevel) const
  79. {
  80. if (FirstLevel)
  81. {
  82. FileName = MaskFileName(FileName, FileMask);
  83. }
  84. switch (FileNameCase) {
  85. case ncUpperCase: FileName = FileName.UpperCase(); break;
  86. case ncLowerCase: FileName = FileName.LowerCase(); break;
  87. case ncFirstUpperCase: FileName = FileName.SubString(1, 1).UpperCase() +
  88. FileName.SubString(2, FileName.Length()-1).LowerCase(); break;
  89. case ncNoChange:
  90. default:
  91. /*nothing*/
  92. break;
  93. }
  94. if (ReplaceInvalidChars && (Side == osRemote))
  95. {
  96. FileName = ValidLocalFileName(FileName);
  97. }
  98. return FileName;
  99. }
  100. //---------------------------------------------------------------------------
  101. bool __fastcall TCopyParamType::UseAsciiTransfer(const AnsiString FileName) const
  102. {
  103. switch (TransferMode) {
  104. case tmBinary: return false;
  105. case tmAscii: return true;
  106. case tmAutomatic: return AsciiFileMask.Matches(FileName);
  107. default: assert(false); return false;
  108. }
  109. }
  110. //---------------------------------------------------------------------------
  111. TRights __fastcall TCopyParamType::RemoteFileRights(Integer Attrs) const
  112. {
  113. TRights R = Rights;
  114. /* if ((Attrs & faReadOnly) && PreserveReadOnly)
  115. R.ReadOnly = True;*/
  116. if ((Attrs & faDirectory) && AddXToDirectories)
  117. R.AddExecute();
  118. return R;
  119. }
  120. //---------------------------------------------------------------------------
  121. AnsiString __fastcall TCopyParamType::GetLogStr() const
  122. {
  123. char CaseC[] = "NULF";
  124. char ModeC[] = "BAM";
  125. char ResumeC[] = "YSN";
  126. return FORMAT(
  127. " PrTime: %s; PrRO: %s; Rght: %s; PrR: %s; FnCs: %s; RIC: %s; "
  128. "Resume: %s (%d); CalcS: %s; Mask: %s\n"
  129. " TM: %s; AscM: %s ",
  130. (BooleanToEngStr(PreserveTime),
  131. BooleanToEngStr(PreserveReadOnly),
  132. Rights.Text,
  133. BooleanToEngStr(PreserveRights),
  134. CaseC[FileNameCase],
  135. BooleanToEngStr(ReplaceInvalidChars),
  136. ResumeC[ResumeSupport],
  137. (int)ResumeThreshold,
  138. BooleanToEngStr(CalculateSize),
  139. FileMask,
  140. ModeC[TransferMode],
  141. AsciiFileMask.Masks));
  142. }
  143. //---------------------------------------------------------------------------
  144. int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
  145. {
  146. int Result = 0;
  147. if (PreserveReadOnly && !Rights.Right[TRights::rrUserWrite])
  148. {
  149. Result |= faReadOnly;
  150. }
  151. return Result;
  152. }
  153. //---------------------------------------------------------------------------
  154. bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
  155. {
  156. switch (ResumeSupport) {
  157. case rsOn: return true;
  158. case rsOff: return false;
  159. case rsSmart: return (Size >= ResumeThreshold);
  160. default: assert(false); return false;
  161. }
  162. }
  163. //---------------------------------------------------------------------------