CopyParam.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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. OnceDoneOperation = odoIdle;
  61. }
  62. //---------------------------------------------------------------------------
  63. UnicodeString __fastcall TCopyParamType::GetInfoStr(
  64. UnicodeString Separator, int Attrs) const
  65. {
  66. UnicodeString Result;
  67. bool SomeAttrIncluded;
  68. UnicodeString ScriptArgs;
  69. UnicodeString AssemblyCode;
  70. DoGetInfoStr(
  71. Separator, Attrs, Result, SomeAttrIncluded,
  72. UnicodeString(), ScriptArgs, TAssemblyLanguage(0), AssemblyCode);
  73. return Result;
  74. }
  75. //---------------------------------------------------------------------------
  76. bool __fastcall TCopyParamType::AnyUsableCopyParam(int Attrs) const
  77. {
  78. UnicodeString Result;
  79. bool SomeAttrIncluded;
  80. UnicodeString ScriptArgs;
  81. UnicodeString AssemblyCode;
  82. DoGetInfoStr(
  83. L";", Attrs, Result, SomeAttrIncluded,
  84. UnicodeString(), ScriptArgs, TAssemblyLanguage(0), AssemblyCode);
  85. return SomeAttrIncluded;
  86. }
  87. //---------------------------------------------------------------------------
  88. UnicodeString __fastcall TCopyParamType::GenerateTransferCommandArgs(int Attrs, const UnicodeString & Link) const
  89. {
  90. UnicodeString Result;
  91. bool SomeAttrIncluded;
  92. UnicodeString ScriptArgs;
  93. UnicodeString AssemblyCode;
  94. DoGetInfoStr(
  95. L";", Attrs, Result, SomeAttrIncluded,
  96. Link, ScriptArgs, TAssemblyLanguage(0), AssemblyCode);
  97. return ScriptArgs;
  98. }
  99. //---------------------------------------------------------------------------
  100. UnicodeString __fastcall TCopyParamType::GenerateAssemblyCode(TAssemblyLanguage Language, int Attrs) const
  101. {
  102. UnicodeString Result;
  103. bool SomeAttrIncluded;
  104. UnicodeString ScriptArgs;
  105. UnicodeString AssemblyCode;
  106. DoGetInfoStr(L";", Attrs, Result, SomeAttrIncluded, UnicodeString(), ScriptArgs, Language, AssemblyCode);
  107. return AssemblyCode;
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TCopyParamType::DoGetInfoStr(
  111. UnicodeString Separator, int Options,
  112. UnicodeString & Result, bool & SomeAttrIncluded,
  113. const UnicodeString & Link, UnicodeString & ScriptArgs, TAssemblyLanguage Language, UnicodeString & AssemblyCode) const
  114. {
  115. TCopyParamType Defaults;
  116. TCopyParamType ScriptNonDefaults;
  117. TCopyParamType CodeNonDefaults;
  118. bool SomeAttrExcluded = false;
  119. SomeAttrIncluded = false;
  120. #define ADD(STR, EXCEPT) \
  121. FLAGCLEAR(Options, EXCEPT) ? (AddToList(Result, (STR), Separator), SomeAttrIncluded = true, true) : (SomeAttrExcluded = true, false)
  122. bool AsciiFileMaskDiffers = (TransferMode == tmAutomatic) && !(AsciiFileMask == Defaults.AsciiFileMask);
  123. bool TransferModeDiffers = ((TransferMode != Defaults.TransferMode) || AsciiFileMaskDiffers);
  124. if (FLAGCLEAR(Options, cpaIncludeMaskOnly | cpaNoTransferMode))
  125. {
  126. // Adding Transfer type unconditionally
  127. bool FormatMask;
  128. int Ident;
  129. switch (TransferMode)
  130. {
  131. case tmBinary:
  132. FormatMask = false;
  133. Ident = 2;
  134. break;
  135. case tmAscii:
  136. FormatMask = false;
  137. Ident = 3;
  138. break;
  139. case tmAutomatic:
  140. default:
  141. FormatMask = !(AsciiFileMask == Defaults.AsciiFileMask);
  142. Ident = FormatMask ? 4 : 5;
  143. break;
  144. }
  145. UnicodeString S = FORMAT(LoadStrPart(COPY_INFO_TRANSFER_TYPE2, 1),
  146. (LoadStrPart(COPY_INFO_TRANSFER_TYPE2, Ident)));
  147. if (FormatMask)
  148. {
  149. S = FORMAT(S, (AsciiFileMask.Masks));
  150. }
  151. AddToList(Result, S, Separator);
  152. if (TransferModeDiffers)
  153. {
  154. ADD("", cpaIncludeMaskOnly | cpaNoTransferMode);
  155. ScriptArgs += RtfSwitchValue(TRANSFER_SWITCH, Link, TransferModeNames[TransferMode]);
  156. const wchar_t * TransferModeMembers[] = { L"Binary", L"Ascii", L"Automatic" };
  157. AssemblyCode += AssemblyProperty(
  158. Language, TransferOptionsClassName, L"TransferMode", L"TransferMode", TransferModeMembers[TransferMode], false);
  159. if (AsciiFileMaskDiffers)
  160. {
  161. ScriptNonDefaults.AsciiFileMask = AsciiFileMask;
  162. CodeNonDefaults.AsciiFileMask = AsciiFileMask;
  163. }
  164. }
  165. }
  166. else
  167. {
  168. if (TransferModeDiffers)
  169. {
  170. SomeAttrExcluded = true;
  171. }
  172. }
  173. if (FileNameCase != Defaults.FileNameCase)
  174. {
  175. if (ADD(FORMAT(LoadStrPart(COPY_INFO_FILENAME, 1),
  176. (LoadStrPart(COPY_INFO_FILENAME, FileNameCase + 2))),
  177. cpaIncludeMaskOnly))
  178. {
  179. ScriptNonDefaults.FileNameCase = FileNameCase;
  180. CodeNonDefaults.FileNameCase = FileNameCase;
  181. }
  182. }
  183. if (InvalidCharsReplacement != Defaults.InvalidCharsReplacement)
  184. {
  185. int Except = cpaIncludeMaskOnly;
  186. if (InvalidCharsReplacement == NoReplacement)
  187. {
  188. ADD(LoadStr(COPY_INFO_DONT_REPLACE_INV_CHARS), Except);
  189. }
  190. if (FLAGCLEAR(Options, Except))
  191. {
  192. ScriptNonDefaults.InvalidCharsReplacement = InvalidCharsReplacement;
  193. CodeNonDefaults.InvalidCharsReplacement = InvalidCharsReplacement;
  194. }
  195. }
  196. if ((PreserveRights != Defaults.PreserveRights) ||
  197. (PreserveRights &&
  198. ((Rights != Defaults.Rights) || (AddXToDirectories != Defaults.AddXToDirectories))))
  199. {
  200. const int Except = cpaIncludeMaskOnly | cpaNoRights;
  201. if (DebugAlwaysTrue(PreserveRights))
  202. {
  203. UnicodeString RightsStr = Rights.Text;
  204. if (AddXToDirectories)
  205. {
  206. RightsStr += L", " + LoadStr(COPY_INFO_ADD_X_TO_DIRS);
  207. }
  208. ADD(FORMAT(LoadStr(COPY_INFO_PERMISSIONS), (RightsStr)),
  209. Except);
  210. if (FLAGCLEAR(Options, Except))
  211. {
  212. ScriptArgs += RtfSwitchValue(PERMISSIONS_SWITCH, Link, Rights.Octal);
  213. const UnicodeString FilePermissionsClassName = L"FilePermissions";
  214. const bool Inline = true;
  215. UnicodeString FilePermissions =
  216. AssemblyNewClassInstanceStart(Language, FilePermissionsClassName, Inline) +
  217. AssemblyProperty(Language, FilePermissionsClassName, L"Octal", Rights.Octal, Inline) +
  218. AssemblyNewClassInstanceEnd(Language, Inline);
  219. AssemblyCode += AssemblyPropertyRaw(Language, TransferOptionsClassName, L"FilePermissions", FilePermissions, false);
  220. }
  221. }
  222. if ((AddXToDirectories != Defaults.AddXToDirectories) && FLAGCLEAR(Options, Except))
  223. {
  224. ScriptNonDefaults.AddXToDirectories = AddXToDirectories;
  225. CodeNonDefaults.AddXToDirectories = AddXToDirectories;
  226. }
  227. }
  228. bool APreserveTimeDirs = PreserveTime && PreserveTimeDirs;
  229. if ((PreserveTime != Defaults.PreserveTime) || (APreserveTimeDirs != Defaults.PreserveTimeDirs))
  230. {
  231. bool AddPreserveTime = false;
  232. UnicodeString Str = LoadStr(PreserveTime ? COPY_INFO_TIMESTAMP : COPY_INFO_DONT_PRESERVE_TIME);
  233. const int ExceptDirs = cpaNoPreserveTimeDirs;
  234. if (APreserveTimeDirs != Defaults.PreserveTimeDirs)
  235. {
  236. if (DebugAlwaysTrue(PreserveTimeDirs))
  237. {
  238. if (FLAGCLEAR(Options, ExceptDirs))
  239. {
  240. Str = FMTLOAD(COPY_INFO_PRESERVE_TIME_DIRS, (Str));
  241. AddPreserveTime = true;
  242. }
  243. }
  244. ADD("", ExceptDirs);
  245. }
  246. const int Except = cpaIncludeMaskOnly | cpaNoPreserveTime;
  247. if (PreserveTime != Defaults.PreserveTime)
  248. {
  249. if (FLAGCLEAR(Options, Except))
  250. {
  251. AddPreserveTime = true;
  252. }
  253. ADD(L"", Except);
  254. }
  255. if (AddPreserveTime)
  256. {
  257. AddToList(Result, Str, Separator);
  258. }
  259. if (FLAGCLEAR(Options, Except))
  260. {
  261. if (PreserveTime)
  262. {
  263. if (PreserveTimeDirs && FLAGCLEAR(Options, ExceptDirs))
  264. {
  265. ScriptArgs += RtfSwitchValue(PRESERVETIME_SWITCH, Link, PRESERVETIMEDIRS_SWITCH_VALUE);
  266. CodeNonDefaults.PreserveTimeDirs = PreserveTimeDirs;
  267. }
  268. else
  269. {
  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_SWITCH, 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. COPY(OnceDoneOperation);
  533. #undef COPY
  534. }
  535. //---------------------------------------------------------------------------
  536. TCopyParamType & __fastcall TCopyParamType::operator =(const TCopyParamType & rhp)
  537. {
  538. Assign(&rhp);
  539. return *this;
  540. }
  541. //---------------------------------------------------------------------------
  542. void __fastcall TCopyParamType::SetLocalInvalidChars(UnicodeString value)
  543. {
  544. if (value != LocalInvalidChars)
  545. {
  546. FLocalInvalidChars = value;
  547. FTokenizibleChars = FLocalInvalidChars + TokenPrefix;
  548. }
  549. }
  550. //---------------------------------------------------------------------------
  551. bool __fastcall TCopyParamType::GetReplaceInvalidChars() const
  552. {
  553. return (InvalidCharsReplacement != NoReplacement);
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TCopyParamType::SetReplaceInvalidChars(bool value)
  557. {
  558. if (ReplaceInvalidChars != value)
  559. {
  560. InvalidCharsReplacement = (value ? TokenReplacement : NoReplacement);
  561. }
  562. }
  563. //---------------------------------------------------------------------------
  564. UnicodeString __fastcall TCopyParamType::ValidLocalFileName(UnicodeString FileName) const
  565. {
  566. return ::ValidLocalFileName(FileName, InvalidCharsReplacement, FTokenizibleChars, LocalInvalidChars);
  567. }
  568. //---------------------------------------------------------------------------
  569. UnicodeString __fastcall TCopyParamType::RestoreChars(UnicodeString FileName) const
  570. {
  571. if (InvalidCharsReplacement == TokenReplacement)
  572. {
  573. wchar_t * InvalidChar = FileName.c_str();
  574. while ((InvalidChar = wcschr(InvalidChar, TokenPrefix)) != NULL)
  575. {
  576. int Index = InvalidChar - FileName.c_str() + 1;
  577. if (FileName.Length() >= Index + 2)
  578. {
  579. UnicodeString Hex = FileName.SubString(Index + 1, 2);
  580. wchar_t Char = static_cast<wchar_t>(HexToByte(Hex));
  581. if ((Char != L'\0') &&
  582. ((FTokenizibleChars.Pos(Char) > 0) ||
  583. (((Char == L' ') || (Char == L'.')) && (Index == FileName.Length() - 2))))
  584. {
  585. FileName[Index] = Char;
  586. FileName.Delete(Index + 1, 2);
  587. InvalidChar = FileName.c_str() + Index;
  588. }
  589. else if ((Hex == L"00") &&
  590. ((Index == FileName.Length() - 2) || (FileName[Index + 3] == L'.')) &&
  591. IsReservedName(FileName.SubString(1, Index - 1) + FileName.SubString(Index + 3, FileName.Length() - Index - 3 + 1)))
  592. {
  593. FileName.Delete(Index, 3);
  594. InvalidChar = FileName.c_str() + Index - 1;
  595. }
  596. else
  597. {
  598. InvalidChar++;
  599. }
  600. }
  601. else
  602. {
  603. InvalidChar++;
  604. }
  605. }
  606. }
  607. return FileName;
  608. }
  609. //---------------------------------------------------------------------------
  610. UnicodeString __fastcall TCopyParamType::ValidLocalPath(UnicodeString Path) const
  611. {
  612. UnicodeString Result;
  613. while (!Path.IsEmpty())
  614. {
  615. if (!Result.IsEmpty())
  616. {
  617. Result += L"\\";
  618. }
  619. Result += ValidLocalFileName(CutToChar(Path, L'\\', false));
  620. }
  621. return Result;
  622. }
  623. //---------------------------------------------------------------------------
  624. UnicodeString __fastcall TCopyParamType::ChangeFileName(UnicodeString FileName,
  625. TOperationSide Side, bool FirstLevel) const
  626. {
  627. if (FirstLevel)
  628. {
  629. FileName = MaskFileName(FileName, FileMask);
  630. }
  631. switch (FileNameCase) {
  632. case ncUpperCase: FileName = FileName.UpperCase(); break;
  633. case ncLowerCase: FileName = FileName.LowerCase(); break;
  634. case ncFirstUpperCase: FileName = FileName.SubString(1, 1).UpperCase() +
  635. FileName.SubString(2, FileName.Length()-1).LowerCase(); break;
  636. case ncLowerCaseShort:
  637. if ((FileName.Length() <= 12) && (FileName.Pos(L".") <= 9) &&
  638. (FileName == FileName.UpperCase()))
  639. {
  640. FileName = FileName.LowerCase();
  641. }
  642. break;
  643. case ncNoChange:
  644. default:
  645. /*nothing*/
  646. break;
  647. }
  648. if (Side == osRemote)
  649. {
  650. FileName = ValidLocalFileName(FileName);
  651. }
  652. else
  653. {
  654. FileName = RestoreChars(FileName);
  655. }
  656. return FileName;
  657. }
  658. //---------------------------------------------------------------------------
  659. bool __fastcall TCopyParamType::UseAsciiTransfer(UnicodeString FileName,
  660. TOperationSide Side, const TFileMasks::TParams & Params) const
  661. {
  662. switch (TransferMode)
  663. {
  664. case tmBinary: return false;
  665. case tmAscii: return true;
  666. case tmAutomatic: return AsciiFileMask.Matches(FileName, (Side == osLocal),
  667. false, &Params);
  668. default: DebugFail(); return false;
  669. }
  670. }
  671. //---------------------------------------------------------------------------
  672. TRights __fastcall TCopyParamType::RemoteFileRights(Integer Attrs) const
  673. {
  674. TRights R = Rights;
  675. if ((Attrs & faDirectory) && AddXToDirectories)
  676. R.AddExecute();
  677. return R;
  678. }
  679. //---------------------------------------------------------------------------
  680. UnicodeString __fastcall TCopyParamType::GetLogStr() const
  681. {
  682. wchar_t CaseC[] = L"NULFS";
  683. wchar_t ModeC[] = L"BAM";
  684. wchar_t ResumeC[] = L"YSN";
  685. // OpenArray (ARRAYOFCONST) supports only up to 19 arguments, so we had to split it
  686. return
  687. FORMAT(
  688. L" PrTime: %s%s; PrRO: %s; Rght: %s; PrR: %s (%s); FnCs: %s; RIC: %s; "
  689. "Resume: %s (%d); CalcS: %s; Mask: %s\n",
  690. (BooleanToEngStr(PreserveTime),
  691. UnicodeString(PreserveTime && PreserveTimeDirs ? L"+Dirs" : L""),
  692. BooleanToEngStr(PreserveReadOnly),
  693. Rights.Text,
  694. BooleanToEngStr(PreserveRights),
  695. BooleanToEngStr(IgnorePermErrors),
  696. CaseC[FileNameCase],
  697. CharToHex(InvalidCharsReplacement),
  698. ResumeC[ResumeSupport],
  699. (int)ResumeThreshold,
  700. BooleanToEngStr(CalculateSize),
  701. FileMask)) +
  702. FORMAT(
  703. L" TM: %s; ClAr: %s; RemEOF: %s; RemBOM: %s; CPS: %u; NewerOnly: %s; EncryptNewFiles: %s; ExcludeHiddenFiles: %s; ExcludeEmptyDirectories: %s; InclM: %s; ResumeL: %d\n"
  704. " AscM: %s\n",
  705. (ModeC[TransferMode],
  706. BooleanToEngStr(ClearArchive),
  707. BooleanToEngStr(RemoveCtrlZ),
  708. BooleanToEngStr(RemoveBOM),
  709. int(CPSLimit),
  710. BooleanToEngStr(NewerOnly),
  711. BooleanToEngStr(EncryptNewFiles),
  712. BooleanToEngStr(ExcludeHiddenFiles),
  713. BooleanToEngStr(ExcludeEmptyDirectories),
  714. IncludeFileMask.Masks,
  715. ((FTransferSkipList.get() != NULL) ? FTransferSkipList->Count : 0) + (!FTransferResumeFile.IsEmpty() ? 1 : 0),
  716. AsciiFileMask.Masks));
  717. }
  718. //---------------------------------------------------------------------------
  719. int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
  720. {
  721. int Result = 0;
  722. if (PreserveReadOnly && !Rights.Right[TRights::rrUserWrite])
  723. {
  724. Result |= faReadOnly;
  725. }
  726. return Result;
  727. }
  728. //---------------------------------------------------------------------------
  729. bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
  730. {
  731. switch (ResumeSupport)
  732. {
  733. case rsOn: return true;
  734. case rsOff: return false;
  735. case rsSmart: return (Size >= ResumeThreshold);
  736. default: DebugFail(); return false;
  737. }
  738. }
  739. //---------------------------------------------------------------------------
  740. bool __fastcall TCopyParamType::AllowAnyTransfer() const
  741. {
  742. return
  743. IncludeFileMask.Masks.IsEmpty() &&
  744. !ExcludeHiddenFiles &&
  745. !ExcludeEmptyDirectories &&
  746. ((FTransferSkipList.get() == NULL) || (FTransferSkipList->Count == 0)) &&
  747. FTransferResumeFile.IsEmpty();
  748. }
  749. //---------------------------------------------------------------------------
  750. bool __fastcall TCopyParamType::AllowTransfer(UnicodeString FileName,
  751. TOperationSide Side, bool Directory, const TFileMasks::TParams & Params, bool Hidden) const
  752. {
  753. bool Result = true;
  754. if (Hidden && ExcludeHiddenFiles)
  755. {
  756. Result = false;
  757. }
  758. else if (!IncludeFileMask.Masks.IsEmpty())
  759. {
  760. Result = IncludeFileMask.Matches(FileName, (Side == osLocal),
  761. Directory, &Params);
  762. }
  763. return Result;
  764. }
  765. //---------------------------------------------------------------------------
  766. bool __fastcall TCopyParamType::SkipTransfer(
  767. UnicodeString FileName, bool Directory) const
  768. {
  769. bool Result = false;
  770. // we deliberatelly do not filter directories, as path is added to resume list
  771. // when a transfer of file or directory is started,
  772. // so for directories we need to recurse and check every single file
  773. if (!Directory && (FTransferSkipList.get() != NULL))
  774. {
  775. Result = (FTransferSkipList->IndexOf(FileName) >= 0);
  776. }
  777. return Result;
  778. }
  779. //---------------------------------------------------------------------------
  780. bool __fastcall TCopyParamType::ResumeTransfer(UnicodeString FileName) const
  781. {
  782. // Returning true has the same effect as cpResume
  783. return
  784. (FileName == FTransferResumeFile) &&
  785. DebugAlwaysTrue(!FTransferResumeFile.IsEmpty());
  786. }
  787. //---------------------------------------------------------------------------
  788. TStrings * __fastcall TCopyParamType::GetTransferSkipList() const
  789. {
  790. return FTransferSkipList.get();
  791. }
  792. //---------------------------------------------------------------------------
  793. void __fastcall TCopyParamType::SetTransferSkipList(TStrings * value)
  794. {
  795. if ((value == NULL) || (value->Count == 0))
  796. {
  797. FTransferSkipList.reset(NULL);
  798. }
  799. else
  800. {
  801. FTransferSkipList.reset(new TStringList());
  802. FTransferSkipList->AddStrings(value);
  803. FTransferSkipList->Sorted = true;
  804. }
  805. }
  806. //---------------------------------------------------------------------------
  807. void __fastcall TCopyParamType::Load(THierarchicalStorage * Storage)
  808. {
  809. AddXToDirectories = Storage->ReadBool(L"AddXToDirectories", AddXToDirectories);
  810. AsciiFileMask.Masks = Storage->ReadString(L"Masks", AsciiFileMask.Masks);
  811. FileNameCase = (TFileNameCase)Storage->ReadInteger(L"FileNameCase", FileNameCase);
  812. PreserveReadOnly = Storage->ReadBool(L"PreserveReadOnly", PreserveReadOnly);
  813. PreserveTime = Storage->ReadBool(L"PreserveTime", PreserveTime);
  814. PreserveTimeDirs = Storage->ReadBool(L"PreserveTimeDirs", PreserveTimeDirs);
  815. PreserveRights = Storage->ReadBool(L"PreserveRights", PreserveRights);
  816. IgnorePermErrors = Storage->ReadBool(L"IgnorePermErrors", IgnorePermErrors);
  817. Rights.Text = Storage->ReadString(L"Text", Rights.Text);
  818. TransferMode = (TTransferMode)Storage->ReadInteger(L"TransferMode", TransferMode);
  819. ResumeSupport = (TResumeSupport)Storage->ReadInteger(L"ResumeSupport", ResumeSupport);
  820. ResumeThreshold = Storage->ReadInt64(L"ResumeThreshold", ResumeThreshold);
  821. InvalidCharsReplacement = (wchar_t)Storage->ReadInteger(L"ReplaceInvalidChars",
  822. (unsigned int)InvalidCharsReplacement);
  823. LocalInvalidChars = Storage->ReadString(L"LocalInvalidChars", LocalInvalidChars);
  824. CalculateSize = Storage->ReadBool(L"CalculateSize", CalculateSize);
  825. if (Storage->ValueExists(L"IncludeFileMask"))
  826. {
  827. IncludeFileMask.Masks = Storage->ReadString(L"IncludeFileMask", IncludeFileMask.Masks);
  828. }
  829. else if (Storage->ValueExists(L"ExcludeFileMask"))
  830. {
  831. UnicodeString ExcludeFileMask = Storage->ReadString(L"ExcludeFileMask", L"");
  832. if (!ExcludeFileMask.IsEmpty())
  833. {
  834. bool NegativeExclude = Storage->ReadBool(L"NegativeExclude", false);
  835. if (NegativeExclude)
  836. {
  837. IncludeFileMask.Masks = ExcludeFileMask;
  838. }
  839. // convert at least simple cases to new format
  840. else if (ExcludeFileMask.Pos(IncludeExcludeFileMasksDelimiter) == 0)
  841. {
  842. IncludeFileMask.Masks = UnicodeString(IncludeExcludeFileMasksDelimiter) + ExcludeFileMask;
  843. }
  844. }
  845. }
  846. TransferSkipList = NULL;
  847. TransferResumeFile = L"";
  848. ClearArchive = Storage->ReadBool(L"ClearArchive", ClearArchive);
  849. RemoveCtrlZ = Storage->ReadBool(L"RemoveCtrlZ", RemoveCtrlZ);
  850. RemoveBOM = Storage->ReadBool(L"RemoveBOM", RemoveBOM);
  851. CPSLimit = Storage->ReadInteger(L"CPSLimit", CPSLimit);
  852. NewerOnly = Storage->ReadBool(L"NewerOnly", NewerOnly);
  853. EncryptNewFiles = Storage->ReadBool(L"EncryptNewFiles", EncryptNewFiles);
  854. ExcludeHiddenFiles = Storage->ReadBool(L"ExcludeHiddenFiles", ExcludeHiddenFiles);
  855. ExcludeEmptyDirectories = Storage->ReadBool(L"ExcludeEmptyDirectories", ExcludeEmptyDirectories);
  856. Size = -1;
  857. OnceDoneOperation = odoIdle;
  858. }
  859. //---------------------------------------------------------------------------
  860. void __fastcall TCopyParamType::Save(THierarchicalStorage * Storage, const TCopyParamType * Defaults) const
  861. {
  862. // Same as in TSessionData::DoSave
  863. #define WRITE_DATA_EX(TYPE, NAME, PROPERTY, CONV) \
  864. if ((Defaults != NULL) && (CONV(Defaults->PROPERTY) == CONV(PROPERTY))) \
  865. { \
  866. Storage->DeleteValue(NAME); \
  867. } \
  868. else \
  869. { \
  870. Storage->Write ## TYPE(NAME, CONV(PROPERTY)); \
  871. }
  872. #define WRITE_DATA_CONV(TYPE, NAME, PROPERTY) WRITE_DATA_EX(TYPE, NAME, PROPERTY, WRITE_DATA_CONV_FUNC)
  873. #define WRITE_DATA(TYPE, PROPERTY) WRITE_DATA_EX(TYPE, TEXT(#PROPERTY), PROPERTY, )
  874. WRITE_DATA(Bool, AddXToDirectories);
  875. WRITE_DATA_EX(String, L"Masks", AsciiFileMask.Masks, );
  876. WRITE_DATA(Integer, FileNameCase);
  877. WRITE_DATA(Bool, PreserveReadOnly);
  878. WRITE_DATA(Bool, PreserveTime);
  879. WRITE_DATA(Bool, PreserveTimeDirs);
  880. WRITE_DATA(Bool, PreserveRights);
  881. WRITE_DATA(Bool, IgnorePermErrors);
  882. WRITE_DATA_EX(String, L"Text", Rights.Text, );
  883. WRITE_DATA(Integer, TransferMode);
  884. WRITE_DATA(Integer, ResumeSupport);
  885. WRITE_DATA(Int64, ResumeThreshold);
  886. #define WRITE_DATA_CONV_FUNC(X) (unsigned int)(X)
  887. WRITE_DATA_CONV(Integer, L"ReplaceInvalidChars", InvalidCharsReplacement);
  888. WRITE_DATA(String, LocalInvalidChars);
  889. WRITE_DATA(Bool, CalculateSize);
  890. WRITE_DATA_EX(String, L"IncludeFileMask", IncludeFileMask.Masks, );
  891. Storage->DeleteValue(L"ExcludeFileMask"); // obsolete
  892. Storage->DeleteValue(L"NegativeExclude"); // obsolete
  893. DebugAssert(FTransferSkipList.get() == NULL);
  894. DebugAssert(FTransferResumeFile.IsEmpty());
  895. WRITE_DATA(Bool, ClearArchive);
  896. WRITE_DATA(Bool, RemoveCtrlZ);
  897. WRITE_DATA(Bool, RemoveBOM);
  898. WRITE_DATA(Integer, CPSLimit);
  899. WRITE_DATA(Bool, NewerOnly);
  900. WRITE_DATA(Bool, EncryptNewFiles);
  901. WRITE_DATA(Bool, ExcludeHiddenFiles);
  902. WRITE_DATA(Bool, ExcludeEmptyDirectories);
  903. DebugAssert(Size < 0);
  904. DebugAssert(OnceDoneOperation == odoIdle);
  905. }
  906. //---------------------------------------------------------------------------
  907. #define C(Property) (Property == rhp.Property)
  908. bool __fastcall TCopyParamType::operator==(const TCopyParamType & rhp) const
  909. {
  910. DebugAssert(FTransferSkipList.get() == NULL);
  911. DebugAssert(FTransferResumeFile.IsEmpty());
  912. DebugAssert(rhp.FTransferSkipList.get() == NULL);
  913. DebugAssert(rhp.FTransferResumeFile.IsEmpty());
  914. return
  915. C(AddXToDirectories) &&
  916. C(AsciiFileMask) &&
  917. C(FileNameCase) &&
  918. C(PreserveReadOnly) &&
  919. C(PreserveTime) &&
  920. C(PreserveTimeDirs) &&
  921. C(PreserveRights) &&
  922. C(IgnorePermErrors) &&
  923. C(Rights) &&
  924. C(TransferMode) &&
  925. C(ResumeSupport) &&
  926. C(ResumeThreshold) &&
  927. C(InvalidCharsReplacement) &&
  928. C(LocalInvalidChars) &&
  929. C(CalculateSize) &&
  930. C(IncludeFileMask) &&
  931. C(ClearArchive) &&
  932. C(RemoveCtrlZ) &&
  933. C(RemoveBOM) &&
  934. C(CPSLimit) &&
  935. C(NewerOnly) &&
  936. C(EncryptNewFiles) &&
  937. C(ExcludeHiddenFiles) &&
  938. C(ExcludeEmptyDirectories) &&
  939. C(Size) &&
  940. C(OnceDoneOperation) &&
  941. true;
  942. }
  943. #undef C
  944. //---------------------------------------------------------------------------
  945. const unsigned long MinSpeed = 8 * 1024;
  946. const unsigned long MaxSpeed = 8 * 1024 * 1024;
  947. //---------------------------------------------------------------------------
  948. static bool __fastcall TryGetSpeedLimit(const UnicodeString & Text, unsigned long & Speed)
  949. {
  950. bool Result;
  951. if (AnsiSameText(Text, LoadStr(SPEED_UNLIMITED)))
  952. {
  953. Speed = 0;
  954. Result = true;
  955. }
  956. else
  957. {
  958. int SSpeed;
  959. Result = TryStrToInt(Text, SSpeed) && (SSpeed >= 0);
  960. if (Result)
  961. {
  962. Speed = SSpeed * 1024;
  963. }
  964. }
  965. return Result;
  966. }
  967. //---------------------------------------------------------------------------
  968. unsigned long __fastcall GetSpeedLimit(const UnicodeString & Text)
  969. {
  970. unsigned long Speed;
  971. if (!TryGetSpeedLimit(Text, Speed))
  972. {
  973. throw Exception(FMTLOAD(SPEED_INVALID, (Text)));
  974. }
  975. return Speed;
  976. }
  977. //---------------------------------------------------------------------------
  978. UnicodeString __fastcall SetSpeedLimit(unsigned long Limit)
  979. {
  980. UnicodeString Text;
  981. if (Limit == 0)
  982. {
  983. Text = LoadStr(SPEED_UNLIMITED);
  984. }
  985. else
  986. {
  987. Text = IntToStr(int(Limit / 1024));
  988. }
  989. return Text;
  990. }
  991. //---------------------------------------------------------------------------
  992. void __fastcall CopySpeedLimits(TStrings * Source, TStrings * Dest)
  993. {
  994. std::unique_ptr<TStringList> Temp(new TStringList());
  995. bool Unlimited = false;
  996. for (int Index = 0; Index < Source->Count; Index++)
  997. {
  998. UnicodeString Text = Source->Strings[Index];
  999. unsigned long Speed;
  1000. bool Valid = TryGetSpeedLimit(Text, Speed);
  1001. if ((!Valid || (Speed == 0)) && !Unlimited)
  1002. {
  1003. Temp->Add(LoadStr(SPEED_UNLIMITED));
  1004. Unlimited = true;
  1005. }
  1006. else if (Valid && (Speed > 0))
  1007. {
  1008. Temp->Add(Text);
  1009. }
  1010. }
  1011. if (!Unlimited)
  1012. {
  1013. Temp->Insert(0, LoadStr(SPEED_UNLIMITED));
  1014. }
  1015. Dest->Assign(Temp.get());
  1016. }
  1017. //---------------------------------------------------------------------------
  1018. TOperationSide ReverseOperationSide(TOperationSide Side)
  1019. {
  1020. TOperationSide Result;
  1021. switch (Side)
  1022. {
  1023. case osLocal:
  1024. Result = osRemote;
  1025. break;
  1026. case osRemote:
  1027. Result = osLocal;
  1028. break;
  1029. default:
  1030. case osCurrent:
  1031. DebugFail();
  1032. Result = Side;
  1033. break;
  1034. }
  1035. return Result;
  1036. }