Use faster APIs for getting drive info

This commit is contained in:
Paddy Xu
2017-05-11 01:28:19 +03:00
parent ba2d5d2ab2
commit 23d90b3de4
2 changed files with 23 additions and 0 deletions

View File

@@ -6,6 +6,16 @@ namespace QuickLook.Plugin.InfoPanel
{
public static class FileHelper
{
public static void GetDriveSpace(string path, out long totalSpace, out long totalFreeSpace)
{
totalSpace = totalFreeSpace = 0L;
var root = new DriveInfo(Path.GetPathRoot(path));
totalSpace = root.TotalSize;
totalFreeSpace = root.AvailableFreeSpace;
}
public static void CountFolder(string root, ref bool stop, out long totalDirs, out long totalFiles,
out long totalSize)
{

View File

@@ -51,6 +51,19 @@ namespace QuickLook.Plugin.InfoPanel
Dispatcher.Invoke(() => { totalSize.Text = size.ToPrettySize(2); });
}
else if (Path.GetPathRoot(path) == path) // is this a drive?
{
long totalSpace;
long totalFreeSpace;
FileHelper.GetDriveSpace(path, out totalSpace, out totalFreeSpace);
Dispatcher.Invoke(() =>
{
totalSize.Text =
$"Capacity {totalSpace.ToPrettySize(2)}, {totalFreeSpace.ToPrettySize(2)} available";
});
}
else if (Directory.Exists(path))
{
long totalDirsL;