FileMasks.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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. TCustomCommand::TCustomCommand()
  740. {
  741. }
  742. //---------------------------------------------------------------------------
  743. void __fastcall TCustomCommand::GetToken(
  744. const UnicodeString & Command, int Index, int & Len, wchar_t & PatternCmd)
  745. {
  746. DebugAssert(Index <= Command.Length());
  747. const wchar_t * Ptr = Command.c_str() + Index - 1;
  748. if (Ptr[0] == L'!')
  749. {
  750. PatternCmd = Ptr[1];
  751. if (PatternCmd == L'\0')
  752. {
  753. Len = 1;
  754. }
  755. else if (PatternCmd == L'!')
  756. {
  757. Len = 2;
  758. }
  759. else
  760. {
  761. Len = PatternLen(Command, Index);
  762. }
  763. if (Len <= 0)
  764. {
  765. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNKNOWN, (PatternCmd, Index)));
  766. }
  767. else
  768. {
  769. if ((Command.Length() - Index + 1) < Len)
  770. {
  771. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (PatternCmd, Index)));
  772. }
  773. }
  774. }
  775. else
  776. {
  777. PatternCmd = TEXT_TOKEN;
  778. const wchar_t * NextPattern = wcschr(Ptr, L'!');
  779. if (NextPattern == NULL)
  780. {
  781. Len = Command.Length() - Index + 1;
  782. }
  783. else
  784. {
  785. Len = NextPattern - Ptr;
  786. }
  787. }
  788. }
  789. //---------------------------------------------------------------------------
  790. void __fastcall TCustomCommand::PatternHint(int /*Index*/, const UnicodeString & /*Pattern*/)
  791. {
  792. // noop
  793. }
  794. //---------------------------------------------------------------------------
  795. UnicodeString __fastcall TCustomCommand::Complete(const UnicodeString & Command,
  796. bool LastPass)
  797. {
  798. int Index = 1;
  799. int PatternIndex = 0;
  800. while (Index <= Command.Length())
  801. {
  802. int Len;
  803. wchar_t PatternCmd;
  804. GetToken(Command, Index, Len, PatternCmd);
  805. if (PatternCmd == TEXT_TOKEN)
  806. {
  807. }
  808. else if (PatternCmd == L'!')
  809. {
  810. }
  811. else
  812. {
  813. UnicodeString Pattern = Command.SubString(Index, Len);
  814. PatternHint(PatternIndex, Pattern);
  815. PatternIndex++;
  816. }
  817. Index += Len;
  818. }
  819. UnicodeString Result;
  820. Index = 1;
  821. PatternIndex = 0;
  822. while (Index <= Command.Length())
  823. {
  824. int Len;
  825. wchar_t PatternCmd;
  826. GetToken(Command, Index, Len, PatternCmd);
  827. if (PatternCmd == TEXT_TOKEN)
  828. {
  829. Result += Command.SubString(Index, Len);
  830. }
  831. else if (PatternCmd == L'!')
  832. {
  833. if (LastPass)
  834. {
  835. Result += L'!';
  836. }
  837. else
  838. {
  839. Result += Command.SubString(Index, Len);
  840. }
  841. }
  842. else
  843. {
  844. wchar_t Quote = NoQuote;
  845. if ((Index > 1) && (Index + Len - 1 < Command.Length()) &&
  846. Command.IsDelimiter(Quotes, Index - 1) &&
  847. Command.IsDelimiter(Quotes, Index + Len) &&
  848. (Command[Index - 1] == Command[Index + Len]))
  849. {
  850. Quote = Command[Index - 1];
  851. }
  852. UnicodeString Pattern = Command.SubString(Index, Len);
  853. UnicodeString Replacement;
  854. bool Delimit = true;
  855. if (PatternReplacement(PatternIndex, Pattern, Replacement, Delimit))
  856. {
  857. if (!LastPass)
  858. {
  859. Replacement = ReplaceStr(Replacement, L"!", L"!!");
  860. }
  861. if (Delimit)
  862. {
  863. DelimitReplacement(Replacement, Quote);
  864. }
  865. Result += Replacement;
  866. }
  867. else
  868. {
  869. Result += Pattern;
  870. }
  871. PatternIndex++;
  872. }
  873. Index += Len;
  874. }
  875. return Result;
  876. }
  877. //---------------------------------------------------------------------------
  878. void __fastcall TCustomCommand::DelimitReplacement(UnicodeString & Replacement, wchar_t Quote)
  879. {
  880. Replacement = ShellDelimitStr(Replacement, Quote);
  881. }
  882. //---------------------------------------------------------------------------
  883. void __fastcall TCustomCommand::Validate(const UnicodeString & Command)
  884. {
  885. CustomValidate(Command, NULL);
  886. }
  887. //---------------------------------------------------------------------------
  888. void __fastcall TCustomCommand::CustomValidate(const UnicodeString & Command,
  889. void * Arg)
  890. {
  891. int Index = 1;
  892. while (Index <= Command.Length())
  893. {
  894. int Len;
  895. wchar_t PatternCmd;
  896. GetToken(Command, Index, Len, PatternCmd);
  897. ValidatePattern(Command, Index, Len, PatternCmd, Arg);
  898. Index += Len;
  899. }
  900. }
  901. //---------------------------------------------------------------------------
  902. bool __fastcall TCustomCommand::FindPattern(const UnicodeString & Command,
  903. wchar_t PatternCmd)
  904. {
  905. bool Result = false;
  906. int Index = 1;
  907. while (!Result && (Index <= Command.Length()))
  908. {
  909. int Len;
  910. wchar_t APatternCmd;
  911. GetToken(Command, Index, Len, APatternCmd);
  912. if (((PatternCmd != L'!') && (PatternCmd == APatternCmd)) ||
  913. ((PatternCmd == L'!') && (Len == 1) && (APatternCmd != TEXT_TOKEN)))
  914. {
  915. Result = true;
  916. }
  917. Index += Len;
  918. }
  919. return Result;
  920. }
  921. //---------------------------------------------------------------------------
  922. void __fastcall TCustomCommand::ValidatePattern(const UnicodeString & /*Command*/,
  923. int /*Index*/, int /*Len*/, wchar_t /*PatternCmd*/, void * /*Arg*/)
  924. {
  925. }
  926. //---------------------------------------------------------------------------
  927. //---------------------------------------------------------------------------
  928. TInteractiveCustomCommand::TInteractiveCustomCommand(
  929. TCustomCommand * ChildCustomCommand)
  930. {
  931. FChildCustomCommand = ChildCustomCommand;
  932. }
  933. //---------------------------------------------------------------------------
  934. void __fastcall TInteractiveCustomCommand::Prompt(
  935. int /*Index*/, const UnicodeString & /*Prompt*/, UnicodeString & Value)
  936. {
  937. Value = L"";
  938. }
  939. //---------------------------------------------------------------------------
  940. void __fastcall TInteractiveCustomCommand::Execute(
  941. const UnicodeString & /*Command*/, UnicodeString & Value)
  942. {
  943. Value = L"";
  944. }
  945. //---------------------------------------------------------------------------
  946. int __fastcall TInteractiveCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  947. {
  948. int Len;
  949. wchar_t PatternCmd = (Index < Command.Length()) ? Command[Index + 1] : L'\0';
  950. switch (PatternCmd)
  951. {
  952. case L'?':
  953. {
  954. const wchar_t * Ptr = Command.c_str() + Index - 1;
  955. const wchar_t * PatternEnd = wcschr(Ptr + 1, L'!');
  956. if (PatternEnd == NULL)
  957. {
  958. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (Command[Index + 1], Index)));
  959. }
  960. Len = PatternEnd - Ptr + 1;
  961. }
  962. break;
  963. case L'`':
  964. {
  965. const wchar_t * Ptr = Command.c_str() + Index - 1;
  966. const wchar_t * PatternEnd = wcschr(Ptr + 2, L'`');
  967. if (PatternEnd == NULL)
  968. {
  969. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (Command[Index + 1], Index)));
  970. }
  971. Len = PatternEnd - Ptr + 1;
  972. }
  973. break;
  974. default:
  975. Len = FChildCustomCommand->PatternLen(Command, Index);
  976. break;
  977. }
  978. return Len;
  979. }
  980. //---------------------------------------------------------------------------
  981. bool __fastcall TInteractiveCustomCommand::IsPromptPattern(const UnicodeString & Pattern)
  982. {
  983. return (Pattern.Length() >= 3) && (Pattern[2] == L'?');
  984. }
  985. //---------------------------------------------------------------------------
  986. void __fastcall TInteractiveCustomCommand::ParsePromptPattern(
  987. const UnicodeString & Pattern, UnicodeString & Prompt, UnicodeString & Default, bool & Delimit)
  988. {
  989. int Pos = Pattern.SubString(3, Pattern.Length() - 2).Pos(L"?");
  990. if (Pos > 0)
  991. {
  992. Default = Pattern.SubString(3 + Pos, Pattern.Length() - 3 - Pos);
  993. if ((Pos > 1) && (Pattern[3 + Pos - 2] == L'\\'))
  994. {
  995. Delimit = false;
  996. Pos--;
  997. }
  998. Prompt = Pattern.SubString(3, Pos - 1);
  999. }
  1000. else
  1001. {
  1002. Prompt = Pattern.SubString(3, Pattern.Length() - 3);
  1003. }
  1004. }
  1005. //---------------------------------------------------------------------------
  1006. bool __fastcall TInteractiveCustomCommand::PatternReplacement(int Index, const UnicodeString & Pattern,
  1007. UnicodeString & Replacement, bool & Delimit)
  1008. {
  1009. bool Result;
  1010. if (IsPromptPattern(Pattern))
  1011. {
  1012. UnicodeString PromptStr;
  1013. // The PromptStr and Replacement are actually never used
  1014. // as the only implementation (TWinInteractiveCustomCommand) uses
  1015. // prompts and defaults from PatternHint.
  1016. ParsePromptPattern(Pattern, PromptStr, Replacement, Delimit);
  1017. Prompt(Index, PromptStr, Replacement);
  1018. Result = true;
  1019. }
  1020. else if ((Pattern.Length() >= 3) && (Pattern[2] == L'`'))
  1021. {
  1022. UnicodeString Command = Pattern.SubString(3, Pattern.Length() - 3);
  1023. Command = FChildCustomCommand->Complete(Command, true);
  1024. Execute(Command, Replacement);
  1025. Delimit = false;
  1026. Result = true;
  1027. }
  1028. else
  1029. {
  1030. Result = false;
  1031. }
  1032. return Result;
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. //---------------------------------------------------------------------------
  1036. __fastcall TCustomCommandData::TCustomCommandData()
  1037. {
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. __fastcall TCustomCommandData::TCustomCommandData(TTerminal * Terminal)
  1041. {
  1042. Init(Terminal->SessionData, Terminal->UserName, Terminal->Password,
  1043. Terminal->GetSessionInfo().HostKeyFingerprint);
  1044. }
  1045. //---------------------------------------------------------------------------
  1046. __fastcall TCustomCommandData::TCustomCommandData(
  1047. TSessionData * SessionData, const UnicodeString & UserName, const UnicodeString & Password)
  1048. {
  1049. Init(SessionData, UserName, Password, UnicodeString());
  1050. }
  1051. //---------------------------------------------------------------------------
  1052. void __fastcall TCustomCommandData::Init(
  1053. TSessionData * ASessionData, const UnicodeString & AUserName,
  1054. const UnicodeString & APassword, const UnicodeString & AHostKey)
  1055. {
  1056. FSessionData.reset(new TSessionData(L""));
  1057. FSessionData->Assign(ASessionData);
  1058. FSessionData->UserName = AUserName;
  1059. FSessionData->Password = APassword;
  1060. FSessionData->HostKey = AHostKey;
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. void __fastcall TCustomCommandData::operator=(const TCustomCommandData & Data)
  1064. {
  1065. DebugAssert(Data.SessionData != NULL);
  1066. FSessionData.reset(new TSessionData(L""));
  1067. FSessionData->Assign(Data.SessionData);
  1068. }
  1069. //---------------------------------------------------------------------------
  1070. TSessionData * __fastcall TCustomCommandData::GetSesssionData() const
  1071. {
  1072. return FSessionData.get();
  1073. }
  1074. //---------------------------------------------------------------------------
  1075. //---------------------------------------------------------------------------
  1076. TFileCustomCommand::TFileCustomCommand()
  1077. {
  1078. }
  1079. //---------------------------------------------------------------------------
  1080. TFileCustomCommand::TFileCustomCommand(const TCustomCommandData & Data,
  1081. const UnicodeString & Path)
  1082. {
  1083. FData = Data;
  1084. FPath = Path;
  1085. }
  1086. //---------------------------------------------------------------------------
  1087. TFileCustomCommand::TFileCustomCommand(const TCustomCommandData & Data,
  1088. const UnicodeString & Path, const UnicodeString & FileName,
  1089. const UnicodeString & FileList) :
  1090. TCustomCommand()
  1091. {
  1092. FData = Data;
  1093. FPath = Path;
  1094. FFileName = FileName;
  1095. FFileList = FileList;
  1096. }
  1097. //---------------------------------------------------------------------------
  1098. int __fastcall TFileCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  1099. {
  1100. int Len;
  1101. wchar_t PatternCmd = (Index < Command.Length()) ? Command[Index + 1] : L'\0';
  1102. switch (PatternCmd)
  1103. {
  1104. case L'S':
  1105. case L'@':
  1106. case L'U':
  1107. case L'P':
  1108. case L'#':
  1109. case L'/':
  1110. case L'&':
  1111. case L'N':
  1112. Len = 2;
  1113. break;
  1114. default:
  1115. Len = 1;
  1116. break;
  1117. }
  1118. return Len;
  1119. }
  1120. //---------------------------------------------------------------------------
  1121. bool __fastcall TFileCustomCommand::PatternReplacement(
  1122. int /*Index*/, const UnicodeString & Pattern, UnicodeString & Replacement, bool & Delimit)
  1123. {
  1124. // keep consistent with TSessionLog::OpenLogFile
  1125. if (SameText(Pattern, L"!s"))
  1126. {
  1127. Replacement = FData.SessionData->GenerateSessionUrl(sufComplete);
  1128. }
  1129. else if (Pattern == L"!@")
  1130. {
  1131. Replacement = FData.SessionData->HostNameExpanded;
  1132. }
  1133. else if (SameText(Pattern, L"!u"))
  1134. {
  1135. Replacement = FData.SessionData->UserName;
  1136. }
  1137. else if (SameText(Pattern, L"!p"))
  1138. {
  1139. Replacement = FData.SessionData->Password;
  1140. }
  1141. else if (SameText(Pattern, L"!#"))
  1142. {
  1143. Replacement = IntToStr(FData.SessionData->PortNumber);
  1144. }
  1145. else if (Pattern == L"!/")
  1146. {
  1147. Replacement = UnixIncludeTrailingBackslash(FPath);
  1148. }
  1149. else if (Pattern == L"!&")
  1150. {
  1151. Replacement = FFileList;
  1152. // already delimited
  1153. Delimit = false;
  1154. }
  1155. else if (SameText(Pattern, L"!n"))
  1156. {
  1157. Replacement = FData.SessionData->SessionName;
  1158. }
  1159. else
  1160. {
  1161. DebugAssert(Pattern.Length() == 1);
  1162. Replacement = FFileName;
  1163. }
  1164. return true;
  1165. }
  1166. //---------------------------------------------------------------------------
  1167. void __fastcall TFileCustomCommand::Validate(const UnicodeString & Command)
  1168. {
  1169. int Found[2] = { 0, 0 };
  1170. CustomValidate(Command, &Found);
  1171. if ((Found[0] > 0) && (Found[1] > 0))
  1172. {
  1173. throw Exception(FMTLOAD(CUSTOM_COMMAND_FILELIST_ERROR,
  1174. (Found[1], Found[0])));
  1175. }
  1176. }
  1177. //---------------------------------------------------------------------------
  1178. void __fastcall TFileCustomCommand::ValidatePattern(const UnicodeString & Command,
  1179. int Index, int /*Len*/, wchar_t PatternCmd, void * Arg)
  1180. {
  1181. int * Found = static_cast<int *>(Arg);
  1182. DebugAssert(Index > 0);
  1183. if (PatternCmd == L'&')
  1184. {
  1185. Found[0] = Index;
  1186. }
  1187. else if ((PatternCmd != TEXT_TOKEN) && (PatternLen(Command, Index) == 1))
  1188. {
  1189. Found[1] = Index;
  1190. }
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. bool __fastcall TFileCustomCommand::IsFileListCommand(const UnicodeString & Command)
  1194. {
  1195. return FindPattern(Command, L'&');
  1196. }
  1197. //---------------------------------------------------------------------------
  1198. bool __fastcall TFileCustomCommand::IsRemoteFileCommand(const UnicodeString & Command)
  1199. {
  1200. return FindPattern(Command, L'!') || FindPattern(Command, L'&');
  1201. }
  1202. //---------------------------------------------------------------------------
  1203. bool __fastcall TFileCustomCommand::IsFileCommand(const UnicodeString & Command)
  1204. {
  1205. return IsRemoteFileCommand(Command);
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. bool __fastcall TFileCustomCommand::IsSiteCommand(const UnicodeString & Command)
  1209. {
  1210. return FindPattern(Command, L'@');
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. bool __fastcall TFileCustomCommand::IsPasswordCommand(const UnicodeString & Command)
  1214. {
  1215. return FindPattern(Command, L'p');
  1216. }
  1217. //---------------------------------------------------------------------------