-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathDriveProperties.cs
More file actions
117 lines (98 loc) · 3.37 KB
/
Copy pathDriveProperties.cs
File metadata and controls
117 lines (98 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Microsoft.Extensions.Logging;
namespace Files.App.ViewModels.Properties
{
internal sealed class DriveProperties : BaseProperties
{
public DriveItem Drive { get; }
public DriveProperties(
SelectedItemsPropertiesViewModel viewModel,
CancellationTokenSource tokenSource,
Microsoft.UI.Dispatching.DispatcherQueue dispatcher,
DriveItem driveItem,
IShellPage instance)
: base(viewModel, tokenSource, dispatcher, instance)
{
Drive = driveItem;
GetBaseProperties();
}
public override void GetBaseProperties()
{
if (Drive is null)
return;
//Drive.IconSource;
ViewModel.CustomIconSource = null;
ViewModel.IconData = Drive.IconData;
// Drive.IconSource is not null && Drive.IconData is null;
ViewModel.LoadCustomIcon = false;
ViewModel.LoadFileIcon = Drive.IconData is not null;
ViewModel.ItemName = Drive.Text;
ViewModel.OriginalItemName = Drive.Text;
// NOTE: If DriveType enum changes, the corresponding resource keys should change too
ViewModel.ItemType = $"DriveType{Drive.Type}".GetLocalizedResource();
}
public async override Task GetSpecialPropertiesAsync()
{
ViewModel.ItemAttributesVisibility = false;
var drivePath = Drive.GetRequiredPath();
var rootResult = await FilesystemTasks.WrapNullable(() => DriveHelpers.GetRootFromPathAsync(drivePath));
var diskRootResult = await FilesystemTasks.WrapNullable(
() => StorageFileExtensions.DangerousGetFolderFromPathAsync(drivePath, rootResult.Result));
var diskRoot = diskRootResult.Result;
if (ViewModel.LoadFileIcon)
{
var result = await FileThumbnailHelper.GetIconAsync(
drivePath,
Constants.ShellIconSizes.ExtraLarge,
true,
IconOptions.ReturnIconOnly | IconOptions.UseCurrentScale);
if (result is not null)
ViewModel.IconData = result;
else
{
result = await FileThumbnailHelper.GetIconAsync(
Drive.DeviceID,
Constants.ShellIconSizes.ExtraLarge,
true,
IconOptions.ReturnIconOnly | IconOptions.UseCurrentScale); // For network shortcuts
ViewModel.IconData = result;
}
}
if (diskRoot is null || diskRoot.Properties is null)
{
ViewModel.LastSeparatorVisibility = false;
return;
}
try
{
var syncRootStatus = await SyncRootHelpers.GetSyncRootQuotaAsync(drivePath);
if (syncRootStatus.Success)
{
ViewModel.DriveCapacityValue = syncRootStatus.Capacity;
ViewModel.DriveUsedSpaceValue = syncRootStatus.Used;
ViewModel.DriveFreeSpaceValue = syncRootStatus.Capacity - syncRootStatus.Used;
return;
}
}
catch (Exception e)
{
App.Logger.LogWarning(e, "Failed to get sync root quota for path: {Path}", LogPathHelper.RedactPath(Drive.Path));
}
try
{
string freeSpace = "System.FreeSpace";
string capacity = "System.Capacity";
string fileSystem = "System.Volume.FileSystem";
var properties = await diskRoot.Properties.RetrievePropertiesAsync((string[])[freeSpace, capacity, fileSystem]);
ViewModel.DriveCapacityValue = (ulong)properties[capacity];
ViewModel.DriveFreeSpaceValue = (ulong)properties[freeSpace];
ViewModel.DriveUsedSpaceValue = ViewModel.DriveCapacityValue - ViewModel.DriveFreeSpaceValue;
ViewModel.DriveFileSystem = (string)properties[fileSystem];
}
catch (Exception e)
{
ViewModel.LastSeparatorVisibility = false;
App.Logger.LogWarning(e, e.Message);
}
}
}
}