FileMasks.cpp 39 KB

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