Skip to content

Commit

Permalink
Add ability to go through all hashes automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamparter authored and yaira2 committed Feb 10, 2025
1 parent aeff6c3 commit a2d481e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -4052,8 +4052,8 @@
<comment>Placeholder that appears in the compare hash text box</comment>
</data>
<data name="HashesMatch" xml:space="preserve">
<value>Hashes match!</value>
<comment>Appears when two compared hashes match</comment>
<value>Matches {0}</value>
<comment>Appears when two compared hashes match, e.g. "Matches SHA256"</comment>
</data>
<data name="HashesDoNotMatch" xml:space="preserve">
<value>Hashes don't match</value>
Expand Down
52 changes: 21 additions & 31 deletions src/Files.App/Views/Properties/HashesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,45 +211,35 @@
CornerRadius="4">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Algorithm Selection -->
<ComboBox
x:Name="AlgorithmComboBox"
Grid.Row="0"
Grid.Column="0"
Margin="12"
DisplayMemberPath="Algorithm"
ItemsSource="{x:Bind HashesViewModel.Hashes}"
PlaceholderText="{helpers:ResourceString Name=SelectAlgorithm}"
SelectedValue="{x:Bind HashesViewModel.SelectedItem.Algorithm, Mode=TwoWay}"
SelectedValuePath="Algorithm"
SelectionChanged="AlgorithmComboBox_SelectionChanged" />

<!-- Hash Input -->
<TextBox
x:Name="HashInputTextBox"
Grid.Row="0"
Grid.Column="1"
Margin="12"
PlaceholderText="{helpers:ResourceString Name=EnterHashToCompare}"
TextChanged="HashInputTextBox_TextChanged" />

<!-- Comparison Result -->
<TextBlock
x:Name="ComparisonResultTextBlock"
<Grid
Grid.Row="0"
Grid.Column="2"
Margin="12"
VerticalAlignment="Center"
Style="{StaticResource App.Theme.BodyTextBlockStyle}" />
Grid.Column="0"
Margin="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBox
x:Name="HashInputTextBox"
Grid.Column="0"
PlaceholderText="{helpers:ResourceString Name=EnterHashToCompare}"
TextChanged="HashInputTextBox_TextChanged" />

<FontIcon
x:Name="HashMatchIcon"
Grid.Column="1"
Margin="8,0,0,0"
VerticalAlignment="Center"
Visibility="Collapsed" />
</Grid>
</Grid>
</Grid>
</vm:BasePropertiesPage>

31 changes: 23 additions & 8 deletions src/Files.App/Views/Properties/HashesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a2d481e

Please sign in to comment.