CopyParam.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Common.h"
  5. #include "Exceptions.h"
  6. #include "CopyParam.h"
  7. #include "HierarchicalStorage.h"
  8. #include "TextsCore.h"
  9. //---------------------------------------------------------------------------
  10. __fastcall TCopyParamType::TCopyParamType()
  11. {
  12. Default();
  13. }
  14. //---------------------------------------------------------------------------
  15. __fastcall TCopyParamType::TCopyParamType(const TCopyParamType & Source)
  16. {
  17. Assign(&Source);
  18. }
  19. //---------------------------------------------------------------------------
  20. __fastcall TCopyParamType::~TCopyParamType()
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TCopyParamType::Default()
  25. {
  26. // when changing defaults, make sure GetInfoStr() can handle it
  27. FileNameCase = ncNoChange;
  28. PreserveReadOnly = false;
  29. PreserveTime = true;
  30. Rights.Number = TRights::rfDefault;
  31. PreserveRights = false; // Was True until #106
  32. IgnorePermErrors = false;
  33. AsciiFileMask.Masks = L"*.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; "
  34. "*.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml";
  35. TransferMode = tmBinary;
  36. AddXToDirectories = true;
  37. ResumeSupport = rsSmart;
  38. ResumeThreshold = 100 * 1024; // (100 KiB)
  39. InvalidCharsReplacement = TokenReplacement;
  40. LocalInvalidChars = ::LocalInvalidChars;
  41. CalculateSize = true;
  42. FileMask = L"*.*";
  43. IncludeFileMask.Masks = L"";
  44. ClearArchive = false;
  45. RemoveCtrlZ = false;
  46. RemoveBOM = false;
  47. CPSLimit = 0;
  48. NewerOnly = false;
  49. }
  50. //---------------------------------------------------------------------------
  51. UnicodeString __fastcall TCopyParamType::GetInfoStr(
  52. UnicodeString Separator, int Attrs) const
  53. {
  54. UnicodeString Result;
  55. bool SomeAttrIncluded;
  56. DoGetInfoStr(Separator, Attrs, Result, SomeAttrIncluded);
  57. return Result;
  58. }
  59. //---------------------------------------------------------------------------
  60. bool __fastcall TCopyParamType::AnyUsableCopyParam(int Attrs) const
  61. {
  62. UnicodeString Result;
  63. bool SomeAttrIncluded;
  64. DoGetInfoStr(L";", Attrs, Result, SomeAttrIncluded);
  65. return SomeAttrIncluded;
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TCopyParamType::DoGetInfoStr(
  69. UnicodeString Separator, int Options,
  70. UnicodeString & Result, bool & SomeAttrIncluded) const
  71. {
  72. TCopyParamType Defaults;
  73. bool SomeAttrExcluded = false;
  74. SomeAttrIncluded = false;
  75. #define ADD(STR, EXCEPT) \
  76. if (FLAGCLEAR(Options, EXCEPT)) \
  77. { \
  78. AddToList(Result, (STR), Separator); \
  79. SomeAttrIncluded = true; \
  80. } \
  81. else \
  82. { \
  83. SomeAttrExcluded = true; \
  84. }
  85. bool TransferModeDiffers =
  86. ((TransferMode != Defaults.TransferMode) ||
  87. ((TransferMode == tmAutomatic) && !(AsciiFileMask == Defaults.AsciiFileMask)));
  88. if (FLAGCLEAR(Options, cpaIncludeMaskOnly | cpaNoTransferMode))
  89. {
  90. // Adding Transfer type unconditionally
  91. bool FormatMask;
  92. int Ident;
  93. switch (TransferMode)
  94. {
  95. case tmBinary:
  96. FormatMask = false;
  97. Ident = 2;
  98. break;
  99. case tmAscii:
  100. FormatMask = false;
  101. Ident = 3;
  102. break;
  103. case tmAutomatic:
  104. default:
  105. FormatMask = !(AsciiFileMask == Defaults.AsciiFileMask);
  106. Ident = FormatMask ? 4 : 5;
  107. break;
  108. }
  109. UnicodeString S = FORMAT(LoadStrPart(COPY_INFO_TRANSFER_TYPE2, 1),
  110. (LoadStrPart(COPY_INFO_TRANSFER_TYPE2, Ident)));
  111. if (FormatMask)
  112. {
  113. S = FORMAT(S, (AsciiFileMask.Masks));
  114. }
  115. AddToList(Result, S, Separator);
  116. if (TransferModeDiffers)
  117. {
  118. ADD("", cpaIncludeMaskOnly | cpaNoTransferMode);
  119. }
  120. }
  121. else
  122. {
  123. if (TransferModeDiffers)
  124. {
  125. SomeAttrExcluded = true;
  126. }
  127. }
  128. if (FileNameCase != Defaults.FileNameCase)
  129. {
  130. ADD(FORMAT(LoadStrPart(COPY_INFO_FILENAME, 1),
  131. (LoadStrPart(COPY_INFO_FILENAME, FileNameCase + 2))),
  132. cpaIncludeMaskOnly);
  133. }
  134. if ((InvalidCharsReplacement == NoReplacement) !=
  135. (Defaults.InvalidCharsReplacement == NoReplacement))
  136. {
  137. assert(InvalidCharsReplacement == NoReplacement);
  138. if (InvalidCharsReplacement == NoReplacement)
  139. {
  140. ADD(LoadStr(COPY_INFO_DONT_REPLACE_INV_CHARS), cpaIncludeMaskOnly);
  141. }
  142. }
  143. if ((PreserveRights != Defaults.PreserveRights) ||
  144. (PreserveRights &&
  145. ((Rights != Defaults.Rights) || (AddXToDirectories != Defaults.AddXToDirectories))))
  146. {
  147. assert(PreserveRights);
  148. if (PreserveRights)
  149. {
  150. UnicodeString RightsStr = Rights.Text;
  151. if (AddXToDirectories)
  152. {
  153. RightsStr += L", " + LoadStr(COPY_INFO_ADD_X_TO_DIRS);
  154. }
  155. ADD(FORMAT(LoadStr(COPY_INFO_PERMISSIONS), (RightsStr)),
  156. cpaIncludeMaskOnly | cpaNoRights);
  157. }
  158. }
  159. if (PreserveTime != Defaults.PreserveTime)
  160. {
  161. ADD(LoadStr(PreserveTime ? COPY_INFO_TIMESTAMP : COPY_INFO_DONT_PRESERVE_TIME),
  162. cpaIncludeMaskOnly | cpaNoPreserveTime);
  163. }
  164. if ((PreserveRights || PreserveTime) &&
  165. (IgnorePermErrors != Defaults.IgnorePermErrors))
  166. {
  167. assert(IgnorePermErrors);
  168. if (IgnorePermErrors)
  169. {
  170. ADD(LoadStr(COPY_INFO_IGNORE_PERM_ERRORS),
  171. cpaIncludeMaskOnly | cpaNoIgnorePermErrors);
  172. }
  173. }
  174. if (PreserveReadOnly != Defaults.PreserveReadOnly)
  175. {
  176. assert(PreserveReadOnly);
  177. if (PreserveReadOnly)
  178. {
  179. ADD(LoadStr(COPY_INFO_PRESERVE_READONLY),
  180. cpaIncludeMaskOnly | cpaNoPreserveReadOnly);
  181. }
  182. }
  183. if (CalculateSize != Defaults.CalculateSize)
  184. {
  185. assert(!CalculateSize);
  186. if (!CalculateSize)
  187. {
  188. ADD(LoadStr(COPY_INFO_DONT_CALCULATE_SIZE), cpaIncludeMaskOnly);
  189. }
  190. }
  191. if (ClearArchive != Defaults.ClearArchive)
  192. {
  193. assert(ClearArchive);
  194. if (ClearArchive)
  195. {
  196. ADD(LoadStr(COPY_INFO_CLEAR_ARCHIVE),
  197. cpaIncludeMaskOnly | cpaNoClearArchive);
  198. }
  199. }
  200. if ((TransferMode == tmAscii) || (TransferMode == tmAutomatic))
  201. {
  202. if (RemoveBOM != Defaults.RemoveBOM)
  203. {
  204. if (ALWAYS_TRUE(RemoveBOM))
  205. {
  206. ADD(LoadStr(COPY_INFO_REMOVE_BOM),
  207. cpaIncludeMaskOnly | cpaNoRemoveBOM | cpaNoTransferMode);
  208. }
  209. }
  210. if (RemoveCtrlZ != Defaults.RemoveCtrlZ)
  211. {
  212. if (ALWAYS_TRUE(RemoveCtrlZ))
  213. {
  214. ADD(LoadStr(COPY_INFO_REMOVE_CTRLZ),
  215. cpaIncludeMaskOnly | cpaNoRemoveCtrlZ | cpaNoTransferMode);
  216. }
  217. }
  218. }
  219. if (!(IncludeFileMask == Defaults.IncludeFileMask))
  220. {
  221. ADD(FORMAT(LoadStr(COPY_INFO_FILE_MASK), (IncludeFileMask.Masks)),
  222. cpaNoIncludeMask);
  223. }
  224. if (CPSLimit > 0)
  225. {
  226. ADD(FMTLOAD(COPY_INFO_CPS_LIMIT, (int(CPSLimit / 1024))), cpaIncludeMaskOnly);
  227. }
  228. if (NewerOnly != Defaults.NewerOnly)
  229. {
  230. if (ALWAYS_TRUE(NewerOnly))
  231. {
  232. ADD(StripHotkey(LoadStr(COPY_PARAM_NEWER_ONLY)), cpaIncludeMaskOnly | cpaNoNewerOnly);
  233. }
  234. }
  235. if (SomeAttrExcluded)
  236. {
  237. Result += (Result.IsEmpty() ? UnicodeString() : Separator) +
  238. FORMAT(LoadStrPart(COPY_INFO_NOT_USABLE, 1),
  239. (LoadStrPart(COPY_INFO_NOT_USABLE, (SomeAttrIncluded ? 2 : 3))));
  240. }
  241. else if (Result.IsEmpty())
  242. {
  243. Result = LoadStr(COPY_INFO_DEFAULT);
  244. }
  245. #undef ADD
  246. }
  247. //---------------------------------------------------------------------------
  248. void __fastcall TCopyParamType::Assign(const TCopyParamType * Source)
  249. {
  250. assert(Source != NULL);
  251. #define COPY(Prop) Prop = Source->Prop
  252. COPY(FileNameCase);
  253. COPY(PreserveReadOnly);
  254. COPY(PreserveTime);
  255. COPY(Rights);
  256. COPY(AsciiFileMask);
  257. COPY(TransferMode);
  258. COPY(AddXToDirectories);
  259. COPY(PreserveRights);
  260. COPY(IgnorePermErrors);
  261. COPY(ResumeSupport);
  262. COPY(ResumeThreshold);
  263. COPY(InvalidCharsReplacement);
  264. COPY(LocalInvalidChars);
  265. COPY(CalculateSize);
  266. COPY(FileMask);
  267. COPY(IncludeFileMask);
  268. COPY(ClearArchive);
  269. COPY(RemoveCtrlZ);
  270. COPY(RemoveBOM);
  271. COPY(CPSLimit);
  272. COPY(NewerOnly);
  273. #undef COPY
  274. }
  275. //---------------------------------------------------------------------------
  276. TCopyParamType & __fastcall TCopyParamType::operator =(const TCopyParamType & rhp)
  277. {
  278. Assign(&rhp);
  279. return *this;
  280. }
  281. //---------------------------------------------------------------------------
  282. void __fastcall TCopyParamType::SetLocalInvalidChars(UnicodeString value)
  283. {
  284. if (value != LocalInvalidChars)
  285. {
  286. FLocalInvalidChars = value;
  287. FTokenizibleChars = FLocalInvalidChars + TokenPrefix;
  288. }
  289. }
  290. //---------------------------------------------------------------------------
  291. bool __fastcall TCopyParamType::GetReplaceInvalidChars() const
  292. {
  293. return (InvalidCharsReplacement != NoReplacement);
  294. }
  295. //---------------------------------------------------------------------------
  296. void __fastcall TCopyParamType::SetReplaceInvalidChars(bool value)
  297. {
  298. if (ReplaceInvalidChars != value)
  299. {
  300. InvalidCharsReplacement = (value ? TokenReplacement : NoReplacement);
  301. }
  302. }
  303. //---------------------------------------------------------------------------
  304. UnicodeString __fastcall TCopyParamType::ValidLocalFileName(UnicodeString FileName) const
  305. {
  306. return ::ValidLocalFileName(FileName, InvalidCharsReplacement, FTokenizibleChars, LocalInvalidChars);
  307. }
  308. //---------------------------------------------------------------------------
  309. UnicodeString __fastcall TCopyParamType::RestoreChars(UnicodeString FileName) const
  310. {
  311. if (InvalidCharsReplacement == TokenReplacement)
  312. {
  313. wchar_t * InvalidChar = FileName.c_str();
  314. while ((InvalidChar = wcschr(InvalidChar, TokenPrefix)) != NULL)
  315. {
  316. int Index = InvalidChar - FileName.c_str() + 1;
  317. if (FileName.Length() >= Index + 2)
  318. {
  319. UnicodeString Hex = FileName.SubString(Index + 1, 2);
  320. wchar_t Char = static_cast<wchar_t>(HexToByte(Hex));
  321. if ((Char != L'\0') &&
  322. ((FTokenizibleChars.Pos(Char) > 0) ||
  323. (((Char == L' ') || (Char == L'.')) && (Index == FileName.Length() - 2))))
  324. {
  325. FileName[Index] = Char;
  326. FileName.Delete(Index + 1, 2);
  327. InvalidChar = FileName.c_str() + Index;
  328. }
  329. else if ((Hex == L"00") &&
  330. ((Index == FileName.Length() - 2) || (FileName[Index + 3] == L'.')) &&
  331. IsReservedName(FileName.SubString(1, Index - 1) + FileName.SubString(Index + 3, FileName.Length() - Index - 3 + 1)))
  332. {
  333. FileName.Delete(Index, 3);
  334. InvalidChar = FileName.c_str() + Index - 1;
  335. }
  336. else
  337. {
  338. InvalidChar++;
  339. }
  340. }
  341. else
  342. {
  343. InvalidChar++;
  344. }
  345. }
  346. }
  347. return FileName;
  348. }
  349. //---------------------------------------------------------------------------
  350. UnicodeString __fastcall TCopyParamType::ValidLocalPath(UnicodeString Path) const
  351. {
  352. UnicodeString Result;
  353. while (!Path.IsEmpty())
  354. {
  355. if (!Result.IsEmpty())
  356. {
  357. Result += L"\\";
  358. }
  359. Result += ValidLocalFileName(CutToChar(Path, L'\\', false));
  360. }
  361. return Result;
  362. }
  363. //---------------------------------------------------------------------------
  364. UnicodeString __fastcall TCopyParamType::ChangeFileName(UnicodeString FileName,
  365. TOperationSide Side, bool FirstLevel) const
  366. {
  367. if (FirstLevel)
  368. {
  369. FileName = MaskFileName(FileName, FileMask);
  370. }
  371. switch (FileNameCase) {
  372. case ncUpperCase: FileName = FileName.UpperCase(); break;
  373. case ncLowerCase: FileName = FileName.LowerCase(); break;
  374. case ncFirstUpperCase: FileName = FileName.SubString(1, 1).UpperCase() +
  375. FileName.SubString(2, FileName.Length()-1).LowerCase(); break;
  376. case ncLowerCaseShort:
  377. if ((FileName.Length() <= 12) && (FileName.Pos(L".") <= 9) &&
  378. (FileName == FileName.UpperCase()))
  379. {
  380. FileName = FileName.LowerCase();
  381. }
  382. break;
  383. case ncNoChange:
  384. default:
  385. /*nothing*/
  386. break;
  387. }
  388. if (Side == osRemote)
  389. {
  390. FileName = ValidLocalFileName(FileName);
  391. }
  392. else
  393. {
  394. FileName = RestoreChars(FileName);
  395. }
  396. return FileName;
  397. }
  398. //---------------------------------------------------------------------------
  399. bool __fastcall TCopyParamType::UseAsciiTransfer(UnicodeString FileName,
  400. TOperationSide Side, const TFileMasks::TParams & Params) const
  401. {
  402. switch (TransferMode)
  403. {
  404. case tmBinary: return false;
  405. case tmAscii: return true;
  406. case tmAutomatic: return AsciiFileMask.Matches(FileName, (Side == osLocal),
  407. false, &Params);
  408. default: assert(false); return false;
  409. }
  410. }
  411. //---------------------------------------------------------------------------
  412. TRights __fastcall TCopyParamType::RemoteFileRights(Integer Attrs) const
  413. {
  414. TRights R = Rights;
  415. if ((Attrs & faDirectory) && AddXToDirectories)
  416. R.AddExecute();
  417. return R;
  418. }
  419. //---------------------------------------------------------------------------
  420. UnicodeString __fastcall TCopyParamType::GetLogStr() const
  421. {
  422. wchar_t CaseC[] = L"NULFS";
  423. wchar_t ModeC[] = L"BAM";
  424. wchar_t ResumeC[] = L"YSN";
  425. return FORMAT(
  426. L" PrTime: %s; PrRO: %s; Rght: %s; PrR: %s (%s); FnCs: %s; RIC: %s; "
  427. "Resume: %s (%d); CalcS: %s; Mask: %s\n"
  428. " TM: %s; ClAr: %s; RemEOF: %s; RemBOM: %s; CPS: %u; NewerOnly: %s; InclM: %s\n"
  429. " AscM: %s\n",
  430. (BooleanToEngStr(PreserveTime),
  431. BooleanToEngStr(PreserveReadOnly),
  432. Rights.Text,
  433. BooleanToEngStr(PreserveRights),
  434. BooleanToEngStr(IgnorePermErrors),
  435. CaseC[FileNameCase],
  436. CharToHex(InvalidCharsReplacement),
  437. ResumeC[ResumeSupport],
  438. (int)ResumeThreshold,
  439. BooleanToEngStr(CalculateSize),
  440. FileMask,
  441. ModeC[TransferMode],
  442. BooleanToEngStr(ClearArchive),
  443. BooleanToEngStr(RemoveCtrlZ),
  444. BooleanToEngStr(RemoveBOM),
  445. int(CPSLimit),
  446. BooleanToEngStr(NewerOnly),
  447. IncludeFileMask.Masks,
  448. AsciiFileMask.Masks));
  449. }
  450. //---------------------------------------------------------------------------
  451. int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
  452. {
  453. int Result = 0;
  454. if (PreserveReadOnly && !Rights.Right[TRights::rrUserWrite])
  455. {
  456. Result |= faReadOnly;
  457. }
  458. return Result;
  459. }
  460. //---------------------------------------------------------------------------
  461. bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
  462. {
  463. switch (ResumeSupport)
  464. {
  465. case rsOn: return true;
  466. case rsOff: return false;
  467. case rsSmart: return (Size >= ResumeThreshold);
  468. default: assert(false); return false;
  469. }
  470. }
  471. //---------------------------------------------------------------------------
  472. bool __fastcall TCopyParamType::AllowAnyTransfer() const
  473. {
  474. return IncludeFileMask.Masks.IsEmpty();
  475. }
  476. //---------------------------------------------------------------------------
  477. bool __fastcall TCopyParamType::AllowTransfer(UnicodeString FileName,
  478. TOperationSide Side, bool Directory, const TFileMasks::TParams & Params) const
  479. {
  480. bool Result = true;
  481. if (!IncludeFileMask.Masks.IsEmpty())
  482. {
  483. Result = IncludeFileMask.Matches(FileName, (Side == osLocal),
  484. Directory, &Params);
  485. }
  486. return Result;
  487. }
  488. //---------------------------------------------------------------------------
  489. void __fastcall TCopyParamType::Load(THierarchicalStorage * Storage)
  490. {
  491. AddXToDirectories = Storage->ReadBool(L"AddXToDirectories", AddXToDirectories);
  492. AsciiFileMask.Masks = Storage->ReadString(L"Masks", AsciiFileMask.Masks);
  493. FileNameCase = (TFileNameCase)Storage->ReadInteger(L"FileNameCase", FileNameCase);
  494. PreserveReadOnly = Storage->ReadBool(L"PreserveReadOnly", PreserveReadOnly);
  495. PreserveTime = Storage->ReadBool(L"PreserveTime", PreserveTime);
  496. PreserveRights = Storage->ReadBool(L"PreserveRights", PreserveRights);
  497. IgnorePermErrors = Storage->ReadBool(L"IgnorePermErrors", IgnorePermErrors);
  498. Rights.Text = Storage->ReadString(L"Text", Rights.Text);
  499. TransferMode = (TTransferMode)Storage->ReadInteger(L"TransferMode", TransferMode);
  500. ResumeSupport = (TResumeSupport)Storage->ReadInteger(L"ResumeSupport", ResumeSupport);
  501. ResumeThreshold = Storage->ReadInt64(L"ResumeThreshold", ResumeThreshold);
  502. InvalidCharsReplacement = (wchar_t)Storage->ReadInteger(L"ReplaceInvalidChars",
  503. (unsigned int)InvalidCharsReplacement);
  504. LocalInvalidChars = Storage->ReadString(L"LocalInvalidChars", LocalInvalidChars);
  505. CalculateSize = Storage->ReadBool(L"CalculateSize", CalculateSize);
  506. if (Storage->ValueExists(L"IncludeFileMask"))
  507. {
  508. IncludeFileMask.Masks = Storage->ReadString(L"IncludeFileMask", IncludeFileMask.Masks);
  509. }
  510. else if (Storage->ValueExists(L"ExcludeFileMask"))
  511. {
  512. UnicodeString ExcludeFileMask = Storage->ReadString(L"ExcludeFileMask", L"");
  513. if (!ExcludeFileMask.IsEmpty())
  514. {
  515. bool NegativeExclude = Storage->ReadBool(L"NegativeExclude", false);
  516. if (NegativeExclude)
  517. {
  518. IncludeFileMask.Masks = ExcludeFileMask;
  519. }
  520. // convert at least simple cases to new format
  521. else if (ExcludeFileMask.Pos(IncludeExcludeFileMasksDelimiter) == 0)
  522. {
  523. IncludeFileMask.Masks = UnicodeString(IncludeExcludeFileMasksDelimiter) + ExcludeFileMask;
  524. }
  525. }
  526. }
  527. ClearArchive = Storage->ReadBool(L"ClearArchive", ClearArchive);
  528. RemoveCtrlZ = Storage->ReadBool(L"RemoveCtrlZ", RemoveCtrlZ);
  529. RemoveBOM = Storage->ReadBool(L"RemoveBOM", RemoveBOM);
  530. CPSLimit = Storage->ReadInteger(L"CPSLimit", CPSLimit);
  531. NewerOnly = Storage->ReadBool(L"NewerOnly", NewerOnly);
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TCopyParamType::Save(THierarchicalStorage * Storage) const
  535. {
  536. Storage->WriteBool(L"AddXToDirectories", AddXToDirectories);
  537. Storage->WriteString(L"Masks", AsciiFileMask.Masks);
  538. Storage->WriteInteger(L"FileNameCase", FileNameCase);
  539. Storage->WriteBool(L"PreserveReadOnly", PreserveReadOnly);
  540. Storage->WriteBool(L"PreserveTime", PreserveTime);
  541. Storage->WriteBool(L"PreserveRights", PreserveRights);
  542. Storage->WriteBool(L"IgnorePermErrors", IgnorePermErrors);
  543. Storage->WriteString(L"Text", Rights.Text);
  544. Storage->WriteInteger(L"TransferMode", TransferMode);
  545. Storage->WriteInteger(L"ResumeSupport", ResumeSupport);
  546. Storage->WriteInt64(L"ResumeThreshold", ResumeThreshold);
  547. Storage->WriteInteger(L"ReplaceInvalidChars", (unsigned int)InvalidCharsReplacement);
  548. Storage->WriteString(L"LocalInvalidChars", LocalInvalidChars);
  549. Storage->WriteBool(L"CalculateSize", CalculateSize);
  550. Storage->WriteString(L"IncludeFileMask", IncludeFileMask.Masks);
  551. Storage->DeleteValue(L"ExcludeFileMask"); // obsolete
  552. Storage->DeleteValue(L"NegativeExclude"); // obsolete
  553. Storage->WriteBool(L"ClearArchive", ClearArchive);
  554. Storage->WriteBool(L"RemoveCtrlZ", RemoveCtrlZ);
  555. Storage->WriteBool(L"RemoveBOM", RemoveBOM);
  556. Storage->WriteInteger(L"CPSLimit", CPSLimit);
  557. Storage->WriteBool(L"NewerOnly", NewerOnly);
  558. }
  559. //---------------------------------------------------------------------------
  560. #define C(Property) (Property == rhp.Property)
  561. bool __fastcall TCopyParamType::operator==(const TCopyParamType & rhp) const
  562. {
  563. return
  564. C(AddXToDirectories) &&
  565. C(AsciiFileMask) &&
  566. C(FileNameCase) &&
  567. C(PreserveReadOnly) &&
  568. C(PreserveTime) &&
  569. C(PreserveRights) &&
  570. C(IgnorePermErrors) &&
  571. C(Rights) &&
  572. C(TransferMode) &&
  573. C(ResumeSupport) &&
  574. C(ResumeThreshold) &&
  575. C(InvalidCharsReplacement) &&
  576. C(LocalInvalidChars) &&
  577. C(CalculateSize) &&
  578. C(IncludeFileMask) &&
  579. C(ClearArchive) &&
  580. C(RemoveCtrlZ) &&
  581. C(RemoveBOM) &&
  582. C(CPSLimit) &&
  583. C(NewerOnly) &&
  584. true;
  585. }
  586. #undef C
  587. //---------------------------------------------------------------------------
  588. unsigned long __fastcall GetSpeedLimit(const UnicodeString & Text)
  589. {
  590. unsigned long Speed;
  591. if (AnsiSameText(Text, LoadStr(SPEED_UNLIMITED)))
  592. {
  593. Speed = 0;
  594. }
  595. else
  596. {
  597. int SSpeed;
  598. if (!TryStrToInt(Text, SSpeed) ||
  599. (SSpeed < 0))
  600. {
  601. throw Exception(FMTLOAD(SPEED_INVALID, (Text)));
  602. }
  603. Speed = SSpeed;
  604. }
  605. return Speed * 1024;
  606. }
  607. //---------------------------------------------------------------------------
  608. UnicodeString __fastcall SetSpeedLimit(unsigned long Limit)
  609. {
  610. UnicodeString Text;
  611. if (Limit == 0)
  612. {
  613. Text = LoadStr(SPEED_UNLIMITED);
  614. }
  615. else
  616. {
  617. Text = IntToStr(int(Limit / 1024));
  618. }
  619. return Text;
  620. }