From d854b3f7ab7e9def1148d8573b20254dc06f7ce5 Mon Sep 17 00:00:00 2001 From: Filippo Ferrario <102259289+ferrariofilippo@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:56:40 +0100 Subject: [PATCH] Feature: Display smartphone/tablet storage size and free space --- src/Files.App/Data/Items/DriveItem.cs | 33 ++++++++++++++++++- .../Properties/Items/DriveProperties.cs | 23 ++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Files.App/Data/Items/DriveItem.cs b/src/Files.App/Data/Items/DriveItem.cs index 6c72c3769c41..73ca56d4179e 100644 --- a/src/Files.App/Data/Items/DriveItem.cs +++ b/src/Files.App/Data/Items/DriveItem.cs @@ -6,6 +6,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Imaging; using Windows.Storage; +using Windows.Storage.Provider; using Windows.Storage.Streams; using ByteSize = ByteSizeLib.ByteSize; @@ -278,7 +279,37 @@ public async Task UpdatePropertiesAsync() { try { - var properties = await Root.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"]) + + // Double check version + //IDictionary? properties = null; + //bool propsAssigned = false; + //if (string.IsNullOrEmpty(Root.Path) && Path.StartsWith(@"\\?\", StringComparison.Ordinal)) + //{ + // var systemFolder = ; + // if (systemFolder != null) + // { + // properties = await systemFolder.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"]) + // .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5)); + // propsAssigned = properties is not null; + // } + //} + + //if (!propsAssigned) + //{ + // properties = await Root.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"]) + // .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5)); + //} + //---------------------------------------------- + + var propertiesSource = Root; + if (string.IsNullOrEmpty(Root.Path) && + Path.StartsWith(@"\\?\", StringComparison.Ordinal) && + (await Root.GetFoldersAsync())[0] is StorageFolder systemFolder) + { + propertiesSource = systemFolder; + } + + var properties = await propertiesSource.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"]) .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5)); if (properties is not null && properties["System.Capacity"] is not null && properties["System.FreeSpace"] is not null) diff --git a/src/Files.App/ViewModels/Properties/Items/DriveProperties.cs b/src/Files.App/ViewModels/Properties/Items/DriveProperties.cs index 750ac63b8ed0..b48493d737b5 100644 --- a/src/Files.App/ViewModels/Properties/Items/DriveProperties.cs +++ b/src/Files.App/ViewModels/Properties/Items/DriveProperties.cs @@ -83,7 +83,28 @@ public async override Task GetSpecialPropertiesAsync() string capacity = "System.Capacity"; string fileSystem = "System.Volume.FileSystem"; - var properties = await diskRoot.Properties.RetrievePropertiesAsync([freeSpace, capacity, fileSystem]); + + IDictionary? properties = null; + bool propsAssigned = false; + if (string.IsNullOrEmpty(diskRoot.Path) && Drive.Path.StartsWith(@"\\?\", StringComparison.Ordinal)) + { + var systemFolder = (await diskRoot.GetFoldersAsync())[0]; + if (systemFolder != null) + { + properties = await systemFolder.Properties.RetrievePropertiesAsync([freeSpace, capacity, fileSystem]) + .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5)); + propsAssigned = properties is not null; + } + } + + if (!propsAssigned) + { + properties = await diskRoot.Properties.RetrievePropertiesAsync([freeSpace, capacity, fileSystem]) + .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5)); + } + + if (properties is null) + return; ViewModel.DriveCapacityValue = (ulong)properties[capacity]; ViewModel.DriveFreeSpaceValue = (ulong)properties[freeSpace];