FileMasks.cpp 39 KB

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