IEDriveInfo.pas 18 KB

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