FileMasks.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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. __int64 DummySize;
  550. if ((!TryStrToInt64(PartStr, DummySize) && TryStrToDateTime(PartStr, Modification, FormatSettings)) ||
  551. TryRelativeStrToDateTime(PartStr, Modification, false))
  552. {
  553. TMask::TMaskBoundary & ModificationMask =
  554. (Low ? Mask.LowModificationMask : Mask.HighModificationMask);
  555. if ((ModificationMask != TMask::None) || Directory)
  556. {
  557. // include delimiter into size part
  558. ThrowError(PartStart - 1, PartEnd);
  559. }
  560. ModificationMask = Boundary;
  561. (Low ? Mask.LowModification : Mask.HighModification) = Modification;
  562. }
  563. else
  564. {
  565. TMask::TMaskBoundary & SizeMask = (Low ? Mask.LowSizeMask : Mask.HighSizeMask);
  566. __int64 & Size = (Low ? Mask.LowSize : Mask.HighSize);
  567. if ((SizeMask != TMask::None) || Directory)
  568. {
  569. // include delimiter into size part
  570. ThrowError(PartStart - 1, PartEnd);
  571. }
  572. SizeMask = Boundary;
  573. if (!TryStrToSize(PartStr, Size))
  574. {
  575. ThrowError(PartStart, PartEnd);
  576. }
  577. }
  578. }
  579. else if (!PartStr.IsEmpty())
  580. {
  581. int D = PartStr.LastDelimiter(DirectoryMaskDelimiters);
  582. Directory = (D > 0) && (D == PartStr.Length());
  583. if (Directory)
  584. {
  585. do
  586. {
  587. PartStr.SetLength(PartStr.Length() - 1);
  588. Mask.UserStr.Delete(PartStart - MaskStart + D, 1);
  589. D--;
  590. }
  591. while (PartStr.IsDelimiter(DirectoryMaskDelimiters, PartStr.Length()));
  592. D = PartStr.LastDelimiter(DirectoryMaskDelimiters);
  593. if (FForceDirectoryMasks == 0)
  594. {
  595. Directory = false;
  596. Mask.MaskStr = Mask.UserStr;
  597. }
  598. }
  599. else if (FForceDirectoryMasks > 0)
  600. {
  601. Directory = true;
  602. Mask.MaskStr.Insert(DirectoryMaskDelimiters[1], PartStart - MaskStart + PartStr.Length());
  603. }
  604. if (D > 0)
  605. {
  606. // make sure sole "/" (root dir) is preserved as is
  607. CreateMaskMask(
  608. SimpleUnixExcludeTrailingBackslash(ToUnixPath(PartStr.SubString(1, D))),
  609. PartStart, PartStart + D - 1, false,
  610. Mask.DirectoryMask);
  611. CreateMaskMask(
  612. PartStr.SubString(D + 1, PartStr.Length() - D),
  613. PartStart + D, PartEnd, true,
  614. Mask.FileNameMask);
  615. }
  616. else
  617. {
  618. CreateMaskMask(PartStr, PartStart, PartEnd, true, Mask.FileNameMask);
  619. }
  620. }
  621. }
  622. FMasks[MASK_INDEX(Directory, Include)].push_back(Mask);
  623. }
  624. //---------------------------------------------------------------------------
  625. TStrings * __fastcall TFileMasks::GetMasksStr(int Index) const
  626. {
  627. if (FMasksStr[Index] == NULL)
  628. {
  629. FMasksStr[Index] = new TStringList();
  630. TMasks::const_iterator I = FMasks[Index].begin();
  631. while (I != FMasks[Index].end())
  632. {
  633. FMasksStr[Index]->Add((*I).UserStr);
  634. I++;
  635. }
  636. }
  637. return FMasksStr[Index];
  638. }
  639. //---------------------------------------------------------------------------
  640. void __fastcall TFileMasks::ReleaseMaskMask(TMaskMask & MaskMask)
  641. {
  642. delete MaskMask.Mask;
  643. }
  644. //---------------------------------------------------------------------------
  645. void __fastcall TFileMasks::TrimEx(UnicodeString & Str, int & Start, int & End)
  646. {
  647. UnicodeString Buf = TrimLeft(Str);
  648. Start += Str.Length() - Buf.Length();
  649. Str = TrimRight(Buf);
  650. End -= Buf.Length() - Str.Length();
  651. }
  652. //---------------------------------------------------------------------------
  653. bool __fastcall TFileMasks::MatchesMaskMask(const TMaskMask & MaskMask, const UnicodeString & Str)
  654. {
  655. bool Result;
  656. if (MaskMask.Kind == TMaskMask::Any)
  657. {
  658. Result = true;
  659. }
  660. else if ((MaskMask.Kind == TMaskMask::NoExt) && (Str.Pos(L".") == 0))
  661. {
  662. Result = true;
  663. }
  664. else
  665. {
  666. Result = MaskMask.Mask->Matches(Str);
  667. }
  668. return Result;
  669. }
  670. //---------------------------------------------------------------------------
  671. void __fastcall TFileMasks::SetMasks(const UnicodeString value)
  672. {
  673. if (FStr != value)
  674. {
  675. SetStr(value, false);
  676. }
  677. }
  678. //---------------------------------------------------------------------------
  679. void __fastcall TFileMasks::SetMask(const UnicodeString & Mask)
  680. {
  681. SetStr(Mask, true);
  682. }
  683. //---------------------------------------------------------------------------
  684. void __fastcall TFileMasks::SetStr(const UnicodeString Str, bool SingleMask)
  685. {
  686. UnicodeString Backup = FStr;
  687. try
  688. {
  689. FStr = Str;
  690. Clear();
  691. int NextMaskFrom = 1;
  692. bool Include = true;
  693. while (NextMaskFrom <= Str.Length())
  694. {
  695. int MaskStart = NextMaskFrom;
  696. wchar_t NextMaskDelimiter;
  697. UnicodeString MaskStr;
  698. if (SingleMask)
  699. {
  700. MaskStr = Str;
  701. NextMaskFrom = Str.Length() + 1;
  702. NextMaskDelimiter = L'\0';
  703. }
  704. else
  705. {
  706. MaskStr = CopyToChars(Str, NextMaskFrom, AllFileMasksDelimiters, false, &NextMaskDelimiter, true);
  707. }
  708. int MaskEnd = NextMaskFrom - 2;
  709. TrimEx(MaskStr, MaskStart, MaskEnd);
  710. if (!MaskStr.IsEmpty())
  711. {
  712. CreateMask(MaskStr, MaskStart, MaskEnd, Include);
  713. }
  714. if (NextMaskDelimiter == IncludeExcludeFileMasksDelimiter)
  715. {
  716. if (Include)
  717. {
  718. Include = false;
  719. }
  720. else
  721. {
  722. ThrowError(NextMaskFrom - 1, Str.Length());
  723. }
  724. }
  725. }
  726. }
  727. catch(...)
  728. {
  729. // this does not work correctly if previous mask was set using SetMask.
  730. // this should not fail (the mask was validated before),
  731. // otherwise we end in an infinite loop
  732. SetStr(Backup, false);
  733. throw;
  734. }
  735. }
  736. //---------------------------------------------------------------------------
  737. //---------------------------------------------------------------------------
  738. #define TEXT_TOKEN L'\255'
  739. //---------------------------------------------------------------------------
  740. const wchar_t TCustomCommand::NoQuote = L'\0';
  741. const UnicodeString TCustomCommand::Quotes = L"\"'";
  742. //---------------------------------------------------------------------------
  743. UnicodeString __fastcall TCustomCommand::Escape(const UnicodeString & S)
  744. {
  745. return ReplaceStr(S, L"!", L"!!");
  746. }
  747. //---------------------------------------------------------------------------
  748. TCustomCommand::TCustomCommand()
  749. {
  750. }
  751. //---------------------------------------------------------------------------
  752. void __fastcall TCustomCommand::GetToken(
  753. const UnicodeString & Command, int Index, int & Len, wchar_t & PatternCmd)
  754. {
  755. DebugAssert(Index <= Command.Length());
  756. const wchar_t * Ptr = Command.c_str() + Index - 1;
  757. if (Ptr[0] == L'!')
  758. {
  759. PatternCmd = Ptr[1];
  760. if (PatternCmd == L'\0')
  761. {
  762. Len = 1;
  763. }
  764. else if (PatternCmd == L'!')
  765. {
  766. Len = 2;
  767. }
  768. else
  769. {
  770. Len = PatternLen(Command, Index);
  771. }
  772. if (Len <= 0)
  773. {
  774. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNKNOWN, (PatternCmd, Index)));
  775. }
  776. else
  777. {
  778. if ((Command.Length() - Index + 1) < Len)
  779. {
  780. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (PatternCmd, Index)));
  781. }
  782. }
  783. }
  784. else
  785. {
  786. PatternCmd = TEXT_TOKEN;
  787. const wchar_t * NextPattern = wcschr(Ptr, L'!');
  788. if (NextPattern == NULL)
  789. {
  790. Len = Command.Length() - Index + 1;
  791. }
  792. else
  793. {
  794. Len = NextPattern - Ptr;
  795. }
  796. }
  797. }
  798. //---------------------------------------------------------------------------
  799. void __fastcall TCustomCommand::PatternHint(int /*Index*/, const UnicodeString & /*Pattern*/)
  800. {
  801. // noop
  802. }
  803. //---------------------------------------------------------------------------
  804. UnicodeString __fastcall TCustomCommand::Complete(const UnicodeString & Command,
  805. bool LastPass)
  806. {
  807. int Index = 1;
  808. int PatternIndex = 0;
  809. while (Index <= Command.Length())
  810. {
  811. int Len;
  812. wchar_t PatternCmd;
  813. GetToken(Command, Index, Len, PatternCmd);
  814. if (PatternCmd == TEXT_TOKEN)
  815. {
  816. }
  817. else if (PatternCmd == L'!')
  818. {
  819. }
  820. else
  821. {
  822. UnicodeString Pattern = Command.SubString(Index, Len);
  823. PatternHint(PatternIndex, Pattern);
  824. PatternIndex++;
  825. }
  826. Index += Len;
  827. }
  828. UnicodeString Result;
  829. Index = 1;
  830. PatternIndex = 0;
  831. while (Index <= Command.Length())
  832. {
  833. int Len;
  834. wchar_t PatternCmd;
  835. GetToken(Command, Index, Len, PatternCmd);
  836. if (PatternCmd == TEXT_TOKEN)
  837. {
  838. Result += Command.SubString(Index, Len);
  839. }
  840. else if (PatternCmd == L'!')
  841. {
  842. if (LastPass)
  843. {
  844. Result += L'!';
  845. }
  846. else
  847. {
  848. Result += Command.SubString(Index, Len);
  849. }
  850. }
  851. else
  852. {
  853. wchar_t Quote = NoQuote;
  854. if ((Index > 1) && (Index + Len - 1 < Command.Length()) &&
  855. Command.IsDelimiter(Quotes, Index - 1) &&
  856. Command.IsDelimiter(Quotes, Index + Len) &&
  857. (Command[Index - 1] == Command[Index + Len]))
  858. {
  859. Quote = Command[Index - 1];
  860. }
  861. UnicodeString Pattern = Command.SubString(Index, Len);
  862. UnicodeString Replacement;
  863. bool Delimit = true;
  864. if (PatternReplacement(PatternIndex, Pattern, Replacement, Delimit))
  865. {
  866. if (!LastPass)
  867. {
  868. Replacement = Escape(Replacement);
  869. }
  870. if (Delimit)
  871. {
  872. DelimitReplacement(Replacement, Quote);
  873. }
  874. Result += Replacement;
  875. }
  876. else
  877. {
  878. Result += Pattern;
  879. }
  880. PatternIndex++;
  881. }
  882. Index += Len;
  883. }
  884. return Result;
  885. }
  886. //---------------------------------------------------------------------------
  887. void __fastcall TCustomCommand::DelimitReplacement(UnicodeString & Replacement, wchar_t Quote)
  888. {
  889. Replacement = ShellDelimitStr(Replacement, Quote);
  890. }
  891. //---------------------------------------------------------------------------
  892. void __fastcall TCustomCommand::Validate(const UnicodeString & Command)
  893. {
  894. CustomValidate(Command, NULL);
  895. }
  896. //---------------------------------------------------------------------------
  897. void __fastcall TCustomCommand::CustomValidate(const UnicodeString & Command,
  898. void * Arg)
  899. {
  900. int Index = 1;
  901. while (Index <= Command.Length())
  902. {
  903. int Len;
  904. wchar_t PatternCmd;
  905. GetToken(Command, Index, Len, PatternCmd);
  906. ValidatePattern(Command, Index, Len, PatternCmd, Arg);
  907. Index += Len;
  908. }
  909. }
  910. //---------------------------------------------------------------------------
  911. bool __fastcall TCustomCommand::FindPattern(const UnicodeString & Command,
  912. wchar_t PatternCmd)
  913. {
  914. bool Result = false;
  915. int Index = 1;
  916. while (!Result && (Index <= Command.Length()))
  917. {
  918. int Len;
  919. wchar_t APatternCmd;
  920. GetToken(Command, Index, Len, APatternCmd);
  921. if (((PatternCmd != L'!') && (tolower(PatternCmd) == tolower(APatternCmd))) ||
  922. ((PatternCmd == L'!') && (Len == 1) && (APatternCmd != TEXT_TOKEN)) ||
  923. ((PatternCmd == L'\0') && (APatternCmd != TEXT_TOKEN)))
  924. {
  925. Result = true;
  926. }
  927. Index += Len;
  928. }
  929. return Result;
  930. }
  931. //---------------------------------------------------------------------------
  932. bool __fastcall TCustomCommand::HasAnyPatterns(const UnicodeString & Command)
  933. {
  934. return FindPattern(Command, L'\0');
  935. }
  936. //---------------------------------------------------------------------------
  937. void __fastcall TCustomCommand::ValidatePattern(const UnicodeString & /*Command*/,
  938. int /*Index*/, int /*Len*/, wchar_t /*PatternCmd*/, void * /*Arg*/)
  939. {
  940. }
  941. //---------------------------------------------------------------------------
  942. //---------------------------------------------------------------------------
  943. TInteractiveCustomCommand::TInteractiveCustomCommand(
  944. TCustomCommand * ChildCustomCommand)
  945. {
  946. FChildCustomCommand = ChildCustomCommand;
  947. }
  948. //---------------------------------------------------------------------------
  949. void __fastcall TInteractiveCustomCommand::Prompt(
  950. int /*Index*/, const UnicodeString & /*Prompt*/, UnicodeString & Value)
  951. {
  952. Value = L"";
  953. }
  954. //---------------------------------------------------------------------------
  955. void __fastcall TInteractiveCustomCommand::Execute(
  956. const UnicodeString & /*Command*/, UnicodeString & Value)
  957. {
  958. Value = L"";
  959. }
  960. //---------------------------------------------------------------------------
  961. int __fastcall TInteractiveCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  962. {
  963. int Len;
  964. wchar_t PatternCmd = (Index < Command.Length()) ? Command[Index + 1] : L'\0';
  965. switch (PatternCmd)
  966. {
  967. case L'?':
  968. {
  969. const wchar_t * Ptr = Command.c_str() + Index - 1;
  970. const wchar_t * PatternEnd = wcschr(Ptr + 1, L'!');
  971. if (PatternEnd == NULL)
  972. {
  973. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (Command[Index + 1], Index)));
  974. }
  975. Len = PatternEnd - Ptr + 1;
  976. }
  977. break;
  978. case L'`':
  979. {
  980. const wchar_t * Ptr = Command.c_str() + Index - 1;
  981. const wchar_t * PatternEnd = wcschr(Ptr + 2, L'`');
  982. if (PatternEnd == NULL)
  983. {
  984. throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, (Command[Index + 1], Index)));
  985. }
  986. Len = PatternEnd - Ptr + 1;
  987. }
  988. break;
  989. default:
  990. Len = FChildCustomCommand->PatternLen(Command, Index);
  991. break;
  992. }
  993. return Len;
  994. }
  995. //---------------------------------------------------------------------------
  996. bool __fastcall TInteractiveCustomCommand::IsPromptPattern(const UnicodeString & Pattern)
  997. {
  998. return (Pattern.Length() >= 3) && (Pattern[2] == L'?');
  999. }
  1000. //---------------------------------------------------------------------------
  1001. void __fastcall TInteractiveCustomCommand::ParsePromptPattern(
  1002. const UnicodeString & Pattern, UnicodeString & Prompt, UnicodeString & Default, bool & Delimit)
  1003. {
  1004. int Pos = Pattern.SubString(3, Pattern.Length() - 2).Pos(L"?");
  1005. if (Pos > 0)
  1006. {
  1007. Default = Pattern.SubString(3 + Pos, Pattern.Length() - 3 - Pos);
  1008. if ((Pos > 1) && (Pattern[3 + Pos - 2] == L'\\'))
  1009. {
  1010. Delimit = false;
  1011. Pos--;
  1012. }
  1013. Prompt = Pattern.SubString(3, Pos - 1);
  1014. }
  1015. else
  1016. {
  1017. Prompt = Pattern.SubString(3, Pattern.Length() - 3);
  1018. }
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. bool __fastcall TInteractiveCustomCommand::PatternReplacement(int Index, const UnicodeString & Pattern,
  1022. UnicodeString & Replacement, bool & Delimit)
  1023. {
  1024. bool Result;
  1025. if (IsPromptPattern(Pattern))
  1026. {
  1027. UnicodeString PromptStr;
  1028. // The PromptStr and Replacement are actually never used
  1029. // as the only implementation (TWinInteractiveCustomCommand) uses
  1030. // prompts and defaults from PatternHint.
  1031. ParsePromptPattern(Pattern, PromptStr, Replacement, Delimit);
  1032. Prompt(Index, PromptStr, Replacement);
  1033. Result = true;
  1034. }
  1035. else if ((Pattern.Length() >= 3) && (Pattern[2] == L'`'))
  1036. {
  1037. UnicodeString Command = Pattern.SubString(3, Pattern.Length() - 3);
  1038. Command = FChildCustomCommand->Complete(Command, true);
  1039. Execute(Command, Replacement);
  1040. Delimit = false;
  1041. Result = true;
  1042. }
  1043. else
  1044. {
  1045. Result = false;
  1046. }
  1047. return Result;
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. //---------------------------------------------------------------------------
  1051. __fastcall TCustomCommandData::TCustomCommandData()
  1052. {
  1053. }
  1054. //---------------------------------------------------------------------------
  1055. __fastcall TCustomCommandData::TCustomCommandData(TTerminal * Terminal)
  1056. {
  1057. Init(Terminal->SessionData, Terminal->UserName, Terminal->Password,
  1058. Terminal->GetSessionInfo().HostKeyFingerprint);
  1059. }
  1060. //---------------------------------------------------------------------------
  1061. __fastcall TCustomCommandData::TCustomCommandData(
  1062. TSessionData * SessionData, const UnicodeString & UserName, const UnicodeString & Password)
  1063. {
  1064. Init(SessionData, UserName, Password, UnicodeString());
  1065. }
  1066. //---------------------------------------------------------------------------
  1067. void __fastcall TCustomCommandData::Init(
  1068. TSessionData * ASessionData, const UnicodeString & AUserName,
  1069. const UnicodeString & APassword, const UnicodeString & AHostKey)
  1070. {
  1071. FSessionData.reset(new TSessionData(L""));
  1072. FSessionData->Assign(ASessionData);
  1073. FSessionData->UserName = AUserName;
  1074. FSessionData->Password = APassword;
  1075. FSessionData->HostKey = AHostKey;
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TCustomCommandData::operator=(const TCustomCommandData & Data)
  1079. {
  1080. DebugAssert(Data.SessionData != NULL);
  1081. FSessionData.reset(new TSessionData(L""));
  1082. FSessionData->Assign(Data.SessionData);
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. TSessionData * __fastcall TCustomCommandData::GetSesssionData() const
  1086. {
  1087. return FSessionData.get();
  1088. }
  1089. //---------------------------------------------------------------------------
  1090. //---------------------------------------------------------------------------
  1091. TFileCustomCommand::TFileCustomCommand()
  1092. {
  1093. }
  1094. //---------------------------------------------------------------------------
  1095. TFileCustomCommand::TFileCustomCommand(const TCustomCommandData & Data,
  1096. const UnicodeString & Path)
  1097. {
  1098. FData = Data;
  1099. FPath = Path;
  1100. }
  1101. //---------------------------------------------------------------------------
  1102. TFileCustomCommand::TFileCustomCommand(const TCustomCommandData & Data,
  1103. const UnicodeString & Path, const UnicodeString & FileName,
  1104. const UnicodeString & FileList) :
  1105. TCustomCommand()
  1106. {
  1107. FData = Data;
  1108. FPath = Path;
  1109. FFileName = FileName;
  1110. FFileList = FileList;
  1111. }
  1112. //---------------------------------------------------------------------------
  1113. int __fastcall TFileCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  1114. {
  1115. int Len;
  1116. wchar_t PatternCmd = (Index < Command.Length()) ? tolower(Command[Index + 1]) : L'\0';
  1117. switch (PatternCmd)
  1118. {
  1119. case L's':
  1120. case L'@':
  1121. case L'u':
  1122. case L'p':
  1123. case L'#':
  1124. case L'/':
  1125. case L'&':
  1126. case L'n':
  1127. Len = 2;
  1128. break;
  1129. default:
  1130. Len = 1;
  1131. break;
  1132. }
  1133. return Len;
  1134. }
  1135. //---------------------------------------------------------------------------
  1136. bool __fastcall TFileCustomCommand::PatternReplacement(
  1137. int /*Index*/, const UnicodeString & Pattern, UnicodeString & Replacement, bool & Delimit)
  1138. {
  1139. // keep consistent with TSessionLog::OpenLogFile
  1140. if (SameText(Pattern, L"!s"))
  1141. {
  1142. Replacement = FData.SessionData->GenerateSessionUrl(sufComplete);
  1143. }
  1144. else if (Pattern == L"!@")
  1145. {
  1146. Replacement = FData.SessionData->HostNameExpanded;
  1147. }
  1148. else if (SameText(Pattern, L"!u"))
  1149. {
  1150. Replacement = FData.SessionData->UserName;
  1151. }
  1152. else if (SameText(Pattern, L"!p"))
  1153. {
  1154. Replacement = FData.SessionData->Password;
  1155. }
  1156. else if (SameText(Pattern, L"!#"))
  1157. {
  1158. Replacement = IntToStr(FData.SessionData->PortNumber);
  1159. }
  1160. else if (Pattern == L"!/")
  1161. {
  1162. Replacement = UnixIncludeTrailingBackslash(FPath);
  1163. }
  1164. else if (Pattern == L"!&")
  1165. {
  1166. Replacement = FFileList;
  1167. // already delimited
  1168. Delimit = false;
  1169. }
  1170. else if (SameText(Pattern, L"!n"))
  1171. {
  1172. Replacement = FData.SessionData->SessionName;
  1173. }
  1174. else
  1175. {
  1176. DebugAssert(Pattern.Length() == 1);
  1177. Replacement = FFileName;
  1178. }
  1179. return true;
  1180. }
  1181. //---------------------------------------------------------------------------
  1182. void __fastcall TFileCustomCommand::Validate(const UnicodeString & Command)
  1183. {
  1184. int Found[2] = { 0, 0 };
  1185. CustomValidate(Command, &Found);
  1186. if ((Found[0] > 0) && (Found[1] > 0))
  1187. {
  1188. throw Exception(FMTLOAD(CUSTOM_COMMAND_FILELIST_ERROR,
  1189. (Found[1], Found[0])));
  1190. }
  1191. }
  1192. //---------------------------------------------------------------------------
  1193. void __fastcall TFileCustomCommand::ValidatePattern(const UnicodeString & Command,
  1194. int Index, int /*Len*/, wchar_t PatternCmd, void * Arg)
  1195. {
  1196. int * Found = static_cast<int *>(Arg);
  1197. DebugAssert(Index > 0);
  1198. if (PatternCmd == L'&')
  1199. {
  1200. Found[0] = Index;
  1201. }
  1202. else if ((PatternCmd != TEXT_TOKEN) && (PatternLen(Command, Index) == 1))
  1203. {
  1204. Found[1] = Index;
  1205. }
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. bool __fastcall TFileCustomCommand::IsFileListCommand(const UnicodeString & Command)
  1209. {
  1210. return FindPattern(Command, L'&');
  1211. }
  1212. //---------------------------------------------------------------------------
  1213. bool __fastcall TFileCustomCommand::IsRemoteFileCommand(const UnicodeString & Command)
  1214. {
  1215. return FindPattern(Command, L'!') || FindPattern(Command, L'&');
  1216. }
  1217. //---------------------------------------------------------------------------
  1218. bool __fastcall TFileCustomCommand::IsFileCommand(const UnicodeString & Command)
  1219. {
  1220. return IsRemoteFileCommand(Command);
  1221. }
  1222. //---------------------------------------------------------------------------
  1223. bool __fastcall TFileCustomCommand::IsSiteCommand(const UnicodeString & Command)
  1224. {
  1225. return FindPattern(Command, L'@');
  1226. }
  1227. //---------------------------------------------------------------------------
  1228. bool __fastcall TFileCustomCommand::IsPasswordCommand(const UnicodeString & Command)
  1229. {
  1230. return FindPattern(Command, L'p');
  1231. }
  1232. //---------------------------------------------------------------------------