IEDriveInfo.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. unit IEDriveInfo;
  2. {==================================================================
  3. Component TDriveInfo / Version 2.6 / January 2000
  4. ====================================================
  5. Description:
  6. ============
  7. Central drive management class. Provides information about all
  8. installed drives, for example wether drive is valid, disk is inserted
  9. displayname or volume size.
  10. Author:
  11. =======
  12. (c) Ingo Eckel 1999
  13. Sodener Weg 38
  14. 65812 Bad Soden
  15. Germany
  16. For detailed documentation and history see the documentation in TDriveInfo.htm.
  17. {==================================================================}
  18. {Required compiler options:}
  19. {$A+,B-,X+,H+,P+}
  20. {$WARN SYMBOL_PLATFORM OFF}
  21. interface
  22. uses
  23. Windows, Registry, SysUtils, Classes, ComCtrls, ShellApi, ShlObj, CommCtrl, Forms,
  24. BaseUtils, System.Generics.Collections;
  25. const
  26. {Flags used by TDriveInfo.ReadDriveStatus and TDriveView.RefreshRootNodes:}
  27. dsValid = 0; {checks only whether drive is still valid}
  28. dsImageIndex = 1; {Fetch imageindex, if not allready fetched}
  29. dsSize = 2; {Fetch disk size and serialnumber}
  30. dsDisplayName = 4; {Fetch drives displayname}
  31. dsAll = dsImageIndex or dsSize or dsDisplayName;
  32. FirstDrive = 'A';
  33. SystemDrive = 'C';
  34. LastDrive = 'Z';
  35. FirstSpecialFolder = CSIDL_DESKTOP;
  36. LastSpecialFolder = CSIDL_PRINTHOOD;
  37. type
  38. TDriveInfoRec = class
  39. PIDL : PItemIDList; {Fully qualyfied PIDL}
  40. Init : Boolean; {Drivestatus was updated once}
  41. Valid : Boolean; {Drivestatus is valid}
  42. DriveReady : Boolean; {Drive is ready}
  43. DriveType : Integer; {DRIVE_REMOVABLE, DRIVE_FIXED, DRIVE_CDROM, DRIVE_RAMDISK, DRIVE_REMOTE}
  44. DisplayName : string; {Windows displayname}
  45. PrettyName : string; {Prettyfied displayname}
  46. DriveSerial : DWORD; {Serial number of the drive}
  47. Size : Int64; {Drivesize}
  48. ImageIndex : Integer; {Drive imageIndex}
  49. end;
  50. TRealDrive = char;
  51. TSpecialFolder = FirstSpecialFolder..LastSpecialFolder;
  52. PSpecialFolderRec = ^TSpecialFolderRec;
  53. TSpecialFolderRec = record
  54. Valid: Boolean;
  55. Location: string;
  56. DisplayName: string;
  57. ImageIndex: Integer;
  58. PIDL: PItemIDList;
  59. end;
  60. TDriveInfo = class(TObject)
  61. private
  62. FData: TObjectDictionary<string, TDriveInfoRec>;
  63. FNoDrives: DWORD;
  64. FDesktop: IShellFolder;
  65. FFolders: array[TSpecialFolder] of TSpecialFolderRec;
  66. FHonorDrivePolicy: Boolean;
  67. FUseABDrives: Boolean;
  68. FLoaded: Boolean;
  69. function GetFolder(Folder: TSpecialFolder): PSpecialFolderRec;
  70. procedure ReadDriveBasicStatus(Drive: string);
  71. procedure ResetDrive(Drive: string);
  72. procedure SetHonorDrivePolicy(Value: Boolean);
  73. function GetFirstFixedDrive: Char;
  74. procedure NeedData;
  75. procedure Load;
  76. function AddDrive(Drive: string): TDriveInfoRec;
  77. public
  78. function Get(Drive: string): TDriveInfoRec;
  79. property SpecialFolder[Folder: TSpecialFolder]: PSpecialFolderRec read GetFolder;
  80. function AnyValidPath: string;
  81. function GetDriveKey(Path: string): string;
  82. function GetDriveRoot(Drive: string): string;
  83. function IsRealDrive(Drive: string): Boolean;
  84. function IsFixedDrive(Drive: string): Boolean;
  85. function GetImageIndex(Drive: string): Integer;
  86. function GetSimpleName(Drive: string): string;
  87. function GetDisplayName(Drive: string): string;
  88. function GetPrettyName(Drive: string): string;
  89. function ReadDriveStatus(Drive: string; Flags: Integer): Boolean;
  90. property HonorDrivePolicy: Boolean read FHonorDrivePolicy write SetHonorDrivePolicy;
  91. property FirstFixedDrive: Char read GetFirstFixedDrive;
  92. property UseABDrives: Boolean read FUseABDrives write FUseABDrives;
  93. constructor Create;
  94. destructor Destroy; override;
  95. end;
  96. function GetShellFileName(const Name: string): string; overload;
  97. function GetShellFileName(PIDL: PItemIDList): string; overload;
  98. function GetNetWorkName(Drive: string): string;
  99. function GetNetWorkConnected(Drive: string): Boolean;
  100. function IsRootPath(Path: string): Boolean;
  101. {Central drive information object instance of TDriveInfo}
  102. var
  103. DriveInfo : TDriveInfo;
  104. resourceString
  105. ErrorInvalidDrive = '%s is a invalid drive letter.';
  106. implementation
  107. uses
  108. Math, PIDL, OperationWithTimeout, PasTools;
  109. constructor TDriveInfo.Create;
  110. begin
  111. inherited;
  112. FHonorDrivePolicy := True;
  113. FUseABDrives := True;
  114. FLoaded := False;
  115. FData := TObjectDictionary<string, TDriveInfoRec>.Create([doOwnsValues]);
  116. end; {TDriveInfo.Create}
  117. destructor TDriveInfo.Destroy;
  118. begin
  119. FData.Free;
  120. inherited;
  121. end; {TDriveInfo.Destroy}
  122. procedure TDriveInfo.NeedData;
  123. begin
  124. if not FLoaded then
  125. begin
  126. Load;
  127. FLoaded := True;
  128. end;
  129. end;
  130. function TDriveInfo.AnyValidPath: string;
  131. var
  132. Drive: TRealDrive;
  133. begin
  134. // Fallback to A:/B: if no other drive is found?
  135. for Drive := SystemDrive to LastDrive do
  136. if Get(Drive).Valid and
  137. (Get(Drive).DriveType = DRIVE_FIXED) and
  138. DirectoryExists(ApiPath(GetDriveRoot(Drive))) then
  139. begin
  140. Result := GetDriveRoot(Drive);
  141. Exit;
  142. end;
  143. for Drive := SystemDrive to LastDrive do
  144. if Get(Drive).Valid and
  145. (Get(Drive).DriveType = DRIVE_REMOTE) and
  146. DirectoryExists(ApiPath(GetDriveRoot(Drive))) then
  147. begin
  148. Result := GetDriveRoot(Drive);
  149. Exit;
  150. end;
  151. raise Exception.Create(SNoValidPath);
  152. end;
  153. function TDriveInfo.IsRealDrive(Drive: string): Boolean;
  154. begin
  155. Result := (Length(Drive) = 1);
  156. Assert((not Result) or ((Drive[1] >= FirstDrive) and (Drive[1] <= LastDrive)));
  157. end;
  158. function TDriveInfo.IsFixedDrive(Drive: string): Boolean;
  159. begin
  160. Result := True;
  161. if IsRealDrive(Drive) and (Drive[1] < FirstFixedDrive) then Result := False;
  162. end;
  163. function TDriveInfo.GetDriveKey(Path: string): string;
  164. begin
  165. Result := ExtractFileDrive(Path);
  166. if (Length(Result) = 2) and (Result[2] = DriveDelim) then
  167. begin
  168. Result := Upcase(Result[1]);
  169. end
  170. else
  171. if IsUncPath(Path) then
  172. begin
  173. Result := LowerCase(Result);
  174. end
  175. else
  176. begin
  177. raise EConvertError.Create(Format(ErrorInvalidDrive, [Path]))
  178. end;
  179. end;
  180. function TDriveInfo.GetDriveRoot(Drive: string): string;
  181. begin
  182. if IsRealDrive(Drive) then
  183. begin
  184. Result := Drive + ':\'
  185. end
  186. else
  187. begin
  188. Assert(IsUncPath(Drive));
  189. Result := IncludeTrailingBackslash(Drive);
  190. end;
  191. end;
  192. function TDriveInfo.GetFolder(Folder: TSpecialFolder): PSpecialFolderRec;
  193. var
  194. FileInfo: TShFileInfo;
  195. Path: PChar;
  196. Flags: Word;
  197. begin
  198. NeedData;
  199. Assert((Folder >= Low(FFolders)) and (Folder <= High(FFolders)));
  200. with FFolders[Folder] do
  201. begin
  202. if not Valid then
  203. begin
  204. SpecialFolderLocation(Folder, Location, PIDL);
  205. if Assigned(PIDL) then
  206. begin
  207. Path := PChar(PIDL);
  208. Flags := SHGFI_PIDL;
  209. end
  210. else
  211. begin
  212. Path := PChar(Location);
  213. Flags := 0;
  214. end;
  215. SHGetFileInfo(Path, 0, FileInfo, SizeOf(FileInfo),
  216. SHGFI_DISPLAYNAME or SHGFI_SYSICONINDEX or SHGFI_SMALLICON or Flags);
  217. ImageIndex := FileInfo.iIcon;
  218. DisplayName := FileInfo.szDisplayName;
  219. Valid := True;
  220. end;
  221. end;
  222. Result := @FFolders[Folder];
  223. end;
  224. procedure TDriveInfo.SetHonorDrivePolicy(Value: Boolean);
  225. var
  226. Drive: TRealDrive;
  227. begin
  228. if HonorDrivePolicy <> Value then
  229. begin
  230. FHonorDrivePolicy := Value;
  231. if FLoaded then
  232. begin
  233. for Drive := FirstDrive to LastDrive do
  234. begin
  235. ReadDriveBasicStatus(Drive);
  236. end;
  237. end;
  238. end;
  239. end;
  240. function TDriveInfo.GetFirstFixedDrive: Char;
  241. begin
  242. if UseABDrives then Result := FirstDrive
  243. else Result := SystemDrive;
  244. end;
  245. procedure TDriveInfo.ReadDriveBasicStatus(Drive: string);
  246. begin
  247. Assert(FData.ContainsKey(Drive));
  248. with FData[Drive] do
  249. begin
  250. DriveType := Windows.GetDriveType(PChar(GetDriveRoot(Drive)));
  251. Valid :=
  252. ((not IsRealDrive(Drive)) or (not FHonorDrivePolicy) or (not Bool((1 shl (Ord(Drive[1]) - 65)) and FNoDrives))) and
  253. (DriveType in [DRIVE_REMOVABLE, DRIVE_FIXED, DRIVE_CDROM, DRIVE_RAMDISK, DRIVE_REMOTE]);
  254. end;
  255. end;
  256. procedure TDriveInfo.ResetDrive(Drive: string);
  257. begin
  258. with FData[Drive] do
  259. begin
  260. DriveReady := False;
  261. DisplayName := '';
  262. PrettyName := '';
  263. DriveSerial := 0;
  264. Size := -1;
  265. ImageIndex := 0;
  266. end;
  267. end;
  268. procedure TDriveInfo.Load;
  269. var
  270. Drive: TRealDrive;
  271. Reg: TRegistry;
  272. Folder: TSpecialFolder;
  273. begin
  274. FNoDrives := 0;
  275. Reg := TRegistry.Create;
  276. try
  277. if Reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') Then
  278. Reg.ReadBinaryData('NoDrives', FNoDrives, SizeOf(FNoDrives));
  279. except
  280. try
  281. FNoDrives := Reg.ReadInteger('NoDrives');
  282. except
  283. end;
  284. end;
  285. Reg.Free;
  286. FDesktop := nil;
  287. for Drive := FirstDrive to LastDrive do
  288. begin
  289. AddDrive(Drive);
  290. end;
  291. for Folder := Low(FFolders) to High(FFolders) do
  292. FFolders[Folder].Valid := False;
  293. end;
  294. function TDriveInfo.AddDrive(Drive: string): TDriveInfoRec;
  295. begin
  296. Result := TDriveInfoRec.Create;
  297. FData.Add(Drive, Result);
  298. ResetDrive(Drive);
  299. ReadDriveBasicStatus(Drive);
  300. end;
  301. function TDriveInfo.GetImageIndex(Drive: string): Integer;
  302. begin
  303. NeedData;
  304. Result := 0;
  305. if Get(Drive).Valid then
  306. begin
  307. if Get(Drive).ImageIndex = 0 then
  308. ReadDriveStatus(Drive, dsImageIndex);
  309. Result := Get(Drive).ImageIndex;
  310. end;
  311. end; {TDriveInfo.GetImageIndex}
  312. function TDriveInfo.GetDisplayName(Drive: string): string;
  313. begin
  314. if Get(Drive).Valid then
  315. begin
  316. if Length(Get(Drive).DisplayName) = 0 then
  317. ReadDriveStatus(Drive, dsDisplayName);
  318. Result := Get(Drive).DisplayName;
  319. end
  320. else
  321. begin
  322. Result := GetSimpleName(Drive);
  323. end;
  324. end; {TDriveInfo.GetDisplayname}
  325. function TDriveInfo.GetPrettyName(Drive: string): string;
  326. begin
  327. if Get(Drive).Valid then
  328. begin
  329. if Length(Get(Drive).PrettyName) = 0 then
  330. ReadDriveStatus(Drive, dsDisplayName);
  331. Result := Get(Drive).PrettyName;
  332. end
  333. else
  334. begin
  335. Result := GetSimpleName(Drive);
  336. end;
  337. end; {TDriveInfo.GetPrettyName}
  338. function TDriveInfo.GetSimpleName(Drive: string): string;
  339. begin
  340. Result := Drive;
  341. if IsRealDrive(Result) then Result := Result + ':';
  342. end;
  343. function TDriveInfo.Get(Drive: string): TDriveInfoRec;
  344. begin
  345. NeedData;
  346. if not FData.TryGetValue(Drive, Result) then
  347. begin
  348. Assert(IsUncPath(Drive));
  349. Result := AddDrive(Drive);
  350. end;
  351. end; {TDriveInfo.GetData}
  352. function TDriveInfo.ReadDriveStatus(Drive: string; Flags: Integer): Boolean;
  353. var
  354. ErrorMode: Word;
  355. FileInfo: TShFileInfo;
  356. DriveRoot: string;
  357. DriveID: string;
  358. CPos: Integer;
  359. Eaten: ULONG;
  360. ShAttr: ULONG;
  361. MaxFileNameLength: DWORD;
  362. FileSystemFlags: DWORD;
  363. FreeSpace: Int64;
  364. SimpleName: string;
  365. DriveInfoRec: TDriveInfoRec;
  366. S: string;
  367. begin
  368. if not Assigned(FDesktop) then
  369. SHGetDesktopFolder(FDesktop);
  370. DriveRoot := GetDriveRoot(Drive);
  371. // When this method is called, the entry always exists already
  372. Assert(FData.ContainsKey(Drive));
  373. DriveInfoRec := FData[Drive];
  374. with DriveInfoRec do
  375. begin
  376. Init := True;
  377. ReadDriveBasicStatus(Drive);
  378. if Valid then
  379. begin
  380. if (not Assigned(PIDL)) and IsFixedDrive(Drive) then
  381. begin
  382. ShAttr := 0;
  383. if DriveType = DRIVE_REMOTE then
  384. begin
  385. ShellFolderParseDisplayNameWithTimeout(
  386. FDesktop, Application.Handle, nil, PChar(DriveRoot), Eaten, PIDL, ShAttr, 2 * MSecsPerSec);
  387. end
  388. else
  389. begin
  390. FDesktop.ParseDisplayName(Application.Handle, nil, PChar(DriveRoot), Eaten, PIDL, ShAttr);
  391. end;
  392. end;
  393. {Read driveStatus:}
  394. if (Flags and dsSize) <> 0 then
  395. begin
  396. { turn off critical errors }
  397. ErrorMode := SetErrorMode(SEM_FailCriticalErrors or SEM_NOOPENFILEERRORBOX);
  398. try
  399. DriveReady := GetDiskFreeSpaceEx(PChar(DriveRoot), FreeSpace, Size, nil);
  400. if DriveReady then
  401. begin
  402. {Access the physical drive:}
  403. if GetVolumeInformation(PChar(DriveRoot), nil, 0,
  404. @DriveSerial, MaxFileNameLength, FileSystemFlags,
  405. nil, 0) then
  406. begin
  407. end
  408. else
  409. begin
  410. DriveSerial := 0;
  411. end;
  412. end
  413. else
  414. begin
  415. DriveSerial := 0;
  416. end;
  417. finally
  418. { restore old error mode }
  419. SetErrorMode(ErrorMode);
  420. end;
  421. end;
  422. {DisplayName:}
  423. if (Flags and dsDisplayName <> 0) then
  424. begin
  425. {Fetch drives displayname:}
  426. SimpleName := GetSimpleName(Drive);
  427. if Assigned(PIDL) then DisplayName := GetShellFileName(PIDL)
  428. else
  429. begin
  430. // typical reason we do not have PIDL is that it took too long to
  431. // call ParseDisplayName, in what case calling SHGetFileInfo with
  432. // path (instead of PIDL) will take long too, avoiding that and using
  433. // fallback
  434. DisplayName := '(' + SimpleName + ')';
  435. end;
  436. if DriveType <> DRIVE_REMOTE then
  437. begin
  438. PrettyName := SimpleName + ' ' + DisplayName;
  439. S := ' (' + SimpleName + ')';
  440. CPos := Pos(S, PrettyName);
  441. if CPos > 0 then
  442. Delete(PrettyName, CPos, Length(S));
  443. end
  444. else
  445. if IsRealDrive(Drive) then
  446. begin
  447. DriveID := GetNetWorkName(Drive);
  448. PrettyName := Format('%s %s (%s)', [SimpleName, ExtractFileName(DriveID), ExtractFileDir(DriveID)]);
  449. end
  450. else
  451. begin
  452. Assert(IsUncPath(DriveRoot));
  453. PrettyName := SimpleName;
  454. end;
  455. end;
  456. {ImageIndex:}
  457. if ((Flags and dsImageIndex) <> 0) and (ImageIndex < 5) then
  458. begin
  459. if Assigned(PIDL) then
  460. begin
  461. SHGetFileInfo(PChar(PIDL), 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON or SHGFI_PIDL)
  462. end
  463. else
  464. begin
  465. SHGetFileInfo(PChar(DriveRoot), 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  466. end;
  467. ImageIndex := FileInfo.iIcon;
  468. end;
  469. end
  470. else
  471. begin
  472. if Assigned(PIDL) then
  473. FreePIDL(PIDL);
  474. ResetDrive(Drive);
  475. end;
  476. Result := Valid and DriveReady;
  477. end;
  478. end; {TDriveInfo.ReadDriveStatus}
  479. function GetShellFileName(const Name: string): string;
  480. var
  481. SFI: TSHFileInfo;
  482. E: Integer;
  483. begin
  484. E := SetErrorMode(SEM_FAILCRITICALERRORS);
  485. try
  486. if SHGetFileInfo(PChar(Name), 0, SFI, SizeOf(TSHFileInfo), SHGFI_DISPLAYNAME) <> 0 then
  487. Result := SFI.szDisplayName;
  488. finally
  489. SetErrorMode(E);
  490. end;
  491. end; {GetShellFileName}
  492. function GetShellFileName(PIDL: PItemIDList): string;
  493. var
  494. SFI: TSHFileInfo;
  495. E: Integer;
  496. begin
  497. E := SetErrorMode(SEM_FAILCRITICALERRORS);
  498. try
  499. if SHGetFileInfo(PChar(PIDL), 0, SFI, SizeOf(TSHFileInfo), SHGFI_PIDL or SHGFI_DISPLAYNAME) <> 0 then
  500. Result := SFI.szDisplayName;
  501. finally
  502. SetErrorMode(E);
  503. end;
  504. end; {GetShellFileName}
  505. function GetNetWorkName(Drive: string): string;
  506. var
  507. Path: string;
  508. P: array[0..MAX_PATH] of Char;
  509. MaxLen : DWORD;
  510. begin
  511. Path := ExcludeTrailingBackslash(DriveInfo.GetDriveRoot(Drive));
  512. MaxLen := MAX_PATH;
  513. if WNetGetConnection(PChar(Path), P, MaxLen) = NO_ERROR then
  514. Result := P
  515. else
  516. Result := '';
  517. end; {GetNetWorkName}
  518. type
  519. LPBYTE = ^BYTE;
  520. LMSTR = LPWSTR;
  521. NET_API_STATUS = DWORD;
  522. _USE_INFO_1 = record
  523. ui1_local: LMSTR;
  524. ui1_remote: LMSTR;
  525. ui1_password: LMSTR;
  526. ui1_status: DWORD;
  527. ui1_asg_type: DWORD;
  528. ui1_refcount: DWORD;
  529. ui1_usecount: DWORD;
  530. end;
  531. USE_INFO_1 = _USE_INFO_1;
  532. PUSE_INFO_1 = ^USE_INFO_1;
  533. LPVOID = Pointer;
  534. const
  535. USE_OK = 0;
  536. USE_PAUSED = 1;
  537. USE_SESSLOST = 2;
  538. USE_DISCONN = 2;
  539. USE_NETERR = 3;
  540. USE_CONN = 4;
  541. USE_RECONN = 5;
  542. function NetUseGetInfo(UncServerName: LMSTR; UseName: LMSTR; Level: DWORD; var BufPtr: LPBYTE): NET_API_STATUS; stdcall; external 'netapi32.dll';
  543. function NetApiBufferFree(Buffer: Pointer): DWORD; stdcall; external 'netapi32.dll';
  544. function GetNetWorkConnected(Drive: string): Boolean;
  545. var
  546. BufPtr: LPBYTE;
  547. NetResult: Integer;
  548. ServerName: string;
  549. PServerName: PChar;
  550. Name: string;
  551. P: Integer;
  552. begin
  553. Name := '';
  554. PServerName := nil;
  555. if DriveInfo.IsRealDrive(Drive) then
  556. begin
  557. Name := Drive + ':';
  558. end
  559. else
  560. if IsUncPath(Drive) then
  561. begin
  562. Name := Copy(Drive, 3, Length(Drive) - 2);
  563. P := Pos('\', Name);
  564. if P > 0 then
  565. begin
  566. ServerName := Copy(Name, P + 1, Length(Name) - P);
  567. PServerName := PChar(ServerName);
  568. SetLength(Name, P - 1);
  569. end
  570. else
  571. begin
  572. Assert(False);
  573. end;
  574. end
  575. else
  576. begin
  577. Assert(False);
  578. end;
  579. if Name = '' then
  580. begin
  581. Result := False;
  582. end
  583. else
  584. begin
  585. NetResult := NetUseGetInfo(PServerName, PChar(Name), 1, BufPtr);
  586. if NetResult = 0 then
  587. begin
  588. Result := (PUSE_INFO_1(BufPtr)^.ui1_status = USE_OK);
  589. NetApiBufferFree(LPVOID(BufPtr));
  590. end
  591. else
  592. begin
  593. // NetUseGetInfo works for DFS shares only, hence when it fails
  594. // we suppose different share type and fallback to "connected"
  595. Result := True;
  596. end;
  597. end;
  598. end;
  599. function IsRootPath(Path: string): Boolean;
  600. begin
  601. Result := SameText(ExcludeTrailingBackslash(ExtractFileDrive(Path)), ExcludeTrailingBackslash(Path));
  602. end;
  603. initialization
  604. if not Assigned(DriveInfo) then
  605. DriveInfo := TDriveInfo.Create;
  606. finalization
  607. if Assigned(DriveInfo) then
  608. begin
  609. DriveInfo.Free;
  610. DriveInfo := nil;
  611. end;
  612. end.