FileMasks.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FileMasks.h"
  5. #include "Common.h"
  6. #include "TextsCore.h"
  7. #include "RemoteFiles.h"
  8. #include "PuttyTools.h"
  9. #include "Terminal.h"
  10. #include <StrUtils.hpp>
  11. //---------------------------------------------------------------------------
  12. extern const wchar_t IncludeExcludeFileMasksDelimiter = L'|';
  13. UnicodeString FileMasksDelimiters = L";,";
  14. static UnicodeString AllFileMasksDelimiters = FileMasksDelimiters + IncludeExcludeFileMasksDelimiter;
  15. static UnicodeString DirectoryMaskDelimiters = L"/\\";
  16. static UnicodeString FileMasksDelimiterStr = UnicodeString(FileMasksDelimiters[1]) + L' ';
  17. //---------------------------------------------------------------------------
  18. __fastcall EFileMasksException::EFileMasksException(
  19. UnicodeString Message, int AErrorStart, int AErrorLen) :
  20. Exception(Message)
  21. {
  22. ErrorStart = AErrorStart;
  23. ErrorLen = AErrorLen;
  24. }
  25. //---------------------------------------------------------------------------
  26. UnicodeString __fastcall MaskFilePart(const UnicodeString Part, const UnicodeString Mask, bool& Masked)
  27. {
  28. UnicodeString Result;
  29. int RestStart = 1;
  30. bool Delim = false;
  31. for (int Index = 1; Index <= Mask.Length(); Index++)
  32. {
  33. switch (Mask[Index])
  34. {
  35. case L'\\':
  36. if (!Delim)
  37. {
  38. Delim = true;
  39. Masked = true;
  40. break;
  41. }
  42. case L'*':
  43. if (!Delim)
  44. {
  45. Result += Part.SubString(RestStart, Part.Length() - RestStart + 1);
  46. RestStart = Part.Length() + 1;
  47. Masked = true;
  48. break;
  49. }
  50. case L'?':
  51. if (!Delim)
  52. {
  53. if (RestStart <= Part.Length())
  54. {
  55. Result += Part[RestStart];
  56. RestStart++;
  57. }
  58. Masked = true;
  59. break;
  60. }
  61. default:
  62. Result += Mask[Index];
  63. RestStart++;
  64. Delim = false;
  65. break;
  66. }
  67. }
  68. return Result;
  69. }
  70. //---------------------------------------------------------------------------
  71. UnicodeString __fastcall MaskFileName(UnicodeString FileName, const UnicodeString Mask)
  72. {
  73. if (IsEffectiveFileNameMask(Mask))
  74. {
  75. bool Masked;
  76. int P = Mask.LastDelimiter(L".");
  77. if (P > 0)
  78. {
  79. int P2 = FileName.LastDelimiter(".");
  80. // only dot at beginning of file name is not considered as
  81. // name/ext separator
  82. UnicodeString FileExt = P2 > 1 ?
  83. FileName.SubString(P2 + 1, FileName.Length() - P2) : UnicodeString();
  84. FileExt = MaskFilePart(FileExt, Mask.SubString(P + 1, Mask.Length() - P), Masked);
  85. if (P2 > 1)
  86. {
  87. FileName.SetLength(P2 - 1);
  88. }
  89. FileName = MaskFilePart(FileName, Mask.SubString(1, P - 1), Masked);
  90. if (!FileExt.IsEmpty())
  91. {
  92. FileName += L"." + FileExt;
  93. }
  94. }
  95. else
  96. {
  97. FileName = MaskFilePart(FileName, Mask, Masked);
  98. }
  99. }
  100. return FileName;
  101. }
  102. //---------------------------------------------------------------------------
  103. bool __fastcall IsFileNameMask(const UnicodeString & Mask)
  104. {
  105. bool Result = Mask.IsEmpty(); // empty mask is the same as *
  106. if (!Result)
  107. {
  108. MaskFilePart(UnicodeString(), Mask, Result);
  109. }
  110. return Result;
  111. }
  112. //---------------------------------------------------------------------------
  113. bool __fastcall IsEffectiveFileNameMask(const UnicodeString & Mask)
  114. {
  115. return !Mask.IsEmpty() && (Mask != L"*") && (Mask != L"*.*");
  116. }
  117. //---------------------------------------------------------------------------
  118. UnicodeString __fastcall DelimitFileNameMask(UnicodeString Mask)
  119. {
  120. for (int i = 1; i <= Mask.Length(); i++)
  121. {
  122. if (wcschr(L"\\*?", Mask[i]) != NULL)
  123. {
  124. Mask.Insert(L"\\", i);
  125. i++;
  126. }
  127. }
  128. return Mask;
  129. }
  130. //---------------------------------------------------------------------------
  131. //---------------------------------------------------------------------------
  132. TFileMasks::TParams::TParams() :
  133. Size(0)
  134. {
  135. }
  136. //---------------------------------------------------------------------------
  137. UnicodeString TFileMasks::TParams::ToString() const
  138. {
  139. return UnicodeString(L"[") + IntToStr(Size) + L"/" + DateTimeToStr(Modification) + L"]";
  140. }
  141. //---------------------------------------------------------------------------
  142. //---------------------------------------------------------------------------
  143. bool __fastcall TFileMasks::IsMask(const UnicodeString Mask)
  144. {
  145. return (Mask.LastDelimiter(L"?*[") > 0);
  146. }
  147. //---------------------------------------------------------------------------
  148. bool __fastcall TFileMasks::IsAnyMask(const UnicodeString & Mask)
  149. {
  150. return Mask.IsEmpty() || (Mask == L"*.*") || (Mask == L"*");
  151. }
  152. //---------------------------------------------------------------------------
  153. UnicodeString __fastcall TFileMasks::NormalizeMask(const UnicodeString & Mask, const UnicodeString & AnyMask)
  154. {
  155. if (IsAnyMask(Mask))
  156. {
  157. return AnyMask;
  158. }
  159. else
  160. {
  161. return Mask;
  162. }
  163. }
  164. //---------------------------------------------------------------------------
  165. UnicodeString __fastcall TFileMasks::ComposeMaskStr(
  166. TStrings * MasksStr, bool Directory)
  167. {
  168. UnicodeString Result;
  169. UnicodeString ResultNoDirMask;
  170. for (int I = 0; I < MasksStr->Count; I++)
  171. {
  172. UnicodeString Str = MasksStr->Strings[I].Trim();
  173. if (!Str.IsEmpty())
  174. {
  175. for (int P = 1; P <= Str.Length(); P++)
  176. {
  177. if (Str.IsDelimiter(AllFileMasksDelimiters, P))
  178. {
  179. Str.Insert(Str[P], P);
  180. P++;
  181. }
  182. }
  183. UnicodeString StrNoDirMask;
  184. if (Directory)
  185. {
  186. StrNoDirMask = Str;
  187. Str = MakeDirectoryMask(Str);
  188. }
  189. else
  190. {
  191. while (Str.IsDelimiter(DirectoryMaskDelimiters, Str.Length()))
  192. {
  193. Str.SetLength(Str.Length() - 1);
  194. }
  195. StrNoDirMask = Str;
  196. }
  197. AddToList(Result, Str, FileMasksDelimiterStr);
  198. AddToList(ResultNoDirMask, StrNoDirMask, FileMasksDelimiterStr);
  199. }
  200. }
  201. // For directories, the above will add slash ay the end of masks,
  202. // breaking size and time masks and thus circumverting their validation.
  203. // This performes as hoc validation to cover the scenario.
  204. // For files this makes no difference, but no harm either
  205. TFileMasks Temp(Directory ? 1 : 0);
  206. Temp = ResultNoDirMask;
  207. return Result;
  208. }
  209. //---------------------------------------------------------------------------
  210. UnicodeString __fastcall TFileMasks::ComposeMaskStr(
  211. TStrings * IncludeFileMasksStr, TStrings * ExcludeFileMasksStr,
  212. TStrings * IncludeDirectoryMasksStr, TStrings * ExcludeDirectoryMasksStr)
  213. {
  214. UnicodeString IncludeMasks = ComposeMaskStr(IncludeFileMasksStr, false);
  215. AddToList(IncludeMasks, ComposeMaskStr(IncludeDirectoryMasksStr, true), FileMasksDelimiterStr);
  216. UnicodeString ExcludeMasks = ComposeMaskStr(ExcludeFileMasksStr, false);
  217. AddToList(ExcludeMasks, ComposeMaskStr(ExcludeDirectoryMasksStr, true), FileMasksDelimiterStr);
  218. UnicodeString Result = IncludeMasks;
  219. if (!ExcludeMasks.IsEmpty())
  220. {
  221. if (!Result.IsEmpty())
  222. {
  223. Result += L' ';
  224. }
  225. Result += UnicodeString(IncludeExcludeFileMasksDelimiter) + L' ' + ExcludeMasks;
  226. }
  227. return Result;
  228. }
  229. //---------------------------------------------------------------------------
  230. __fastcall TFileMasks::TFileMasks()
  231. {
  232. Init();
  233. }
  234. //---------------------------------------------------------------------------
  235. __fastcall TFileMasks::TFileMasks(int ForceDirectoryMasks)
  236. {
  237. Init();
  238. FForceDirectoryMasks = ForceDirectoryMasks;
  239. }
  240. //---------------------------------------------------------------------------
  241. __fastcall TFileMasks::TFileMasks(const TFileMasks & Source)
  242. {
  243. Init();
  244. FForceDirectoryMasks = Source.FForceDirectoryMasks;
  245. SetStr(Source.Masks, false);
  246. }
  247. //---------------------------------------------------------------------------
  248. __fastcall TFileMasks::TFileMasks(const UnicodeString & AMasks)
  249. {
  250. Init();
  251. SetStr(AMasks, false);
  252. }
  253. //---------------------------------------------------------------------------
  254. __fastcall TFileMasks::~TFileMasks()
  255. {
  256. Clear();
  257. }
  258. //---------------------------------------------------------------------------
  259. void __fastcall TFileMasks::Init()
  260. {
  261. FForceDirectoryMasks = -1;
  262. DoInit(false);
  263. }
  264. //---------------------------------------------------------------------------
  265. void __fastcall TFileMasks::DoInit(bool Delete)
  266. {
  267. for (int Index = 0; Index < 4; Index++)
  268. {
  269. if (Delete)
  270. {
  271. delete FMasksStr[Index];
  272. }
  273. FMasksStr[Index] = NULL;
  274. }
  275. }
  276. //---------------------------------------------------------------------------
  277. void __fastcall TFileMasks::Clear()
  278. {
  279. DoInit(true);
  280. for (int Index = 0; Index < 4; Index++)
  281. {
  282. Clear(FMasks[Index]);
  283. }
  284. }
  285. //---------------------------------------------------------------------------
  286. void __fastcall TFileMasks::Clear(TMasks & Masks)
  287. {
  288. TMasks::iterator I = Masks.begin();
  289. while (I != Masks.end())
  290. {
  291. ReleaseMaskMask((*I).FileNameMask);
  292. ReleaseMaskMask((*I).DirectoryMask);
  293. I++;
  294. }
  295. Masks.clear();
  296. }
  297. //---------------------------------------------------------------------------
  298. bool __fastcall TFileMasks::MatchesMasks(const UnicodeString FileName, bool Directory,
  299. const UnicodeString Path, const TParams * Params, const TMasks & Masks, bool Recurse)
  300. {
  301. bool Result = false;
  302. TMasks::const_iterator I = Masks.begin();
  303. while (!Result && (I != Masks.end()))
  304. {
  305. const TMask & Mask = *I;
  306. Result =
  307. MatchesMaskMask(Mask.DirectoryMask, Path) &&
  308. MatchesMaskMask(Mask.FileNameMask, FileName);
  309. if (Result)
  310. {
  311. bool HasSize = (Params != NULL);
  312. switch (Mask.HighSizeMask)
  313. {
  314. case TMask::None:
  315. Result = true;
  316. break;
  317. case TMask::Open:
  318. Result = HasSize && (Params->Size < Mask.HighSize);
  319. break;
  320. case TMask::Close:
  321. Result = HasSize && (Params->Size <= Mask.HighSize);
  322. break;
  323. }
  324. if (Result)
  325. {
  326. switch (Mask.LowSizeMask)
  327. {
  328. case TMask::None:
  329. Result = true;
  330. break;
  331. case TMask::Open:
  332. Result = HasSize && (Params->Size > Mask.LowSize);
  333. break;
  334. case TMask::Close:
  335. Result = HasSize && (Params->Size >= Mask.LowSize);
  336. break;
  337. }
  338. }
  339. bool HasModification = (Params != NULL);
  340. if (Result)
  341. {
  342. switch (Mask.HighModificationMask)
  343. {
  344. case TMask::None:
  345. Result = true;
  346. break;
  347. case TMask::Open:
  348. Result = HasModification && (Params->Modification < Mask.HighModification);
  349. break;
  350. case TMask::Close:
  351. Result = HasModification && (Params->Modification <= Mask.HighModification);
  352. break;
  353. }
  354. }
  355. if (Result)
  356. {
  357. switch (Mask.LowModificationMask)
  358. {
  359. case TMask::None:
  360. Result = true;
  361. break;
  362. case TMask::Open:
  363. Result = HasModification && (Params->Modification > Mask.LowModification);
  364. break;
  365. case TMask::Close:
  366. Result = HasModification && (Params->Modification >= Mask.LowModification);
  367. break;
  368. }
  369. }
  370. }
  371. I++;
  372. }
  373. if (!Result && Directory && !IsUnixRootPath(Path) && Recurse)
  374. {
  375. UnicodeString ParentFileName = UnixExtractFileName(Path);
  376. UnicodeString ParentPath = SimpleUnixExcludeTrailingBackslash(UnixExtractFilePath(Path));
  377. // Pass Params down or not?
  378. // Currently it includes Size/Time only, what is not used for directories.
  379. // So it depends on future use. Possibly we should make a copy
  380. // and pass on only relevant fields.
  381. Result = MatchesMasks(ParentFileName, true, ParentPath, Params, Masks, Recurse);
  382. }
  383. return Result;
  384. }
  385. //---------------------------------------------------------------------------
  386. bool __fastcall TFileMasks::Matches(const UnicodeString FileName, bool Directory,
  387. const UnicodeString Path, const TParams * Params) const
  388. {
  389. bool ImplicitMatch;
  390. return Matches(FileName, Directory, Path, Params, true, ImplicitMatch);
  391. }
  392. //---------------------------------------------------------------------------
  393. bool __fastcall TFileMasks::Matches(const UnicodeString FileName, bool Directory,
  394. const UnicodeString Path, const TParams * Params,
  395. bool RecurseInclude, bool & ImplicitMatch) const
  396. {
  397. bool ImplicitIncludeMatch = FMasks[MASK_INDEX(Directory, true)].empty();
  398. bool ExplicitIncludeMatch = MatchesMasks(FileName, Directory, Path, Params, FMasks[MASK_INDEX(Directory, true)], RecurseInclude);
  399. bool Result =
  400. (ImplicitIncludeMatch || ExplicitIncludeMatch) &&
  401. !MatchesMasks(FileName, Directory, Path, Params, FMasks[MASK_INDEX(Directory, false)], false);
  402. ImplicitMatch =
  403. Result && ImplicitIncludeMatch && !ExplicitIncludeMatch &&
  404. FMasks[MASK_INDEX(Directory, false)].empty();
  405. return Result;
  406. }
  407. //---------------------------------------------------------------------------
  408. bool __fastcall TFileMasks::Matches(const UnicodeString FileName, bool Local,
  409. bool Directory, const TParams * Params) const
  410. {
  411. bool ImplicitMatch;
  412. return Matches(FileName, Local, Directory, Params, true, ImplicitMatch);
  413. }
  414. //---------------------------------------------------------------------------
  415. bool __fastcall TFileMasks::Matches(const UnicodeString FileName, bool Local,
  416. bool Directory, const TParams * Params, bool RecurseInclude, bool & ImplicitMatch) const
  417. {
  418. bool Result;
  419. if (Local)
  420. {
  421. UnicodeString Path = ExtractFilePath(FileName);
  422. if (!Path.IsEmpty())
  423. {
  424. Path = ToUnixPath(ExcludeTrailingBackslash(Path));
  425. }
  426. Result = Matches(ExtractFileName(FileName), Directory, Path, Params,
  427. RecurseInclude, ImplicitMatch);
  428. }
  429. else
  430. {
  431. Result = Matches(UnixExtractFileName(FileName), Directory,
  432. SimpleUnixExcludeTrailingBackslash(UnixExtractFilePath(FileName)), Params,
  433. RecurseInclude, ImplicitMatch);
  434. }
  435. return Result;
  436. }
  437. //---------------------------------------------------------------------------
  438. bool __fastcall TFileMasks::operator ==(const TFileMasks & rhm) const
  439. {
  440. return (Masks == rhm.Masks);
  441. }
  442. //---------------------------------------------------------------------------
  443. TFileMasks & __fastcall TFileMasks::operator =(const UnicodeString & rhs)
  444. {
  445. Masks = rhs;
  446. return *this;
  447. }
  448. //---------------------------------------------------------------------------
  449. TFileMasks & __fastcall TFileMasks::operator =(const TFileMasks & rhm)
  450. {
  451. FForceDirectoryMasks = rhm.FForceDirectoryMasks;
  452. Masks = rhm.Masks;
  453. return *this;
  454. }
  455. //---------------------------------------------------------------------------
  456. bool __fastcall TFileMasks::operator ==(const UnicodeString & rhs) const
  457. {
  458. return (Masks == rhs);
  459. }
  460. //---------------------------------------------------------------------------
  461. void __fastcall TFileMasks::ThrowError(int Start, int End)
  462. {
  463. throw EFileMasksException(
  464. FMTLOAD(MASK_ERROR, (Masks.SubString(Start, End - Start + 1))),
  465. Start, End - Start + 1);
  466. }
  467. //---------------------------------------------------------------------------
  468. void __fastcall TFileMasks::CreateMaskMask(const UnicodeString & Mask, int Start, int End,
  469. bool Ex, TMaskMask & MaskMask)
  470. {
  471. try
  472. {
  473. DebugAssert(MaskMask.Mask == NULL);
  474. if (Ex && IsAnyMask(Mask))
  475. {
  476. MaskMask.Kind = TMaskMask::Any;
  477. MaskMask.Mask = NULL;
  478. }
  479. else
  480. {
  481. MaskMask.Kind = (Ex && (Mask == L"*.")) ? TMaskMask::NoExt : TMaskMask::Regular;
  482. MaskMask.Mask = new Masks::TMask(Mask);
  483. }
  484. }
  485. catch(...)
  486. {
  487. ThrowError(Start, End);
  488. }
  489. }
  490. //---------------------------------------------------------------------------
  491. UnicodeString __fastcall TFileMasks::MakeDirectoryMask(UnicodeString Str)
  492. {
  493. DebugAssert(!Str.IsEmpty());
  494. if (Str.IsEmpty() || !Str.IsDelimiter(DirectoryMaskDelimiters, Str.Length()))
  495. {
  496. int D = Str.LastDelimiter(DirectoryMaskDelimiters);
  497. // if there's any [back]slash anywhere in str,
  498. // add the same [back]slash at the end, otherwise add slash
  499. wchar_t Delimiter = (D > 0) ? Str[D] : DirectoryMaskDelimiters[1];
  500. Str += Delimiter;
  501. }
  502. return Str;
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TFileMasks::CreateMask(
  506. const UnicodeString & MaskStr, int MaskStart, int /*MaskEnd*/, bool Include)
  507. {
  508. bool Directory = false; // shut up
  509. TMask Mask;
  510. Mask.MaskStr = MaskStr;
  511. Mask.UserStr = MaskStr;
  512. Mask.FileNameMask.Kind = TMaskMask::Any;
  513. Mask.FileNameMask.Mask = NULL;
  514. Mask.DirectoryMask.Kind = TMaskMask::Any;
  515. Mask.DirectoryMask.Mask = NULL;
  516. Mask.HighSizeMask = TMask::None;
  517. Mask.LowSizeMask = TMask::None;
  518. Mask.HighModificationMask = TMask::None;
  519. Mask.LowModificationMask = TMask::None;
  520. wchar_t NextPartDelimiter = L'\0';
  521. int NextPartFrom = 1;
  522. while (NextPartFrom <= MaskStr.Length())
  523. {
  524. wchar_t PartDelimiter = NextPartDelimiter;
  525. int PartFrom = NextPartFrom;
  526. UnicodeString PartStr = CopyToChars(MaskStr, NextPartFrom, L"<>", false, &NextPartDelimiter, true);
  527. int PartStart = MaskStart + PartFrom - 1;
  528. int PartEnd = MaskStart + NextPartFrom - 1 - 2;
  529. TrimEx(PartStr, PartStart, PartEnd);
  530. if (PartDelimiter != L'\0')
  531. {
  532. bool Low = (PartDelimiter == L'>');
  533. TMask::TMaskBoundary Boundary;
  534. if ((PartStr.Length() >= 1) && (PartStr[1] == L'='))
  535. {
  536. Boundary = TMask::Close;
  537. PartStr.Delete(1, 1);
  538. }
  539. else
  540. {
  541. Boundary = TMask::Open;
  542. }
  543. TFormatSettings FormatSettings = TFormatSettings::Create(GetDefaultLCID());
  544. FormatSettings.DateSeparator = L'-';
  545. FormatSettings.TimeSeparator = L':';
  546. FormatSettings.ShortDateFormat = "yyyy/mm/dd";
  547. FormatSettings.ShortTimeFormat = "hh:nn:ss";
  548. TDateTime Modification;
  549. if (TryStrToDateTime(PartStr, Modification, FormatSettings) ||
  550. TryRelativeStrToDateTime(PartStr, Modification, false))
  551. {
  552. TMask::TMaskBoundary & ModificationMask =
  553. (Low ? Mask.LowModificationMask : Mask.HighModificationMask);
  554. if ((ModificationMask != TMask::None) || Directory)
  555. {
  556. // include delimiter into size part
  557. ThrowError(PartStart - 1, PartEnd);
  558. }
  559. ModificationMask = Boundary;
  560. (Low ? Mask.LowModification : Mask.HighModification) = Modification;
  561. }
  562. else
  563. {
  564. TMask::TMaskBoundary & SizeMask = (Low ? Mask.LowSizeMask : Mask.HighSizeMask);
  565. __int64 & Size = (Low ? Mask.LowSize : Mask.HighSize);
  566. if ((SizeMask != TMask::None) || Directory)
  567. {
  568. // include delimiter into size part
  569. ThrowError(PartStart - 1, PartEnd);
  570. }
  571. SizeMask = Boundary;
  572. Size = ParseSize(PartStr);
  573. }
  574. }
  575. else if (!PartStr.IsEmpty())
  576. {
  577. int D = PartStr.LastDelimiter(DirectoryMaskDelimiters);
  578. Directory = (D > 0) && (D == PartStr.Length());
  579. if (Directory)
  580. {
  581. do
  582. {
  583. PartStr.SetLength(PartStr.Length() - 1);
  584. Mask.UserStr.Delete(PartStart - MaskStart + D, 1);
  585. D--;
  586. }
  587. while (PartStr.IsDelimiter(DirectoryMaskDelimiters, PartStr.Length()));
  588. D = PartStr.LastDelimiter(DirectoryMaskDelimiters);
  589. if (FForceDirectoryMasks == 0)
  590. {
  591. Directory = false;
  592. Mask.MaskStr = Mask.UserStr;
  593. }
  594. }
  595. else if (FForceDirectoryMasks > 0)
  596. {
  597. Directory = true;
  598. Mask.MaskStr.Insert(DirectoryMaskDelimiters[1], PartStart - MaskStart + PartStr.Length());
  599. }
  600. if (D > 0)
  601. {
  602. // make sure sole "/" (root dir) is preserved as is
  603. CreateMaskMask(
  604. SimpleUnixExcludeTrailingBackslash(ToUnixPath(PartStr.SubString(1, D))),
  605. PartStart, PartStart + D - 1, false,
  606. Mask.DirectoryMask);
  607. CreateMaskMask(
  608. PartStr.SubString(D + 1, PartStr.Length() - D),
  609. PartStart + D, PartEnd, true,
  610. Mask.FileNameMask);
  611. }
  612. else
  613. {
  614. CreateMaskMask(PartStr, PartStart, PartEnd, true, Mask.FileNameMask);
  615. }
  616. }
  617. }
  618. FMasks[MASK_INDEX(Directory, Include)].push_back(Mask);
  619. }
  620. //---------------------------------------------------------------------------
  621. TStrings * __fastcall TFileMasks::GetMasksStr(int Index) const
  622. {
  623. if (FMasksStr[Index] == NULL)
  624. {
  625. FMasksStr[Index] = new TStringList();
  626. TMasks::const_iterator I = FMasks[Index].begin();
  627. while (I != FMasks[Index].end())
  628. {
  629. FMasksStr[Index]->Add((*I).UserStr);
  630. I++;
  631. }
  632. }
  633. return FMasksStr[Index];
  634. }
  635. //---------------------------------------------------------------------------
  636. void __fastcall TFileMasks::ReleaseMaskMask(TMaskMask & MaskMask)
  637. {
  638. delete MaskMask.Mask;
  639. }
  640. //---------------------------------------------------------------------------
  641. void __fastcall TFileMasks::TrimEx(UnicodeString & Str, int & Start, int & End)
  642. {
  643. UnicodeString Buf = TrimLeft(Str);
  644. Start += Str.Length() - Buf.Length();
  645. Str = TrimRight(Buf);
  646. End -= Buf.Length() - Str.Length();
  647. }
  648. //---------------------------------------------------------------------------
  649. bool __fastcall TFileMasks::MatchesMaskMask(const TMaskMask & MaskMask, const UnicodeString & Str)
  650. {
  651. bool Result;
  652. if (MaskMask.Kind == TMaskMask::Any)
  653. {
  654. Result = true;
  655. }
  656. else if ((MaskMask.Kind == TMaskMask::NoExt) && (Str.Pos(L".") == 0))
  657. {
  658. Result = true;
  659. }
  660. else
  661. {
  662. Result = MaskMask.Mask->Matches(Str);
  663. }
  664. return Result;
  665. }
  666. //---------------------------------------------------------------------------
  667. void __fastcall TFileMasks::SetMasks(const UnicodeString value)
  668. {
  669. if (FStr != value)
  670. {
  671. SetStr(value, false);
  672. }
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TFileMasks::SetMask(const UnicodeString & Mask)
  676. {
  677. SetStr(Mask, true);
  678. }
  679. //---------------------------------------------------------------------------
  680. void __fastcall TFileMasks::SetStr(const UnicodeString Str, bool SingleMask)
  681. {
  682. UnicodeString Backup = FStr;
  683. try
  684. {
  685. FStr = Str;
  686. Clear();
  687. int NextMaskFrom = 1;
  688. bool Include = true;
  689. while (NextMaskFrom <= Str.Length())
  690. {
  691. int MaskStart = NextMaskFrom;
  692. wchar_t NextMaskDelimiter;
  693. UnicodeString MaskStr;
  694. if (SingleMask)
  695. {
  696. MaskStr = Str;
  697. NextMaskFrom = Str.Length() + 1;
  698. NextMaskDelimiter = L'\0';
  699. }
  700. else
  701. {
  702. MaskStr = CopyToChars(Str, NextMaskFrom, AllFileMasksDelimiters, false, &NextMaskDelimiter, true);
  703. }
  704. int MaskEnd = NextMaskFrom - 2;
  705. TrimEx(MaskStr, MaskStart, MaskEnd);
  706. if (!MaskStr.IsEmpty())
  707. {
  708. CreateMask(MaskStr, MaskStart, MaskEnd, Include);
  709. }
  710. if (NextMaskDelimiter == IncludeExcludeFileMasksDelimiter)
  711. {
  712. if (Include)
  713. {
  714. Include = false;
  715. }
  716. else
  717. {
  718. ThrowError(NextMaskFrom - 1, Str.Length());
  719. }
  720. }
  721. }
  722. }
  723. catch(...)
  724. {
  725. // this does not work correctly if previous mask was set using SetMask.
  726. // this should not fail (the mask was validated before),
  727. // otherwise we end in an infinite loop
  728. SetStr(Backup, false);
  729. throw;
  730. }
  731. }
  732. //---------------------------------------------------------------------------
  733. //---------------------------------------------------------------------------
  734. #define TEXT_TOKEN L'\255'
  735. //---------------------------------------------------------------------------
  736. const wchar_t TCustomCommand::NoQuote = L'\0';
  737. const UnicodeString TCustomCommand::Quotes = L"\"'";
  738. //---------------------------------------------------------------------------
  739. UnicodeString __fastcall TCustomCommand::Escape(const UnicodeString & S)
  740. {
  741. return ReplaceStr(S, L"!", L"!!");
  742. }
  743. //---------------------------------------------------------------------------
  744. TCustomCommand::TCustomCommand()
  745. {
  746. }
  747. //---------------------------------------------------------------------------
  748. void __fastcall TCustomCommand::GetToken(
  749. const UnicodeString & Command, int Index, int & Len, wchar_t & PatternCmd)
  750. {
  751. DebugAssert(Index <= Command.Length());
  752. const wchar_t * Ptr = Command.c_str() + Index - 1;
  753. if (Ptr[0] == L'!')
  754. {
  755. PatternCmd = Ptr[1];
  756. if (PatternCmd == L'\0')
  757. {
  758. Len = 1;
  759. }
  760. else if (PatternCmd == L'!')
  761. {
  762. Len = 2;
  763. }
  764. else
  765. {
  766. Len = PatternLen(Command, Index);
  767. }
  768. if (Len <= 0)
  769. {
  770. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNKNOWN, (PatternCmd, Index)));
  771. }
  772. else
  773. {
  774. if ((Command.Length() - Index + 1) < Len)
  775. {
  776. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (PatternCmd, Index)));
  777. }
  778. }
  779. }
  780. else
  781. {
  782. PatternCmd = TEXT_TOKEN;
  783. const wchar_t * NextPattern = wcschr(Ptr, L'!');
  784. if (NextPattern == NULL)
  785. {
  786. Len = Command.Length() - Index + 1;
  787. }
  788. else
  789. {
  790. Len = NextPattern - Ptr;
  791. }
  792. }
  793. }
  794. //---------------------------------------------------------------------------
  795. void __fastcall TCustomCommand::PatternHint(int /*Index*/, const UnicodeString & /*Pattern*/)
  796. {
  797. // noop
  798. }
  799. //---------------------------------------------------------------------------
  800. UnicodeString __fastcall TCustomCommand::Complete(const UnicodeString & Command,
  801. bool LastPass)
  802. {
  803. int Index = 1;
  804. int PatternIndex = 0;
  805. while (Index <= Command.Length())
  806. {
  807. int Len;
  808. wchar_t PatternCmd;
  809. GetToken(Command, Index, Len, PatternCmd);
  810. if (PatternCmd == TEXT_TOKEN)
  811. {
  812. }
  813. else if (PatternCmd == L'!')
  814. {
  815. }
  816. else
  817. {
  818. UnicodeString Pattern = Command.SubString(Index, Len);
  819. PatternHint(PatternIndex, Pattern);
  820. PatternIndex++;
  821. }
  822. Index += Len;
  823. }
  824. UnicodeString Result;
  825. Index = 1;
  826. PatternIndex = 0;
  827. while (Index <= Command.Length())
  828. {
  829. int Len;
  830. wchar_t PatternCmd;
  831. GetToken(Command, Index, Len, PatternCmd);
  832. if (PatternCmd == TEXT_TOKEN)
  833. {
  834. Result += Command.SubString(Index, Len);
  835. }
  836. else if (PatternCmd == L'!')
  837. {
  838. if (LastPass)
  839. {
  840. Result += L'!';
  841. }
  842. else
  843. {
  844. Result += Command.SubString(Index, Len);
  845. }
  846. }
  847. else
  848. {
  849. wchar_t Quote = NoQuote;
  850. if ((Index > 1) && (Index + Len - 1 < Command.Length()) &&
  851. Command.IsDelimiter(Quotes, Index - 1) &&
  852. Command.IsDelimiter(Quotes, Index + Len) &&
  853. (Command[Index - 1] == Command[Index + Len]))
  854. {
  855. Quote = Command[Index - 1];
  856. }
  857. UnicodeString Pattern = Command.SubString(Index, Len);
  858. UnicodeString Replacement;
  859. bool Delimit = true;
  860. if (PatternReplacement(PatternIndex, Pattern, Replacement, Delimit))
  861. {
  862. if (!LastPass)
  863. {
  864. Replacement = Escape(Replacement);
  865. }
  866. if (Delimit)
  867. {
  868. DelimitReplacement(Replacement, Quote);
  869. }
  870. Result += Replacement;
  871. }
  872. else
  873. {
  874. Result += Pattern;
  875. }
  876. PatternIndex++;
  877. }
  878. Index += Len;
  879. }
  880. return Result;
  881. }
  882. //---------------------------------------------------------------------------
  883. void __fastcall TCustomCommand::DelimitReplacement(UnicodeString & Replacement, wchar_t Quote)
  884. {
  885. Replacement = ShellDelimitStr(Replacement, Quote);
  886. }
  887. //---------------------------------------------------------------------------
  888. void __fastcall TCustomCommand::Validate(const UnicodeString & Command)
  889. {
  890. CustomValidate(Command, NULL);
  891. }
  892. //---------------------------------------------------------------------------
  893. void __fastcall TCustomCommand::CustomValidate(const UnicodeString & Command,
  894. void * Arg)
  895. {
  896. int Index = 1;
  897. while (Index <= Command.Length())
  898. {
  899. int Len;
  900. wchar_t PatternCmd;
  901. GetToken(Command, Index, Len, PatternCmd);
  902. ValidatePattern(Command, Index, Len, PatternCmd, Arg);
  903. Index += Len;
  904. }
  905. }
  906. //---------------------------------------------------------------------------
  907. bool __fastcall TCustomCommand::FindPattern(const UnicodeString & Command,
  908. wchar_t PatternCmd)
  909. {
  910. bool Result = false;
  911. int Index = 1;
  912. while (!Result && (Index <= Command.Length()))
  913. {
  914. int Len;
  915. wchar_t APatternCmd;
  916. GetToken(Command, Index, Len, APatternCmd);
  917. if (((PatternCmd != L'!') && (tolower(PatternCmd) == tolower(APatternCmd))) ||
  918. ((PatternCmd == L'!') && (Len == 1) && (APatternCmd != TEXT_TOKEN)))
  919. {
  920. Result = true;
  921. }
  922. Index += Len;
  923. }
  924. return Result;
  925. }
  926. //---------------------------------------------------------------------------
  927. void __fastcall TCustomCommand::ValidatePattern(const UnicodeString & /*Command*/,
  928. int /*Index*/, int /*Len*/, wchar_t /*PatternCmd*/, void * /*Arg*/)
  929. {
  930. }
  931. //---------------------------------------------------------------------------
  932. //---------------------------------------------------------------------------
  933. TInteractiveCustomCommand::TInteractiveCustomCommand(
  934. TCustomCommand * ChildCustomCommand)
  935. {
  936. FChildCustomCommand = ChildCustomCommand;
  937. }
  938. //---------------------------------------------------------------------------
  939. void __fastcall TInteractiveCustomCommand::Prompt(
  940. int /*Index*/, const UnicodeString & /*Prompt*/, UnicodeString & Value)
  941. {
  942. Value = L"";
  943. }
  944. //---------------------------------------------------------------------------
  945. void __fastcall TInteractiveCustomCommand::Execute(
  946. const UnicodeString & /*Command*/, UnicodeString & Value)
  947. {
  948. Value = L"";
  949. }
  950. //---------------------------------------------------------------------------
  951. int __fastcall TInteractiveCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  952. {
  953. int Len;
  954. wchar_t PatternCmd = (Index < Command.Length()) ? Command[Index + 1] : L'\0';
  955. switch (PatternCmd)
  956. {
  957. case L'?':
  958. {
  959. const wchar_t * Ptr = Command.c_str() + Index - 1;
  960. const wchar_t * PatternEnd = wcschr(Ptr + 1, L'!');
  961. if (PatternEnd == NULL)
  962. {
  963. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (Command[Index + 1], Index)));
  964. }
  965. Len = PatternEnd - Ptr + 1;
  966. }
  967. break;
  968. case L'`':
  969. {
  970. const wchar_t * Ptr = Command.c_str() + Index - 1;
  971. const wchar_t * PatternEnd = wcschr(Ptr + 2, L'`');
  972. if (PatternEnd == NULL)
  973. {
  974. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (Command[Index + 1], Index)));
  975. }
  976. Len = PatternEnd - Ptr + 1;
  977. }
  978. break;
  979. default:
  980. Len = FChildCustomCommand->PatternLen(Command, Index);
  981. break;
  982. }
  983. return Len;
  984. }
  985. //---------------------------------------------------------------------------
  986. bool __fastcall TInteractiveCustomCommand::IsPromptPattern(const UnicodeString & Pattern)
  987. {
  988. return (Pattern.Length() >= 3) && (Pattern[2] == L'?');
  989. }
  990. //---------------------------------------------------------------------------
  991. void __fastcall TInteractiveCustomCommand::ParsePromptPattern(
  992. const UnicodeString & Pattern, UnicodeString & Prompt, UnicodeString & Default, bool & Delimit)
  993. {
  994. int Pos = Pattern.SubString(3, Pattern.Length() - 2).Pos(L"?");
  995. if (Pos > 0)
  996. {
  997. Default = Pattern.SubString(3 + Pos, Pattern.Length() - 3 - Pos);
  998. if ((Pos > 1) && (Pattern[3 + Pos - 2] == L'\\'))
  999. {
  1000. Delimit = false;
  1001. Pos--;
  1002. }
  1003. Prompt = Pattern.SubString(3, Pos - 1);
  1004. }
  1005. else
  1006. {
  1007. Prompt = Pattern.SubString(3, Pattern.Length() - 3);
  1008. }
  1009. }
  1010. //---------------------------------------------------------------------------
  1011. bool __fastcall TInteractiveCustomCommand::PatternReplacement(int Index, const UnicodeString & Pattern,
  1012. UnicodeString & Replacement, bool & Delimit)
  1013. {
  1014. bool Result;
  1015. if (IsPromptPattern(Pattern))
  1016. {
  1017. UnicodeString PromptStr;
  1018. // The PromptStr and Replacement are actually never used
  1019. // as the only implementation (TWinInteractiveCustomCommand) uses
  1020. // prompts and defaults from PatternHint.
  1021. ParsePromptPattern(Pattern, PromptStr, Replacement, Delimit);
  1022. Prompt(Index, PromptStr, Replacement);
  1023. Result = true;
  1024. }
  1025. else if ((Pattern.Length() >= 3) && (Pattern[2] == L'`'))
  1026. {
  1027. UnicodeString Command = Pattern.SubString(3, Pattern.Length() - 3);
  1028. Command = FChildCustomCommand->Complete(Command, true);
  1029. Execute(Command, Replacement);
  1030. Delimit = false;
  1031. Result = true;
  1032. }
  1033. else
  1034. {
  1035. Result = false;
  1036. }
  1037. return Result;
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. //---------------------------------------------------------------------------
  1041. __fastcall TCustomCommandData::TCustomCommandData()
  1042. {
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. __fastcall TCustomCommandData::TCustomCommandData(TTerminal * Terminal)
  1046. {
  1047. Init(Terminal->SessionData, Terminal->UserName, Terminal->Password,
  1048. Terminal->GetSessionInfo().HostKeyFingerprint);
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. __fastcall TCustomCommandData::TCustomCommandData(
  1052. TSessionData * SessionData, const UnicodeString & UserName, const UnicodeString & Password)
  1053. {
  1054. Init(SessionData, UserName, Password, UnicodeString());
  1055. }
  1056. //---------------------------------------------------------------------------
  1057. void __fastcall TCustomCommandData::Init(
  1058. TSessionData * ASessionData, const UnicodeString & AUserName,
  1059. const UnicodeString & APassword, const UnicodeString & AHostKey)
  1060. {
  1061. FSessionData.reset(new TSessionData(L""));
  1062. FSessionData->Assign(ASessionData);
  1063. FSessionData->UserName = AUserName;
  1064. FSessionData->Password = APassword;
  1065. FSessionData->HostKey = AHostKey;
  1066. }
  1067. //---------------------------------------------------------------------------
  1068. void __fastcall TCustomCommandData::operator=(const TCustomCommandData & Data)
  1069. {
  1070. DebugAssert(Data.SessionData != NULL);
  1071. FSessionData.reset(new TSessionData(L""));
  1072. FSessionData->Assign(Data.SessionData);
  1073. }
  1074. //---------------------------------------------------------------------------
  1075. TSessionData * __fastcall TCustomCommandData::GetSesssionData() const
  1076. {
  1077. return FSessionData.get();
  1078. }
  1079. //---------------------------------------------------------------------------
  1080. //---------------------------------------------------------------------------
  1081. TFileCustomCommand::TFileCustomCommand()
  1082. {
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. TFileCustomCommand::TFileCustomCommand(const TCustomCommandData & Data,
  1086. const UnicodeString & Path)
  1087. {
  1088. FData = Data;
  1089. FPath = Path;
  1090. }
  1091. //---------------------------------------------------------------------------
  1092. TFileCustomCommand::TFileCustomCommand(const TCustomCommandData & Data,
  1093. const UnicodeString & Path, const UnicodeString & FileName,
  1094. const UnicodeString & FileList) :
  1095. TCustomCommand()
  1096. {
  1097. FData = Data;
  1098. FPath = Path;
  1099. FFileName = FileName;
  1100. FFileList = FileList;
  1101. }
  1102. //---------------------------------------------------------------------------
  1103. int __fastcall TFileCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  1104. {
  1105. int Len;
  1106. wchar_t PatternCmd = (Index < Command.Length()) ? tolower(Command[Index + 1]) : L'\0';
  1107. switch (PatternCmd)
  1108. {
  1109. case L's':
  1110. case L'@':
  1111. case L'u':
  1112. case L'p':
  1113. case L'#':
  1114. case L'/':
  1115. case L'&':
  1116. case L'n':
  1117. Len = 2;
  1118. break;
  1119. default:
  1120. Len = 1;
  1121. break;
  1122. }
  1123. return Len;
  1124. }
  1125. //---------------------------------------------------------------------------
  1126. bool __fastcall TFileCustomCommand::PatternReplacement(
  1127. int /*Index*/, const UnicodeString & Pattern, UnicodeString & Replacement, bool & Delimit)
  1128. {
  1129. // keep consistent with TSessionLog::OpenLogFile
  1130. if (SameText(Pattern, L"!s"))
  1131. {
  1132. Replacement = FData.SessionData->GenerateSessionUrl(sufComplete);
  1133. }
  1134. else if (Pattern == L"!@")
  1135. {
  1136. Replacement = FData.SessionData->HostNameExpanded;
  1137. }
  1138. else if (SameText(Pattern, L"!u"))
  1139. {
  1140. Replacement = FData.SessionData->UserName;
  1141. }
  1142. else if (SameText(Pattern, L"!p"))
  1143. {
  1144. Replacement = FData.SessionData->Password;
  1145. }
  1146. else if (SameText(Pattern, L"!#"))
  1147. {
  1148. Replacement = IntToStr(FData.SessionData->PortNumber);
  1149. }
  1150. else if (Pattern == L"!/")
  1151. {
  1152. Replacement = UnixIncludeTrailingBackslash(FPath);
  1153. }
  1154. else if (Pattern == L"!&")
  1155. {
  1156. Replacement = FFileList;
  1157. // already delimited
  1158. Delimit = false;
  1159. }
  1160. else if (SameText(Pattern, L"!n"))
  1161. {
  1162. Replacement = FData.SessionData->SessionName;
  1163. }
  1164. else
  1165. {
  1166. DebugAssert(Pattern.Length() == 1);
  1167. Replacement = FFileName;
  1168. }
  1169. return true;
  1170. }
  1171. //---------------------------------------------------------------------------
  1172. void __fastcall TFileCustomCommand::Validate(const UnicodeString & Command)
  1173. {
  1174. int Found[2] = { 0, 0 };
  1175. CustomValidate(Command, &Found);
  1176. if ((Found[0] > 0) && (Found[1] > 0))
  1177. {
  1178. throw Exception(FMTLOAD(CUSTOM_COMMAND_FILELIST_ERROR,
  1179. (Found[1], Found[0])));
  1180. }
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. void __fastcall TFileCustomCommand::ValidatePattern(const UnicodeString & Command,
  1184. int Index, int /*Len*/, wchar_t PatternCmd, void * Arg)
  1185. {
  1186. int * Found = static_cast<int *>(Arg);
  1187. DebugAssert(Index > 0);
  1188. if (PatternCmd == L'&')
  1189. {
  1190. Found[0] = Index;
  1191. }
  1192. else if ((PatternCmd != TEXT_TOKEN) && (PatternLen(Command, Index) == 1))
  1193. {
  1194. Found[1] = Index;
  1195. }
  1196. }
  1197. //---------------------------------------------------------------------------
  1198. bool __fastcall TFileCustomCommand::IsFileListCommand(const UnicodeString & Command)
  1199. {
  1200. return FindPattern(Command, L'&');
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. bool __fastcall TFileCustomCommand::IsRemoteFileCommand(const UnicodeString & Command)
  1204. {
  1205. return FindPattern(Command, L'!') || FindPattern(Command, L'&');
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. bool __fastcall TFileCustomCommand::IsFileCommand(const UnicodeString & Command)
  1209. {
  1210. return IsRemoteFileCommand(Command);
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. bool __fastcall TFileCustomCommand::IsSiteCommand(const UnicodeString & Command)
  1214. {
  1215. return FindPattern(Command, L'@');
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. bool __fastcall TFileCustomCommand::IsPasswordCommand(const UnicodeString & Command)
  1219. {
  1220. return FindPattern(Command, L'p');
  1221. }
  1222. //---------------------------------------------------------------------------