CopyParam.cpp 19 KB

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