Skip to content

Commit d17ab07

Browse files
committed
Uppdate
1 parent 92fbb65 commit d17ab07

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,4 @@ _SICHINTF
226226
RoGetAgileReference
227227
IQueryInfo
228228
QITIPF_FLAGS
229+
GetDiskFreeSpaceEx

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Storage.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4+
using OwlCore.Storage;
45
using Windows.Win32;
56
using Windows.Win32.Foundation;
67
using Windows.Win32.Storage.FileSystem;
@@ -85,11 +86,24 @@ public static bool TryShowFormatDriveDialog(HWND hWnd, uint driveLetterIndex, SH
8586
return result is 0xFFFF;
8687
}
8788

88-
public static bool TryGetDriveInfo(this IWindowsStorable storable)
89+
public static bool TryGetDriveTotalSpace(this IWindowsStorable storable, out ulong totalSize)
8990
{
91+
ulong ulTotalSize = 0UL;
92+
bool res = PInvoke.GetDiskFreeSpaceEx(storable.GetDisplayName(), null, &ulTotalSize, null);
9093

94+
totalSize = ulTotalSize;
9195

92-
return true;
96+
return res;
97+
}
98+
99+
public static bool TryGetDriveFreeSpace(this IWindowsStorable storable, out ulong freeSize)
100+
{
101+
ulong ulFreeSize = 0UL;
102+
bool res = PInvoke.GetDiskFreeSpaceEx(storable.GetDisplayName(), null, null, &ulFreeSize);
103+
104+
freeSize = ulFreeSize;
105+
106+
return res;
93107
}
94108
}
95109
}

src/Files.App/Data/Items/WidgetDriveCardItem.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ public sealed partial class WidgetDriveCardItem : WidgetCardItem, IWidgetCardIte
1717

1818
public required string Text { get; set; }
1919

20-
public bool ShowStorageSense { get; set; }
20+
public bool ShowStorageSense => UsedSize.GigaBytes / TotalSize.GigaBytes >= Constants.Widgets.Drives.LowStorageSpacePercentageThreshold;
2121

22-
public bool ShowDriveUsage { get; set; } = true;
22+
public bool ShowDriveUsage => TotalSize.GigaBytes > 0D;
2323

24-
public string? UsageText { get; set; }
24+
public ByteSizeLib.ByteSize TotalSize { get; set; } = default;
2525

26-
public ByteSizeLib.ByteSize TotalSpace { get; set; }
26+
public ByteSizeLib.ByteSize FreeSize { get; set; } = default;
2727

28-
public ByteSizeLib.ByteSize SpaceUsed { get; set; }
28+
public ByteSizeLib.ByteSize UsedSize => ByteSizeLib.ByteSize.FromBytes(TotalSize.Bytes - FreeSize.Bytes);
29+
30+
public string? UsageText => string.Format(Strings.DriveFreeSpaceAndCapacity.GetLocalizedResource(), FreeSize.ToSizeString(), TotalSize.ToSizeString());
2931

3032
private BitmapImage? _Thumbnail;
3133
public BitmapImage? Thumbnail { get => _Thumbnail; set => SetProperty(ref _Thumbnail, value); }

src/Files.App/UserControls/Widgets/DrivesWidget.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
VerticalContentAlignment="Stretch"
8888
x:Load="{x:Bind ShowDriveUsage, Mode=OneWay}"
8989
AutomationProperties.AccessibilityView="Raw"
90-
Maximum="{x:Bind TotalSpace.GigaBytes, Mode=OneWay}"
91-
Value="{x:Bind SpaceUsed.GigaBytes, Mode=OneWay}" />
90+
Maximum="{x:Bind TotalSize.GigaBytes, Mode=OneWay}"
91+
Value="{x:Bind UsedSize.GigaBytes, Mode=OneWay}" />
9292

9393
<Button
9494
x:Name="GoToStorageSense"

src/Files.App/UserControls/Widgets/NetworkLocationsWidget.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@
113113
VerticalContentAlignment="Stretch"
114114
x:Load="{x:Bind ShowDriveUsage, Mode=OneWay}"
115115
AutomationProperties.AccessibilityView="Raw"
116-
Maximum="{x:Bind TotalSpace.GigaBytes, Mode=OneWay}"
117-
Value="{x:Bind SpaceUsed.GigaBytes, Mode=OneWay}" />
116+
Maximum="{x:Bind TotalSize.GigaBytes, Mode=OneWay}"
117+
Value="{x:Bind UsedSize.GigaBytes, Mode=OneWay}" />
118118

119119
<TextBlock
120120
x:Name="DriveSpaceTextBlock"

src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,18 @@ public Task RefreshWidgetAsync()
6363

6464
await foreach (IWindowsStorable folder in HomePageContext.HomeFolder.GetLogicalDrivesAsync(default))
6565
{
66+
folder.TryGetDriveTotalSpace(out var totalSize);
67+
folder.TryGetDriveFreeSpace(out var freeSize);
68+
6669
Items.Insert(
6770
Items.Count,
6871
new()
6972
{
7073
Item = (IFolder)folder,
7174
Text = folder.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORUI),
7275
Path = folder.GetDisplayName(SIGDN.SIGDN_FILESYSPATH),
76+
TotalSize = ByteSizeLib.ByteSize.FromBytes(totalSize),
77+
FreeSize = ByteSizeLib.ByteSize.FromBytes(freeSize),
7378
});
7479
}
7580
});

0 commit comments

Comments
 (0)