CopyParam.cpp 5.2 KB

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