CopyParam.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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. #include "Interface.h"
  10. //---------------------------------------------------------------------------
  11. const wchar_t * TransferModeNames[] = { L"binary", L"ascii", L"automatic" };
  12. const int TransferModeNamesCount = LENOF(TransferModeNames);
  13. //---------------------------------------------------------------------------
  14. __fastcall TCopyParamType::TCopyParamType()
  15. {
  16. Default();
  17. }
  18. //---------------------------------------------------------------------------
  19. __fastcall TCopyParamType::TCopyParamType(const TCopyParamType & Source)
  20. {
  21. Assign(&Source);
  22. }
  23. //---------------------------------------------------------------------------
  24. __fastcall TCopyParamType::~TCopyParamType()
  25. {
  26. }
  27. //---------------------------------------------------------------------------
  28. void __fastcall TCopyParamType::Default()
  29. {
  30. // when changing defaults, make sure GetInfoStr() can handle it
  31. FileNameCase = ncNoChange;
  32. PreserveReadOnly = false;
  33. PreserveTime = true;
  34. PreserveTimeDirs = false;
  35. Rights.Number = TRights::rfDefault;
  36. PreserveRights = false; // Was True until #106
  37. IgnorePermErrors = false;
  38. AsciiFileMask.Masks = L"*.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; "
  39. "*.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml";
  40. TransferMode = tmBinary;
  41. AddXToDirectories = true;
  42. ResumeSupport = rsSmart;
  43. ResumeThreshold = 100 * 1024; // (100 KB)
  44. InvalidCharsReplacement = TokenReplacement;
  45. LocalInvalidChars = ::LocalInvalidChars;
  46. CalculateSize = true;
  47. FileMask = AnyMask;
  48. IncludeFileMask.Masks = L"";
  49. TransferSkipList = NULL;
  50. TransferResumeFile = L"";
  51. ClearArchive = false;
  52. RemoveCtrlZ = false;
  53. RemoveBOM = false;
  54. CPSLimit = 0;
  55. NewerOnly = false;
  56. EncryptNewFiles = true;
  57. ExcludeHiddenFiles = false;
  58. ExcludeEmptyDirectories = false;
  59. Size = -1;
  60. }
  61. //---------------------------------------------------------------------------
  62. UnicodeString __fastcall TCopyParamType::GetInfoStr(
  63. UnicodeString Separator, int Attrs) const
  64. {
  65. UnicodeString Result;
  66. bool SomeAttrIncluded;
  67. UnicodeString ScriptArgs;
  68. UnicodeString AssemblyCode;
  69. DoGetInfoStr(
  70. Separator, Attrs, Result, SomeAttrIncluded,
  71. UnicodeString(), ScriptArgs, TAssemblyLanguage(0), AssemblyCode);
  72. return Result;
  73. }
  74. //---------------------------------------------------------------------------
  75. bool __fastcall TCopyParamType::AnyUsableCopyParam(int Attrs) const
  76. {
  77. UnicodeString Result;
  78. bool SomeAttrIncluded;
  79. UnicodeString ScriptArgs;
  80. UnicodeString AssemblyCode;
  81. DoGetInfoStr(
  82. L";", Attrs, Result, SomeAttrIncluded,
  83. UnicodeString(), ScriptArgs, TAssemblyLanguage(0), AssemblyCode);
  84. return SomeAttrIncluded;
  85. }
  86. //---------------------------------------------------------------------------
  87. UnicodeString __fastcall TCopyParamType::GenerateTransferCommandArgs(int Attrs, const UnicodeString & Link) const
  88. {
  89. UnicodeString Result;
  90. bool SomeAttrIncluded;
  91. UnicodeString ScriptArgs;
  92. UnicodeString AssemblyCode;
  93. DoGetInfoStr(
  94. L";", Attrs, Result, SomeAttrIncluded,
  95. Link, ScriptArgs, TAssemblyLanguage(0), AssemblyCode);
  96. return ScriptArgs;
  97. }
  98. //---------------------------------------------------------------------------
  99. UnicodeString __fastcall TCopyParamType::GenerateAssemblyCode(TAssemblyLanguage Language, int Attrs) const
  100. {
  101. UnicodeString Result;
  102. bool SomeAttrIncluded;
  103. UnicodeString ScriptArgs;
  104. UnicodeString AssemblyCode;
  105. DoGetInfoStr(L";", Attrs, Result, SomeAttrIncluded, UnicodeString(), ScriptArgs, Language, AssemblyCode);
  106. return AssemblyCode;
  107. }
  108. //---------------------------------------------------------------------------
  109. void __fastcall TCopyParamType::DoGetInfoStr(
  110. UnicodeString Separator, int Options,
  111. UnicodeString & Result, bool & SomeAttrIncluded,
  112. const UnicodeString & Link, UnicodeString & ScriptArgs, TAssemblyLanguage Language, UnicodeString & AssemblyCode) const
  113. {
  114. TCopyParamType Defaults;
  115. TCopyParamType ScriptNonDefaults;
  116. TCopyParamType CodeNonDefaults;
  117. bool SomeAttrExcluded = false;
  118. SomeAttrIncluded = false;
  119. #define ADD(STR, EXCEPT) \
  120. FLAGCLEAR(Options, EXCEPT) ? (AddToList(Result, (STR), Separator), SomeAttrIncluded = true, true) : (SomeAttrExcluded = true, false)
  121. bool AsciiFileMaskDiffers = (TransferMode == tmAutomatic) && !(AsciiFileMask == Defaults.AsciiFileMask);
  122. bool TransferModeDiffers = ((TransferMode != Defaults.TransferMode) || AsciiFileMaskDiffers);
  123. if (FLAGCLEAR(Options, cpaIncludeMaskOnly | cpaNoTransferMode))
  124. {
  125. // Adding Transfer type unconditionally
  126. bool FormatMask;
  127. int Ident;
  128. switch (TransferMode)
  129. {
  130. case tmBinary:
  131. FormatMask = false;
  132. Ident = 2;
  133. break;
  134. case tmAscii:
  135. FormatMask = false;
  136. Ident = 3;
  137. break;
  138. case tmAutomatic:
  139. default:
  140. FormatMask = !(AsciiFileMask == Defaults.AsciiFileMask);
  141. Ident = FormatMask ? 4 : 5;
  142. break;
  143. }
  144. UnicodeString S = FORMAT(LoadStrPart(COPY_INFO_TRANSFER_TYPE2, 1),
  145. (LoadStrPart(COPY_INFO_TRANSFER_TYPE2, Ident)));
  146. if (FormatMask)
  147. {
  148. S = FORMAT(S, (AsciiFileMask.Masks));
  149. }
  150. AddToList(Result, S, Separator);
  151. if (TransferModeDiffers)
  152. {
  153. ADD("", cpaIncludeMaskOnly | cpaNoTransferMode);
  154. ScriptArgs += RtfSwitchValue(TRANSFER_SWITCH, Link, TransferModeNames[TransferMode]);
  155. const wchar_t * TransferModeMembers[] = { L"Binary", L"Ascii", L"Automatic" };
  156. AssemblyCode += AssemblyProperty(
  157. Language, TransferOptionsClassName, L"TransferMode", L"TransferMode", TransferModeMembers[TransferMode], false);
  158. if (AsciiFileMaskDiffers)
  159. {
  160. ScriptNonDefaults.AsciiFileMask = AsciiFileMask;
  161. CodeNonDefaults.AsciiFileMask = AsciiFileMask;
  162. }
  163. }
  164. }
  165. else
  166. {
  167. if (TransferModeDiffers)
  168. {
  169. SomeAttrExcluded = true;
  170. }
  171. }
  172. if (FileNameCase != Defaults.FileNameCase)
  173. {
  174. if (ADD(FORMAT(LoadStrPart(COPY_INFO_FILENAME, 1),
  175. (LoadStrPart(COPY_INFO_FILENAME, FileNameCase + 2))),
  176. cpaIncludeMaskOnly))
  177. {
  178. ScriptNonDefaults.FileNameCase = FileNameCase;
  179. CodeNonDefaults.FileNameCase = FileNameCase;
  180. }
  181. }
  182. if (InvalidCharsReplacement != Defaults.InvalidCharsReplacement)
  183. {
  184. int Except = cpaIncludeMaskOnly;
  185. if (InvalidCharsReplacement == NoReplacement)
  186. {
  187. ADD(LoadStr(COPY_INFO_DONT_REPLACE_INV_CHARS), Except);
  188. }
  189. if (FLAGCLEAR(Options, Except))
  190. {
  191. ScriptNonDefaults.InvalidCharsReplacement = InvalidCharsReplacement;
  192. CodeNonDefaults.InvalidCharsReplacement = InvalidCharsReplacement;
  193. }
  194. }
  195. if ((PreserveRights != Defaults.PreserveRights) ||
  196. (PreserveRights &&
  197. ((Rights != Defaults.Rights) || (AddXToDirectories != Defaults.AddXToDirectories))))
  198. {
  199. const int Except = cpaIncludeMaskOnly | cpaNoRights;
  200. if (DebugAlwaysTrue(PreserveRights))
  201. {
  202. UnicodeString RightsStr = Rights.Text;
  203. if (AddXToDirectories)
  204. {
  205. RightsStr += L", " + LoadStr(COPY_INFO_ADD_X_TO_DIRS);
  206. }
  207. ADD(FORMAT(LoadStr(COPY_INFO_PERMISSIONS), (RightsStr)),
  208. Except);
  209. if (FLAGCLEAR(Options, Except))
  210. {
  211. ScriptArgs += RtfSwitchValue(PERMISSIONS_SWITCH, Link, Rights.Octal);
  212. const UnicodeString FilePermissionsClassName = L"FilePermissions";
  213. const bool Inline = true;
  214. UnicodeString FilePermissions =
  215. AssemblyNewClassInstanceStart(Language, FilePermissionsClassName, Inline) +
  216. AssemblyProperty(Language, FilePermissionsClassName, L"Octal", Rights.Octal, Inline) +
  217. AssemblyNewClassInstanceEnd(Language, Inline);
  218. AssemblyCode += AssemblyPropertyRaw(Language, TransferOptionsClassName, L"FilePermissions", FilePermissions, false);
  219. }
  220. }
  221. if ((AddXToDirectories != Defaults.AddXToDirectories) && FLAGCLEAR(Options, Except))
  222. {
  223. ScriptNonDefaults.AddXToDirectories = AddXToDirectories;
  224. CodeNonDefaults.AddXToDirectories = AddXToDirectories;
  225. }
  226. }
  227. bool APreserveTimeDirs = PreserveTime && PreserveTimeDirs;
  228. if ((PreserveTime != Defaults.PreserveTime) || (APreserveTimeDirs != Defaults.PreserveTimeDirs))
  229. {
  230. bool AddPreserveTime = false;
  231. UnicodeString Str = LoadStr(PreserveTime ? COPY_INFO_TIMESTAMP : COPY_INFO_DONT_PRESERVE_TIME);
  232. const int ExceptDirs = cpaNoPreserveTimeDirs;
  233. if (APreserveTimeDirs != Defaults.PreserveTimeDirs)
  234. {
  235. if (DebugAlwaysTrue(PreserveTimeDirs))
  236. {
  237. if (FLAGCLEAR(Options, ExceptDirs))
  238. {
  239. Str = FMTLOAD(COPY_INFO_PRESERVE_TIME_DIRS, (Str));
  240. AddPreserveTime = true;
  241. }
  242. }
  243. ADD("", ExceptDirs);
  244. }
  245. const int Except = cpaIncludeMaskOnly | cpaNoPreserveTime;
  246. if (PreserveTime != Defaults.PreserveTime)
  247. {
  248. if (FLAGCLEAR(Options, Except))
  249. {
  250. AddPreserveTime = true;
  251. }
  252. ADD(L"", Except);
  253. }
  254. if (AddPreserveTime)
  255. {
  256. AddToList(Result, Str, Separator);
  257. }
  258. if (FLAGCLEAR(Options, Except))
  259. {
  260. if (PreserveTime)
  261. {
  262. if (PreserveTimeDirs && FLAGCLEAR(Options, ExceptDirs))
  263. {
  264. ScriptArgs += RtfSwitchValue(PRESERVETIME_SWITCH, Link, PRESERVETIMEDIRS_SWITCH_VALUE);
  265. CodeNonDefaults.PreserveTimeDirs = PreserveTimeDirs;
  266. }
  267. else
  268. {
  269. DebugFail(); // should never get here
  270. ScriptArgs += RtfSwitch(PRESERVETIME_SWITCH, Link);
  271. }
  272. }
  273. else
  274. {
  275. ScriptArgs += RtfSwitch(NOPRESERVETIME_SWITCH, Link);
  276. AssemblyCode += AssemblyProperty(Language, TransferOptionsClassName, L"PreserveTimestamp", false, false);
  277. }
  278. }
  279. }
  280. if ((PreserveRights || PreserveTime) &&
  281. (IgnorePermErrors != Defaults.IgnorePermErrors))
  282. {
  283. if (DebugAlwaysTrue(IgnorePermErrors))
  284. {
  285. if (ADD(LoadStr(COPY_INFO_IGNORE_PERM_ERRORS), cpaIncludeMaskOnly | cpaNoIgnorePermErrors))
  286. {
  287. ScriptNonDefaults.IgnorePermErrors = IgnorePermErrors;
  288. CodeNonDefaults.IgnorePermErrors = IgnorePermErrors;
  289. }
  290. }
  291. }
  292. if (PreserveReadOnly != Defaults.PreserveReadOnly)
  293. {
  294. if (DebugAlwaysTrue(PreserveReadOnly))
  295. {
  296. if (ADD(LoadStr(COPY_INFO_PRESERVE_READONLY), cpaIncludeMaskOnly | cpaNoPreserveReadOnly))
  297. {
  298. ScriptNonDefaults.PreserveReadOnly = PreserveReadOnly;
  299. CodeNonDefaults.PreserveReadOnly = PreserveReadOnly;
  300. }
  301. }
  302. }
  303. if (CalculateSize != Defaults.CalculateSize)
  304. {
  305. if (DebugAlwaysTrue(!CalculateSize))
  306. {
  307. ADD(LoadStr(COPY_INFO_DONT_CALCULATE_SIZE), cpaIncludeMaskOnly | cpaNoCalculateSize);
  308. // Always false in scripting, in assembly controlled by use of FileTransferProgress
  309. }
  310. }
  311. if (ClearArchive != Defaults.ClearArchive)
  312. {
  313. if (DebugAlwaysTrue(ClearArchive))
  314. {
  315. if (ADD(LoadStr(COPY_INFO_CLEAR_ARCHIVE), cpaIncludeMaskOnly | cpaNoClearArchive))
  316. {
  317. ScriptNonDefaults.ClearArchive = ClearArchive;
  318. CodeNonDefaults.ClearArchive = ClearArchive;
  319. }
  320. }
  321. }
  322. if ((TransferMode == tmAscii) || (TransferMode == tmAutomatic))
  323. {
  324. if (RemoveBOM != Defaults.RemoveBOM)
  325. {
  326. if (DebugAlwaysTrue(RemoveBOM))
  327. {
  328. if (ADD(LoadStr(COPY_INFO_REMOVE_BOM), cpaIncludeMaskOnly | cpaNoRemoveBOM | cpaNoTransferMode))
  329. {
  330. ScriptNonDefaults.RemoveBOM = RemoveBOM;
  331. CodeNonDefaults.RemoveBOM = RemoveBOM;
  332. }
  333. }
  334. }
  335. if (RemoveCtrlZ != Defaults.RemoveCtrlZ)
  336. {
  337. if (DebugAlwaysTrue(RemoveCtrlZ))
  338. {
  339. if (ADD(LoadStr(COPY_INFO_REMOVE_CTRLZ), cpaIncludeMaskOnly | cpaNoRemoveCtrlZ | cpaNoTransferMode))
  340. {
  341. ScriptNonDefaults.RemoveCtrlZ = RemoveCtrlZ;
  342. CodeNonDefaults.RemoveCtrlZ = RemoveCtrlZ;
  343. }
  344. }
  345. }
  346. }
  347. if (!(IncludeFileMask == Defaults.IncludeFileMask))
  348. {
  349. if (ADD(FORMAT(LoadStr(COPY_INFO_FILE_MASK), (IncludeFileMask.Masks)), cpaNoIncludeMask))
  350. {
  351. ScriptArgs += RtfSwitch(FILEMASK_SWITCH, Link, IncludeFileMask.Masks);
  352. AssemblyCode += AssemblyProperty(Language, TransferOptionsClassName, L"FileMask", IncludeFileMask.Masks, false);
  353. }
  354. }
  355. DebugAssert(FTransferSkipList.get() == NULL);
  356. DebugAssert(FTransferResumeFile.IsEmpty());
  357. if (CPSLimit > 0)
  358. {
  359. int LimitKB = int(CPSLimit / 1024);
  360. if (ADD(FMTLOAD(COPY_INFO_CPS_LIMIT2, (LimitKB)), cpaIncludeMaskOnly))
  361. {
  362. ScriptArgs += RtfSwitch(SPEED_SWITCH, Link, LimitKB);
  363. AssemblyCode += AssemblyProperty(Language, TransferOptionsClassName, L"SpeedLimit", LimitKB, false);
  364. }
  365. }
  366. if (NewerOnly != Defaults.NewerOnly)
  367. {
  368. if (DebugAlwaysTrue(NewerOnly))
  369. {
  370. if (ADD(StripHotkey(LoadStr(COPY_PARAM_NEWER_ONLY)), cpaIncludeMaskOnly | cpaNoNewerOnly))
  371. {
  372. ScriptArgs += RtfSwitch(NEWERONLY_SWICH, Link);
  373. CodeNonDefaults.NewerOnly = NewerOnly;
  374. }
  375. }
  376. }
  377. if (EncryptNewFiles != Defaults.EncryptNewFiles)
  378. {
  379. if (!DebugAlwaysFalse(EncryptNewFiles))
  380. {
  381. if (ADD(StripHotkey(LoadStr(COPY_INFO_DONT_ENCRYPT_NEW_FILES)), cpaIncludeMaskOnly | cpaNoEncryptNewFiles))
  382. {
  383. ScriptNonDefaults.EncryptNewFiles = EncryptNewFiles;
  384. CodeNonDefaults.EncryptNewFiles = EncryptNewFiles;
  385. }
  386. }
  387. }
  388. if (ExcludeHiddenFiles != Defaults.ExcludeHiddenFiles)
  389. {
  390. if (DebugAlwaysTrue(ExcludeHiddenFiles))
  391. {
  392. if (ADD(StripHotkey(LoadStr(COPY_INFO_EXCLUDE_HIDDEN_FILES)), cpaNoIncludeMask))
  393. {
  394. ScriptNonDefaults.ExcludeHiddenFiles = ExcludeHiddenFiles;
  395. CodeNonDefaults.ExcludeHiddenFiles = ExcludeHiddenFiles;
  396. }
  397. }
  398. }
  399. if (ExcludeEmptyDirectories != Defaults.ExcludeEmptyDirectories)
  400. {
  401. if (DebugAlwaysTrue(ExcludeEmptyDirectories))
  402. {
  403. if (ADD(StripHotkey(LoadStr(COPY_INFO_EXCLUDE_EMPTY_DIRS)), 0))
  404. {
  405. ScriptNonDefaults.ExcludeEmptyDirectories = ExcludeEmptyDirectories;
  406. CodeNonDefaults.ExcludeEmptyDirectories = ExcludeEmptyDirectories;
  407. }
  408. }
  409. }
  410. bool ResumeThresholdDiffers = ((ResumeSupport == rsSmart) && (ResumeThreshold != Defaults.ResumeThreshold));
  411. if (((ResumeSupport != Defaults.ResumeSupport) || ResumeThresholdDiffers) &&
  412. (TransferMode != tmAscii) && FLAGCLEAR(Options, cpaNoResumeSupport))
  413. {
  414. UnicodeString Value;
  415. UnicodeString CodeState;
  416. int ResumeThresholdKB = (ResumeThreshold / 1024);
  417. switch (ResumeSupport)
  418. {
  419. case rsOff:
  420. Value = ToggleNames[ToggleOff];
  421. CodeState = L"Off";
  422. break;
  423. case rsOn:
  424. Value = ToggleNames[ToggleOn];
  425. CodeState = L"On";
  426. break;
  427. case rsSmart:
  428. Value = IntToStr(ResumeThresholdKB);
  429. break;
  430. }
  431. ScriptArgs += RtfSwitchValue(RESUMESUPPORT_SWITCH, Link, Value);
  432. const UnicodeString ResumeSupportClassName = L"TransferResumeSupport";
  433. const bool Inline = true;
  434. UnicodeString ResumeSupportCode =
  435. AssemblyNewClassInstanceStart(Language, ResumeSupportClassName, Inline);
  436. if (ResumeSupport == rsSmart)
  437. {
  438. ResumeSupportCode += AssemblyProperty(Language, ResumeSupportClassName, L"Threshold", ResumeThresholdKB, Inline);
  439. }
  440. else
  441. {
  442. ResumeSupportCode += AssemblyProperty(Language, ResumeSupportClassName, L"State", L"TransferResumeSupportState", CodeState, Inline);
  443. }
  444. ResumeSupportCode += AssemblyNewClassInstanceEnd(Language, Inline);
  445. AssemblyCode += AssemblyPropertyRaw(Language, TransferOptionsClassName, L"ResumeSupport", ResumeSupportCode, false);
  446. }
  447. std::unique_ptr<TStringList> RawOptions;
  448. std::unique_ptr<TOptionsStorage> OptionsStorage;
  449. RawOptions.reset(new TStringList());
  450. OptionsStorage.reset(new TOptionsStorage(RawOptions.get(), true));
  451. ScriptNonDefaults.Save(OptionsStorage.get(), &Defaults);
  452. if (RawOptions->Count > 0)
  453. {
  454. ScriptArgs +=
  455. RtfSwitch(RAWTRANSFERSETTINGS_SWICH, Link) +
  456. FORMAT(L"[%d]", (RawOptions->Count)) +
  457. StringsToParams(RawOptions.get());
  458. }
  459. RawOptions.reset(new TStringList());
  460. OptionsStorage.reset(new TOptionsStorage(RawOptions.get(), true));
  461. CodeNonDefaults.Save(OptionsStorage.get(), &Defaults);
  462. if (!AssemblyCode.IsEmpty())
  463. {
  464. AssemblyCode =
  465. AssemblyNewClassInstanceStart(Language, TransferOptionsClassName, false) +
  466. AssemblyCode +
  467. AssemblyNewClassInstanceEnd(Language, false);
  468. }
  469. if (RawOptions->Count > 0)
  470. {
  471. if (AssemblyCode.IsEmpty())
  472. {
  473. AssemblyCode = AssemblyVariableDeclaration(Language) + AssemblyNewClassInstance(Language, TransferOptionsClassName, false);
  474. if (Language == alCSharp)
  475. {
  476. AssemblyCode += RtfText(L"()");
  477. }
  478. AssemblyCode += AssemblyStatementSeparator(Language) + RtfPara;
  479. }
  480. else
  481. {
  482. AssemblyCode += RtfPara;
  483. }
  484. AssemblyCode +=
  485. AssemblyAddRawSettings(Language, RawOptions.get(), TransferOptionsClassName, L"AddRawSettings");
  486. }
  487. if (SomeAttrExcluded)
  488. {
  489. Result += (Result.IsEmpty() ? UnicodeString() : Separator) +
  490. FORMAT(LoadStrPart(COPY_INFO_NOT_USABLE, 1),
  491. (LoadStrPart(COPY_INFO_NOT_USABLE, (SomeAttrIncluded ? 2 : 3))));
  492. }
  493. else if (Result.IsEmpty())
  494. {
  495. Result = LoadStr(COPY_INFO_DEFAULT);
  496. }
  497. #undef ADD
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TCopyParamType::Assign(const TCopyParamType * Source)
  501. {
  502. DebugAssert(Source != NULL);
  503. #define COPY(Prop) Prop = Source->Prop
  504. COPY(FileNameCase);
  505. COPY(PreserveReadOnly);
  506. COPY(PreserveTime);
  507. COPY(PreserveTimeDirs);
  508. COPY(Rights);
  509. COPY(AsciiFileMask);
  510. COPY(TransferMode);
  511. COPY(AddXToDirectories);
  512. COPY(PreserveRights);
  513. COPY(IgnorePermErrors);
  514. COPY(ResumeSupport);
  515. COPY(ResumeThreshold);
  516. COPY(InvalidCharsReplacement);
  517. COPY(LocalInvalidChars);
  518. COPY(CalculateSize);
  519. COPY(FileMask);
  520. COPY(IncludeFileMask);
  521. COPY(TransferSkipList);
  522. COPY(TransferResumeFile);
  523. COPY(ClearArchive);
  524. COPY(RemoveCtrlZ);
  525. COPY(RemoveBOM);
  526. COPY(CPSLimit);
  527. COPY(NewerOnly);
  528. COPY(EncryptNewFiles);
  529. COPY(ExcludeHiddenFiles);
  530. COPY(ExcludeEmptyDirectories);
  531. COPY(Size);
  532. #undef COPY
  533. }
  534. //---------------------------------------------------------------------------
  535. TCopyParamType & __fastcall TCopyParamType::operator =(const TCopyParamType & rhp)
  536. {
  537. Assign(&rhp);
  538. return *this;
  539. }
  540. //---------------------------------------------------------------------------
  541. void __fastcall TCopyParamType::SetLocalInvalidChars(UnicodeString value)
  542. {
  543. if (value != LocalInvalidChars)
  544. {
  545. FLocalInvalidChars = value;
  546. FTokenizibleChars = FLocalInvalidChars + TokenPrefix;
  547. }
  548. }
  549. //---------------------------------------------------------------------------
  550. bool __fastcall TCopyParamType::GetReplaceInvalidChars() const
  551. {
  552. return (InvalidCharsReplacement != NoReplacement);
  553. }
  554. //---------------------------------------------------------------------------
  555. void __fastcall TCopyParamType::SetReplaceInvalidChars(bool value)
  556. {
  557. if (ReplaceInvalidChars != value)
  558. {
  559. InvalidCharsReplacement = (value ? TokenReplacement : NoReplacement);
  560. }
  561. }
  562. //---------------------------------------------------------------------------
  563. UnicodeString __fastcall TCopyParamType::ValidLocalFileName(UnicodeString FileName) const
  564. {
  565. return ::ValidLocalFileName(FileName, InvalidCharsReplacement, FTokenizibleChars, LocalInvalidChars);
  566. }
  567. //---------------------------------------------------------------------------
  568. UnicodeString __fastcall TCopyParamType::RestoreChars(UnicodeString FileName) const
  569. {
  570. if (InvalidCharsReplacement == TokenReplacement)
  571. {
  572. wchar_t * InvalidChar = FileName.c_str();
  573. while ((InvalidChar = wcschr(InvalidChar, TokenPrefix)) != NULL)
  574. {
  575. int Index = InvalidChar - FileName.c_str() + 1;
  576. if (FileName.Length() >= Index + 2)
  577. {
  578. UnicodeString Hex = FileName.SubString(Index + 1, 2);
  579. wchar_t Char = static_cast<wchar_t>(HexToByte(Hex));
  580. if ((Char != L'\0') &&
  581. ((FTokenizibleChars.Pos(Char) > 0) ||
  582. (((Char == L' ') || (Char == L'.')) && (Index == FileName.Length() - 2))))
  583. {
  584. FileName[Index] = Char;
  585. FileName.Delete(Index + 1, 2);
  586. InvalidChar = FileName.c_str() + Index;
  587. }
  588. else if ((Hex == L"00") &&
  589. ((Index == FileName.Length() - 2) || (FileName[Index + 3] == L'.')) &&
  590. IsReservedName(FileName.SubString(1, Index - 1) + FileName.SubString(Index + 3, FileName.Length() - Index - 3 + 1)))
  591. {
  592. FileName.Delete(Index, 3);
  593. InvalidChar = FileName.c_str() + Index - 1;
  594. }
  595. else
  596. {
  597. InvalidChar++;
  598. }
  599. }
  600. else
  601. {
  602. InvalidChar++;
  603. }
  604. }
  605. }
  606. return FileName;
  607. }
  608. //---------------------------------------------------------------------------
  609. UnicodeString __fastcall TCopyParamType::ValidLocalPath(UnicodeString Path) const
  610. {
  611. UnicodeString Result;
  612. while (!Path.IsEmpty())
  613. {
  614. if (!Result.IsEmpty())
  615. {
  616. Result += L"\\";
  617. }
  618. Result += ValidLocalFileName(CutToChar(Path, L'\\', false));
  619. }
  620. return Result;
  621. }
  622. //---------------------------------------------------------------------------
  623. UnicodeString __fastcall TCopyParamType::ChangeFileName(UnicodeString FileName,
  624. TOperationSide Side, bool FirstLevel) const
  625. {
  626. if (FirstLevel)
  627. {
  628. FileName = MaskFileName(FileName, FileMask);
  629. }
  630. switch (FileNameCase) {
  631. case ncUpperCase: FileName = FileName.UpperCase(); break;
  632. case ncLowerCase: FileName = FileName.LowerCase(); break;
  633. case ncFirstUpperCase: FileName = FileName.SubString(1, 1).UpperCase() +
  634. FileName.SubString(2, FileName.Length()-1).LowerCase(); break;
  635. case ncLowerCaseShort:
  636. if ((FileName.Length() <= 12) && (FileName.Pos(L".") <= 9) &&
  637. (FileName == FileName.UpperCase()))
  638. {
  639. FileName = FileName.LowerCase();
  640. }
  641. break;
  642. case ncNoChange:
  643. default:
  644. /*nothing*/
  645. break;
  646. }
  647. if (Side == osRemote)
  648. {
  649. FileName = ValidLocalFileName(FileName);
  650. }
  651. else
  652. {
  653. FileName = RestoreChars(FileName);
  654. }
  655. return FileName;
  656. }
  657. //---------------------------------------------------------------------------
  658. bool __fastcall TCopyParamType::UseAsciiTransfer(UnicodeString FileName,
  659. TOperationSide Side, const TFileMasks::TParams & Params) const
  660. {
  661. switch (TransferMode)
  662. {
  663. case tmBinary: return false;
  664. case tmAscii: return true;
  665. case tmAutomatic: return AsciiFileMask.Matches(FileName, (Side == osLocal),
  666. false, &Params);
  667. default: DebugFail(); return false;
  668. }
  669. }
  670. //---------------------------------------------------------------------------
  671. TRights __fastcall TCopyParamType::RemoteFileRights(Integer Attrs) const
  672. {
  673. TRights R = Rights;
  674. if ((Attrs & faDirectory) && AddXToDirectories)
  675. R.AddExecute();
  676. return R;
  677. }
  678. //---------------------------------------------------------------------------
  679. UnicodeString __fastcall TCopyParamType::GetLogStr() const
  680. {
  681. wchar_t CaseC[] = L"NULFS";
  682. wchar_t ModeC[] = L"BAM";
  683. wchar_t ResumeC[] = L"YSN";
  684. // OpenArray (ARRAYOFCONST) supports only up to 19 arguments, so we had to split it
  685. return
  686. FORMAT(
  687. L" PrTime: %s%s; PrRO: %s; Rght: %s; PrR: %s (%s); FnCs: %s; RIC: %s; "
  688. "Resume: %s (%d); CalcS: %s; Mask: %s\n",
  689. (BooleanToEngStr(PreserveTime),
  690. UnicodeString(PreserveTime && PreserveTimeDirs ? L"+Dirs" : L""),
  691. BooleanToEngStr(PreserveReadOnly),
  692. Rights.Text,
  693. BooleanToEngStr(PreserveRights),
  694. BooleanToEngStr(IgnorePermErrors),
  695. CaseC[FileNameCase],
  696. CharToHex(InvalidCharsReplacement),
  697. ResumeC[ResumeSupport],
  698. (int)ResumeThreshold,
  699. BooleanToEngStr(CalculateSize),
  700. FileMask)) +
  701. FORMAT(
  702. L" TM: %s; ClAr: %s; RemEOF: %s; RemBOM: %s; CPS: %u; NewerOnly: %s; EncryptNewFiles: %s; ExcludeHiddenFiles: %s; ExcludeEmptyDirectories: %s; InclM: %s; ResumeL: %d\n"
  703. " AscM: %s\n",
  704. (ModeC[TransferMode],
  705. BooleanToEngStr(ClearArchive),
  706. BooleanToEngStr(RemoveCtrlZ),
  707. BooleanToEngStr(RemoveBOM),
  708. int(CPSLimit),
  709. BooleanToEngStr(NewerOnly),
  710. BooleanToEngStr(EncryptNewFiles),
  711. BooleanToEngStr(ExcludeHiddenFiles),
  712. BooleanToEngStr(ExcludeEmptyDirectories),
  713. IncludeFileMask.Masks,
  714. ((FTransferSkipList.get() != NULL) ? FTransferSkipList->Count : 0) + (!FTransferResumeFile.IsEmpty() ? 1 : 0),
  715. AsciiFileMask.Masks));
  716. }
  717. //---------------------------------------------------------------------------
  718. int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
  719. {
  720. int Result = 0;
  721. if (PreserveReadOnly && !Rights.Right[TRights::rrUserWrite])
  722. {
  723. Result |= faReadOnly;
  724. }
  725. return Result;
  726. }
  727. //---------------------------------------------------------------------------
  728. bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
  729. {
  730. switch (ResumeSupport)
  731. {
  732. case rsOn: return true;
  733. case rsOff: return false;
  734. case rsSmart: return (Size >= ResumeThreshold);
  735. default: DebugFail(); return false;
  736. }
  737. }
  738. //---------------------------------------------------------------------------
  739. bool __fastcall TCopyParamType::AllowAnyTransfer() const
  740. {
  741. return
  742. IncludeFileMask.Masks.IsEmpty() &&
  743. !ExcludeHiddenFiles &&
  744. !ExcludeEmptyDirectories &&
  745. ((FTransferSkipList.get() == NULL) || (FTransferSkipList->Count == 0)) &&
  746. FTransferResumeFile.IsEmpty();
  747. }
  748. //---------------------------------------------------------------------------
  749. bool __fastcall TCopyParamType::AllowTransfer(UnicodeString FileName,
  750. TOperationSide Side, bool Directory, const TFileMasks::TParams & Params, bool Hidden) const
  751. {
  752. bool Result = true;
  753. if (Hidden && ExcludeHiddenFiles)
  754. {
  755. Result = false;
  756. }
  757. else if (!IncludeFileMask.Masks.IsEmpty())
  758. {
  759. Result = IncludeFileMask.Matches(FileName, (Side == osLocal),
  760. Directory, &Params);
  761. }
  762. return Result;
  763. }
  764. //---------------------------------------------------------------------------
  765. bool __fastcall TCopyParamType::SkipTransfer(
  766. UnicodeString FileName, bool Directory) const
  767. {
  768. bool Result = false;
  769. // we deliberatelly do not filter directories, as path is added to resume list
  770. // when a transfer of file or directory is started,
  771. // so for directories we need to recurse and check every single file
  772. if (!Directory && (FTransferSkipList.get() != NULL))
  773. {
  774. Result = (FTransferSkipList->IndexOf(FileName) >= 0);
  775. }
  776. return Result;
  777. }
  778. //---------------------------------------------------------------------------
  779. bool __fastcall TCopyParamType::ResumeTransfer(UnicodeString FileName) const
  780. {
  781. // Returning true has the same effect as cpResume
  782. return
  783. (FileName == FTransferResumeFile) &&
  784. DebugAlwaysTrue(!FTransferResumeFile.IsEmpty());
  785. }
  786. //---------------------------------------------------------------------------
  787. TStrings * __fastcall TCopyParamType::GetTransferSkipList() const
  788. {
  789. return FTransferSkipList.get();
  790. }
  791. //---------------------------------------------------------------------------
  792. void __fastcall TCopyParamType::SetTransferSkipList(TStrings * value)
  793. {
  794. if ((value == NULL) || (value->Count == 0))
  795. {
  796. FTransferSkipList.reset(NULL);
  797. }
  798. else
  799. {
  800. FTransferSkipList.reset(new TStringList());
  801. FTransferSkipList->AddStrings(value);
  802. FTransferSkipList->Sorted = true;
  803. }
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TCopyParamType::Load(THierarchicalStorage * Storage)
  807. {
  808. AddXToDirectories = Storage->ReadBool(L"AddXToDirectories", AddXToDirectories);
  809. AsciiFileMask.Masks = Storage->ReadString(L"Masks", AsciiFileMask.Masks);
  810. FileNameCase = (TFileNameCase)Storage->ReadInteger(L"FileNameCase", FileNameCase);
  811. PreserveReadOnly = Storage->ReadBool(L"PreserveReadOnly", PreserveReadOnly);
  812. PreserveTime = Storage->ReadBool(L"PreserveTime", PreserveTime);
  813. PreserveTimeDirs = Storage->ReadBool(L"PreserveTimeDirs", PreserveTimeDirs);
  814. PreserveRights = Storage->ReadBool(L"PreserveRights", PreserveRights);
  815. IgnorePermErrors = Storage->ReadBool(L"IgnorePermErrors", IgnorePermErrors);
  816. Rights.Text = Storage->ReadString(L"Text", Rights.Text);
  817. TransferMode = (TTransferMode)Storage->ReadInteger(L"TransferMode", TransferMode);
  818. ResumeSupport = (TResumeSupport)Storage->ReadInteger(L"ResumeSupport", ResumeSupport);
  819. ResumeThreshold = Storage->ReadInt64(L"ResumeThreshold", ResumeThreshold);
  820. InvalidCharsReplacement = (wchar_t)Storage->ReadInteger(L"ReplaceInvalidChars",
  821. (unsigned int)InvalidCharsReplacement);
  822. LocalInvalidChars = Storage->ReadString(L"LocalInvalidChars", LocalInvalidChars);
  823. CalculateSize = Storage->ReadBool(L"CalculateSize", CalculateSize);
  824. if (Storage->ValueExists(L"IncludeFileMask"))
  825. {
  826. IncludeFileMask.Masks = Storage->ReadString(L"IncludeFileMask", IncludeFileMask.Masks);
  827. }
  828. else if (Storage->ValueExists(L"ExcludeFileMask"))
  829. {
  830. UnicodeString ExcludeFileMask = Storage->ReadString(L"ExcludeFileMask", L"");
  831. if (!ExcludeFileMask.IsEmpty())
  832. {
  833. bool NegativeExclude = Storage->ReadBool(L"NegativeExclude", false);
  834. if (NegativeExclude)
  835. {
  836. IncludeFileMask.Masks = ExcludeFileMask;
  837. }
  838. // convert at least simple cases to new format
  839. else if (ExcludeFileMask.Pos(IncludeExcludeFileMasksDelimiter) == 0)
  840. {
  841. IncludeFileMask.Masks = UnicodeString(IncludeExcludeFileMasksDelimiter) + ExcludeFileMask;
  842. }
  843. }
  844. }
  845. TransferSkipList = NULL;
  846. TransferResumeFile = L"";
  847. ClearArchive = Storage->ReadBool(L"ClearArchive", ClearArchive);
  848. RemoveCtrlZ = Storage->ReadBool(L"RemoveCtrlZ", RemoveCtrlZ);
  849. RemoveBOM = Storage->ReadBool(L"RemoveBOM", RemoveBOM);
  850. CPSLimit = Storage->ReadInteger(L"CPSLimit", CPSLimit);
  851. NewerOnly = Storage->ReadBool(L"NewerOnly", NewerOnly);
  852. EncryptNewFiles = Storage->ReadBool(L"EncryptNewFiles", EncryptNewFiles);
  853. ExcludeHiddenFiles = Storage->ReadBool(L"ExcludeHiddenFiles", ExcludeHiddenFiles);
  854. ExcludeEmptyDirectories = Storage->ReadBool(L"ExcludeEmptyDirectories", ExcludeEmptyDirectories);
  855. Size = -1;
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TCopyParamType::Save(THierarchicalStorage * Storage, const TCopyParamType * Defaults) const
  859. {
  860. // Same as in TSessionData::DoSave
  861. #define WRITE_DATA_EX(TYPE, NAME, PROPERTY, CONV) \
  862. if ((Defaults != NULL) && (CONV(Defaults->PROPERTY) == CONV(PROPERTY))) \
  863. { \
  864. Storage->DeleteValue(NAME); \
  865. } \
  866. else \
  867. { \
  868. Storage->Write ## TYPE(NAME, CONV(PROPERTY)); \
  869. }
  870. #define WRITE_DATA_CONV(TYPE, NAME, PROPERTY) WRITE_DATA_EX(TYPE, NAME, PROPERTY, WRITE_DATA_CONV_FUNC)
  871. #define WRITE_DATA(TYPE, PROPERTY) WRITE_DATA_EX(TYPE, TEXT(#PROPERTY), PROPERTY, )
  872. WRITE_DATA(Bool, AddXToDirectories);
  873. WRITE_DATA_EX(String, L"Masks", AsciiFileMask.Masks, );
  874. WRITE_DATA(Integer, FileNameCase);
  875. WRITE_DATA(Bool, PreserveReadOnly);
  876. WRITE_DATA(Bool, PreserveTime);
  877. WRITE_DATA(Bool, PreserveTimeDirs);
  878. WRITE_DATA(Bool, PreserveRights);
  879. WRITE_DATA(Bool, IgnorePermErrors);
  880. WRITE_DATA_EX(String, L"Text", Rights.Text, );
  881. WRITE_DATA(Integer, TransferMode);
  882. WRITE_DATA(Integer, ResumeSupport);
  883. WRITE_DATA(Int64, ResumeThreshold);
  884. #define WRITE_DATA_CONV_FUNC(X) (unsigned int)(X)
  885. WRITE_DATA_CONV(Integer, L"ReplaceInvalidChars", InvalidCharsReplacement);
  886. WRITE_DATA(String, LocalInvalidChars);
  887. WRITE_DATA(Bool, CalculateSize);
  888. WRITE_DATA_EX(String, L"IncludeFileMask", IncludeFileMask.Masks, );
  889. Storage->DeleteValue(L"ExcludeFileMask"); // obsolete
  890. Storage->DeleteValue(L"NegativeExclude"); // obsolete
  891. DebugAssert(FTransferSkipList.get() == NULL);
  892. DebugAssert(FTransferResumeFile.IsEmpty());
  893. WRITE_DATA(Bool, ClearArchive);
  894. WRITE_DATA(Bool, RemoveCtrlZ);
  895. WRITE_DATA(Bool, RemoveBOM);
  896. WRITE_DATA(Integer, CPSLimit);
  897. WRITE_DATA(Bool, NewerOnly);
  898. WRITE_DATA(Bool, EncryptNewFiles);
  899. WRITE_DATA(Bool, ExcludeHiddenFiles);
  900. WRITE_DATA(Bool, ExcludeEmptyDirectories);
  901. DebugAssert(Size < 0);
  902. }
  903. //---------------------------------------------------------------------------
  904. #define C(Property) (Property == rhp.Property)
  905. bool __fastcall TCopyParamType::operator==(const TCopyParamType & rhp) const
  906. {
  907. DebugAssert(FTransferSkipList.get() == NULL);
  908. DebugAssert(FTransferResumeFile.IsEmpty());
  909. DebugAssert(rhp.FTransferSkipList.get() == NULL);
  910. DebugAssert(rhp.FTransferResumeFile.IsEmpty());
  911. return
  912. C(AddXToDirectories) &&
  913. C(AsciiFileMask) &&
  914. C(FileNameCase) &&
  915. C(PreserveReadOnly) &&
  916. C(PreserveTime) &&
  917. C(PreserveTimeDirs) &&
  918. C(PreserveRights) &&
  919. C(IgnorePermErrors) &&
  920. C(Rights) &&
  921. C(TransferMode) &&
  922. C(ResumeSupport) &&
  923. C(ResumeThreshold) &&
  924. C(InvalidCharsReplacement) &&
  925. C(LocalInvalidChars) &&
  926. C(CalculateSize) &&
  927. C(IncludeFileMask) &&
  928. C(ClearArchive) &&
  929. C(RemoveCtrlZ) &&
  930. C(RemoveBOM) &&
  931. C(CPSLimit) &&
  932. C(NewerOnly) &&
  933. C(EncryptNewFiles) &&
  934. C(ExcludeHiddenFiles) &&
  935. C(ExcludeEmptyDirectories) &&
  936. C(Size) &&
  937. true;
  938. }
  939. #undef C
  940. //---------------------------------------------------------------------------
  941. static bool __fastcall TryGetSpeedLimit(const UnicodeString & Text, unsigned long & Speed)
  942. {
  943. bool Result;
  944. if (AnsiSameText(Text, LoadStr(SPEED_UNLIMITED)))
  945. {
  946. Speed = 0;
  947. Result = true;
  948. }
  949. else
  950. {
  951. int SSpeed;
  952. Result = TryStrToInt(Text, SSpeed) && (SSpeed >= 0);
  953. if (Result)
  954. {
  955. Speed = SSpeed * 1024;
  956. }
  957. }
  958. return Result;
  959. }
  960. //---------------------------------------------------------------------------
  961. unsigned long __fastcall GetSpeedLimit(const UnicodeString & Text)
  962. {
  963. unsigned long Speed;
  964. if (!TryGetSpeedLimit(Text, Speed))
  965. {
  966. throw Exception(FMTLOAD(SPEED_INVALID, (Text)));
  967. }
  968. return Speed;
  969. }
  970. //---------------------------------------------------------------------------
  971. UnicodeString __fastcall SetSpeedLimit(unsigned long Limit)
  972. {
  973. UnicodeString Text;
  974. if (Limit == 0)
  975. {
  976. Text = LoadStr(SPEED_UNLIMITED);
  977. }
  978. else
  979. {
  980. Text = IntToStr(int(Limit / 1024));
  981. }
  982. return Text;
  983. }
  984. //---------------------------------------------------------------------------
  985. void __fastcall CopySpeedLimits(TStrings * Source, TStrings * Dest)
  986. {
  987. std::unique_ptr<TStringList> Temp(new TStringList());
  988. bool Unlimited = false;
  989. for (int Index = 0; Index < Source->Count; Index++)
  990. {
  991. UnicodeString Text = Source->Strings[Index];
  992. unsigned long Speed;
  993. bool Valid = TryGetSpeedLimit(Text, Speed);
  994. if ((!Valid || (Speed == 0)) && !Unlimited)
  995. {
  996. Temp->Add(LoadStr(SPEED_UNLIMITED));
  997. Unlimited = true;
  998. }
  999. else if (Valid && (Speed > 0))
  1000. {
  1001. Temp->Add(Text);
  1002. }
  1003. }
  1004. if (!Unlimited)
  1005. {
  1006. Temp->Insert(0, LoadStr(SPEED_UNLIMITED));
  1007. }
  1008. Dest->Assign(Temp.get());
  1009. }
  1010. //---------------------------------------------------------------------------
  1011. TOperationSide ReverseOperationSide(TOperationSide Side)
  1012. {
  1013. TOperationSide Result;
  1014. switch (Side)
  1015. {
  1016. case osLocal:
  1017. Result = osRemote;
  1018. break;
  1019. case osRemote:
  1020. Result = osLocal;
  1021. break;
  1022. default:
  1023. case osCurrent:
  1024. DebugFail();
  1025. Result = Side;
  1026. break;
  1027. }
  1028. return Result;
  1029. }