Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Display storage information for phones and tablets #16695

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/Files.App/Data/Items/DriveItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<string, object>? 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;
}
Comment on lines +304 to +310
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var propertiesSource = Root;
if (string.IsNullOrEmpty(Root.Path) &&
Path.StartsWith(@"\\?\", StringComparison.Ordinal) &&
(await Root.GetFoldersAsync())[0] is StorageFolder systemFolder)
{
propertiesSource = systemFolder;
}
var propertiesSource = (string.IsNullOrEmpty(Root.Path) &&
Path.StartsWith(@"\\?\", StringComparison.Ordinal) &&
(await Root.GetFoldersAsync())[0] is StorageFolder systemFolder)
? systemFolder
: Root;


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)
Expand Down
23 changes: 22 additions & 1 deletion src/Files.App/ViewModels/Properties/Items/DriveProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>? 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];
Expand Down