Skip to content

Commit 6de2ff5

Browse files
authored
Feature: Added storage information for phones and tablets (#16729)
1 parent f20e3a9 commit 6de2ff5

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Text;
1111
using Windows.Storage;
1212
using Windows.Win32.UI.WindowsAndMessaging;
13+
using ByteSize = ByteSizeLib.ByteSize;
1314

1415
#pragma warning disable CS0618 // Type or member is obsolete
1516

@@ -329,6 +330,29 @@ public ObservableCollection<FileProperty> ItemProperties
329330
set => SetProperty(ref itemProperties, value);
330331
}
331332

333+
private bool showDriveStorageDetails;
334+
public bool ShowDriveStorageDetails
335+
{
336+
get => showDriveStorageDetails;
337+
set => SetProperty(ref showDriveStorageDetails, value);
338+
}
339+
340+
private ByteSize maxSpace;
341+
public ByteSize MaxSpace
342+
{
343+
get => maxSpace;
344+
set => SetProperty(ref maxSpace, value);
345+
346+
}
347+
348+
private ByteSize spaceUsed;
349+
public ByteSize SpaceUsed
350+
{
351+
get => spaceUsed;
352+
set => SetProperty(ref spaceUsed, value);
353+
354+
}
355+
332356
private string imageDimensions;
333357
public string ImageDimensions
334358
{

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using static Files.App.Helpers.Win32PInvoke;
2222
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
2323
using FileAttributes = System.IO.FileAttributes;
24+
using ByteSize = ByteSizeLib.ByteSize;
25+
using Windows.Win32.System.SystemServices;
2426

2527
namespace Files.App.ViewModels
2628
{
@@ -1209,6 +1211,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
12091211
var fileFRN = await FileTagsHelper.GetFileFRN(matchingStorageFolder);
12101212
var fileTag = FileTagsHelper.ReadFileTag(item.ItemPath);
12111213
var itemType = (item.ItemType == Strings.Folder.GetLocalizedResource()) ? item.ItemType : matchingStorageFolder.DisplayType;
1214+
var extraProperties = await GetExtraProperties(matchingStorageFolder);
12121215

12131216
cts.Token.ThrowIfCancellationRequested();
12141217

@@ -1219,7 +1222,30 @@ await dispatcherQueue.EnqueueOrInvokeAsync(() =>
12191222
item.SyncStatusUI = CloudDriveSyncStatusUI.FromCloudDriveSyncStatus(syncStatus);
12201223
item.FileFRN = fileFRN;
12211224
item.FileTags = fileTag;
1222-
item.ContextualProperty = $"{Strings.Modified.GetLocalizedResource()}: {item.ItemDateModified}";
1225+
1226+
if (extraProperties is not null)
1227+
{
1228+
// Drive Storage Details
1229+
if (extraProperties.Result["System.SFGAOFlags"] is uint attributesRaw &&
1230+
extraProperties.Result["System.Capacity"] is ulong capacityRaw &&
1231+
extraProperties.Result["System.FreeSpace"] is ulong freeSpaceRaw &&
1232+
((SFGAO_FLAGS)attributesRaw).HasFlag(SFGAO_FLAGS.SFGAO_REMOVABLE) &&
1233+
!((SFGAO_FLAGS)attributesRaw).HasFlag(SFGAO_FLAGS.SFGAO_FILESYSTEM))
1234+
{
1235+
var maxSpace = ByteSize.FromBytes(capacityRaw);
1236+
var freeSpace = ByteSize.FromBytes(freeSpaceRaw);
1237+
1238+
item.MaxSpace = maxSpace;
1239+
item.SpaceUsed = maxSpace - freeSpace;
1240+
item.FileSize = string.Format(Strings.DriveFreeSpaceAndCapacity.GetLocalizedResource(), freeSpace.ToSizeString(), maxSpace.ToSizeString());
1241+
item.ShowDriveStorageDetails = true;
1242+
}
1243+
1244+
}
1245+
else
1246+
{
1247+
item.ContextualProperty = $"{Strings.Modified.GetLocalizedResource()}: {item.ItemDateModified}";
1248+
}
12231249
},
12241250
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
12251251

@@ -1937,6 +1963,9 @@ public async Task<CloudDriveSyncStatus> CheckCloudDriveSyncStatusAsync(IStorageI
19371963
if (matchingStorageItem is BaseStorageFile file && file.Properties != null)
19381964
return await FilesystemTasks.Wrap(() => file.Properties.RetrievePropertiesAsync(["System.Image.Dimensions", "System.Media.Duration", "System.FileVersion"]).AsTask());
19391965

1966+
else if (matchingStorageItem is BaseStorageFolder folder && folder.Properties != null)
1967+
return await FilesystemTasks.Wrap(() => folder.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.SFGAOFlags"]).AsTask());
1968+
19401969
return null;
19411970
}
19421971

src/Files.App/Views/Layouts/GridLayoutPage.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,14 @@
613613
TextWrapping="NoWrap"
614614
Visibility="{Binding ElementName=PageRoot, Path=CardsViewShowContextualProperty, Mode=OneWay}" />
615615

616+
<!-- Drive Storage Information -->
617+
<ProgressBar
618+
x:Name="DriveStorageProgressBar"
619+
x:Load="{x:Bind ShowDriveStorageDetails, Mode=OneWay}"
620+
AutomationProperties.AccessibilityView="Raw"
621+
Maximum="{x:Bind MaxSpace.GigaBytes, Mode=OneWay}"
622+
Value="{x:Bind SpaceUsed.GigaBytes, Mode=OneWay}" />
623+
616624
<!-- Item Size -->
617625
<TextBlock
618626
Foreground="{ThemeResource TextFillColorSecondaryBrush}"

0 commit comments

Comments
 (0)