From a2d481e4b649262977f7ad8a24d7d8acd80b4904 Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sat, 1 Feb 2025 17:09:23 +0000 Subject: [PATCH] Add ability to go through all hashes automatically --- src/Files.App/Strings/en-US/Resources.resw | 4 +- .../Views/Properties/HashesPage.xaml | 52 ++++++++----------- .../Views/Properties/HashesPage.xaml.cs | 31 ++++++++--- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index 21c172f4112c..a6fee8e4ec00 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -4052,8 +4052,8 @@ Placeholder that appears in the compare hash text box - Hashes match! - Appears when two compared hashes match + Matches {0} + Appears when two compared hashes match, e.g. "Matches SHA256" Hashes don't match diff --git a/src/Files.App/Views/Properties/HashesPage.xaml b/src/Files.App/Views/Properties/HashesPage.xaml index 7f8ff6dad433..5b4fa643b68e 100644 --- a/src/Files.App/Views/Properties/HashesPage.xaml +++ b/src/Files.App/Views/Properties/HashesPage.xaml @@ -211,45 +211,35 @@ CornerRadius="4"> - - - - - - - - - + Grid.Column="0" + Margin="12"> + + + + + + + + + - diff --git a/src/Files.App/Views/Properties/HashesPage.xaml.cs b/src/Files.App/Views/Properties/HashesPage.xaml.cs index 05d47dd38a99..59dbdd6e4a57 100644 --- a/src/Files.App/Views/Properties/HashesPage.xaml.cs +++ b/src/Files.App/Views/Properties/HashesPage.xaml.cs @@ -5,10 +5,12 @@ using Files.App.Utils; using Files.App.ViewModels.Properties; using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Navigation; using System.Threading.Tasks; +using Windows.UI; namespace Files.App.Views.Properties { @@ -49,19 +51,32 @@ private void ToggleMenuFlyoutItem_Click(object sender, RoutedEventArgs e) private void HashInputTextBox_TextChanged(object sender, TextChangedEventArgs e) => CompareHashes(); - private void AlgorithmComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) - => CompareHashes(); - private void CompareHashes() { - var selectedAlgorithm = AlgorithmComboBox.SelectedValue as string; var hashToCompare = HashInputTextBox.Text; - if (string.IsNullOrEmpty(selectedAlgorithm) || string.IsNullOrEmpty(hashToCompare)) + if (string.IsNullOrEmpty(hashToCompare)) + { + HashMatchIcon.Visibility = Visibility.Collapsed; return; - - var result = HashesViewModel.CompareHash(selectedAlgorithm, hashToCompare); - ComparisonResultTextBlock.Text = result ? Strings.HashesMatch.GetLocalizedResource() : Strings.HashesDoNotMatch.GetLocalizedResource(); + } + + foreach (var hashInfo in HashesViewModel.Hashes) + { + if (hashInfo.HashValue != null && hashInfo.HashValue.Equals(hashToCompare, StringComparison.OrdinalIgnoreCase)) + { + HashMatchIcon.Glyph = "\uE73E"; // Check mark + //HashMatchIcon.Foreground = new SolidColorBrush(Colors.Green); + ToolTipService.SetToolTip(HashMatchIcon, string.Format(Strings.HashesMatch.GetLocalizedResource(), hashInfo.Algorithm)); + HashMatchIcon.Visibility = Visibility.Visible; + return; + } + } + + HashMatchIcon.Glyph = "\uE711"; // Cross mark + //HashMatchIcon.Foreground = new SolidColorBrush(Colors.Red); + ToolTipService.SetToolTip(HashMatchIcon, Strings.HashesDoNotMatch.GetLocalizedResource()); + HashMatchIcon.Visibility = Visibility.Visible; } private void MenuFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs e)