CopyParam.cpp 23 KB

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