Skip to content

Commit 94ca1d7

Browse files
authored
A small fix for very annoying Exception (#2619)
1 parent 27a3aec commit 94ca1d7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Files/Filesystem/DriveItem.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,19 @@ public async Task UpdatePropertiesAsync()
109109
var properties = await Root.Properties.RetrievePropertiesAsync(new[] { "System.FreeSpace", "System.Capacity" })
110110
.AsTask().WithTimeoutAsync(TimeSpan.FromSeconds(5));
111111

112-
MaxSpace = ByteSize.FromBytes((ulong)properties["System.Capacity"]);
113-
FreeSpace = ByteSize.FromBytes((ulong)properties["System.FreeSpace"]);
114-
SpaceUsed = MaxSpace - FreeSpace;
115-
116-
SpaceText = string.Format(
117-
"DriveFreeSpaceAndCapacity".GetLocalized(),
118-
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
119-
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
112+
if (properties["System.Capacity"] != null && properties["System.FreeSpace"] != null)
113+
{
114+
MaxSpace = ByteSize.FromBytes((ulong)properties["System.Capacity"]);
115+
FreeSpace = ByteSize.FromBytes((ulong)properties["System.FreeSpace"]);
116+
SpaceUsed = MaxSpace - FreeSpace;
117+
118+
SpaceText = string.Format(
119+
"DriveFreeSpaceAndCapacity".GetLocalized(),
120+
FreeSpace.ToBinaryString().ConvertSizeAbbreviation(),
121+
MaxSpace.ToBinaryString().ConvertSizeAbbreviation());
122+
}
120123
}
121-
catch (NullReferenceException)
124+
catch (Exception)
122125
{
123126
SpaceText = "DriveCapacityUnknown".GetLocalized();
124127
SpaceUsed = ByteSize.FromBytes(0);

0 commit comments

Comments
 (0)