Skip to content

Commit a2d481e

Browse files
Lamparteryaira2
authored andcommitted
Add ability to go through all hashes automatically
1 parent aeff6c3 commit a2d481e

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,8 +4052,8 @@
40524052
<comment>Placeholder that appears in the compare hash text box</comment>
40534053
</data>
40544054
<data name="HashesMatch" xml:space="preserve">
4055-
<value>Hashes match!</value>
4056-
<comment>Appears when two compared hashes match</comment>
4055+
<value>Matches {0}</value>
4056+
<comment>Appears when two compared hashes match, e.g. "Matches SHA256"</comment>
40574057
</data>
40584058
<data name="HashesDoNotMatch" xml:space="preserve">
40594059
<value>Hashes don't match</value>

src/Files.App/Views/Properties/HashesPage.xaml

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -211,45 +211,35 @@
211211
CornerRadius="4">
212212
<Grid.RowDefinitions>
213213
<RowDefinition Height="Auto" />
214-
<RowDefinition Height="Auto" />
215214
</Grid.RowDefinitions>
216215
<Grid.ColumnDefinitions>
217-
<ColumnDefinition Width="*" />
218216
<ColumnDefinition Width="*" />
219217
<ColumnDefinition Width="Auto" />
220218
</Grid.ColumnDefinitions>
221219

222-
<!-- Algorithm Selection -->
223-
<ComboBox
224-
x:Name="AlgorithmComboBox"
225-
Grid.Row="0"
226-
Grid.Column="0"
227-
Margin="12"
228-
DisplayMemberPath="Algorithm"
229-
ItemsSource="{x:Bind HashesViewModel.Hashes}"
230-
PlaceholderText="{helpers:ResourceString Name=SelectAlgorithm}"
231-
SelectedValue="{x:Bind HashesViewModel.SelectedItem.Algorithm, Mode=TwoWay}"
232-
SelectedValuePath="Algorithm"
233-
SelectionChanged="AlgorithmComboBox_SelectionChanged" />
234-
235220
<!-- Hash Input -->
236-
<TextBox
237-
x:Name="HashInputTextBox"
238-
Grid.Row="0"
239-
Grid.Column="1"
240-
Margin="12"
241-
PlaceholderText="{helpers:ResourceString Name=EnterHashToCompare}"
242-
TextChanged="HashInputTextBox_TextChanged" />
243-
244-
<!-- Comparison Result -->
245-
<TextBlock
246-
x:Name="ComparisonResultTextBlock"
221+
<Grid
247222
Grid.Row="0"
248-
Grid.Column="2"
249-
Margin="12"
250-
VerticalAlignment="Center"
251-
Style="{StaticResource App.Theme.BodyTextBlockStyle}" />
223+
Grid.Column="0"
224+
Margin="12">
225+
<Grid.ColumnDefinitions>
226+
<ColumnDefinition Width="*" />
227+
<ColumnDefinition Width="Auto" />
228+
</Grid.ColumnDefinitions>
229+
230+
<TextBox
231+
x:Name="HashInputTextBox"
232+
Grid.Column="0"
233+
PlaceholderText="{helpers:ResourceString Name=EnterHashToCompare}"
234+
TextChanged="HashInputTextBox_TextChanged" />
235+
236+
<FontIcon
237+
x:Name="HashMatchIcon"
238+
Grid.Column="1"
239+
Margin="8,0,0,0"
240+
VerticalAlignment="Center"
241+
Visibility="Collapsed" />
242+
</Grid>
252243
</Grid>
253244
</Grid>
254245
</vm:BasePropertiesPage>
255-

src/Files.App/Views/Properties/HashesPage.xaml.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
using Files.App.Utils;
66
using Files.App.ViewModels.Properties;
77
using Microsoft.UI.Xaml;
8+
using Microsoft.UI.Xaml.Media;
89
using Microsoft.UI.Xaml.Controls;
910
using Microsoft.UI.Xaml.Controls.Primitives;
1011
using Microsoft.UI.Xaml.Navigation;
1112
using System.Threading.Tasks;
13+
using Windows.UI;
1214

1315
namespace Files.App.Views.Properties
1416
{
@@ -49,19 +51,32 @@ private void ToggleMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
4951
private void HashInputTextBox_TextChanged(object sender, TextChangedEventArgs e)
5052
=> CompareHashes();
5153

52-
private void AlgorithmComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
53-
=> CompareHashes();
54-
5554
private void CompareHashes()
5655
{
57-
var selectedAlgorithm = AlgorithmComboBox.SelectedValue as string;
5856
var hashToCompare = HashInputTextBox.Text;
5957

60-
if (string.IsNullOrEmpty(selectedAlgorithm) || string.IsNullOrEmpty(hashToCompare))
58+
if (string.IsNullOrEmpty(hashToCompare))
59+
{
60+
HashMatchIcon.Visibility = Visibility.Collapsed;
6161
return;
62-
63-
var result = HashesViewModel.CompareHash(selectedAlgorithm, hashToCompare);
64-
ComparisonResultTextBlock.Text = result ? Strings.HashesMatch.GetLocalizedResource() : Strings.HashesDoNotMatch.GetLocalizedResource();
62+
}
63+
64+
foreach (var hashInfo in HashesViewModel.Hashes)
65+
{
66+
if (hashInfo.HashValue != null && hashInfo.HashValue.Equals(hashToCompare, StringComparison.OrdinalIgnoreCase))
67+
{
68+
HashMatchIcon.Glyph = "\uE73E"; // Check mark
69+
//HashMatchIcon.Foreground = new SolidColorBrush(Colors.Green);
70+
ToolTipService.SetToolTip(HashMatchIcon, string.Format(Strings.HashesMatch.GetLocalizedResource(), hashInfo.Algorithm));
71+
HashMatchIcon.Visibility = Visibility.Visible;
72+
return;
73+
}
74+
}
75+
76+
HashMatchIcon.Glyph = "\uE711"; // Cross mark
77+
//HashMatchIcon.Foreground = new SolidColorBrush(Colors.Red);
78+
ToolTipService.SetToolTip(HashMatchIcon, Strings.HashesDoNotMatch.GetLocalizedResource());
79+
HashMatchIcon.Visibility = Visibility.Visible;
6580
}
6681

6782
private void MenuFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs e)

0 commit comments

Comments
 (0)