Skip to content

Commit d854b3f

Browse files
Feature: Display smartphone/tablet storage size and free space
1 parent bc7e862 commit d854b3f

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.UI.Xaml.Controls;
77
using Microsoft.UI.Xaml.Media.Imaging;
88
using Windows.Storage;
9+
using Windows.Storage.Provider;
910
using Windows.Storage.Streams;
1011
using ByteSize = ByteSizeLib.ByteSize;
1112

@@ -278,7 +279,37 @@ public async Task UpdatePropertiesAsync()
278279
{
279280
try
280281
{
281-
var properties = await Root.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"])
282+
283+
// Double check version
284+
//IDictionary<string, object>? properties = null;
285+
//bool propsAssigned = false;
286+
//if (string.IsNullOrEmpty(Root.Path) && Path.StartsWith(@"\\?\", StringComparison.Ordinal))
287+
//{
288+
// var systemFolder = ;
289+
// if (systemFolder != null)
290+
// {
291+
// properties = await systemFolder.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"])
292+
// .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
293+
// propsAssigned = properties is not null;
294+
// }
295+
//}
296+
297+
//if (!propsAssigned)
298+
//{
299+
// properties = await Root.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"])
300+
// .AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
301+
//}
302+
//----------------------------------------------
303+
304+
var propertiesSource = Root;
305+
if (string.IsNullOrEmpty(Root.Path) &&
306+
Path.StartsWith(@"\\?\", StringComparison.Ordinal) &&
307+
(await Root.GetFoldersAsync())[0] is StorageFolder systemFolder)
308+
{
309+
propertiesSource = systemFolder;
310+
}
311+
312+
var properties = await propertiesSource.Properties.RetrievePropertiesAsync(["System.FreeSpace", "System.Capacity", "System.Volume.FileSystem"])
282313
.AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
283314

284315
if (properties is not null && properties["System.Capacity"] is not null && properties["System.FreeSpace"] is not null)

src/Files.App/ViewModels/Properties/Items/DriveProperties.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,28 @@ public async override Task GetSpecialPropertiesAsync()
8383
string capacity = "System.Capacity";
8484
string fileSystem = "System.Volume.FileSystem";
8585

86-
var properties = await diskRoot.Properties.RetrievePropertiesAsync([freeSpace, capacity, fileSystem]);
86+
87+
IDictionary<string, object>? properties = null;
88+
bool propsAssigned = false;
89+
if (string.IsNullOrEmpty(diskRoot.Path) && Drive.Path.StartsWith(@"\\?\", StringComparison.Ordinal))
90+
{
91+
var systemFolder = (await diskRoot.GetFoldersAsync())[0];
92+
if (systemFolder != null)
93+
{
94+
properties = await systemFolder.Properties.RetrievePropertiesAsync([freeSpace, capacity, fileSystem])
95+
.AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
96+
propsAssigned = properties is not null;
97+
}
98+
}
99+
100+
if (!propsAssigned)
101+
{
102+
properties = await diskRoot.Properties.RetrievePropertiesAsync([freeSpace, capacity, fileSystem])
103+
.AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
104+
}
105+
106+
if (properties is null)
107+
return;
87108

88109
ViewModel.DriveCapacityValue = (ulong)properties[capacity];
89110
ViewModel.DriveFreeSpaceValue = (ulong)properties[freeSpace];

0 commit comments

Comments
 (0)