CopyParam.cpp 36 KB

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