Skip to content

Commit

Permalink
Show file hashes in properties like HashTab (fix) files-community#3722
Browse files Browse the repository at this point in the history
  • Loading branch information
oleitao committed Apr 7, 2021
1 parent 154d857 commit 68ae61c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
13 changes: 5 additions & 8 deletions Files/ViewModels/Properties/FileProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,15 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode
}
}

private async Task<string> GetHashForFileAsync(StorageFile file, string nameOfAlg, CancellationToken token, ProgressBar progress, IShellPage associatedInstance)
private async Task<string> GetHashForFileAsync(StorageFile itemFromPath, string nameOfAlg, CancellationToken token, ProgressBar progress, IShellPage associatedInstance)
{
HashAlgorithmProvider algorithmProvider = HashAlgorithmProvider.OpenAlgorithm(nameOfAlg);
if (file == null)
if (itemFromPath == null)
{
return "";
}

Stream stream = await FilesystemTasks.Wrap(() => file.OpenStreamForReadAsync());
Stream stream = await FilesystemTasks.Wrap(() => itemFromPath.OpenStreamForReadAsync());
if (stream == null)
{
return "";
Expand All @@ -465,7 +465,7 @@ private async Task<string> GetHashForFileAsync(StorageFile file, string nameOfAl

Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer(capacity);
var hash = algorithmProvider.CreateHash();
while (!token.IsCancellationRequested)
while (token.IsCancellationRequested)
{
await inputStream.ReadAsync(buffer, capacity, InputStreamOptions.None);
if (buffer.Length > 0)
Expand All @@ -483,10 +483,7 @@ private async Task<string> GetHashForFileAsync(StorageFile file, string nameOfAl
}
inputStream.Dispose();
stream.Dispose();
if (token.IsCancellationRequested)
{
return "";
}

return CryptographicBuffer.EncodeToHexString(hash.GetValueAndReset()).ToLower();
}

Expand Down
2 changes: 1 addition & 1 deletion Files/Views/Pages/Properties.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
Content="Hashes"
Tag="Hashes">
<NavigationViewItem.Icon>
<FontIcon FontFamily="{StaticResource FluentGlyphs}" Glyph="&#xE946;" />
<FontIcon FontFamily="{StaticResource CustomGlyph}" Glyph="&#xE946;" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem
Expand Down
20 changes: 10 additions & 10 deletions Files/Views/Pages/PropertiesHashes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
Text="MD5Hash:"
Visibility="{x:Bind ViewModel.ItemMD5HashVisibility, Mode=OneWay}" />
<TextBlock
x:Name="itemMD5HashValue"
x:Name="ItemMD5HashValue"
Grid.Row="2"
Grid.Column="1"
Style="{StaticResource PropertyValueTextBlock}"
Expand All @@ -100,7 +100,7 @@
Text="SHA1Hash:"
Visibility="{x:Bind ViewModel.ItemSHA1HashVisibility, Mode=OneWay}" />
<TextBlock
x:Name="itemSHA1HashValue"
x:Name="ItemSHA1HashValue"
Grid.Row="3"
Grid.Column="1"
Style="{StaticResource PropertyValueTextBlock}"
Expand All @@ -124,7 +124,7 @@
Text="CRC32Hash:"
Visibility="{x:Bind ViewModel.ItemCRC32HashVisibility, Mode=OneWay}" />
<TextBlock
x:Name="itemCRC32HashValue"
x:Name="ItemCRC32HashValue"
Grid.Row="4"
Grid.Column="1"
Style="{StaticResource PropertyValueTextBlock}"
Expand All @@ -149,30 +149,30 @@
Text="Hash Comparison:"/>

<TextBox
x:Name="txtCompareHash"
x:Uid="txtCompareHash"
x:Name="CompareHashOutput"
x:Uid="CompareHashOutput"
Grid.Row="6"
Grid.Column="1"
Margin="5,27,5,5"
HorizontalAlignment="Stretch"
Style="{StaticResource PropertyName}"
Text="{x:Bind ViewModel.ItemCompareHash, Mode=OneWay}"/>

<ComboBox x:Name="ddlCompareHash"
x:Uid="ddlCompareHash"
<ComboBox x:Name="CompareHashSelector"
x:Uid="CompareHashSelector"
Grid.Row="7"
Grid.Column="0"
Margin="5,5,0,0"
SelectionChanged="ddlCompareHash_SelectionChanged"
SelectionChanged="CompareHashSelector_SelectionChanged"
HorizontalAlignment="Left">
<ComboBoxItem Name="MD5" Content="MD5"></ComboBoxItem>
<ComboBoxItem Name="SHA1" Content="SHA1" IsSelected="True"></ComboBoxItem>
<ComboBoxItem Name="CRC32" Content="CRC32"></ComboBoxItem>
</ComboBox>

<Button
x:Name="btnCompareHash"
x:Uid="btnCompareHash"
x:Name="CompareHash"
x:Uid="CompareHash"
Click="CompareHash_Click"
Grid.Row="7"
Grid.Column="1"
Expand Down
6 changes: 3 additions & 3 deletions Files/Views/Pages/PropertiesHashes.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private async void CompareHash_Click(object sender, RoutedEventArgs e)
{
Stopwatch stopwatch = Stopwatch.StartNew();

ComboBoxItem ComboItem = (ComboBoxItem)ddlCompareHash.SelectedItem;
ComboBoxItem ComboItem = (ComboBoxItem)CompareHashSelector.SelectedItem;
switch (ComboItem.Name)
{
case "MD5":
Expand All @@ -104,9 +104,9 @@ private async void CompareHash_Click(object sender, RoutedEventArgs e)
}
}

private void ddlCompareHash_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void CompareHashSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
txtCompareHash.Text = string.Empty;
CompareHashOutput.Text = string.Empty;
}
}
}

0 comments on commit 68ae61c

Please sign in to comment.