CopyParam.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. DebugFail(); // should never get here
  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. #undef COPY
  535. }
  536. //---------------------------------------------------------------------------
  537. TCopyParamType & __fastcall TCopyParamType::operator =(const TCopyParamType & rhp)
  538. {
  539. Assign(&rhp);
  540. return *this;
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TCopyParamType::SetLocalInvalidChars(UnicodeString value)
  544. {
  545. if (value != LocalInvalidChars)
  546. {
  547. FLocalInvalidChars = value;
  548. FTokenizibleChars = FLocalInvalidChars + TokenPrefix;
  549. }
  550. }
  551. //---------------------------------------------------------------------------
  552. bool __fastcall TCopyParamType::GetReplaceInvalidChars() const
  553. {
  554. return (InvalidCharsReplacement != NoReplacement);
  555. }
  556. //---------------------------------------------------------------------------
  557. void __fastcall TCopyParamType::SetReplaceInvalidChars(bool value)
  558. {
  559. if (ReplaceInvalidChars != value)
  560. {
  561. InvalidCharsReplacement = (value ? TokenReplacement : NoReplacement);
  562. }
  563. }
  564. //---------------------------------------------------------------------------
  565. UnicodeString __fastcall TCopyParamType::ValidLocalFileName(UnicodeString FileName) const
  566. {
  567. return ::ValidLocalFileName(FileName, InvalidCharsReplacement, FTokenizibleChars, LocalInvalidChars);
  568. }
  569. //---------------------------------------------------------------------------
  570. UnicodeString __fastcall TCopyParamType::RestoreChars(UnicodeString FileName) const
  571. {
  572. if (InvalidCharsReplacement == TokenReplacement)
  573. {
  574. wchar_t * InvalidChar = FileName.c_str();
  575. while ((InvalidChar = wcschr(InvalidChar, TokenPrefix)) != NULL)
  576. {
  577. int Index = InvalidChar - FileName.c_str() + 1;
  578. if (FileName.Length() >= Index + 2)
  579. {
  580. UnicodeString Hex = FileName.SubString(Index + 1, 2);
  581. wchar_t Char = static_cast<wchar_t>(HexToByte(Hex));
  582. if ((Char != L'\0') &&
  583. ((FTokenizibleChars.Pos(Char) > 0) ||
  584. (((Char == L' ') || (Char == L'.')) && (Index == FileName.Length() - 2))))
  585. {
  586. FileName[Index] = Char;
  587. FileName.Delete(Index + 1, 2);
  588. InvalidChar = FileName.c_str() + Index;
  589. }
  590. else if ((Hex == L"00") &&
  591. ((Index == FileName.Length() - 2) || (FileName[Index + 3] == L'.')) &&
  592. IsReservedName(FileName.SubString(1, Index - 1) + FileName.SubString(Index + 3, FileName.Length() - Index - 3 + 1)))
  593. {
  594. FileName.Delete(Index, 3);
  595. InvalidChar = FileName.c_str() + Index - 1;
  596. }
  597. else
  598. {
  599. InvalidChar++;
  600. }
  601. }
  602. else
  603. {
  604. InvalidChar++;
  605. }
  606. }
  607. }
  608. return FileName;
  609. }
  610. //---------------------------------------------------------------------------
  611. UnicodeString __fastcall TCopyParamType::ValidLocalPath(UnicodeString Path) const
  612. {
  613. UnicodeString Result;
  614. while (!Path.IsEmpty())
  615. {
  616. if (!Result.IsEmpty())
  617. {
  618. Result += L"\\";
  619. }
  620. Result += ValidLocalFileName(CutToChar(Path, L'\\', false));
  621. }
  622. return Result;
  623. }
  624. //---------------------------------------------------------------------------
  625. UnicodeString __fastcall TCopyParamType::ChangeFileName(UnicodeString FileName,
  626. TOperationSide Side, bool FirstLevel) const
  627. {
  628. if (FirstLevel)
  629. {
  630. FileName = MaskFileName(FileName, FileMask);
  631. }
  632. switch (FileNameCase) {
  633. case ncUpperCase: FileName = FileName.UpperCase(); break;
  634. case ncLowerCase: FileName = FileName.LowerCase(); break;
  635. case ncFirstUpperCase: FileName = FileName.SubString(1, 1).UpperCase() +
  636. FileName.SubString(2, FileName.Length()-1).LowerCase(); break;
  637. case ncLowerCaseShort:
  638. if ((FileName.Length() <= 12) && (FileName.Pos(L".") <= 9) &&
  639. (FileName == FileName.UpperCase()))
  640. {
  641. FileName = FileName.LowerCase();
  642. }
  643. break;
  644. case ncNoChange:
  645. default:
  646. /*nothing*/
  647. break;
  648. }
  649. if (Side == osRemote)
  650. {
  651. FileName = ValidLocalFileName(FileName);
  652. }
  653. else
  654. {
  655. FileName = RestoreChars(FileName);
  656. }
  657. return FileName;
  658. }
  659. //---------------------------------------------------------------------------
  660. bool __fastcall TCopyParamType::UseAsciiTransfer(UnicodeString FileName,
  661. TOperationSide Side, const TFileMasks::TParams & Params) const
  662. {
  663. switch (TransferMode)
  664. {
  665. case tmBinary: return false;
  666. case tmAscii: return true;
  667. case tmAutomatic: return AsciiFileMask.Matches(FileName, (Side == osLocal),
  668. false, &Params);
  669. default: DebugFail(); return false;
  670. }
  671. }
  672. //---------------------------------------------------------------------------
  673. TRights __fastcall TCopyParamType::RemoteFileRights(Integer Attrs) const
  674. {
  675. TRights R = Rights;
  676. if ((Attrs & faDirectory) && AddXToDirectories)
  677. R.AddExecute();
  678. return R;
  679. }
  680. //---------------------------------------------------------------------------
  681. UnicodeString __fastcall TCopyParamType::GetLogStr() const
  682. {
  683. wchar_t CaseC[] = L"NULFS";
  684. wchar_t ModeC[] = L"BAM";
  685. wchar_t ResumeC[] = L"YSN";
  686. // OpenArray (ARRAYOFCONST) supports only up to 19 arguments, so we had to split it
  687. return
  688. FORMAT(
  689. L" PrTime: %s%s; PrRO: %s; Rght: %s; PrR: %s (%s); FnCs: %s; RIC: %s; "
  690. "Resume: %s (%d); CalcS: %s; Mask: %s\n",
  691. (BooleanToEngStr(PreserveTime),
  692. UnicodeString(PreserveTime && PreserveTimeDirs ? L"+Dirs" : L""),
  693. BooleanToEngStr(PreserveReadOnly),
  694. Rights.Text,
  695. BooleanToEngStr(PreserveRights),
  696. BooleanToEngStr(IgnorePermErrors),
  697. CaseC[FileNameCase],
  698. CharToHex(InvalidCharsReplacement),
  699. ResumeC[ResumeSupport],
  700. (int)ResumeThreshold,
  701. BooleanToEngStr(CalculateSize),
  702. FileMask)) +
  703. FORMAT(
  704. L" TM: %s; ClAr: %s; RemEOF: %s; RemBOM: %s; CPS: %u; NewerOnly: %s; EncryptNewFiles: %s; ExcludeHiddenFiles: %s; ExcludeEmptyDirectories: %s; InclM: %s; ResumeL: %d\n"
  705. " AscM: %s\n",
  706. (ModeC[TransferMode],
  707. BooleanToEngStr(ClearArchive),
  708. BooleanToEngStr(RemoveCtrlZ),
  709. BooleanToEngStr(RemoveBOM),
  710. int(CPSLimit),
  711. BooleanToEngStr(NewerOnly),
  712. BooleanToEngStr(EncryptNewFiles),
  713. BooleanToEngStr(ExcludeHiddenFiles),
  714. BooleanToEngStr(ExcludeEmptyDirectories),
  715. IncludeFileMask.Masks,
  716. ((FTransferSkipList.get() != NULL) ? FTransferSkipList->Count : 0) + (!FTransferResumeFile.IsEmpty() ? 1 : 0),
  717. AsciiFileMask.Masks));
  718. }
  719. //---------------------------------------------------------------------------
  720. int __fastcall TCopyParamType::LocalFileAttrs(const TRights & Rights) const
  721. {
  722. int Result = 0;
  723. if (PreserveReadOnly && !Rights.Right[TRights::rrUserWrite])
  724. {
  725. Result |= faReadOnly;
  726. }
  727. return Result;
  728. }
  729. //---------------------------------------------------------------------------
  730. bool __fastcall TCopyParamType::AllowResume(__int64 Size) const
  731. {
  732. switch (ResumeSupport)
  733. {
  734. case rsOn: return true;
  735. case rsOff: return false;
  736. case rsSmart: return (Size >= ResumeThreshold);
  737. default: DebugFail(); return false;
  738. }
  739. }
  740. //---------------------------------------------------------------------------
  741. bool __fastcall TCopyParamType::AllowAnyTransfer() const
  742. {
  743. return
  744. IncludeFileMask.Masks.IsEmpty() &&
  745. !ExcludeHiddenFiles &&
  746. !ExcludeEmptyDirectories &&
  747. ((FTransferSkipList.get() == NULL) || (FTransferSkipList->Count == 0)) &&
  748. FTransferResumeFile.IsEmpty();
  749. }
  750. //---------------------------------------------------------------------------
  751. bool __fastcall TCopyParamType::AllowTransfer(UnicodeString FileName,
  752. TOperationSide Side, bool Directory, const TFileMasks::TParams & Params, bool Hidden) const
  753. {
  754. bool Result = true;
  755. if (Hidden && ExcludeHiddenFiles)
  756. {
  757. Result = false;
  758. }
  759. else if (!IncludeFileMask.Masks.IsEmpty())
  760. {
  761. Result = IncludeFileMask.Matches(FileName, (Side == osLocal),
  762. Directory, &Params);
  763. }
  764. return Result;
  765. }
  766. //---------------------------------------------------------------------------
  767. bool __fastcall TCopyParamType::SkipTransfer(
  768. UnicodeString FileName, bool Directory) const
  769. {
  770. bool Result = false;
  771. // we deliberatelly do not filter directories, as path is added to resume list
  772. // when a transfer of file or directory is started,
  773. // so for directories we need to recurse and check every single file
  774. if (!Directory && (FTransferSkipList.get() != NULL))
  775. {
  776. Result = (FTransferSkipList->IndexOf(FileName) >= 0);
  777. }
  778. return Result;
  779. }
  780. //---------------------------------------------------------------------------
  781. bool __fastcall TCopyParamType::ResumeTransfer(UnicodeString FileName) const
  782. {
  783. // Returning true has the same effect as cpResume
  784. return
  785. (FileName == FTransferResumeFile) &&
  786. DebugAlwaysTrue(!FTransferResumeFile.IsEmpty());
  787. }
  788. //---------------------------------------------------------------------------
  789. TStrings * __fastcall TCopyParamType::GetTransferSkipList() const
  790. {
  791. return FTransferSkipList.get();
  792. }
  793. //---------------------------------------------------------------------------
  794. void __fastcall TCopyParamType::SetTransferSkipList(TStrings * value)
  795. {
  796. if ((value == NULL) || (value->Count == 0))
  797. {
  798. FTransferSkipList.reset(NULL);
  799. }
  800. else
  801. {
  802. FTransferSkipList.reset(new TStringList());
  803. FTransferSkipList->AddStrings(value);
  804. FTransferSkipList->Sorted = true;
  805. }
  806. }
  807. //---------------------------------------------------------------------------
  808. void __fastcall TCopyParamType::Load(THierarchicalStorage * Storage)
  809. {
  810. AddXToDirectories = Storage->ReadBool(L"AddXToDirectories", AddXToDirectories);
  811. AsciiFileMask.Masks = Storage->ReadString(L"Masks", AsciiFileMask.Masks);
  812. FileNameCase = (TFileNameCase)Storage->ReadInteger(L"FileNameCase", FileNameCase);
  813. PreserveReadOnly = Storage->ReadBool(L"PreserveReadOnly", PreserveReadOnly);
  814. PreserveTime = Storage->ReadBool(L"PreserveTime", PreserveTime);
  815. PreserveTimeDirs = Storage->ReadBool(L"PreserveTimeDirs", PreserveTimeDirs);
  816. PreserveRights = Storage->ReadBool(L"PreserveRights", PreserveRights);
  817. IgnorePermErrors = Storage->ReadBool(L"IgnorePermErrors", IgnorePermErrors);
  818. Rights.Text = Storage->ReadString(L"Text", Rights.Text);
  819. TransferMode = (TTransferMode)Storage->ReadInteger(L"TransferMode", TransferMode);
  820. ResumeSupport = (TResumeSupport)Storage->ReadInteger(L"ResumeSupport", ResumeSupport);
  821. ResumeThreshold = Storage->ReadInt64(L"ResumeThreshold", ResumeThreshold);
  822. InvalidCharsReplacement = (wchar_t)Storage->ReadInteger(L"ReplaceInvalidChars",
  823. (unsigned int)InvalidCharsReplacement);
  824. LocalInvalidChars = Storage->ReadString(L"LocalInvalidChars", LocalInvalidChars);
  825. CalculateSize = Storage->ReadBool(L"CalculateSize", CalculateSize);
  826. if (Storage->ValueExists(L"IncludeFileMask"))
  827. {
  828. IncludeFileMask.Masks = Storage->ReadString(L"IncludeFileMask", IncludeFileMask.Masks);
  829. }
  830. else if (Storage->ValueExists(L"ExcludeFileMask"))
  831. {
  832. UnicodeString ExcludeFileMask = Storage->ReadString(L"ExcludeFileMask", L"");
  833. if (!ExcludeFileMask.IsEmpty())
  834. {
  835. bool NegativeExclude = Storage->ReadBool(L"NegativeExclude", false);
  836. if (NegativeExclude)
  837. {
  838. IncludeFileMask.Masks = ExcludeFileMask;
  839. }
  840. // convert at least simple cases to new format
  841. else if (ExcludeFileMask.Pos(IncludeExcludeFileMasksDelimiter) == 0)
  842. {
  843. IncludeFileMask.Masks = UnicodeString(IncludeExcludeFileMasksDelimiter) + ExcludeFileMask;
  844. }
  845. }
  846. }
  847. TransferSkipList = NULL;
  848. TransferResumeFile = L"";
  849. ClearArchive = Storage->ReadBool(L"ClearArchive", ClearArchive);
  850. RemoveCtrlZ = Storage->ReadBool(L"RemoveCtrlZ", RemoveCtrlZ);
  851. RemoveBOM = Storage->ReadBool(L"RemoveBOM", RemoveBOM);
  852. CPSLimit = Storage->ReadInteger(L"CPSLimit", CPSLimit);
  853. NewerOnly = Storage->ReadBool(L"NewerOnly", NewerOnly);
  854. EncryptNewFiles = Storage->ReadBool(L"EncryptNewFiles", EncryptNewFiles);
  855. ExcludeHiddenFiles = Storage->ReadBool(L"ExcludeHiddenFiles", ExcludeHiddenFiles);
  856. ExcludeEmptyDirectories = Storage->ReadBool(L"ExcludeEmptyDirectories", ExcludeEmptyDirectories);
  857. Size = -1;
  858. OnceDoneOperation = odoIdle;
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TCopyParamType::Save(THierarchicalStorage * Storage, const TCopyParamType * Defaults) const
  862. {
  863. // Same as in TSessionData::DoSave
  864. #define WRITE_DATA_EX(TYPE, NAME, PROPERTY, CONV) \
  865. if ((Defaults != NULL) && (CONV(Defaults->PROPERTY) == CONV(PROPERTY))) \
  866. { \
  867. Storage->DeleteValue(NAME); \
  868. } \
  869. else \
  870. { \
  871. Storage->Write ## TYPE(NAME, CONV(PROPERTY)); \
  872. }
  873. #define WRITE_DATA_CONV(TYPE, NAME, PROPERTY) WRITE_DATA_EX(TYPE, NAME, PROPERTY, WRITE_DATA_CONV_FUNC)
  874. #define WRITE_DATA(TYPE, PROPERTY) WRITE_DATA_EX(TYPE, TEXT(#PROPERTY), PROPERTY, )
  875. WRITE_DATA(Bool, AddXToDirectories);
  876. WRITE_DATA_EX(String, L"Masks", AsciiFileMask.Masks, );
  877. WRITE_DATA(Integer, FileNameCase);
  878. WRITE_DATA(Bool, PreserveReadOnly);
  879. WRITE_DATA(Bool, PreserveTime);
  880. WRITE_DATA(Bool, PreserveTimeDirs);
  881. WRITE_DATA(Bool, PreserveRights);
  882. WRITE_DATA(Bool, IgnorePermErrors);
  883. WRITE_DATA_EX(String, L"Text", Rights.Text, );
  884. WRITE_DATA(Integer, TransferMode);
  885. WRITE_DATA(Integer, ResumeSupport);
  886. WRITE_DATA(Int64, ResumeThreshold);
  887. #define WRITE_DATA_CONV_FUNC(X) (unsigned int)(X)
  888. WRITE_DATA_CONV(Integer, L"ReplaceInvalidChars", InvalidCharsReplacement);
  889. WRITE_DATA(String, LocalInvalidChars);
  890. WRITE_DATA(Bool, CalculateSize);
  891. WRITE_DATA_EX(String, L"IncludeFileMask", IncludeFileMask.Masks, );
  892. Storage->DeleteValue(L"ExcludeFileMask"); // obsolete
  893. Storage->DeleteValue(L"NegativeExclude"); // obsolete
  894. DebugAssert(FTransferSkipList.get() == NULL);
  895. DebugAssert(FTransferResumeFile.IsEmpty());
  896. WRITE_DATA(Bool, ClearArchive);
  897. WRITE_DATA(Bool, RemoveCtrlZ);
  898. WRITE_DATA(Bool, RemoveBOM);
  899. WRITE_DATA(Integer, CPSLimit);
  900. WRITE_DATA(Bool, NewerOnly);
  901. WRITE_DATA(Bool, EncryptNewFiles);
  902. WRITE_DATA(Bool, ExcludeHiddenFiles);
  903. WRITE_DATA(Bool, ExcludeEmptyDirectories);
  904. DebugAssert(Size < 0);
  905. DebugAssert(OnceDoneOperation == odoIdle);
  906. }
  907. //---------------------------------------------------------------------------
  908. #define C(Property) (Property == rhp.Property)
  909. bool __fastcall TCopyParamType::operator==(const TCopyParamType & rhp) const
  910. {
  911. DebugAssert(FTransferSkipList.get() == NULL);
  912. DebugAssert(FTransferResumeFile.IsEmpty());
  913. DebugAssert(rhp.FTransferSkipList.get() == NULL);
  914. DebugAssert(rhp.FTransferResumeFile.IsEmpty());
  915. return
  916. C(AddXToDirectories) &&
  917. C(AsciiFileMask) &&
  918. C(FileNameCase) &&
  919. C(PreserveReadOnly) &&
  920. C(PreserveTime) &&
  921. C(PreserveTimeDirs) &&
  922. C(PreserveRights) &&
  923. C(IgnorePermErrors) &&
  924. C(Rights) &&
  925. C(TransferMode) &&
  926. C(ResumeSupport) &&
  927. C(ResumeThreshold) &&
  928. C(InvalidCharsReplacement) &&
  929. C(LocalInvalidChars) &&
  930. C(CalculateSize) &&
  931. C(IncludeFileMask) &&
  932. C(ClearArchive) &&
  933. C(RemoveCtrlZ) &&
  934. C(RemoveBOM) &&
  935. C(CPSLimit) &&
  936. C(NewerOnly) &&
  937. C(EncryptNewFiles) &&
  938. C(ExcludeHiddenFiles) &&
  939. C(ExcludeEmptyDirectories) &&
  940. C(Size) &&
  941. C(OnceDoneOperation) &&
  942. true;
  943. }
  944. #undef C
  945. //---------------------------------------------------------------------------
  946. const unsigned long MinSpeed = 8 * 1024;
  947. const unsigned long MaxSpeed = 8 * 1024 * 1024;
  948. //---------------------------------------------------------------------------
  949. static bool __fastcall TryGetSpeedLimit(const UnicodeString & Text, unsigned long & Speed)
  950. {
  951. bool Result;
  952. if (AnsiSameText(Text, LoadStr(SPEED_UNLIMITED)))
  953. {
  954. Speed = 0;
  955. Result = true;
  956. }
  957. else
  958. {
  959. int SSpeed;
  960. Result = TryStrToInt(Text, SSpeed) && (SSpeed >= 0);
  961. if (Result)
  962. {
  963. Speed = SSpeed * 1024;
  964. }
  965. }
  966. return Result;
  967. }
  968. //---------------------------------------------------------------------------
  969. unsigned long __fastcall GetSpeedLimit(const UnicodeString & Text)
  970. {
  971. unsigned long Speed;
  972. if (!TryGetSpeedLimit(Text, Speed))
  973. {
  974. throw Exception(FMTLOAD(SPEED_INVALID, (Text)));
  975. }
  976. return Speed;
  977. }
  978. //---------------------------------------------------------------------------
  979. UnicodeString __fastcall SetSpeedLimit(unsigned long Limit)
  980. {
  981. UnicodeString Text;
  982. if (Limit == 0)
  983. {
  984. Text = LoadStr(SPEED_UNLIMITED);
  985. }
  986. else
  987. {
  988. Text = IntToStr(int(Limit / 1024));
  989. }
  990. return Text;
  991. }
  992. //---------------------------------------------------------------------------
  993. void __fastcall CopySpeedLimits(TStrings * Source, TStrings * Dest)
  994. {
  995. std::unique_ptr<TStringList> Temp(new TStringList());
  996. bool Unlimited = false;
  997. for (int Index = 0; Index < Source->Count; Index++)
  998. {
  999. UnicodeString Text = Source->Strings[Index];
  1000. unsigned long Speed;
  1001. bool Valid = TryGetSpeedLimit(Text, Speed);
  1002. if ((!Valid || (Speed == 0)) && !Unlimited)
  1003. {
  1004. Temp->Add(LoadStr(SPEED_UNLIMITED));
  1005. Unlimited = true;
  1006. }
  1007. else if (Valid && (Speed > 0))
  1008. {
  1009. Temp->Add(Text);
  1010. }
  1011. }
  1012. if (!Unlimited)
  1013. {
  1014. Temp->Insert(0, LoadStr(SPEED_UNLIMITED));
  1015. }
  1016. Dest->Assign(Temp.get());
  1017. }
  1018. //---------------------------------------------------------------------------
  1019. TOperationSide ReverseOperationSide(TOperationSide Side)
  1020. {
  1021. TOperationSide Result;
  1022. switch (Side)
  1023. {
  1024. case osLocal:
  1025. Result = osRemote;
  1026. break;
  1027. case osRemote:
  1028. Result = osLocal;
  1029. break;
  1030. default:
  1031. case osCurrent:
  1032. DebugFail();
  1033. Result = Side;
  1034. break;
  1035. }
  1036. return Result;
  1037. }