RemoteFiles.cpp 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Common.h"
  5. #include "RemoteFiles.h"
  6. #include <SysUtils.hpp>
  7. #include <StrUtils.hpp>
  8. #include "Exceptions.h"
  9. #include "Interface.h"
  10. #include "Terminal.h"
  11. #include "TextsCore.h"
  12. #include "HelpCore.h"
  13. /* TODO 1 : Path class instead of UnicodeString (handle relativity...) */
  14. //---------------------------------------------------------------------------
  15. UnicodeString __fastcall UnixIncludeTrailingBackslash(const UnicodeString Path)
  16. {
  17. // it used to return "/" when input path was empty
  18. if (!Path.IsEmpty() && !Path.IsDelimiter(L"/", Path.Length()))
  19. {
  20. return Path + L"/";
  21. }
  22. else
  23. {
  24. return Path;
  25. }
  26. }
  27. //---------------------------------------------------------------------------
  28. // Keeps "/" for root path
  29. UnicodeString __fastcall UnixExcludeTrailingBackslash(const UnicodeString Path)
  30. {
  31. if ((Path.Length() > 1) && Path.IsDelimiter(L"/", Path.Length()))
  32. return Path.SubString(1, Path.Length() - 1);
  33. else return Path;
  34. }
  35. //---------------------------------------------------------------------------
  36. Boolean __fastcall UnixComparePaths(const UnicodeString Path1, const UnicodeString Path2)
  37. {
  38. return (UnixIncludeTrailingBackslash(Path1) == UnixIncludeTrailingBackslash(Path2));
  39. }
  40. //---------------------------------------------------------------------------
  41. bool __fastcall UnixIsChildPath(UnicodeString Parent, UnicodeString Child)
  42. {
  43. Parent = UnixIncludeTrailingBackslash(Parent);
  44. Child = UnixIncludeTrailingBackslash(Child);
  45. return (Child.SubString(1, Parent.Length()) == Parent);
  46. }
  47. //---------------------------------------------------------------------------
  48. UnicodeString __fastcall UnixExtractFileDir(const UnicodeString Path)
  49. {
  50. int Pos = Path.LastDelimiter(L'/');
  51. // it used to return Path when no slash was found
  52. if (Pos > 1)
  53. {
  54. return Path.SubString(1, Pos - 1);
  55. }
  56. else
  57. {
  58. return (Pos == 1) ? UnicodeString(L"/") : UnicodeString();
  59. }
  60. }
  61. //---------------------------------------------------------------------------
  62. // must return trailing backslash
  63. UnicodeString __fastcall UnixExtractFilePath(const UnicodeString Path)
  64. {
  65. int Pos = Path.LastDelimiter(L'/');
  66. // it used to return Path when no slash was found
  67. return (Pos > 0) ? Path.SubString(1, Pos) : UnicodeString();
  68. }
  69. //---------------------------------------------------------------------------
  70. UnicodeString __fastcall UnixExtractFileName(const UnicodeString Path)
  71. {
  72. int Pos = Path.LastDelimiter(L'/');
  73. UnicodeString Result;
  74. if (Pos > 0)
  75. {
  76. Result = Path.SubString(Pos + 1, Path.Length() - Pos);
  77. }
  78. else
  79. {
  80. Result = Path;
  81. }
  82. return Result;
  83. }
  84. //---------------------------------------------------------------------------
  85. UnicodeString __fastcall UnixExtractFileExt(const UnicodeString Path)
  86. {
  87. UnicodeString FileName = UnixExtractFileName(Path);
  88. int Pos = FileName.LastDelimiter(L".");
  89. return (Pos > 0) ? Path.SubString(Pos, Path.Length() - Pos + 1) : UnicodeString();
  90. }
  91. //---------------------------------------------------------------------------
  92. UnicodeString __fastcall ExtractFileName(const UnicodeString & Path, bool Unix)
  93. {
  94. if (Unix)
  95. {
  96. return UnixExtractFileName(Path);
  97. }
  98. else
  99. {
  100. return ExtractFileName(Path);
  101. }
  102. }
  103. //---------------------------------------------------------------------------
  104. bool __fastcall ExtractCommonPath(TStrings * Files, UnicodeString & Path)
  105. {
  106. assert(Files->Count > 0);
  107. Path = ExtractFilePath(Files->Strings[0]);
  108. bool Result = !Path.IsEmpty();
  109. if (Result)
  110. {
  111. for (int Index = 1; Index < Files->Count; Index++)
  112. {
  113. while (!Path.IsEmpty() &&
  114. (Files->Strings[Index].SubString(1, Path.Length()) != Path))
  115. {
  116. int PrevLen = Path.Length();
  117. Path = ExtractFilePath(ExcludeTrailingBackslash(Path));
  118. if (Path.Length() == PrevLen)
  119. {
  120. Path = L"";
  121. Result = false;
  122. }
  123. }
  124. }
  125. }
  126. return Result;
  127. }
  128. //---------------------------------------------------------------------------
  129. bool __fastcall UnixExtractCommonPath(TStrings * Files, UnicodeString & Path)
  130. {
  131. assert(Files->Count > 0);
  132. Path = UnixExtractFilePath(Files->Strings[0]);
  133. bool Result = !Path.IsEmpty();
  134. if (Result)
  135. {
  136. for (int Index = 1; Index < Files->Count; Index++)
  137. {
  138. while (!Path.IsEmpty() &&
  139. (Files->Strings[Index].SubString(1, Path.Length()) != Path))
  140. {
  141. int PrevLen = Path.Length();
  142. Path = UnixExtractFilePath(UnixExcludeTrailingBackslash(Path));
  143. if (Path.Length() == PrevLen)
  144. {
  145. Path = L"";
  146. Result = false;
  147. }
  148. }
  149. }
  150. }
  151. return Result;
  152. }
  153. //---------------------------------------------------------------------------
  154. bool __fastcall IsUnixRootPath(const UnicodeString Path)
  155. {
  156. return Path.IsEmpty() || (Path == ROOTDIRECTORY);
  157. }
  158. //---------------------------------------------------------------------------
  159. bool __fastcall IsUnixHiddenFile(const UnicodeString FileName)
  160. {
  161. return (FileName != ROOTDIRECTORY) && (FileName != PARENTDIRECTORY) &&
  162. !FileName.IsEmpty() && (FileName[1] == L'.');
  163. }
  164. //---------------------------------------------------------------------------
  165. UnicodeString __fastcall AbsolutePath(const UnicodeString & Base, const UnicodeString & Path)
  166. {
  167. UnicodeString Result;
  168. if (Path.IsEmpty())
  169. {
  170. Result = Base;
  171. }
  172. else if (Path[1] == L'/')
  173. {
  174. Result = UnixExcludeTrailingBackslash(Path);
  175. }
  176. else
  177. {
  178. Result = UnixIncludeTrailingBackslash(
  179. UnixIncludeTrailingBackslash(Base) + Path);
  180. int P;
  181. while ((P = Result.Pos(L"/../")) > 0)
  182. {
  183. int P2 = Result.SubString(1, P-1).LastDelimiter(L"/");
  184. assert(P2 > 0);
  185. Result.Delete(P2, P - P2 + 3);
  186. }
  187. while ((P = Result.Pos(L"/./")) > 0)
  188. {
  189. Result.Delete(P, 2);
  190. }
  191. Result = UnixExcludeTrailingBackslash(Result);
  192. }
  193. return Result;
  194. }
  195. //---------------------------------------------------------------------------
  196. UnicodeString __fastcall FromUnixPath(const UnicodeString Path)
  197. {
  198. return ReplaceStr(Path, L"/", L"\\");
  199. }
  200. //---------------------------------------------------------------------------
  201. UnicodeString __fastcall ToUnixPath(const UnicodeString Path)
  202. {
  203. return ReplaceStr(Path, L"\\", L"/");
  204. }
  205. //---------------------------------------------------------------------------
  206. static void __fastcall CutFirstDirectory(UnicodeString & S, bool Unix)
  207. {
  208. bool Root;
  209. int P;
  210. UnicodeString Sep = Unix ? L"/" : L"\\";
  211. if (S == Sep)
  212. {
  213. S = L"";
  214. }
  215. else
  216. {
  217. if (S[1] == Sep[1])
  218. {
  219. Root = true;
  220. S.Delete(1, 1);
  221. }
  222. else
  223. {
  224. Root = false;
  225. }
  226. if (S[1] == L'.')
  227. {
  228. S.Delete(1, 4);
  229. }
  230. P = S.Pos(Sep[1]);
  231. if (P)
  232. {
  233. S.Delete(1, P);
  234. S = L"..." + Sep + S;
  235. }
  236. else
  237. {
  238. S = L"";
  239. }
  240. if (Root)
  241. {
  242. S = Sep + S;
  243. }
  244. }
  245. }
  246. //---------------------------------------------------------------------------
  247. UnicodeString __fastcall MinimizeName(const UnicodeString FileName, int MaxLen, bool Unix)
  248. {
  249. UnicodeString Drive, Dir, Name, Result;
  250. UnicodeString Sep = Unix ? L"/" : L"\\";
  251. Result = FileName;
  252. if (Unix)
  253. {
  254. int P = Result.LastDelimiter(L"/");
  255. if (P)
  256. {
  257. Dir = Result.SubString(1, P);
  258. Name = Result.SubString(P + 1, Result.Length() - P);
  259. }
  260. else
  261. {
  262. Dir = L"";
  263. Name = Result;
  264. }
  265. }
  266. else
  267. {
  268. Dir = ExtractFilePath(Result);
  269. Name = ExtractFileName(Result);
  270. if (Dir.Length() >= 2 && Dir[2] == L':')
  271. {
  272. Drive = Dir.SubString(1, 2);
  273. Dir.Delete(1, 2);
  274. }
  275. }
  276. while ((!Dir.IsEmpty() || !Drive.IsEmpty()) && (Result.Length() > MaxLen))
  277. {
  278. if (Dir == Sep + L"..." + Sep)
  279. {
  280. Dir = L"..." + Sep;
  281. }
  282. else if (Dir == L"")
  283. {
  284. Drive = L"";
  285. }
  286. else
  287. {
  288. CutFirstDirectory(Dir, Unix);
  289. }
  290. Result = Drive + Dir + Name;
  291. }
  292. if (Result.Length() > MaxLen)
  293. {
  294. Result = Result.SubString(1, MaxLen);
  295. }
  296. return Result;
  297. }
  298. //---------------------------------------------------------------------------
  299. UnicodeString __fastcall MakeFileList(TStrings * FileList)
  300. {
  301. UnicodeString Result;
  302. for (int Index = 0; Index < FileList->Count; Index++)
  303. {
  304. if (!Result.IsEmpty())
  305. {
  306. Result += L" ";
  307. }
  308. UnicodeString FileName = FileList->Strings[Index];
  309. // currently this is used for local file only, so no delimiting is done
  310. if (FileName.Pos(L" ") > 0)
  311. {
  312. Result += L"\"" + FileName + L"\"";
  313. }
  314. else
  315. {
  316. Result += FileName;
  317. }
  318. }
  319. return Result;
  320. }
  321. //---------------------------------------------------------------------------
  322. // copy from BaseUtils.pas
  323. TDateTime __fastcall ReduceDateTimePrecision(TDateTime DateTime,
  324. TModificationFmt Precision)
  325. {
  326. if (Precision == mfNone)
  327. {
  328. DateTime = double(0);
  329. }
  330. else if (Precision != mfFull)
  331. {
  332. unsigned short Y, M, D, H, N, S, MS;
  333. DecodeDate(DateTime, Y, M, D);
  334. DecodeTime(DateTime, H, N, S, MS);
  335. switch (Precision)
  336. {
  337. case mfMDHM:
  338. S = 0;
  339. MS = 0;
  340. break;
  341. case mfMDY:
  342. H = 0;
  343. N = 0;
  344. S = 0;
  345. MS = 0;
  346. break;
  347. default:
  348. assert(false);
  349. }
  350. DateTime = EncodeDateVerbose(Y, M, D) + EncodeTimeVerbose(H, N, S, MS);
  351. }
  352. return DateTime;
  353. }
  354. //---------------------------------------------------------------------------
  355. TModificationFmt __fastcall LessDateTimePrecision(
  356. TModificationFmt Precision1, TModificationFmt Precision2)
  357. {
  358. return (Precision1 < Precision2) ? Precision1 : Precision2;
  359. }
  360. //---------------------------------------------------------------------------
  361. UnicodeString __fastcall UserModificationStr(TDateTime DateTime,
  362. TModificationFmt Precision)
  363. {
  364. switch (Precision)
  365. {
  366. case mfNone:
  367. return L"";
  368. case mfMDY:
  369. return FormatDateTime(L"ddddd", DateTime);
  370. case mfMDHM:
  371. return FormatDateTime(L"ddddd t", DateTime);
  372. case mfFull:
  373. default:
  374. return FormatDateTime(L"ddddd tt", DateTime);
  375. }
  376. }
  377. //---------------------------------------------------------------------------
  378. UnicodeString __fastcall ModificationStr(TDateTime DateTime,
  379. TModificationFmt Precision)
  380. {
  381. Word Year, Month, Day, Hour, Min, Sec, MSec;
  382. DateTime.DecodeDate(&Year, &Month, &Day);
  383. DateTime.DecodeTime(&Hour, &Min, &Sec, &MSec);
  384. switch (Precision)
  385. {
  386. case mfNone:
  387. return L"";
  388. case mfMDY:
  389. return FORMAT(L"%3s %2d %2d", (EngShortMonthNames[Month-1], Day, Year));
  390. case mfMDHM:
  391. return FORMAT(L"%3s %2d %2d:%2.2d",
  392. (EngShortMonthNames[Month-1], Day, Hour, Min));
  393. default:
  394. assert(false);
  395. // fall thru
  396. case mfFull:
  397. return FORMAT(L"%3s %2d %2d:%2.2d:%2.2d %4d",
  398. (EngShortMonthNames[Month-1], Day, Hour, Min, Sec, Year));
  399. }
  400. }
  401. //---------------------------------------------------------------------------
  402. int __fastcall FakeFileImageIndex(UnicodeString FileName, unsigned long Attrs,
  403. UnicodeString * TypeName)
  404. {
  405. Attrs |= FILE_ATTRIBUTE_NORMAL;
  406. TSHFileInfoW SHFileInfo;
  407. // On Win2k we get icon of "ZIP drive" for ".." (parent directory)
  408. if ((FileName == L"..") ||
  409. ((FileName.Length() == 2) && (FileName[2] == L':') &&
  410. (towlower(FileName[1]) >= L'a') && (towlower(FileName[1]) <= L'z')) ||
  411. IsReservedName(FileName))
  412. {
  413. FileName = L"dumb";
  414. }
  415. // this should be somewhere else, probably in TUnixDirView,
  416. // as the "partial" overlay is added there too
  417. if (AnsiSameText(UnixExtractFileExt(FileName), PARTIAL_EXT))
  418. {
  419. static const size_t PartialExtLen = LENOF(PARTIAL_EXT) - 1;
  420. FileName.SetLength(FileName.Length() - PartialExtLen);
  421. }
  422. int Icon;
  423. if (SHGetFileInfo(UnicodeString(FileName).c_str(),
  424. Attrs, &SHFileInfo, sizeof(SHFileInfo),
  425. SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES | SHGFI_TYPENAME) != 0)
  426. {
  427. if (TypeName != NULL)
  428. {
  429. *TypeName = SHFileInfo.szTypeName;
  430. }
  431. Icon = SHFileInfo.iIcon;
  432. }
  433. else
  434. {
  435. if (TypeName != NULL)
  436. {
  437. *TypeName = L"";
  438. }
  439. Icon = -1;
  440. }
  441. return Icon;
  442. }
  443. //---------------------------------------------------------------------------
  444. __fastcall TRemoteToken::TRemoteToken() :
  445. FID(0),
  446. FIDValid(false)
  447. {
  448. }
  449. //---------------------------------------------------------------------------
  450. __fastcall TRemoteToken::TRemoteToken(const UnicodeString & Name) :
  451. FName(Name),
  452. FID(0),
  453. FIDValid(false)
  454. {
  455. }
  456. //---------------------------------------------------------------------------
  457. void __fastcall TRemoteToken::Clear()
  458. {
  459. FID = 0;
  460. FIDValid = false;
  461. }
  462. //---------------------------------------------------------------------------
  463. bool __fastcall TRemoteToken::operator ==(const TRemoteToken & rht) const
  464. {
  465. return
  466. (FName == rht.FName) &&
  467. (FIDValid == rht.FIDValid) &&
  468. (!FIDValid || (FID == rht.FID));
  469. }
  470. //---------------------------------------------------------------------------
  471. bool __fastcall TRemoteToken::operator !=(const TRemoteToken & rht) const
  472. {
  473. return !(*this == rht);
  474. }
  475. //---------------------------------------------------------------------------
  476. TRemoteToken & __fastcall TRemoteToken::operator =(const TRemoteToken & rht)
  477. {
  478. if (this != &rht)
  479. {
  480. FName = rht.FName;
  481. FIDValid = rht.FIDValid;
  482. FID = rht.FID;
  483. }
  484. return *this;
  485. }
  486. //---------------------------------------------------------------------------
  487. int __fastcall TRemoteToken::Compare(const TRemoteToken & rht) const
  488. {
  489. int Result;
  490. if (!FName.IsEmpty())
  491. {
  492. if (!rht.FName.IsEmpty())
  493. {
  494. Result = AnsiCompareText(FName, rht.FName);
  495. }
  496. else
  497. {
  498. Result = -1;
  499. }
  500. }
  501. else
  502. {
  503. if (!rht.FName.IsEmpty())
  504. {
  505. Result = 1;
  506. }
  507. else
  508. {
  509. if (FIDValid)
  510. {
  511. if (rht.FIDValid)
  512. {
  513. Result = (FID < rht.FID) ? -1 : ((FID > rht.FID) ? 1 : 0);
  514. }
  515. else
  516. {
  517. Result = -1;
  518. }
  519. }
  520. else
  521. {
  522. if (rht.FIDValid)
  523. {
  524. Result = 1;
  525. }
  526. else
  527. {
  528. Result = 0;
  529. }
  530. }
  531. }
  532. }
  533. return Result;
  534. }
  535. //---------------------------------------------------------------------------
  536. void __fastcall TRemoteToken::SetID(unsigned int value)
  537. {
  538. FID = value;
  539. FIDValid = true;
  540. }
  541. //---------------------------------------------------------------------------
  542. bool __fastcall TRemoteToken::GetNameValid() const
  543. {
  544. return !FName.IsEmpty();
  545. }
  546. //---------------------------------------------------------------------------
  547. bool __fastcall TRemoteToken::GetIsSet() const
  548. {
  549. return !FName.IsEmpty() || FIDValid;
  550. }
  551. //---------------------------------------------------------------------------
  552. UnicodeString __fastcall TRemoteToken::GetDisplayText() const
  553. {
  554. if (!FName.IsEmpty())
  555. {
  556. return FName;
  557. }
  558. else if (FIDValid)
  559. {
  560. return IntToStr(int(FID));
  561. }
  562. else
  563. {
  564. return UnicodeString();
  565. }
  566. }
  567. //---------------------------------------------------------------------------
  568. UnicodeString __fastcall TRemoteToken::GetLogText() const
  569. {
  570. return FORMAT(L"\"%s\" [%d]", (FName, int(FID)));
  571. }
  572. //---------------------------------------------------------------------------
  573. //---------------------------------------------------------------------------
  574. TRemoteTokenList * __fastcall TRemoteTokenList::Duplicate() const
  575. {
  576. TRemoteTokenList * Result = new TRemoteTokenList();
  577. try
  578. {
  579. TTokens::const_iterator I = FTokens.begin();
  580. while (I != FTokens.end())
  581. {
  582. Result->Add(*I);
  583. ++I;
  584. }
  585. }
  586. catch(...)
  587. {
  588. delete Result;
  589. throw;
  590. }
  591. return Result;
  592. }
  593. //---------------------------------------------------------------------------
  594. void __fastcall TRemoteTokenList::Clear()
  595. {
  596. FTokens.clear();
  597. FNameMap.clear();
  598. FIDMap.clear();
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TRemoteTokenList::Add(const TRemoteToken & Token)
  602. {
  603. FTokens.push_back(Token);
  604. if (Token.IDValid)
  605. {
  606. std::pair<TIDMap::iterator, bool> Position =
  607. FIDMap.insert(TIDMap::value_type(Token.ID, FTokens.size() - 1));
  608. }
  609. if (Token.NameValid)
  610. {
  611. std::pair<TNameMap::iterator, bool> Position =
  612. FNameMap.insert(TNameMap::value_type(Token.Name, FTokens.size() - 1));
  613. }
  614. }
  615. //---------------------------------------------------------------------------
  616. void __fastcall TRemoteTokenList::AddUnique(const TRemoteToken & Token)
  617. {
  618. if (Token.IDValid)
  619. {
  620. TIDMap::const_iterator I = FIDMap.find(Token.ID);
  621. if (I != FIDMap.end())
  622. {
  623. // is present already.
  624. // may have different name (should not),
  625. // but what can we do about it anyway?
  626. }
  627. else
  628. {
  629. Add(Token);
  630. }
  631. }
  632. else if (Token.NameValid)
  633. {
  634. TNameMap::const_iterator I = FNameMap.find(Token.Name);
  635. if (I != FNameMap.end())
  636. {
  637. // is present already.
  638. }
  639. else
  640. {
  641. Add(Token);
  642. }
  643. }
  644. else
  645. {
  646. // can happen, e.g. with winsshd/SFTP
  647. }
  648. }
  649. //---------------------------------------------------------------------------
  650. bool __fastcall TRemoteTokenList::Exists(const UnicodeString & Name) const
  651. {
  652. return (FNameMap.find(Name) != FNameMap.end());
  653. }
  654. //---------------------------------------------------------------------------
  655. const TRemoteToken * TRemoteTokenList::Find(unsigned int ID) const
  656. {
  657. TIDMap::const_iterator I = FIDMap.find(ID);
  658. const TRemoteToken * Result;
  659. if (I != FIDMap.end())
  660. {
  661. Result = &FTokens[(*I).second];
  662. }
  663. else
  664. {
  665. Result = NULL;
  666. }
  667. return Result;
  668. }
  669. //---------------------------------------------------------------------------
  670. const TRemoteToken * TRemoteTokenList::Find(const UnicodeString & Name) const
  671. {
  672. TNameMap::const_iterator I = FNameMap.find(Name);
  673. const TRemoteToken * Result;
  674. if (I != FNameMap.end())
  675. {
  676. Result = &FTokens[(*I).second];
  677. }
  678. else
  679. {
  680. Result = NULL;
  681. }
  682. return Result;
  683. }
  684. //---------------------------------------------------------------------------
  685. void __fastcall TRemoteTokenList::Log(TTerminal * Terminal, const wchar_t * Title)
  686. {
  687. if (!FTokens.empty())
  688. {
  689. Terminal->LogEvent(FORMAT(L"Following %s found:", (Title)));
  690. for (size_t Index = 0; Index < FTokens.size(); Index++)
  691. {
  692. Terminal->LogEvent(UnicodeString(L" ") + FTokens[Index].LogText);
  693. }
  694. }
  695. else
  696. {
  697. Terminal->LogEvent(FORMAT(L"No %s found.", (Title)));
  698. }
  699. }
  700. //---------------------------------------------------------------------------
  701. int __fastcall TRemoteTokenList::Count() const
  702. {
  703. return (int)FTokens.size();
  704. }
  705. //---------------------------------------------------------------------------
  706. const TRemoteToken * __fastcall TRemoteTokenList::Token(int Index) const
  707. {
  708. return &FTokens[Index];
  709. }
  710. //---------------------------------------------------------------------------
  711. //---------------------------------------------------------------------------
  712. __fastcall TRemoteFile::TRemoteFile(TRemoteFile * ALinkedByFile):
  713. TPersistent()
  714. {
  715. FLinkedFile = NULL;
  716. FRights = new TRights();
  717. FIconIndex = -1;
  718. FCyclicLink = false;
  719. FModificationFmt = mfFull;
  720. FLinkedByFile = ALinkedByFile;
  721. FTerminal = NULL;
  722. FDirectory = NULL;
  723. FIsHidden = -1;
  724. }
  725. //---------------------------------------------------------------------------
  726. __fastcall TRemoteFile::~TRemoteFile()
  727. {
  728. delete FRights;
  729. delete FLinkedFile;
  730. }
  731. //---------------------------------------------------------------------------
  732. TRemoteFile * __fastcall TRemoteFile::Duplicate(bool Standalone) const
  733. {
  734. TRemoteFile * Result;
  735. Result = new TRemoteFile();
  736. try
  737. {
  738. if (FLinkedFile)
  739. {
  740. Result->FLinkedFile = FLinkedFile->Duplicate(true);
  741. Result->FLinkedFile->FLinkedByFile = Result;
  742. }
  743. *Result->Rights = *FRights;
  744. #define COPY_FP(PROP) Result->F ## PROP = F ## PROP;
  745. COPY_FP(Terminal);
  746. COPY_FP(Owner);
  747. COPY_FP(ModificationFmt);
  748. COPY_FP(Size);
  749. COPY_FP(FileName);
  750. COPY_FP(INodeBlocks);
  751. COPY_FP(Modification);
  752. COPY_FP(LastAccess);
  753. COPY_FP(Group);
  754. COPY_FP(IconIndex);
  755. COPY_FP(TypeName);
  756. COPY_FP(IsSymLink);
  757. COPY_FP(LinkTo);
  758. COPY_FP(Type);
  759. COPY_FP(Selected);
  760. COPY_FP(CyclicLink);
  761. #undef COPY_FP
  762. if (Standalone && (!FFullFileName.IsEmpty() || (Directory != NULL)))
  763. {
  764. Result->FFullFileName = FullFileName;
  765. }
  766. }
  767. catch(...)
  768. {
  769. delete Result;
  770. throw;
  771. }
  772. return Result;
  773. }
  774. //---------------------------------------------------------------------------
  775. void __fastcall TRemoteFile::LoadTypeInfo()
  776. {
  777. /* TODO : If file is link: Should be attributes taken from linked file? */
  778. unsigned long Attrs = 0;
  779. if (IsDirectory) Attrs |= FILE_ATTRIBUTE_DIRECTORY;
  780. if (IsHidden) Attrs |= FILE_ATTRIBUTE_HIDDEN;
  781. UnicodeString DumbFileName = (IsSymLink && !LinkTo.IsEmpty() ? LinkTo : FileName);
  782. FIconIndex = FakeFileImageIndex(DumbFileName, Attrs, &FTypeName);
  783. }
  784. //---------------------------------------------------------------------------
  785. Integer __fastcall TRemoteFile::GetIconIndex() const
  786. {
  787. if (FIconIndex == -1)
  788. {
  789. const_cast<TRemoteFile *>(this)->LoadTypeInfo();
  790. }
  791. return FIconIndex;
  792. }
  793. //---------------------------------------------------------------------------
  794. UnicodeString __fastcall TRemoteFile::GetTypeName()
  795. {
  796. // check availability of type info by icon index, because type name can be empty
  797. if (FIconIndex < 0)
  798. {
  799. LoadTypeInfo();
  800. }
  801. return FTypeName;
  802. }
  803. //---------------------------------------------------------------------------
  804. Boolean __fastcall TRemoteFile::GetIsHidden()
  805. {
  806. bool Result;
  807. switch (FIsHidden)
  808. {
  809. case 0:
  810. Result = false;
  811. break;
  812. case 1:
  813. Result = true;
  814. break;
  815. default:
  816. Result = IsUnixHiddenFile(FileName);
  817. break;
  818. }
  819. return Result;
  820. }
  821. //---------------------------------------------------------------------------
  822. void __fastcall TRemoteFile::SetIsHidden(bool value)
  823. {
  824. FIsHidden = value ? 1 : 0;
  825. }
  826. //---------------------------------------------------------------------------
  827. Boolean __fastcall TRemoteFile::GetIsDirectory() const
  828. {
  829. return (toupper(Type) == FILETYPE_DIRECTORY);
  830. }
  831. //---------------------------------------------------------------------------
  832. Boolean __fastcall TRemoteFile::GetIsParentDirectory() const
  833. {
  834. return (FileName == PARENTDIRECTORY);
  835. }
  836. //---------------------------------------------------------------------------
  837. Boolean __fastcall TRemoteFile::GetIsThisDirectory() const
  838. {
  839. return (FileName == THISDIRECTORY);
  840. }
  841. //---------------------------------------------------------------------------
  842. Boolean __fastcall TRemoteFile::GetIsInaccesibleDirectory() const
  843. {
  844. Boolean Result;
  845. if (IsDirectory)
  846. {
  847. assert(Terminal);
  848. Result = !
  849. (((Rights->RightUndef[TRights::rrOtherExec] != TRights::rsNo)) ||
  850. ((Rights->Right[TRights::rrGroupExec] != TRights::rsNo) &&
  851. Terminal->Membership->Exists(Group.Name)) ||
  852. ((Rights->Right[TRights::rrUserExec] != TRights::rsNo) &&
  853. (AnsiCompareText(Terminal->UserName, Owner.Name) == 0)));
  854. }
  855. else Result = False;
  856. return Result;
  857. }
  858. //---------------------------------------------------------------------------
  859. wchar_t __fastcall TRemoteFile::GetType() const
  860. {
  861. if (IsSymLink && FLinkedFile) return FLinkedFile->Type;
  862. else return FType;
  863. }
  864. //---------------------------------------------------------------------------
  865. void __fastcall TRemoteFile::SetType(wchar_t AType)
  866. {
  867. FType = AType;
  868. FIsSymLink = ((wchar_t)towupper(FType) == FILETYPE_SYMLINK);
  869. }
  870. //---------------------------------------------------------------------------
  871. TRemoteFile * __fastcall TRemoteFile::GetLinkedFile()
  872. {
  873. // do not call FindLinkedFile as it would be called repeatedly for broken symlinks
  874. return FLinkedFile;
  875. }
  876. //---------------------------------------------------------------------------
  877. void __fastcall TRemoteFile::SetLinkedFile(TRemoteFile * value)
  878. {
  879. if (FLinkedFile != value)
  880. {
  881. if (FLinkedFile) delete FLinkedFile;
  882. FLinkedFile = value;
  883. }
  884. }
  885. //---------------------------------------------------------------------------
  886. bool __fastcall TRemoteFile::GetBrokenLink()
  887. {
  888. assert(Terminal);
  889. // If file is symlink but we couldn't find linked file we assume broken link
  890. return (IsSymLink && (FCyclicLink || !FLinkedFile) &&
  891. Terminal->ResolvingSymlinks);
  892. // "!FLinkTo.IsEmpty()" removed because it does not work with SFTP
  893. }
  894. //---------------------------------------------------------------------------
  895. void __fastcall TRemoteFile::ShiftTime(const TDateTime & Difference)
  896. {
  897. double D = double(Difference);
  898. if ((D != 0) && (FModificationFmt != mfMDY))
  899. {
  900. assert(int(FModification) != 0);
  901. FModification = double(FModification) + D;
  902. assert(int(FLastAccess) != 0);
  903. FLastAccess = double(FLastAccess) + D;
  904. }
  905. }
  906. //---------------------------------------------------------------------------
  907. void __fastcall TRemoteFile::SetModification(const TDateTime & value)
  908. {
  909. if (FModification != value)
  910. {
  911. FModificationFmt = mfFull;
  912. FModification = value;
  913. }
  914. }
  915. //---------------------------------------------------------------------------
  916. UnicodeString __fastcall TRemoteFile::GetUserModificationStr()
  917. {
  918. return ::UserModificationStr(Modification, FModificationFmt);
  919. }
  920. //---------------------------------------------------------------------------
  921. UnicodeString __fastcall TRemoteFile::GetModificationStr()
  922. {
  923. return ::ModificationStr(Modification, FModificationFmt);
  924. }
  925. //---------------------------------------------------------------------------
  926. UnicodeString __fastcall TRemoteFile::GetExtension()
  927. {
  928. return UnixExtractFileExt(FFileName);
  929. }
  930. //---------------------------------------------------------------------------
  931. void __fastcall TRemoteFile::SetRights(TRights * value)
  932. {
  933. FRights->Assign(value);
  934. }
  935. //---------------------------------------------------------------------------
  936. UnicodeString __fastcall TRemoteFile::GetRightsStr()
  937. {
  938. return FRights->Unknown ? UnicodeString() : FRights->Text;
  939. }
  940. //---------------------------------------------------------------------------
  941. void __fastcall TRemoteFile::SetListingStr(UnicodeString value)
  942. {
  943. // Value stored in 'value' can be used for error message
  944. UnicodeString Line = value;
  945. FIconIndex = -1;
  946. try
  947. {
  948. UnicodeString Col;
  949. // Do we need to do this (is ever TAB is LS output)?
  950. Line = ReplaceChar(Line, L'\t', L' ');
  951. Type = Line[1];
  952. Line.Delete(1, 1);
  953. #define GETNCOL \
  954. { if (Line.IsEmpty()) throw Exception(L""); \
  955. Integer P = Line.Pos(L' '); \
  956. if (P) { Col = Line.SubString(1, P-1); Line.Delete(1, P); } \
  957. else { Col = Line; Line = L""; } \
  958. }
  959. #define GETCOL { GETNCOL; Line = TrimLeft(Line); }
  960. // Rights string may contain special permission attributes (S,t, ...)
  961. // (TODO: maybe no longer necessary, once we can handle the special permissions)
  962. Rights->AllowUndef = True;
  963. // On some system there is no space between permissions and node blocks count columns
  964. // so we get only first 9 characters and trim all following spaces (if any)
  965. Rights->Text = Line.SubString(1, 9);
  966. Line.Delete(1, 9);
  967. // Rights column maybe followed by '+', '@' or '.' signs, we ignore them
  968. // (On MacOS, there may be a space in between)
  969. if (!Line.IsEmpty() && ((Line[1] == L'+') || (Line[1] == L'@') || (Line[1] == L'.')))
  970. {
  971. Line.Delete(1, 1);
  972. }
  973. else if ((Line.Length() >= 2) && (Line[1] == L' ') &&
  974. ((Line[2] == L'+') || (Line[2] == L'@') || (Line[2] == L'.')))
  975. {
  976. Line.Delete(1, 2);
  977. }
  978. Line = Line.TrimLeft();
  979. GETCOL;
  980. if (!TryStrToInt(Col, FINodeBlocks))
  981. {
  982. // if the column is not an integer, suppose it's owner
  983. // (Android BusyBox)
  984. FINodeBlocks = 0;
  985. }
  986. else
  987. {
  988. GETCOL;
  989. }
  990. FOwner.Name = Col;
  991. // #60 17.10.01: group name can contain space
  992. FGroup.Name = L"";
  993. GETCOL;
  994. __int64 ASize;
  995. do
  996. {
  997. FGroup.Name = FGroup.Name + Col;
  998. GETCOL;
  999. assert(!Col.IsEmpty());
  1000. // for devices etc.. there is additional column ending by comma, we ignore it
  1001. if (Col[Col.Length()] == L',') GETCOL;
  1002. ASize = StrToInt64Def(Col, -1);
  1003. // if it's not a number (file size) we take it as part of group name
  1004. // (at least on CygWin, there can be group with space in its name)
  1005. if (ASize < 0) Col = L" " + Col;
  1006. }
  1007. while (ASize < 0);
  1008. // do not read modification time and filename if it is already set
  1009. if (double(FModification) == 0 && FileName.IsEmpty())
  1010. {
  1011. FSize = ASize;
  1012. bool FullTime = false;
  1013. bool DayMonthFormat = false;
  1014. Word Day, Month, Year, Hour, Min, Sec, P;
  1015. GETCOL;
  1016. // format dd mmm or mmm dd ?
  1017. Day = (Word)StrToIntDef(Col, 0);
  1018. if (Day > 0)
  1019. {
  1020. DayMonthFormat = true;
  1021. GETCOL;
  1022. }
  1023. Month = 0;
  1024. #define COL2MONTH \
  1025. for (Word IMonth = 0; IMonth < 12; IMonth++) \
  1026. if (!Col.CompareIC(EngShortMonthNames[IMonth])) { Month = IMonth; Month++; break; }
  1027. COL2MONTH;
  1028. // if the column is not known month name, it may have been "yyyy-mm-dd"
  1029. // for --full-time format
  1030. if ((Month == 0) && (Col.Length() == 10) && (Col[5] == L'-') && (Col[8] == L'-'))
  1031. {
  1032. Year = (Word)Col.SubString(1, 4).ToInt();
  1033. Month = (Word)Col.SubString(6, 2).ToInt();
  1034. Day = (Word)Col.SubString(9, 2).ToInt();
  1035. GETCOL;
  1036. Hour = (Word)Col.SubString(1, 2).ToInt();
  1037. Min = (Word)Col.SubString(4, 2).ToInt();
  1038. if (Col.Length() >= 8)
  1039. {
  1040. Sec = (Word)StrToInt(Col.SubString(7, 2));
  1041. }
  1042. else
  1043. {
  1044. Sec = 0;
  1045. }
  1046. FModificationFmt = mfFull;
  1047. // skip TZ (TODO)
  1048. // do not trim leading space of filename
  1049. GETNCOL;
  1050. }
  1051. else
  1052. {
  1053. // or it may have been day name for another format of --full-time
  1054. if (Month == 0)
  1055. {
  1056. GETCOL;
  1057. COL2MONTH;
  1058. // neither standard, not --full-time format
  1059. if (Month == 0)
  1060. {
  1061. Abort();
  1062. }
  1063. else
  1064. {
  1065. FullTime = true;
  1066. }
  1067. }
  1068. #undef COL2MONTH
  1069. if (Day == 0)
  1070. {
  1071. GETNCOL;
  1072. Day = (Word)StrToInt(Col);
  1073. }
  1074. if ((Day < 1) || (Day > 31)) Abort();
  1075. // second full-time format
  1076. // ddd mmm dd hh:nn:ss yyyy
  1077. if (FullTime)
  1078. {
  1079. GETCOL;
  1080. if (Col.Length() != 8)
  1081. {
  1082. Abort();
  1083. }
  1084. Hour = (Word)StrToInt(Col.SubString(1, 2));
  1085. Min = (Word)StrToInt(Col.SubString(4, 2));
  1086. Sec = (Word)StrToInt(Col.SubString(7, 2));
  1087. FModificationFmt = mfFull;
  1088. // do not trim leading space of filename
  1089. GETNCOL;
  1090. Year = (Word)StrToInt(Col);
  1091. }
  1092. else
  1093. {
  1094. // for format dd mmm the below description seems not to be true,
  1095. // the year is not aligned to 5 characters
  1096. if (DayMonthFormat)
  1097. {
  1098. GETCOL;
  1099. }
  1100. else
  1101. {
  1102. // Time/Year indicator is always 5 characters long (???), on most
  1103. // systems year is aligned to right (_YYYY), but on some to left (YYYY_),
  1104. // we must ensure that trailing space is also deleted, so real
  1105. // separator space is not treated as part of file name
  1106. Col = Line.SubString(1, 6).Trim();
  1107. Line.Delete(1, 6);
  1108. }
  1109. // GETNCOL; // We don't want to trim input strings (name with space at beginning???)
  1110. // Check if we got time (contains :) or year
  1111. if ((P = (Word)Col.Pos(L':')) > 0)
  1112. {
  1113. Word CurrMonth, CurrDay;
  1114. Hour = (Word)StrToInt(Col.SubString(1, P-1));
  1115. Min = (Word)StrToInt(Col.SubString(P+1, Col.Length() - P));
  1116. if (Hour > 23 || Min > 59) Abort();
  1117. // When we don't got year, we assume current year
  1118. // with exception that the date would be in future
  1119. // in this case we assume last year.
  1120. DecodeDate(Date(), Year, CurrMonth, CurrDay);
  1121. if ((Month > CurrMonth) ||
  1122. (Month == CurrMonth && Day > CurrDay)) Year--;
  1123. Sec = 0;
  1124. FModificationFmt = mfMDHM;
  1125. }
  1126. else
  1127. {
  1128. Year = (Word)StrToInt(Col);
  1129. if (Year > 10000) Abort();
  1130. // When we don't got time we assume midnight
  1131. Hour = 0; Min = 0; Sec = 0;
  1132. FModificationFmt = mfMDY;
  1133. }
  1134. }
  1135. }
  1136. FModification = EncodeDateVerbose(Year, Month, Day) + EncodeTimeVerbose(Hour, Min, Sec, 0);
  1137. // adjust only when time is known,
  1138. // adjusting default "midnight" time makes no sense
  1139. if ((FModificationFmt == mfMDHM) || (FModificationFmt == mfFull))
  1140. {
  1141. assert(Terminal != NULL);
  1142. FModification = AdjustDateTimeFromUnix(FModification,
  1143. Terminal->SessionData->DSTMode);
  1144. }
  1145. if (double(FLastAccess) == 0)
  1146. {
  1147. FLastAccess = FModification;
  1148. }
  1149. // separating space is already deleted, other spaces are treated as part of name
  1150. {
  1151. int P;
  1152. FLinkTo = L"";
  1153. if (IsSymLink)
  1154. {
  1155. P = Line.Pos(SYMLINKSTR);
  1156. if (P)
  1157. {
  1158. FLinkTo = Line.SubString(
  1159. P + wcslen(SYMLINKSTR), Line.Length() - P + wcslen(SYMLINKSTR) + 1);
  1160. Line.SetLength(P - 1);
  1161. }
  1162. else
  1163. {
  1164. Abort();
  1165. }
  1166. }
  1167. FFileName = UnixExtractFileName(Line);
  1168. }
  1169. }
  1170. #undef GETNCOL
  1171. #undef GETCOL
  1172. }
  1173. catch (Exception &E)
  1174. {
  1175. throw ETerminal(&E, FmtLoadStr(LIST_LINE_ERROR, ARRAYOFCONST((value))), HELP_LIST_LINE_ERROR);
  1176. }
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. void __fastcall TRemoteFile::Complete()
  1180. {
  1181. assert(Terminal != NULL);
  1182. if (IsSymLink && Terminal->ResolvingSymlinks)
  1183. {
  1184. FindLinkedFile();
  1185. }
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. void __fastcall TRemoteFile::FindLinkedFile()
  1189. {
  1190. assert(Terminal && IsSymLink);
  1191. if (FLinkedFile) delete FLinkedFile;
  1192. FLinkedFile = NULL;
  1193. FCyclicLink = false;
  1194. if (!LinkTo.IsEmpty())
  1195. {
  1196. // check for cyclic link
  1197. TRemoteFile * LinkedBy = FLinkedByFile;
  1198. while (LinkedBy)
  1199. {
  1200. if (LinkedBy->LinkTo == LinkTo)
  1201. {
  1202. // this is currenly redundant information, because it is used only to
  1203. // detect broken symlink, which would be otherwise detected
  1204. // by FLinkedFile == NULL
  1205. FCyclicLink = true;
  1206. break;
  1207. }
  1208. LinkedBy = LinkedBy->FLinkedByFile;
  1209. }
  1210. }
  1211. if (FCyclicLink)
  1212. {
  1213. TRemoteFile * LinkedBy = FLinkedByFile;
  1214. while (LinkedBy)
  1215. {
  1216. LinkedBy->FCyclicLink = true;
  1217. LinkedBy = LinkedBy->FLinkedByFile;
  1218. }
  1219. }
  1220. else
  1221. {
  1222. assert(Terminal->ResolvingSymlinks);
  1223. Terminal->ExceptionOnFail = true;
  1224. try
  1225. {
  1226. try
  1227. {
  1228. Terminal->ReadSymlink(this, FLinkedFile);
  1229. }
  1230. __finally
  1231. {
  1232. Terminal->ExceptionOnFail = false;
  1233. }
  1234. }
  1235. catch (Exception &E)
  1236. {
  1237. if (E.InheritsFrom(__classid(EFatal))) throw;
  1238. else
  1239. {
  1240. Terminal->Log->AddException(&E);
  1241. }
  1242. }
  1243. }
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. UnicodeString __fastcall TRemoteFile::GetListingStr()
  1247. {
  1248. // note that ModificationStr is longer than 12 for mfFull
  1249. UnicodeString LinkPart;
  1250. // expanded from ?: to avoid memory leaks
  1251. if (IsSymLink)
  1252. {
  1253. LinkPart = UnicodeString(SYMLINKSTR) + LinkTo;
  1254. }
  1255. return Format(L"%s%s %3s %-8s %-8s %9s %-12s %s%s", ARRAYOFCONST((
  1256. Type, Rights->Text, IntToStr(INodeBlocks), Owner.Name,
  1257. Group.Name, IntToStr(Size), ModificationStr, FileName,
  1258. LinkPart)));
  1259. }
  1260. //---------------------------------------------------------------------------
  1261. UnicodeString __fastcall TRemoteFile::GetFullFileName() const
  1262. {
  1263. if (FFullFileName.IsEmpty())
  1264. {
  1265. assert(Terminal);
  1266. assert(Directory != NULL);
  1267. UnicodeString Path;
  1268. if (IsParentDirectory) Path = Directory->ParentPath;
  1269. else if (IsDirectory) Path = UnixIncludeTrailingBackslash(Directory->FullDirectory + FileName);
  1270. else Path = Directory->FullDirectory + FileName;
  1271. return Terminal->TranslateLockedPath(Path, true);
  1272. }
  1273. else
  1274. {
  1275. return FFullFileName;
  1276. }
  1277. }
  1278. //---------------------------------------------------------------------------
  1279. bool __fastcall TRemoteFile::GetHaveFullFileName() const
  1280. {
  1281. return !FFullFileName.IsEmpty() || (Directory != NULL);
  1282. }
  1283. //---------------------------------------------------------------------------
  1284. Integer __fastcall TRemoteFile::GetAttr()
  1285. {
  1286. Integer Result = 0;
  1287. if (Rights->ReadOnly) Result |= faReadOnly;
  1288. if (IsHidden) Result |= faHidden;
  1289. return Result;
  1290. }
  1291. //---------------------------------------------------------------------------
  1292. void __fastcall TRemoteFile::SetTerminal(TTerminal * value)
  1293. {
  1294. FTerminal = value;
  1295. if (FLinkedFile)
  1296. {
  1297. FLinkedFile->Terminal = value;
  1298. }
  1299. }
  1300. //---------------------------------------------------------------------------
  1301. //---------------------------------------------------------------------------
  1302. __fastcall TRemoteDirectoryFile::TRemoteDirectoryFile() : TRemoteFile()
  1303. {
  1304. Modification = double(0);
  1305. ModificationFmt = mfNone;
  1306. LastAccess = Modification;
  1307. Type = L'D';
  1308. Size = 0;
  1309. }
  1310. //---------------------------------------------------------------------------
  1311. //---------------------------------------------------------------------------
  1312. __fastcall TRemoteParentDirectory::TRemoteParentDirectory(TTerminal * ATerminal)
  1313. : TRemoteDirectoryFile()
  1314. {
  1315. FileName = PARENTDIRECTORY;
  1316. Terminal = ATerminal;
  1317. }
  1318. //=== TRemoteFileList ------------------------------------------------------
  1319. __fastcall TRemoteFileList::TRemoteFileList():
  1320. TObjectList()
  1321. {
  1322. FTimestamp = Now();
  1323. }
  1324. //---------------------------------------------------------------------------
  1325. void __fastcall TRemoteFileList::AddFile(TRemoteFile * File)
  1326. {
  1327. Add(File);
  1328. File->Directory = this;
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TRemoteFileList::DuplicateTo(TRemoteFileList * Copy)
  1332. {
  1333. Copy->Reset();
  1334. for (int Index = 0; Index < Count; Index++)
  1335. {
  1336. TRemoteFile * File = Files[Index];
  1337. Copy->AddFile(File->Duplicate(false));
  1338. }
  1339. Copy->FDirectory = Directory;
  1340. Copy->FTimestamp = FTimestamp;
  1341. }
  1342. //---------------------------------------------------------------------------
  1343. void __fastcall TRemoteFileList::Reset()
  1344. {
  1345. FTimestamp = Now();
  1346. Clear();
  1347. }
  1348. //---------------------------------------------------------------------------
  1349. void __fastcall TRemoteFileList::SetDirectory(UnicodeString value)
  1350. {
  1351. FDirectory = UnixExcludeTrailingBackslash(value);
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. UnicodeString __fastcall TRemoteFileList::GetFullDirectory()
  1355. {
  1356. return UnixIncludeTrailingBackslash(Directory);
  1357. }
  1358. //---------------------------------------------------------------------------
  1359. TRemoteFile * __fastcall TRemoteFileList::GetFiles(Integer Index)
  1360. {
  1361. return (TRemoteFile *)Items[Index];
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. Boolean __fastcall TRemoteFileList::GetIsRoot()
  1365. {
  1366. return (Directory == ROOTDIRECTORY);
  1367. }
  1368. //---------------------------------------------------------------------------
  1369. UnicodeString __fastcall TRemoteFileList::GetParentPath()
  1370. {
  1371. return UnixExtractFilePath(Directory);
  1372. }
  1373. //---------------------------------------------------------------------------
  1374. __int64 __fastcall TRemoteFileList::GetTotalSize()
  1375. {
  1376. __int64 Result = 0;
  1377. for (Integer Index = 0; Index < Count; Index++)
  1378. if (!Files[Index]->IsDirectory) Result += Files[Index]->Size;
  1379. return Result;
  1380. }
  1381. //---------------------------------------------------------------------------
  1382. TRemoteFile * __fastcall TRemoteFileList::FindFile(const UnicodeString &FileName)
  1383. {
  1384. for (Integer Index = 0; Index < Count; Index++)
  1385. if (Files[Index]->FileName == FileName) return Files[Index];
  1386. return NULL;
  1387. }
  1388. //=== TRemoteDirectory ------------------------------------------------------
  1389. __fastcall TRemoteDirectory::TRemoteDirectory(TTerminal * aTerminal, TRemoteDirectory * Template) :
  1390. TRemoteFileList(), FTerminal(aTerminal)
  1391. {
  1392. FSelectedFiles = NULL;
  1393. FThisDirectory = NULL;
  1394. FParentDirectory = NULL;
  1395. if (Template == NULL)
  1396. {
  1397. FIncludeThisDirectory = false;
  1398. FIncludeParentDirectory = true;
  1399. }
  1400. else
  1401. {
  1402. FIncludeThisDirectory = Template->FIncludeThisDirectory;
  1403. FIncludeParentDirectory = Template->FIncludeParentDirectory;
  1404. }
  1405. }
  1406. //---------------------------------------------------------------------------
  1407. __fastcall TRemoteDirectory::~TRemoteDirectory()
  1408. {
  1409. ReleaseRelativeDirectories();
  1410. }
  1411. //---------------------------------------------------------------------------
  1412. void __fastcall TRemoteDirectory::ReleaseRelativeDirectories()
  1413. {
  1414. if ((ThisDirectory != NULL) && !IncludeThisDirectory)
  1415. {
  1416. delete FThisDirectory;
  1417. FThisDirectory = NULL;
  1418. }
  1419. if ((ParentDirectory != NULL) && !IncludeParentDirectory)
  1420. {
  1421. delete FParentDirectory;
  1422. FParentDirectory = NULL;
  1423. }
  1424. }
  1425. //---------------------------------------------------------------------------
  1426. void __fastcall TRemoteDirectory::Reset()
  1427. {
  1428. ReleaseRelativeDirectories();
  1429. TRemoteFileList::Reset();
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TRemoteDirectory::SetDirectory(UnicodeString value)
  1433. {
  1434. TRemoteFileList::SetDirectory(value);
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TRemoteDirectory::AddFile(TRemoteFile * File)
  1438. {
  1439. if (File->IsThisDirectory) FThisDirectory = File;
  1440. if (File->IsParentDirectory) FParentDirectory = File;
  1441. if ((!File->IsThisDirectory || IncludeThisDirectory) &&
  1442. (!File->IsParentDirectory || IncludeParentDirectory))
  1443. {
  1444. TRemoteFileList::AddFile(File);
  1445. }
  1446. File->Terminal = Terminal;
  1447. }
  1448. //---------------------------------------------------------------------------
  1449. void __fastcall TRemoteDirectory::DuplicateTo(TRemoteFileList * Copy)
  1450. {
  1451. TRemoteFileList::DuplicateTo(Copy);
  1452. if (ThisDirectory && !IncludeThisDirectory)
  1453. {
  1454. Copy->AddFile(ThisDirectory->Duplicate(false));
  1455. }
  1456. if (ParentDirectory && !IncludeParentDirectory)
  1457. {
  1458. Copy->AddFile(ParentDirectory->Duplicate(false));
  1459. }
  1460. }
  1461. //---------------------------------------------------------------------------
  1462. bool __fastcall TRemoteDirectory::GetLoaded()
  1463. {
  1464. return ((Terminal != NULL) && Terminal->Active && !Directory.IsEmpty());
  1465. }
  1466. //---------------------------------------------------------------------------
  1467. TStrings * __fastcall TRemoteDirectory::GetSelectedFiles()
  1468. {
  1469. if (!FSelectedFiles)
  1470. {
  1471. FSelectedFiles = new TStringList();
  1472. }
  1473. else
  1474. {
  1475. FSelectedFiles->Clear();
  1476. }
  1477. for (int Index = 0; Index < Count; Index ++)
  1478. {
  1479. if (Files[Index]->Selected)
  1480. {
  1481. FSelectedFiles->Add(Files[Index]->FullFileName);
  1482. }
  1483. }
  1484. return FSelectedFiles;
  1485. }
  1486. //---------------------------------------------------------------------------
  1487. void __fastcall TRemoteDirectory::SetIncludeParentDirectory(Boolean value)
  1488. {
  1489. if (IncludeParentDirectory != value)
  1490. {
  1491. FIncludeParentDirectory = value;
  1492. if (value && ParentDirectory)
  1493. {
  1494. assert(IndexOf(ParentDirectory) < 0);
  1495. Add(ParentDirectory);
  1496. }
  1497. else if (!value && ParentDirectory)
  1498. {
  1499. assert(IndexOf(ParentDirectory) >= 0);
  1500. Extract(ParentDirectory);
  1501. }
  1502. }
  1503. }
  1504. //---------------------------------------------------------------------------
  1505. void __fastcall TRemoteDirectory::SetIncludeThisDirectory(Boolean value)
  1506. {
  1507. if (IncludeThisDirectory != value)
  1508. {
  1509. FIncludeThisDirectory = value;
  1510. if (value && ThisDirectory)
  1511. {
  1512. assert(IndexOf(ThisDirectory) < 0);
  1513. Add(ThisDirectory);
  1514. }
  1515. else if (!value && ThisDirectory)
  1516. {
  1517. assert(IndexOf(ThisDirectory) >= 0);
  1518. Extract(ThisDirectory);
  1519. }
  1520. }
  1521. }
  1522. //===========================================================================
  1523. __fastcall TRemoteDirectoryCache::TRemoteDirectoryCache(): TStringList()
  1524. {
  1525. FSection = new TCriticalSection();
  1526. Sorted = true;
  1527. Duplicates = dupError;
  1528. CaseSensitive = true;
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. __fastcall TRemoteDirectoryCache::~TRemoteDirectoryCache()
  1532. {
  1533. Clear();
  1534. delete FSection;
  1535. }
  1536. //---------------------------------------------------------------------------
  1537. void __fastcall TRemoteDirectoryCache::Clear()
  1538. {
  1539. TGuard Guard(FSection);
  1540. try
  1541. {
  1542. for (int Index = 0; Index < Count; Index++)
  1543. {
  1544. delete (TRemoteFileList *)Objects[Index];
  1545. Objects[Index] = NULL;
  1546. }
  1547. }
  1548. __finally
  1549. {
  1550. TStringList::Clear();
  1551. }
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. bool __fastcall TRemoteDirectoryCache::GetIsEmpty() const
  1555. {
  1556. TGuard Guard(FSection);
  1557. return (const_cast<TRemoteDirectoryCache*>(this)->Count == 0);
  1558. }
  1559. //---------------------------------------------------------------------------
  1560. bool __fastcall TRemoteDirectoryCache::HasFileList(const UnicodeString Directory)
  1561. {
  1562. TGuard Guard(FSection);
  1563. int Index = IndexOf(UnixExcludeTrailingBackslash(Directory));
  1564. return (Index >= 0);
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. bool __fastcall TRemoteDirectoryCache::HasNewerFileList(const UnicodeString Directory,
  1568. TDateTime Timestamp)
  1569. {
  1570. TGuard Guard(FSection);
  1571. int Index = IndexOf(UnixExcludeTrailingBackslash(Directory));
  1572. if (Index >= 0)
  1573. {
  1574. TRemoteFileList * FileList = dynamic_cast<TRemoteFileList *>(Objects[Index]);
  1575. if (FileList->Timestamp <= Timestamp)
  1576. {
  1577. Index = -1;
  1578. }
  1579. }
  1580. return (Index >= 0);
  1581. }
  1582. //---------------------------------------------------------------------------
  1583. bool __fastcall TRemoteDirectoryCache::GetFileList(const UnicodeString Directory,
  1584. TRemoteFileList * FileList)
  1585. {
  1586. TGuard Guard(FSection);
  1587. int Index = IndexOf(UnixExcludeTrailingBackslash(Directory));
  1588. bool Result = (Index >= 0);
  1589. if (Result)
  1590. {
  1591. assert(Objects[Index] != NULL);
  1592. dynamic_cast<TRemoteFileList *>(Objects[Index])->DuplicateTo(FileList);
  1593. }
  1594. return Result;
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TRemoteDirectoryCache::AddFileList(TRemoteFileList * FileList)
  1598. {
  1599. assert(FileList);
  1600. TRemoteFileList * Copy = new TRemoteFileList();
  1601. FileList->DuplicateTo(Copy);
  1602. {
  1603. TGuard Guard(FSection);
  1604. // file list cannot be cached already with only one thread, but it can be
  1605. // when directory is loaded by secondary terminal
  1606. DoClearFileList(FileList->Directory, false);
  1607. AddObject(Copy->Directory, Copy);
  1608. }
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TRemoteDirectoryCache::ClearFileList(UnicodeString Directory, bool SubDirs)
  1612. {
  1613. TGuard Guard(FSection);
  1614. DoClearFileList(Directory, SubDirs);
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. void __fastcall TRemoteDirectoryCache::DoClearFileList(UnicodeString Directory, bool SubDirs)
  1618. {
  1619. Directory = UnixExcludeTrailingBackslash(Directory);
  1620. int Index = IndexOf(Directory);
  1621. if (Index >= 0)
  1622. {
  1623. Delete(Index);
  1624. }
  1625. if (SubDirs)
  1626. {
  1627. Directory = UnixIncludeTrailingBackslash(Directory);
  1628. Index = Count-1;
  1629. while (Index >= 0)
  1630. {
  1631. if (Strings[Index].SubString(1, Directory.Length()) == Directory)
  1632. {
  1633. Delete(Index);
  1634. }
  1635. Index--;
  1636. }
  1637. }
  1638. }
  1639. //---------------------------------------------------------------------------
  1640. void __fastcall TRemoteDirectoryCache::Delete(int Index)
  1641. {
  1642. delete dynamic_cast<TRemoteFileList *>(Objects[Index]);
  1643. TStringList::Delete(Index);
  1644. }
  1645. //---------------------------------------------------------------------------
  1646. //---------------------------------------------------------------------------
  1647. __fastcall TRemoteDirectoryChangesCache::TRemoteDirectoryChangesCache(int MaxSize) :
  1648. TStringList(),
  1649. FMaxSize(MaxSize)
  1650. {
  1651. }
  1652. //---------------------------------------------------------------------------
  1653. void __fastcall TRemoteDirectoryChangesCache::Clear()
  1654. {
  1655. TStringList::Clear();
  1656. }
  1657. //---------------------------------------------------------------------------
  1658. bool __fastcall TRemoteDirectoryChangesCache::GetIsEmpty() const
  1659. {
  1660. return (const_cast<TRemoteDirectoryChangesCache*>(this)->Count == 0);
  1661. }
  1662. //---------------------------------------------------------------------------
  1663. void __fastcall TRemoteDirectoryChangesCache::SetValue(const UnicodeString & Name,
  1664. const UnicodeString & Value)
  1665. {
  1666. int Index = IndexOfName(Name);
  1667. if (Index > 0)
  1668. {
  1669. Delete(Index);
  1670. }
  1671. Values[Name] = Value;
  1672. }
  1673. //---------------------------------------------------------------------------
  1674. UnicodeString __fastcall TRemoteDirectoryChangesCache::GetValue(const UnicodeString & Name)
  1675. {
  1676. UnicodeString Value = Values[Name];
  1677. SetValue(Name, Value);
  1678. return Value;
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. void __fastcall TRemoteDirectoryChangesCache::AddDirectoryChange(
  1682. const UnicodeString SourceDir, const UnicodeString Change,
  1683. const UnicodeString TargetDir)
  1684. {
  1685. assert(!TargetDir.IsEmpty());
  1686. SetValue(TargetDir, L"//");
  1687. if (TTerminal::ExpandFileName(Change, SourceDir) != TargetDir)
  1688. {
  1689. UnicodeString Key;
  1690. if (DirectoryChangeKey(SourceDir, Change, Key))
  1691. {
  1692. SetValue(Key, TargetDir);
  1693. }
  1694. }
  1695. }
  1696. //---------------------------------------------------------------------------
  1697. void __fastcall TRemoteDirectoryChangesCache::ClearDirectoryChange(
  1698. UnicodeString SourceDir)
  1699. {
  1700. for (int Index = 0; Index < Count; Index++)
  1701. {
  1702. if (Names[Index].SubString(1, SourceDir.Length()) == SourceDir)
  1703. {
  1704. Delete(Index);
  1705. Index--;
  1706. }
  1707. }
  1708. }
  1709. //---------------------------------------------------------------------------
  1710. void __fastcall TRemoteDirectoryChangesCache::ClearDirectoryChangeTarget(
  1711. UnicodeString TargetDir)
  1712. {
  1713. UnicodeString Key;
  1714. // hack to clear at least local sym-link change in case symlink is deleted
  1715. DirectoryChangeKey(UnixExcludeTrailingBackslash(UnixExtractFilePath(TargetDir)),
  1716. UnixExtractFileName(TargetDir), Key);
  1717. for (int Index = 0; Index < Count; Index++)
  1718. {
  1719. UnicodeString Name = Names[Index];
  1720. if ((Name.SubString(1, TargetDir.Length()) == TargetDir) ||
  1721. (Values[Name].SubString(1, TargetDir.Length()) == TargetDir) ||
  1722. (!Key.IsEmpty() && (Name == Key)))
  1723. {
  1724. Delete(Index);
  1725. Index--;
  1726. }
  1727. }
  1728. }
  1729. //---------------------------------------------------------------------------
  1730. bool __fastcall TRemoteDirectoryChangesCache::GetDirectoryChange(
  1731. const UnicodeString SourceDir, const UnicodeString Change, UnicodeString & TargetDir)
  1732. {
  1733. UnicodeString Key;
  1734. bool Result;
  1735. Key = TTerminal::ExpandFileName(Change, SourceDir);
  1736. Result = (IndexOfName(Key) >= 0);
  1737. if (Result)
  1738. {
  1739. TargetDir = GetValue(Key);
  1740. // TargetDir is not "//" here only when Change is full path to symbolic link
  1741. if (TargetDir == L"//")
  1742. {
  1743. TargetDir = Key;
  1744. }
  1745. }
  1746. else
  1747. {
  1748. Result = DirectoryChangeKey(SourceDir, Change, Key);
  1749. if (Result)
  1750. {
  1751. UnicodeString Directory = GetValue(Key);
  1752. Result = !Directory.IsEmpty();
  1753. if (Result)
  1754. {
  1755. TargetDir = Directory;
  1756. }
  1757. }
  1758. }
  1759. return Result;
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. void __fastcall TRemoteDirectoryChangesCache::Serialize(UnicodeString & Data)
  1763. {
  1764. Data = L"A";
  1765. int ACount = Count;
  1766. if (ACount > FMaxSize)
  1767. {
  1768. TStrings * Limited = new TStringList();
  1769. try
  1770. {
  1771. int Index = ACount - FMaxSize;
  1772. while (Index < ACount)
  1773. {
  1774. Limited->Add(Strings[Index]);
  1775. Index++;
  1776. }
  1777. Data += Limited->Text;
  1778. }
  1779. __finally
  1780. {
  1781. delete Limited;
  1782. }
  1783. }
  1784. else
  1785. {
  1786. Data += Text;
  1787. }
  1788. }
  1789. //---------------------------------------------------------------------------
  1790. void __fastcall TRemoteDirectoryChangesCache::Deserialize(const UnicodeString Data)
  1791. {
  1792. if (Data.IsEmpty())
  1793. {
  1794. Text = L"";
  1795. }
  1796. else
  1797. {
  1798. Text = Data.c_str() + 1;
  1799. }
  1800. }
  1801. //---------------------------------------------------------------------------
  1802. bool __fastcall TRemoteDirectoryChangesCache::DirectoryChangeKey(
  1803. const UnicodeString SourceDir, const UnicodeString Change, UnicodeString & Key)
  1804. {
  1805. bool Result = !Change.IsEmpty();
  1806. if (Result)
  1807. {
  1808. bool Absolute = TTerminal::IsAbsolutePath(Change);
  1809. Result = !SourceDir.IsEmpty() || Absolute;
  1810. if (Result)
  1811. {
  1812. // expanded from ?: to avoid memory leaks
  1813. if (Absolute)
  1814. {
  1815. Key = Change;
  1816. }
  1817. else
  1818. {
  1819. Key = SourceDir + L"," + Change;
  1820. }
  1821. }
  1822. }
  1823. return Result;
  1824. }
  1825. //=== TRights ---------------------------------------------------------------
  1826. const wchar_t TRights::BasicSymbols[] = L"rwxrwxrwx";
  1827. const wchar_t TRights::CombinedSymbols[] = L"--s--s--t";
  1828. const wchar_t TRights::ExtendedSymbols[] = L"--S--S--T";
  1829. const wchar_t TRights::ModeGroups[] = L"ugo";
  1830. //---------------------------------------------------------------------------
  1831. __fastcall TRights::TRights()
  1832. {
  1833. FAllowUndef = false;
  1834. FSet = 0;
  1835. FUnset = 0;
  1836. Number = 0;
  1837. FUnknown = true;
  1838. }
  1839. //---------------------------------------------------------------------------
  1840. __fastcall TRights::TRights(unsigned short ANumber)
  1841. {
  1842. FAllowUndef = false;
  1843. FSet = 0;
  1844. FUnset = 0;
  1845. Number = ANumber;
  1846. }
  1847. //---------------------------------------------------------------------------
  1848. __fastcall TRights::TRights(const TRights & Source)
  1849. {
  1850. Assign(&Source);
  1851. }
  1852. //---------------------------------------------------------------------------
  1853. //---------------------------------------------------------------------------
  1854. void __fastcall TRights::Assign(const TRights * Source)
  1855. {
  1856. FAllowUndef = Source->AllowUndef;
  1857. FSet = Source->FSet;
  1858. FUnset = Source->FUnset;
  1859. FText = Source->FText;
  1860. FUnknown = Source->FUnknown;
  1861. }
  1862. //---------------------------------------------------------------------------
  1863. TRights::TFlag __fastcall TRights::RightToFlag(TRights::TRight Right)
  1864. {
  1865. return static_cast<TFlag>(1 << (rrLast - Right));
  1866. }
  1867. //---------------------------------------------------------------------------
  1868. bool __fastcall TRights::operator ==(const TRights & rhr) const
  1869. {
  1870. if (AllowUndef || rhr.AllowUndef)
  1871. {
  1872. for (int Right = rrFirst; Right <= rrLast; Right++)
  1873. {
  1874. if (RightUndef[static_cast<TRight>(Right)] !=
  1875. rhr.RightUndef[static_cast<TRight>(Right)])
  1876. {
  1877. return false;
  1878. }
  1879. }
  1880. return true;
  1881. }
  1882. else
  1883. {
  1884. return (Number == rhr.Number);
  1885. }
  1886. }
  1887. //---------------------------------------------------------------------------
  1888. bool __fastcall TRights::operator ==(unsigned short rhr) const
  1889. {
  1890. return (Number == rhr);
  1891. }
  1892. //---------------------------------------------------------------------------
  1893. bool __fastcall TRights::operator !=(const TRights & rhr) const
  1894. {
  1895. return !(*this == rhr);
  1896. }
  1897. //---------------------------------------------------------------------------
  1898. TRights & __fastcall TRights::operator =(unsigned short rhr)
  1899. {
  1900. Number = rhr;
  1901. return *this;
  1902. }
  1903. //---------------------------------------------------------------------------
  1904. TRights & __fastcall TRights::operator =(const TRights & rhr)
  1905. {
  1906. Assign(&rhr);
  1907. return *this;
  1908. }
  1909. //---------------------------------------------------------------------------
  1910. TRights __fastcall TRights::operator ~() const
  1911. {
  1912. TRights Result(static_cast<unsigned short>(~Number));
  1913. return Result;
  1914. }
  1915. //---------------------------------------------------------------------------
  1916. TRights __fastcall TRights::operator &(const TRights & rhr) const
  1917. {
  1918. TRights Result(*this);
  1919. Result &= rhr;
  1920. return Result;
  1921. }
  1922. //---------------------------------------------------------------------------
  1923. TRights __fastcall TRights::operator &(unsigned short rhr) const
  1924. {
  1925. TRights Result(*this);
  1926. Result &= rhr;
  1927. return Result;
  1928. }
  1929. //---------------------------------------------------------------------------
  1930. TRights & __fastcall TRights::operator &=(const TRights & rhr)
  1931. {
  1932. if (AllowUndef || rhr.AllowUndef)
  1933. {
  1934. for (int Right = rrFirst; Right <= rrLast; Right++)
  1935. {
  1936. if (RightUndef[static_cast<TRight>(Right)] !=
  1937. rhr.RightUndef[static_cast<TRight>(Right)])
  1938. {
  1939. RightUndef[static_cast<TRight>(Right)] = rsUndef;
  1940. }
  1941. }
  1942. }
  1943. else
  1944. {
  1945. Number &= rhr.Number;
  1946. }
  1947. return *this;
  1948. }
  1949. //---------------------------------------------------------------------------
  1950. TRights & __fastcall TRights::operator &=(unsigned short rhr)
  1951. {
  1952. Number &= rhr;
  1953. return *this;
  1954. }
  1955. //---------------------------------------------------------------------------
  1956. TRights __fastcall TRights::operator |(const TRights & rhr) const
  1957. {
  1958. TRights Result(*this);
  1959. Result |= rhr;
  1960. return Result;
  1961. }
  1962. //---------------------------------------------------------------------------
  1963. TRights __fastcall TRights::operator |(unsigned short rhr) const
  1964. {
  1965. TRights Result(*this);
  1966. Result |= rhr;
  1967. return Result;
  1968. }
  1969. //---------------------------------------------------------------------------
  1970. TRights & __fastcall TRights::operator |=(const TRights & rhr)
  1971. {
  1972. Number |= rhr.Number;
  1973. return *this;
  1974. }
  1975. //---------------------------------------------------------------------------
  1976. TRights & __fastcall TRights::operator |=(unsigned short rhr)
  1977. {
  1978. Number |= rhr;
  1979. return *this;
  1980. }
  1981. //---------------------------------------------------------------------------
  1982. void __fastcall TRights::SetAllowUndef(bool value)
  1983. {
  1984. if (FAllowUndef != value)
  1985. {
  1986. assert(!value || ((FSet | FUnset) == rfAllSpecials));
  1987. FAllowUndef = value;
  1988. }
  1989. }
  1990. //---------------------------------------------------------------------------
  1991. void __fastcall TRights::SetText(const UnicodeString & value)
  1992. {
  1993. if (value != Text)
  1994. {
  1995. if ((value.Length() != TextLen) ||
  1996. (!AllowUndef && (value.Pos(UndefSymbol) > 0)) ||
  1997. (value.Pos(L" ") > 0))
  1998. {
  1999. throw Exception(FMTLOAD(RIGHTS_ERROR, (value)));
  2000. }
  2001. FSet = 0;
  2002. FUnset = 0;
  2003. int Flag = 00001;
  2004. int ExtendedFlag = 01000;
  2005. bool KeepText = false;
  2006. for (int i = TextLen; i >= 1; i--)
  2007. {
  2008. if (value[i] == UnsetSymbol)
  2009. {
  2010. FUnset |= static_cast<unsigned short>(Flag | ExtendedFlag);
  2011. }
  2012. else if (value[i] == UndefSymbol)
  2013. {
  2014. // do nothing
  2015. }
  2016. else if (value[i] == CombinedSymbols[i - 1])
  2017. {
  2018. FSet |= static_cast<unsigned short>(Flag | ExtendedFlag);
  2019. }
  2020. else if (value[i] == ExtendedSymbols[i - 1])
  2021. {
  2022. FSet |= static_cast<unsigned short>(ExtendedFlag);
  2023. FUnset |= static_cast<unsigned short>(Flag);
  2024. }
  2025. else
  2026. {
  2027. if (value[i] != BasicSymbols[i - 1])
  2028. {
  2029. KeepText = true;
  2030. }
  2031. FSet |= static_cast<unsigned short>(Flag);
  2032. if (i % 3 == 0)
  2033. {
  2034. FUnset |= static_cast<unsigned short>(ExtendedFlag);
  2035. }
  2036. }
  2037. Flag <<= 1;
  2038. if (i % 3 == 1)
  2039. {
  2040. ExtendedFlag <<= 1;
  2041. }
  2042. }
  2043. FText = KeepText ? value : UnicodeString();
  2044. }
  2045. FUnknown = false;
  2046. }
  2047. //---------------------------------------------------------------------------
  2048. UnicodeString __fastcall TRights::GetText() const
  2049. {
  2050. if (!FText.IsEmpty())
  2051. {
  2052. return FText;
  2053. }
  2054. else
  2055. {
  2056. UnicodeString Result;
  2057. Result.SetLength(TextLen);
  2058. int Flag = 00001;
  2059. int ExtendedFlag = 01000;
  2060. bool ExtendedPos = true;
  2061. wchar_t Symbol;
  2062. int i = TextLen;
  2063. while (i >= 1)
  2064. {
  2065. if (ExtendedPos &&
  2066. ((FSet & (Flag | ExtendedFlag)) == (Flag | ExtendedFlag)))
  2067. {
  2068. Symbol = CombinedSymbols[i - 1];
  2069. }
  2070. else if ((FSet & Flag) != 0)
  2071. {
  2072. Symbol = BasicSymbols[i - 1];
  2073. }
  2074. else if (ExtendedPos && ((FSet & ExtendedFlag) != 0))
  2075. {
  2076. Symbol = ExtendedSymbols[i - 1];
  2077. }
  2078. else if ((!ExtendedPos && ((FUnset & Flag) == Flag)) ||
  2079. (ExtendedPos && ((FUnset & (Flag | ExtendedFlag)) == (Flag | ExtendedFlag))))
  2080. {
  2081. Symbol = UnsetSymbol;
  2082. }
  2083. else
  2084. {
  2085. Symbol = UndefSymbol;
  2086. }
  2087. Result[i] = Symbol;
  2088. Flag <<= 1;
  2089. i--;
  2090. ExtendedPos = ((i % 3) == 0);
  2091. if (ExtendedPos)
  2092. {
  2093. ExtendedFlag <<= 1;
  2094. }
  2095. }
  2096. return Result;
  2097. }
  2098. }
  2099. //---------------------------------------------------------------------------
  2100. void __fastcall TRights::SetOctal(UnicodeString value)
  2101. {
  2102. UnicodeString AValue(value);
  2103. if (AValue.Length() == 3)
  2104. {
  2105. AValue = L"0" + AValue;
  2106. }
  2107. if (Octal != AValue)
  2108. {
  2109. bool Correct = (AValue.Length() == 4);
  2110. if (Correct)
  2111. {
  2112. for (int i = 1; (i <= AValue.Length()) && Correct; i++)
  2113. {
  2114. Correct = (AValue[i] >= L'0') && (AValue[i] <= L'7');
  2115. }
  2116. }
  2117. if (!Correct)
  2118. {
  2119. throw Exception(FMTLOAD(INVALID_OCTAL_PERMISSIONS, (value)));
  2120. }
  2121. Number = static_cast<unsigned short>(
  2122. ((AValue[1] - L'0') << 9) +
  2123. ((AValue[2] - L'0') << 6) +
  2124. ((AValue[3] - L'0') << 3) +
  2125. ((AValue[4] - L'0') << 0));
  2126. }
  2127. FUnknown = false;
  2128. }
  2129. //---------------------------------------------------------------------------
  2130. unsigned long __fastcall TRights::GetNumberDecadic() const
  2131. {
  2132. unsigned long N = NumberSet; // used to be "Number"
  2133. unsigned long Result =
  2134. ((N & 07000) / 01000 * 1000) +
  2135. ((N & 00700) / 0100 * 100) +
  2136. ((N & 00070) / 010 * 10) +
  2137. ((N & 00007) / 01 * 1);
  2138. return Result;
  2139. }
  2140. //---------------------------------------------------------------------------
  2141. UnicodeString __fastcall TRights::GetOctal() const
  2142. {
  2143. UnicodeString Result;
  2144. unsigned short N = NumberSet; // used to be "Number"
  2145. Result.SetLength(4);
  2146. Result[1] = static_cast<wchar_t>(L'0' + ((N & 07000) >> 9));
  2147. Result[2] = static_cast<wchar_t>(L'0' + ((N & 00700) >> 6));
  2148. Result[3] = static_cast<wchar_t>(L'0' + ((N & 00070) >> 3));
  2149. Result[4] = static_cast<wchar_t>(L'0' + ((N & 00007) >> 0));
  2150. return Result;
  2151. }
  2152. //---------------------------------------------------------------------------
  2153. void __fastcall TRights::SetNumber(unsigned short value)
  2154. {
  2155. if ((FSet != value) || ((FSet | FUnset) != rfAllSpecials))
  2156. {
  2157. FSet = value;
  2158. FUnset = static_cast<unsigned short>(rfAllSpecials & ~FSet);
  2159. FText = L"";
  2160. }
  2161. FUnknown = false;
  2162. }
  2163. //---------------------------------------------------------------------------
  2164. unsigned short __fastcall TRights::GetNumber() const
  2165. {
  2166. assert(!IsUndef);
  2167. return FSet;
  2168. }
  2169. //---------------------------------------------------------------------------
  2170. void __fastcall TRights::SetRight(TRight Right, bool value)
  2171. {
  2172. RightUndef[Right] = (value ? rsYes : rsNo);
  2173. }
  2174. //---------------------------------------------------------------------------
  2175. bool __fastcall TRights::GetRight(TRight Right) const
  2176. {
  2177. TState State = RightUndef[Right];
  2178. assert(State != rsUndef);
  2179. return (State == rsYes);
  2180. }
  2181. //---------------------------------------------------------------------------
  2182. void __fastcall TRights::SetRightUndef(TRight Right, TState value)
  2183. {
  2184. if (value != RightUndef[Right])
  2185. {
  2186. assert((value != rsUndef) || AllowUndef);
  2187. TFlag Flag = RightToFlag(Right);
  2188. switch (value)
  2189. {
  2190. case rsYes:
  2191. FSet |= static_cast<unsigned short>(Flag);
  2192. FUnset &= static_cast<unsigned short>(~Flag);
  2193. break;
  2194. case rsNo:
  2195. FSet &= static_cast<unsigned short>(~Flag);
  2196. FUnset |= static_cast<unsigned short>(Flag);
  2197. break;
  2198. case rsUndef:
  2199. default:
  2200. FSet &= static_cast<unsigned short>(~Flag);
  2201. FUnset &= static_cast<unsigned short>(~Flag);
  2202. break;
  2203. }
  2204. FText = L"";
  2205. }
  2206. FUnknown = false;
  2207. }
  2208. //---------------------------------------------------------------------------
  2209. TRights::TState __fastcall TRights::GetRightUndef(TRight Right) const
  2210. {
  2211. TFlag Flag = RightToFlag(Right);
  2212. TState Result;
  2213. if ((FSet & Flag) != 0)
  2214. {
  2215. Result = rsYes;
  2216. }
  2217. else if ((FUnset & Flag) != 0)
  2218. {
  2219. Result = rsNo;
  2220. }
  2221. else
  2222. {
  2223. Result = rsUndef;
  2224. }
  2225. return Result;
  2226. }
  2227. //---------------------------------------------------------------------------
  2228. void __fastcall TRights::SetReadOnly(bool value)
  2229. {
  2230. Right[rrUserWrite] = !value;
  2231. Right[rrGroupWrite] = !value;
  2232. Right[rrOtherWrite] = !value;
  2233. }
  2234. //---------------------------------------------------------------------------
  2235. bool __fastcall TRights::GetReadOnly()
  2236. {
  2237. return Right[rrUserWrite] && Right[rrGroupWrite] && Right[rrOtherWrite];
  2238. }
  2239. //---------------------------------------------------------------------------
  2240. UnicodeString __fastcall TRights::GetSimplestStr() const
  2241. {
  2242. if (IsUndef)
  2243. {
  2244. return ModeStr;
  2245. }
  2246. else
  2247. {
  2248. return Octal;
  2249. }
  2250. }
  2251. //---------------------------------------------------------------------------
  2252. UnicodeString __fastcall TRights::GetModeStr() const
  2253. {
  2254. UnicodeString Result;
  2255. UnicodeString SetModeStr, UnsetModeStr;
  2256. TRight Right;
  2257. int Index;
  2258. for (int Group = 0; Group < 3; Group++)
  2259. {
  2260. SetModeStr = L"";
  2261. UnsetModeStr = L"";
  2262. for (int Mode = 0; Mode < 3; Mode++)
  2263. {
  2264. Index = (Group * 3) + Mode;
  2265. Right = static_cast<TRight>(rrUserRead + Index);
  2266. switch (RightUndef[Right])
  2267. {
  2268. case rsYes:
  2269. SetModeStr += BasicSymbols[Index];
  2270. break;
  2271. case rsNo:
  2272. UnsetModeStr += BasicSymbols[Index];
  2273. break;
  2274. }
  2275. }
  2276. Right = static_cast<TRight>(rrUserIDExec + Group);
  2277. Index = (Group * 3) + 2;
  2278. switch (RightUndef[Right])
  2279. {
  2280. case rsYes:
  2281. SetModeStr += CombinedSymbols[Index];
  2282. break;
  2283. case rsNo:
  2284. UnsetModeStr += CombinedSymbols[Index];
  2285. break;
  2286. }
  2287. if (!SetModeStr.IsEmpty() || !UnsetModeStr.IsEmpty())
  2288. {
  2289. if (!Result.IsEmpty())
  2290. {
  2291. Result += L',';
  2292. }
  2293. Result += ModeGroups[Group];
  2294. if (!SetModeStr.IsEmpty())
  2295. {
  2296. Result += L"+" + SetModeStr;
  2297. }
  2298. if (!UnsetModeStr.IsEmpty())
  2299. {
  2300. Result += L"-" + UnsetModeStr;
  2301. }
  2302. }
  2303. }
  2304. return Result;
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TRights::AddExecute()
  2308. {
  2309. for (int Group = 0; Group < 3; Group++)
  2310. {
  2311. if ((RightUndef[static_cast<TRight>(rrUserRead + (Group * 3))] == rsYes) ||
  2312. (RightUndef[static_cast<TRight>(rrUserWrite + (Group * 3))] == rsYes))
  2313. {
  2314. Right[static_cast<TRight>(rrUserExec + (Group * 3))] = true;
  2315. }
  2316. }
  2317. FUnknown = false;
  2318. }
  2319. //---------------------------------------------------------------------------
  2320. void __fastcall TRights::AllUndef()
  2321. {
  2322. if ((FSet != 0) || (FUnset != 0))
  2323. {
  2324. FSet = 0;
  2325. FUnset = 0;
  2326. FText = L"";
  2327. }
  2328. FUnknown = false;
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. bool __fastcall TRights::GetIsUndef() const
  2332. {
  2333. return ((FSet | FUnset) != rfAllSpecials);
  2334. }
  2335. //---------------------------------------------------------------------------
  2336. __fastcall TRights::operator unsigned short() const
  2337. {
  2338. return Number;
  2339. }
  2340. //---------------------------------------------------------------------------
  2341. __fastcall TRights::operator unsigned long() const
  2342. {
  2343. return Number;
  2344. }
  2345. //=== TRemoteProperties -------------------------------------------------------
  2346. __fastcall TRemoteProperties::TRemoteProperties()
  2347. {
  2348. Default();
  2349. }
  2350. //---------------------------------------------------------------------------
  2351. __fastcall TRemoteProperties::TRemoteProperties(const TRemoteProperties & rhp) :
  2352. Valid(rhp.Valid),
  2353. Recursive(rhp.Recursive),
  2354. Rights(rhp.Rights),
  2355. AddXToDirectories(rhp.AddXToDirectories),
  2356. Group(rhp.Group),
  2357. Owner(rhp.Owner),
  2358. Modification(rhp.Modification),
  2359. LastAccess(rhp.Modification)
  2360. {
  2361. }
  2362. //---------------------------------------------------------------------------
  2363. void __fastcall TRemoteProperties::Default()
  2364. {
  2365. Valid.Clear();
  2366. AddXToDirectories = false;
  2367. Rights.AllowUndef = false;
  2368. Rights.Number = 0;
  2369. Group.Clear();
  2370. Owner.Clear();
  2371. Recursive = false;
  2372. }
  2373. //---------------------------------------------------------------------------
  2374. bool __fastcall TRemoteProperties::operator ==(const TRemoteProperties & rhp) const
  2375. {
  2376. bool Result = (Valid == rhp.Valid && Recursive == rhp.Recursive);
  2377. if (Result)
  2378. {
  2379. if ((Valid.Contains(vpRights) &&
  2380. (Rights != rhp.Rights || AddXToDirectories != rhp.AddXToDirectories)) ||
  2381. (Valid.Contains(vpOwner) && (Owner != rhp.Owner)) ||
  2382. (Valid.Contains(vpGroup) && (Group != rhp.Group)) ||
  2383. (Valid.Contains(vpModification) && (Modification != rhp.Modification)) ||
  2384. (Valid.Contains(vpLastAccess) && (LastAccess != rhp.LastAccess)))
  2385. {
  2386. Result = false;
  2387. }
  2388. }
  2389. return Result;
  2390. }
  2391. //---------------------------------------------------------------------------
  2392. bool __fastcall TRemoteProperties::operator !=(const TRemoteProperties & rhp) const
  2393. {
  2394. return !(*this == rhp);
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. TRemoteProperties __fastcall TRemoteProperties::CommonProperties(TStrings * FileList)
  2398. {
  2399. // TODO: Modification and LastAccess
  2400. TRemoteProperties CommonProperties;
  2401. for (int Index = 0; Index < FileList->Count; Index++)
  2402. {
  2403. TRemoteFile * File = (TRemoteFile *)(FileList->Objects[Index]);
  2404. assert(File);
  2405. if (!Index)
  2406. {
  2407. CommonProperties.Rights = *(File->Rights);
  2408. // previously we allowed undef implicitly for directories,
  2409. // now we do it explicitly in properties dialog and only in combination
  2410. // with "recursive" option
  2411. CommonProperties.Rights.AllowUndef = File->Rights->IsUndef;
  2412. CommonProperties.Valid << vpRights;
  2413. if (File->Owner.IsSet)
  2414. {
  2415. CommonProperties.Owner = File->Owner;
  2416. CommonProperties.Valid << vpOwner;
  2417. }
  2418. if (File->Group.IsSet)
  2419. {
  2420. CommonProperties.Group = File->Group;
  2421. CommonProperties.Valid << vpGroup;
  2422. }
  2423. }
  2424. else
  2425. {
  2426. CommonProperties.Rights.AllowUndef = True;
  2427. CommonProperties.Rights &= *File->Rights;
  2428. if (CommonProperties.Owner != File->Owner)
  2429. {
  2430. CommonProperties.Owner.Clear();
  2431. CommonProperties.Valid >> vpOwner;
  2432. }
  2433. if (CommonProperties.Group != File->Group)
  2434. {
  2435. CommonProperties.Group.Clear();
  2436. CommonProperties.Valid >> vpGroup;
  2437. }
  2438. }
  2439. }
  2440. return CommonProperties;
  2441. }
  2442. //---------------------------------------------------------------------------
  2443. TRemoteProperties __fastcall TRemoteProperties::ChangedProperties(
  2444. const TRemoteProperties & OriginalProperties, TRemoteProperties NewProperties)
  2445. {
  2446. // TODO: Modification and LastAccess
  2447. if (!NewProperties.Recursive)
  2448. {
  2449. if (NewProperties.Rights == OriginalProperties.Rights &&
  2450. !NewProperties.AddXToDirectories)
  2451. {
  2452. NewProperties.Valid >> vpRights;
  2453. }
  2454. if (NewProperties.Group == OriginalProperties.Group)
  2455. {
  2456. NewProperties.Valid >> vpGroup;
  2457. }
  2458. if (NewProperties.Owner == OriginalProperties.Owner)
  2459. {
  2460. NewProperties.Valid >> vpOwner;
  2461. }
  2462. }
  2463. return NewProperties;
  2464. }
  2465. //---------------------------------------------------------------------------
  2466. void __fastcall TRemoteProperties::Load(THierarchicalStorage * Storage)
  2467. {
  2468. unsigned char Buf[sizeof(Valid)];
  2469. if (static_cast<size_t>(Storage->ReadBinaryData(L"Valid", &Buf, sizeof(Buf))) == sizeof(Buf))
  2470. {
  2471. memmove(&Valid, Buf, sizeof(Valid));
  2472. }
  2473. if (Valid.Contains(vpRights))
  2474. {
  2475. Rights.Text = Storage->ReadString(L"Rights", Rights.Text);
  2476. }
  2477. // TODO
  2478. }
  2479. //---------------------------------------------------------------------------
  2480. void __fastcall TRemoteProperties::Save(THierarchicalStorage * Storage) const
  2481. {
  2482. Storage->WriteBinaryData(UnicodeString(L"Valid"),
  2483. static_cast<const void *>(&Valid), sizeof(Valid));
  2484. if (Valid.Contains(vpRights))
  2485. {
  2486. Storage->WriteString(L"Rights", Rights.Text);
  2487. }
  2488. // TODO
  2489. }