Skip to content

Commit a3bfc55

Browse files
authored
Properties: prevent crash when access denied (#1139)
1 parent a18288d commit a3bfc55

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Files/View Models/SelectedItemsPropertiesViewModel.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ public string ItemMD5Hash
150150
}
151151
}
152152
}
153+
private bool _ItemMD5HashCalcError;
154+
public bool ItemMD5HashCalcError
155+
{
156+
get => _ItemMD5HashCalcError;
157+
set => Set(ref _ItemMD5HashCalcError, value);
158+
}
159+
153160
public Visibility _ItemMD5HashVisibility = Visibility.Collapsed;
154161

155162
public Visibility ItemMD5HashVisibility
@@ -316,7 +323,16 @@ public async Task GetPropertiesAsync(CancellationTokenSource _tokenSource)
316323
var hashAlgTypeName = HashAlgorithmNames.Md5;
317324
ItemMD5HashProgressVisibility = Visibility.Visible;
318325
ItemMD5HashVisibility = Visibility.Visible;
319-
ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(Item, hashAlgTypeName, _tokenSource.Token, ItemMD5HashProgress);
326+
try
327+
{
328+
ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(Item, hashAlgTypeName, _tokenSource.Token, ItemMD5HashProgress);
329+
}
330+
catch (Exception ex)
331+
{
332+
NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
333+
ItemMD5HashProgress.Value = ItemMD5HashProgress.Maximum;
334+
ItemMD5HashCalcError = true;
335+
}
320336
}
321337
else if (Item.PrimaryItemAttribute == StorageItemTypes.Folder)
322338
{

Files/Views/Pages/Properties.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
Grid.Row="5"
184184
Grid.Column="1"
185185
Margin="20,0,0,0"
186+
ShowError="{x:Bind ViewModel.ItemMD5HashCalcError, Mode=OneWay}"
186187
Visibility="{x:Bind ViewModel.ItemMD5HashProgressVisibility, Mode=OneWay}" />
187188

188189

0 commit comments

Comments
 (0)