CopyParam.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. PreserveTimeDirs = false;
  31. Rights.Number = TRights::rfDefault;
  32. PreserveRights = false; // Was True until #106
  33. IgnorePermErrors = false;
  34. AsciiFileMask.Masks = L"*.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; "
  35. "*.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml";
  36. TransferMode = tmBinary;
  37. AddXToDirectories = true;
  38. ResumeSupport = rsSmart;
  39. ResumeThreshold = 100 * 1024; // (100 KB)
  40. InvalidCharsReplacement = TokenReplacement;
  41. LocalInvalidChars = ::LocalInvalidChars;
  42. CalculateSize = true;
  43. FileMask = L"*.*";
  44. IncludeFileMask.Masks = L"";
  45. TransferSkipList = NULL;
  46. TransferResumeFile = L"";
  47. ClearArchive = false;
  48. RemoveCtrlZ = false;
  49. RemoveBOM = false;
  50. CPSLimit = 0;
  51. NewerOnly = false;
  52. }
  53. //---------------------------------------------------------------------------
  54. UnicodeString __fastcall TCopyParamType::GetInfoStr(
  55. UnicodeString Separator, int Attrs) const
  56. {
  57. UnicodeString Result;
  58. bool SomeAttrIncluded;
  59. DoGetInfoStr(Separator, Attrs, Result, SomeAttrIncluded);
  60. return Result;
  61. }
  62. //---------------------------------------------------------------------------
  63. bool __fastcall TCopyParamType::AnyUsableCopyParam(int Attrs) const
  64. {
  65. UnicodeString Result;
  66. bool SomeAttrIncluded;
  67. DoGetInfoStr(L";", Attrs, Result, SomeAttrIncluded);
  68. return SomeAttrIncluded;
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TCopyParamType::DoGetInfoStr(
  72. UnicodeString Separator, int Options,
  73. UnicodeString & Result, bool & SomeAttrIncluded) const
  74. {
  75. TCopyParamType Defaults;
  76. bool SomeAttrExcluded = false;
  77. SomeAttrIncluded = false;
  78. #define ADD(STR, EXCEPT) \
  79. if (FLAGCLEAR(Options, EXCEPT)) \
  80. { \
  81. AddToList(Result, (STR), Separator); \
  82. SomeAttrIncluded = true; \
  83. } \
  84. else \
  85. { \
  86. SomeAttrExcluded = true; \
  87. }
  88. bool TransferModeDiffers =
  89. ((TransferMode != Defaults.TransferMode) ||
  90. ((TransferMode == tmAutomatic) && !(AsciiFileMask == Defaults.AsciiFileMask)));
  91. if (FLAGCLEAR(Options, cpaIncludeMaskOnly | cpaNoTransferMode))
  92. {
  93. // Adding Transfer type unconditionally
  94. bool FormatMask;
  95. int Ident;
  96. switch (TransferMode)
  97. {
  98. case tmBinary:
  99. FormatMask = false;
  100. Ident = 2;
  101. break;
  102. case tmAscii:
  103. FormatMask = false;
  104. Ident = 3;
  105. break;
  106. case tmAutomatic:
  107. default:
  108. FormatMask = !(AsciiFileMask == Defaults.AsciiFileMask);
  109. Ident = FormatMask ? 4 : 5;
  110. break;
  111. }
  112. UnicodeString S = FORMAT(LoadStrPart(COPY_INFO_TRANSFER_TYPE2, 1),
  113. (LoadStrPart(COPY_INFO_TRANSFER_TYPE2, Ident)));
  114. if (FormatMask)
  115. {
  116. S = FORMAT(S, (AsciiFileMask.Masks));
  117. }
  118. AddToList(Result, S, Separator);
  119. if (TransferModeDiffers)
  120. {
  121. ADD("", cpaIncludeMaskOnly | cpaNoTransferMode);
  122. }
  123. }
  124. else
  125. {
  126. if (TransferModeDiffers)
  127. {
  128. SomeAttrExcluded = true;
  129. }
  130. }
  131. if (FileNameCase != Defaults.FileNameCase)
  132. {
  133. ADD(FORMAT(LoadStrPart(COPY_INFO_FILENAME, 1),
  134. (LoadStrPart(COPY_INFO_FILENAME, FileNameCase + 2))),
  135. cpaIncludeMaskOnly);
  136. }
  137. if ((InvalidCharsReplacement == NoReplacement) !=
  138. (Defaults.InvalidCharsReplacement == NoReplacement))
  139. {
  140. DebugAssert(InvalidCharsReplacement == NoReplacement);
  141. if (InvalidCharsReplacement == NoReplacement)
  142. {
  143. ADD(LoadStr(COPY_INFO_DONT_REPLACE_INV_CHARS), cpaIncludeMaskOnly);
  144. }
  145. }
  146. if ((PreserveRights != Defaults.PreserveRights) ||
  147. (PreserveRights &&
  148. ((Rights != Defaults.Rights) || (AddXToDirectories != Defaults.AddXToDirectories))))
  149. {
  150. DebugAssert(PreserveRights);
  151. if (PreserveRights)
  152. {
  153. UnicodeString RightsStr = Rights.Text;
  154. if (AddXToDirectories)
  155. {
  156. RightsStr += L", " + LoadStr(COPY_INFO_ADD_X_TO_DIRS);
  157. }
  158. ADD(FORMAT(LoadStr(COPY_INFO_PERMISSIONS), (RightsStr)),
  159. cpaIncludeMaskOnly | cpaNoRights);
  160. }
  161. }
  162. bool AddPreserveTime = (PreserveTime != Defaults.PreserveTime);
  163. bool APreserveTimeDirs = PreserveTime && PreserveTimeDirs;
  164. if (AddPreserveTime || (APreserveTimeDirs != Defaults.PreserveTimeDirs))
  165. {
  166. UnicodeString Str = LoadStr(PreserveTime ? COPY_INFO_TIMESTAMP : COPY_INFO_DONT_PRESERVE_TIME);
  167. if (APreserveTimeDirs != Defaults.PreserveTimeDirs)
  168. {
  169. if (DebugAlwaysTrue(PreserveTimeDirs))
  170. {
  171. if (FLAGCLEAR(Options, cpaNoPreserveTimeDirs))
  172. {
  173. Str = FMTLOAD(COPY_INFO_PRESERVE_TIME_DIRS, (Str));
  174. AddPreserveTime = true;
  175. }
  176. }
  177. ADD("", cpaIncludeMaskOnly | cpaNoPreserveTime | cpaNoPreserveTimeDirs);
  178. }
  179. if (AddPreserveTime)
  180. {
  181. ADD(Str, cpaIncludeMaskOnly | cpaNoPreserveTime);
  182. }
  183. }
  184. if ((PreserveRights || PreserveTime) &&
  185. (IgnorePermErrors != Defaults.IgnorePermErrors))
  186. {
  187. DebugAssert(IgnorePermErrors);
  188. if (IgnorePermErrors)
  189. {
  190. ADD(LoadStr(COPY_INFO_IGNORE_PERM_ERRORS),
  191. cpaIncludeMaskOnly | cpaNoIgnorePermErrors);
  192. }
  193. }
  194. if (PreserveReadOnly != Defaults.PreserveReadOnly)
  195. {
  196. DebugAssert(PreserveReadOnly);
  197. if (PreserveReadOnly)
  198. {
  199. ADD(LoadStr(COPY_INFO_PRESERVE_READONLY),
  200. cpaIncludeMaskOnly | cpaNoPreserveReadOnly);
  201. }
  202. }
  203. if (CalculateSize != Defaults.CalculateSize)
  204. {
  205. DebugAssert(!CalculateSize);
  206. if (!CalculateSize)
  207. {
  208. ADD(LoadStr(COPY_INFO_DONT_CALCULATE_SIZE), cpaIncludeMaskOnly);
  209. }
  210. }
  211. if (ClearArchive != Defaults.ClearArchive)
  212. {
  213. DebugAssert(ClearArchive);
  214. if (ClearArchive)
  215. {
  216. ADD(LoadStr(COPY_INFO_CLEAR_ARCHIVE),
  217. cpaIncludeMaskOnly | cpaNoClearArchive);
  218. }
  219. }
  220. if ((TransferMode == tmAscii) || (TransferMode == tmAutomatic))
  221. {
  222. if (RemoveBOM != Defaults.RemoveBOM)
  223. {
  224. if (DebugAlwaysTrue(RemoveBOM))
  225. {
  226. ADD(LoadStr(COPY_INFO_REMOVE_BOM),
  227. cpaIncludeMaskOnly | cpaNoRemoveBOM | cpaNoTransferMode);
  228. }
  229. }
  230. if (RemoveCtrlZ != Defaults.RemoveCtrlZ)
  231. {
  232. if (DebugAlwaysTrue(RemoveCtrlZ))
  233. {
  234. ADD(LoadStr(COPY_INFO_REMOVE_CTRLZ),
  235. cpaIncludeMaskOnly | cpaNoRemoveCtrlZ | cpaNoTransferMode);
  236. }
  237. }
  238. }
  239. if (!(IncludeFileMask == Defaults.IncludeFileMask))
  240. {
  241. ADD(FORMAT(LoadStr(COPY_INFO_FILE_MASK), (IncludeFileMask.Masks)),
  242. cpaNoIncludeMask);
  243. }
  244. DebugAssert(FTransferSkipList.get() == NULL);
  245. DebugAssert(FTransferResumeFile.IsEmpty());
  246. if (CPSLimit > 0)
  247. {
  248. ADD(FMTLOAD(COPY_INFO_CPS_LIMIT2, (int(CPSLimit / 1024))), cpaIncludeMaskOnly);
  249. }
  250. if (NewerOnly != Defaults.NewerOnly)
  251. {
  252. if (DebugAlwaysTrue(NewerOnly))
  253. {
  254. ADD(StripHotkey(LoadStr(COPY_PARAM_NEWER_ONLY)), cpaIncludeMaskOnly | cpaNoNewerOnly);
  255. }
  256. }
  257. if (SomeAttrExcluded)
  258. {
  259. Result += (Result.IsEmpty() ? UnicodeString() : Separator) +
  260. FORMAT(LoadStrPart(COPY_INFO_NOT_USABLE, 1),
  261. (LoadStrPart(COPY_INFO_NOT_USABLE, (SomeAttrIncluded ? 2 : 3))));
  262. }
  263. else if (Result.IsEmpty())
  264. {
  265. Result = LoadStr(COPY_INFO_DEFAULT);
  266. }
  267. #undef ADD
  268. }
  269. //---------------------------------------------------------------------------
  270. void __fastcall TCopyParamType::Assign(const TCopyParamType * Source)
  271. {
  272. DebugAssert(Source != NULL);
  273. #define COPY(Prop) Prop = Source->Prop
  274. COPY(FileNameCase);
  275. COPY(PreserveReadOnly);
  276. COPY(PreserveTime);
  277. COPY(PreserveTimeDirs);
  278. COPY(Rights);
  279. COPY(AsciiFileMask);
  280. COPY(TransferMode);
  281. COPY(AddXToDirectories);
  282. COPY(PreserveRights);
  283. COPY(IgnorePermErrors);
  284. COPY(ResumeSupport);
  285. COPY(ResumeThreshold);
  286. COPY(InvalidCharsReplacement);
  287. COPY(LocalInvalidChars);
  288. COPY(CalculateSize);
  289. COPY(FileMask);
  290. COPY(IncludeFileMask);
  291. COPY(TransferSkipList);
  292. COPY(TransferResumeFile);
  293. COPY(ClearArchive);
  294. COPY(RemoveCtrlZ);
  295. COPY(RemoveBOM);
  296. COPY(CPSLimit);
  297. COPY(NewerOnly);
  298. #undef COPY
  299. }
  300. //---------------------------------------------------------------------------
  301. TCopyParamType & __fastcall TCopyParamType::operator =(const TCopyParamType & rhp)
  302. {
  303. Assign(&rhp);
  304. return *this;
  305. }
  306. //---------------------------------------------------------------------------
  307. void __fastcall TCopyParamType::SetLocalInvalidChars(UnicodeString value)
  308. {
  309. if (value != LocalInvalidChars)
  310. {
  311. FLocalInvalidChars = value;
  312. FTokenizibleChars = FLocalInvalidChars + TokenPrefix;
  313. }
  314. }
  315. //---------------------------------------------------------------------------
  316. bool __fastcall TCopyParamType::GetReplaceInvalidChars() const
  317. {
  318. return (InvalidCharsReplacement != NoReplacement);
  319. }
  320. //---------------------------------------------------------------------------
  321. void __fastcall TCopyParamType::SetReplaceInvalidChars(bool value)
  322. {
  323. if (ReplaceInvalidChars != value)
  324. {
  325. InvalidCharsReplacement = (value ? TokenReplacement : NoReplacement);
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. UnicodeString __fastcall TCopyParamType::ValidLocalFileName(UnicodeString FileName) const
  330. {
  331. return ::ValidLocalFileName(FileName, InvalidCharsReplacement, FTokenizibleChars, LocalInvalidChars);
  332. }
  333. //---------------------------------------------------------------------------
  334. UnicodeString __fastcall TCopyParamType::RestoreChars(UnicodeString FileName) const
  335. {
  336. if (InvalidCharsReplacement == TokenReplacement)
  337. {
  338. wchar_t * InvalidChar = FileName.c_str();
  339. while ((InvalidChar = wcschr(InvalidChar, TokenPrefix)) != NULL)
  340. {
  341. int Index = InvalidChar - FileName.c_str() + 1;
  342. if (FileName.Length() >= Index + 2)
  343. {
  344. UnicodeString Hex = FileName.SubString(Index + 1, 2);
  345. wchar_t Char = static_cast<wchar_t>(HexToByte(Hex));
  346. if ((Char != L'\0') &&
  347. ((FTokenizibleChars.Pos(Char) > 0) ||
  348. (((Char == L' ') || (Char == L'.')) && (Index == FileName.Length() - 2))))
  349. {
  350. FileName[Index] = Char;
  351. FileName.Delete(Index + 1, 2);
  352. InvalidChar = FileName.c_str() + Index;
  353. }
  354. else if ((Hex == L"00") &&
  355. ((Index == FileName.Length() - 2) || (FileName[Index + 3] == L'.')) &&
  356. IsReservedName(FileName.SubString(1, Index - 1) + FileName.SubString(Index + 3, FileName.Length() - Index - 3 + 1)))
  357. {
  358. FileName.Delete(Index, 3);
  359. InvalidChar = FileName.c_str() + Index - 1;
  360. }
  361. else
  362. {
  363. InvalidChar++;
  364. }
  365. }
  366. else
  367. {
  368. InvalidChar++;
  369. }
  370. }
  371. }
  372. return FileName;
  373. }
  374. //---------------------------------------------------------------------------
  375. UnicodeString __fastcall TCopyParamType::ValidLocalPath(UnicodeString Path) const
  376. {
  377. UnicodeString Result;
  378. while (!Path.IsEmpty())
  379. {
  380. if (!Result.IsEmpty())
  381. {
  382. Result += L"\\";
  383. }
  384. Result += ValidLocalFileName(CutToChar(Path, L'\\', false));
  385. }
  386. return Result;
  387. }
  388. //---------------------------------------------------------------------------
  389. UnicodeString __fastcall TCopyParamType::ChangeFileName(UnicodeString FileName,
  390. TOperationSide Side, bool FirstLevel) const
  391. {
  392. if (FirstLevel)
  393. {
  394. FileName = MaskFileName(FileName, FileMask);
  395. }
  396. switch (FileNameCase) {
  397. case ncUpperCase: FileName = FileName.UpperCase(); break;
  398. case ncLowerCase: FileName = FileName.LowerCase(); break;
  399. case ncFirstUpperCase: FileName = FileName.SubString(1, 1).UpperCase() +
  400. FileName.SubString(2, FileName.Length()-1).LowerCase(); break;
  401. case ncLowerCaseShort:
  402. if ((FileName.Length() <= 12) && (FileName.Pos(L".") <= 9) &&
  403. (FileName == FileName.UpperCase()))
  404. {
  405. FileName = FileName.LowerCase();
  406. }
  407. break;
  408. case ncNoChange:
  409. default:
  410. /*nothing*/
  411. break;
  412. }
  413. if (Side == osRemote)
  414. {
  415. FileName = ValidLocalFileName(FileName);
  416. }
  417. else
  418. {
  419. FileName = RestoreChars(FileName);
  420. }
  421. return FileName;
  422. }
  423. //---------------------------------------------------------------------------
  424. bool __fastcall TCopyParamType::UseAsciiTransfer(UnicodeString FileName,
  425. TOperationSide Side, const TFileMasks::TParams & Params) const
  426. {
  427. switch (TransferMode)
  428. {
  429. case tmBinary: return false;
  430. case tmAscii: return true;
  431. case tmAutomatic: return AsciiFileMask.Matches(FileName, (Side == osLocal),
  432. false, &Params);
  433. default: DebugFail(); return false;
  434. }
  435. }
  436. //---------------------------------------------------------------------------
  437. TRights __fastcall TCopyParamType::RemoteFileRights(Integer Attrs) const
  438. {
  439. TRights R = Rights;
  440. if ((Attrs & faDirectory) && AddXToDirectories)
  441. R.AddExecute();
  442. return R;
  443. }
  444. //---------------------------------------------------------------------------
  445. UnicodeString __fastcall TCopyParamType::GetLogStr() const
  446. {
  447. wchar_t CaseC[] = L"NULFS";
  448. wchar_t ModeC[] = L"BAM";
  449. wchar_t ResumeC[] = L"YSN";
  450. // OpenArray (ARRAYOFCONST) supports only up to 19 arguments, so we had to split it
  451. return
  452. FORMAT(
  453. L" PrTime: %s%s; PrRO: %s; Rght: %s; PrR: %s (%s); FnCs: %s; RIC: %s; "
  454. "Resume: %s (%d); CalcS: %s; Mask: %s\n",
  455. (BooleanToEngStr(PreserveTime),
  456. UnicodeString(PreserveTime && PreserveTimeDirs ? L"+Dirs" : L""),
  457. BooleanToEngStr(PreserveReadOnly),
  458. Rights.Text,
  459. BooleanToEngStr(PreserveRights),
  460. BooleanToEngStr(IgnorePermErrors),
  461. CaseC[FileNameCase],
  462. CharToHex(InvalidCharsReplacement),
  463. ResumeC[ResumeSupport],
  464. (int)ResumeThreshold,
  465. BooleanToEngStr(CalculateSize),
  466. FileMask)) +
  467. FORMAT(
  468. L" TM: %s; ClAr: %s; RemEOF: %s; RemBOM: %s; CPS: %u; NewerOnly: %s; InclM: %s; ResumeL: %d\n"
  469. " AscM: %s\n",
  470. (ModeC[TransferMode],
  471. BooleanToEngStr(ClearArchive),
  472. BooleanToEngStr(RemoveCtrlZ),
  473. BooleanToEngStr(RemoveBOM),
  474. int(CPSLimit),
  475. BooleanToEngStr(NewerOnly),
  476. IncludeFileMask.Masks,
  477. ((FTransferSkipList.get() != NULL) ? FTransferSkipList->Count : 0) + (!FTransferResumeFile.IsEmpty() ? 1 : 0),
  478. AsciiFileMask.Masks));
  479. }
  480. //---------------------------------------------------------------------------
  481. int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
  482. {
  483. int Result = 0;
  484. if (PreserveReadOnly && !Rights.Right[TRights::rrUserWrite])
  485. {
  486. Result |= faReadOnly;
  487. }
  488. return Result;
  489. }
  490. //---------------------------------------------------------------------------
  491. bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
  492. {
  493. switch (ResumeSupport)
  494. {
  495. case rsOn: return true;
  496. case rsOff: return false;
  497. case rsSmart: return (Size >= ResumeThreshold);
  498. default: DebugFail(); return false;
  499. }
  500. }
  501. //---------------------------------------------------------------------------
  502. bool __fastcall TCopyParamType::AllowAnyTransfer() const
  503. {
  504. return
  505. IncludeFileMask.Masks.IsEmpty() &&
  506. ((FTransferSkipList.get() == NULL) || (FTransferSkipList->Count == 0)) &&
  507. FTransferResumeFile.IsEmpty();
  508. }
  509. //---------------------------------------------------------------------------
  510. bool __fastcall TCopyParamType::AllowTransfer(UnicodeString FileName,
  511. TOperationSide Side, bool Directory, const TFileMasks::TParams & Params) const
  512. {
  513. bool Result = true;
  514. if (!IncludeFileMask.Masks.IsEmpty())
  515. {
  516. Result = IncludeFileMask.Matches(FileName, (Side == osLocal),
  517. Directory, &Params);
  518. }
  519. return Result;
  520. }
  521. //---------------------------------------------------------------------------
  522. bool __fastcall TCopyParamType::SkipTransfer(
  523. UnicodeString FileName, bool Directory) const
  524. {
  525. bool Result = false;
  526. // we deliberatelly do not filter directories, as path is added to resume list
  527. // when a transfer of file or directory is started,
  528. // so for directories we need to recurse and check every single file
  529. if (!Directory && (FTransferSkipList.get() != NULL))
  530. {
  531. Result = (FTransferSkipList->IndexOf(FileName) >= 0);
  532. }
  533. return Result;
  534. }
  535. //---------------------------------------------------------------------------
  536. bool __fastcall TCopyParamType::ResumeTransfer(UnicodeString FileName) const
  537. {
  538. // Returning true has the same effect as cpResume
  539. return
  540. (FileName == FTransferResumeFile) &&
  541. DebugAlwaysTrue(!FTransferResumeFile.IsEmpty());
  542. }
  543. //---------------------------------------------------------------------------
  544. TStrings * __fastcall TCopyParamType::GetTransferSkipList() const
  545. {
  546. return FTransferSkipList.get();
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TCopyParamType::SetTransferSkipList(TStrings * value)
  550. {
  551. if ((value == NULL) || (value->Count == 0))
  552. {
  553. FTransferSkipList.reset(NULL);
  554. }
  555. else
  556. {
  557. FTransferSkipList.reset(new TStringList());
  558. FTransferSkipList->AddStrings(value);
  559. FTransferSkipList->Sorted = true;
  560. }
  561. }
  562. //---------------------------------------------------------------------------
  563. void __fastcall TCopyParamType::Load(THierarchicalStorage * Storage)
  564. {
  565. AddXToDirectories = Storage->ReadBool(L"AddXToDirectories", AddXToDirectories);
  566. AsciiFileMask.Masks = Storage->ReadString(L"Masks", AsciiFileMask.Masks);
  567. FileNameCase = (TFileNameCase)Storage->ReadInteger(L"FileNameCase", FileNameCase);
  568. PreserveReadOnly = Storage->ReadBool(L"PreserveReadOnly", PreserveReadOnly);
  569. PreserveTime = Storage->ReadBool(L"PreserveTime", PreserveTime);
  570. PreserveTimeDirs = Storage->ReadBool(L"PreserveTimeDirs", PreserveTimeDirs);
  571. PreserveRights = Storage->ReadBool(L"PreserveRights", PreserveRights);
  572. IgnorePermErrors = Storage->ReadBool(L"IgnorePermErrors", IgnorePermErrors);
  573. Rights.Text = Storage->ReadString(L"Text", Rights.Text);
  574. TransferMode = (TTransferMode)Storage->ReadInteger(L"TransferMode", TransferMode);
  575. ResumeSupport = (TResumeSupport)Storage->ReadInteger(L"ResumeSupport", ResumeSupport);
  576. ResumeThreshold = Storage->ReadInt64(L"ResumeThreshold", ResumeThreshold);
  577. InvalidCharsReplacement = (wchar_t)Storage->ReadInteger(L"ReplaceInvalidChars",
  578. (unsigned int)InvalidCharsReplacement);
  579. LocalInvalidChars = Storage->ReadString(L"LocalInvalidChars", LocalInvalidChars);
  580. CalculateSize = Storage->ReadBool(L"CalculateSize", CalculateSize);
  581. if (Storage->ValueExists(L"IncludeFileMask"))
  582. {
  583. IncludeFileMask.Masks = Storage->ReadString(L"IncludeFileMask", IncludeFileMask.Masks);
  584. }
  585. else if (Storage->ValueExists(L"ExcludeFileMask"))
  586. {
  587. UnicodeString ExcludeFileMask = Storage->ReadString(L"ExcludeFileMask", L"");
  588. if (!ExcludeFileMask.IsEmpty())
  589. {
  590. bool NegativeExclude = Storage->ReadBool(L"NegativeExclude", false);
  591. if (NegativeExclude)
  592. {
  593. IncludeFileMask.Masks = ExcludeFileMask;
  594. }
  595. // convert at least simple cases to new format
  596. else if (ExcludeFileMask.Pos(IncludeExcludeFileMasksDelimiter) == 0)
  597. {
  598. IncludeFileMask.Masks = UnicodeString(IncludeExcludeFileMasksDelimiter) + ExcludeFileMask;
  599. }
  600. }
  601. }
  602. TransferSkipList = NULL;
  603. TransferResumeFile = L"";
  604. ClearArchive = Storage->ReadBool(L"ClearArchive", ClearArchive);
  605. RemoveCtrlZ = Storage->ReadBool(L"RemoveCtrlZ", RemoveCtrlZ);
  606. RemoveBOM = Storage->ReadBool(L"RemoveBOM", RemoveBOM);
  607. CPSLimit = Storage->ReadInteger(L"CPSLimit", CPSLimit);
  608. NewerOnly = Storage->ReadBool(L"NewerOnly", NewerOnly);
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TCopyParamType::Save(THierarchicalStorage * Storage) const
  612. {
  613. Storage->WriteBool(L"AddXToDirectories", AddXToDirectories);
  614. Storage->WriteString(L"Masks", AsciiFileMask.Masks);
  615. Storage->WriteInteger(L"FileNameCase", FileNameCase);
  616. Storage->WriteBool(L"PreserveReadOnly", PreserveReadOnly);
  617. Storage->WriteBool(L"PreserveTime", PreserveTime);
  618. Storage->WriteBool(L"PreserveTimeDirs", PreserveTimeDirs);
  619. Storage->WriteBool(L"PreserveRights", PreserveRights);
  620. Storage->WriteBool(L"IgnorePermErrors", IgnorePermErrors);
  621. Storage->WriteString(L"Text", Rights.Text);
  622. Storage->WriteInteger(L"TransferMode", TransferMode);
  623. Storage->WriteInteger(L"ResumeSupport", ResumeSupport);
  624. Storage->WriteInt64(L"ResumeThreshold", ResumeThreshold);
  625. Storage->WriteInteger(L"ReplaceInvalidChars", (unsigned int)InvalidCharsReplacement);
  626. Storage->WriteString(L"LocalInvalidChars", LocalInvalidChars);
  627. Storage->WriteBool(L"CalculateSize", CalculateSize);
  628. Storage->WriteString(L"IncludeFileMask", IncludeFileMask.Masks);
  629. Storage->DeleteValue(L"ExcludeFileMask"); // obsolete
  630. Storage->DeleteValue(L"NegativeExclude"); // obsolete
  631. DebugAssert(FTransferSkipList.get() == NULL);
  632. DebugAssert(FTransferResumeFile.IsEmpty());
  633. Storage->WriteBool(L"ClearArchive", ClearArchive);
  634. Storage->WriteBool(L"RemoveCtrlZ", RemoveCtrlZ);
  635. Storage->WriteBool(L"RemoveBOM", RemoveBOM);
  636. Storage->WriteInteger(L"CPSLimit", CPSLimit);
  637. Storage->WriteBool(L"NewerOnly", NewerOnly);
  638. }
  639. //---------------------------------------------------------------------------
  640. #define C(Property) (Property == rhp.Property)
  641. bool __fastcall TCopyParamType::operator==(const TCopyParamType & rhp) const
  642. {
  643. DebugAssert(FTransferSkipList.get() == NULL);
  644. DebugAssert(FTransferResumeFile.IsEmpty());
  645. DebugAssert(rhp.FTransferSkipList.get() == NULL);
  646. DebugAssert(rhp.FTransferResumeFile.IsEmpty());
  647. return
  648. C(AddXToDirectories) &&
  649. C(AsciiFileMask) &&
  650. C(FileNameCase) &&
  651. C(PreserveReadOnly) &&
  652. C(PreserveTime) &&
  653. C(PreserveTimeDirs) &&
  654. C(PreserveRights) &&
  655. C(IgnorePermErrors) &&
  656. C(Rights) &&
  657. C(TransferMode) &&
  658. C(ResumeSupport) &&
  659. C(ResumeThreshold) &&
  660. C(InvalidCharsReplacement) &&
  661. C(LocalInvalidChars) &&
  662. C(CalculateSize) &&
  663. C(IncludeFileMask) &&
  664. C(ClearArchive) &&
  665. C(RemoveCtrlZ) &&
  666. C(RemoveBOM) &&
  667. C(CPSLimit) &&
  668. C(NewerOnly) &&
  669. true;
  670. }
  671. #undef C
  672. //---------------------------------------------------------------------------
  673. static bool __fastcall TryGetSpeedLimit(const UnicodeString & Text, unsigned long & Speed)
  674. {
  675. bool Result;
  676. if (AnsiSameText(Text, LoadStr(SPEED_UNLIMITED)))
  677. {
  678. Speed = 0;
  679. Result = true;
  680. }
  681. else
  682. {
  683. int SSpeed;
  684. Result = TryStrToInt(Text, SSpeed) && (SSpeed >= 0);
  685. if (Result)
  686. {
  687. Speed = SSpeed * 1024;
  688. }
  689. }
  690. return Result;
  691. }
  692. //---------------------------------------------------------------------------
  693. unsigned long __fastcall GetSpeedLimit(const UnicodeString & Text)
  694. {
  695. unsigned long Speed;
  696. if (!TryGetSpeedLimit(Text, Speed))
  697. {
  698. throw Exception(FMTLOAD(SPEED_INVALID, (Text)));
  699. }
  700. return Speed;
  701. }
  702. //---------------------------------------------------------------------------
  703. UnicodeString __fastcall SetSpeedLimit(unsigned long Limit)
  704. {
  705. UnicodeString Text;
  706. if (Limit == 0)
  707. {
  708. Text = LoadStr(SPEED_UNLIMITED);
  709. }
  710. else
  711. {
  712. Text = IntToStr(int(Limit / 1024));
  713. }
  714. return Text;
  715. }
  716. //---------------------------------------------------------------------------
  717. void __fastcall CopySpeedLimits(TStrings * Source, TStrings * Dest)
  718. {
  719. std::unique_ptr<TStringList> Temp(new TStringList());
  720. bool Unlimited = false;
  721. for (int Index = 0; Index < Source->Count; Index++)
  722. {
  723. UnicodeString Text = Source->Strings[Index];
  724. unsigned long Speed;
  725. bool Valid = TryGetSpeedLimit(Text, Speed);
  726. if ((!Valid || (Speed == 0)) && !Unlimited)
  727. {
  728. Temp->Add(LoadStr(SPEED_UNLIMITED));
  729. Unlimited = true;
  730. }
  731. else if (Valid && (Speed > 0))
  732. {
  733. Temp->Add(Text);
  734. }
  735. }
  736. if (!Unlimited)
  737. {
  738. Temp->Insert(0, LoadStr(SPEED_UNLIMITED));
  739. }
  740. Dest->Assign(Temp.get());
  741. }