CopyParam.cpp 36 KB

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