Skip to content

Commit e165254

Browse files
committed
Feature
1 parent d079525 commit e165254

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,4 +4043,20 @@
40434043
<value>Add to shelf</value>
40444044
<comment>Tooltip that displays when dragging items to the Shelf Pane</comment>
40454045
</data>
4046+
<data name="SelectAlgorithm" xml:space="preserve">
4047+
<value>Select algorithm</value>
4048+
<comment>Placeholder that displays in the hash properties combo box</comment>
4049+
</data>
4050+
<data name="EnterHashToCompare" xml:space="preserve">
4051+
<value>Enter a hash to compare</value>
4052+
<comment>Placeholder that appears in the compare hash text box</comment>
4053+
</data>
4054+
<data name="HashesMatch" xml:space="preserve">
4055+
<value>Hashes match!</value>
4056+
<comment>Appears when two compared hashes match</comment>
4057+
</data>
4058+
<data name="HashesDoNotMatch" xml:space="preserve">
4059+
<value>Hashes don't match</value>
4060+
<comment>Appears when two compared hashes don't match</comment>
4061+
</data>
40464062
</root>

src/Files.App/ViewModels/Properties/HashesViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Files Community
1+
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

44
using Files.Shared.Helpers;
@@ -120,6 +120,17 @@ private void ToggleIsEnabled(string? algorithm)
120120
}
121121
}
122122

123+
public bool CompareHash(string algorithm, string hashToCompare)
124+
{
125+
var hashInfoItem = Hashes.FirstOrDefault(x => x.Algorithm == algorithm);
126+
if (hashInfoItem == null || hashInfoItem.HashValue == null)
127+
{
128+
return false;
129+
}
130+
131+
return hashInfoItem.HashValue.Equals(hashToCompare, StringComparison.OrdinalIgnoreCase);
132+
}
133+
123134
public void Dispose()
124135
{
125136
_cancellationTokenSource.Cancel();

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
Text="SHA1" />
110110
<ToggleMenuFlyoutItem
111111
Click="ToggleMenuFlyoutItem_Click"
112-
Command="{x:Bind HashesViewModel.ToggleIsEnabledCommand}"
113112
CommandParameter="SHA256"
114113
IsChecked="{x:Bind HashesViewModel.ShowHashes['SHA256']}"
115114
Text="SHA256" />
@@ -201,5 +200,56 @@
201200
</ListView>
202201
</Grid>
203202

203+
<!-- Hash Comparison Section -->
204+
<Grid
205+
x:Name="HashComparisonGrid"
206+
Margin="12,0,12,12"
207+
VerticalAlignment="Bottom"
208+
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
209+
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
210+
BorderThickness="1"
211+
CornerRadius="4">
212+
<Grid.RowDefinitions>
213+
<RowDefinition Height="Auto" />
214+
<RowDefinition Height="Auto" />
215+
</Grid.RowDefinitions>
216+
<Grid.ColumnDefinitions>
217+
<ColumnDefinition Width="*" />
218+
<ColumnDefinition Width="*" />
219+
<ColumnDefinition Width="Auto" />
220+
</Grid.ColumnDefinitions>
221+
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+
235+
<!-- 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"
247+
Grid.Row="0"
248+
Grid.Column="2"
249+
Margin="12"
250+
VerticalAlignment="Center"
251+
Style="{StaticResource App.Theme.BodyTextBlockStyle}" />
252+
</Grid>
204253
</Grid>
205254
</vm:BasePropertiesPage>
255+

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ private void ToggleMenuFlyoutItem_Click(object sender, RoutedEventArgs e)
4646
_cancel = true;
4747
}
4848

49+
private void HashInputTextBox_TextChanged(object sender, TextChangedEventArgs e)
50+
=> CompareHashes();
51+
52+
private void AlgorithmComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
53+
=> CompareHashes();
54+
55+
private void CompareHashes()
56+
{
57+
var selectedAlgorithm = AlgorithmComboBox.SelectedValue as string;
58+
var hashToCompare = HashInputTextBox.Text;
59+
60+
if (string.IsNullOrEmpty(selectedAlgorithm) || string.IsNullOrEmpty(hashToCompare))
61+
return;
62+
63+
var result = HashesViewModel.CompareHash(selectedAlgorithm, hashToCompare);
64+
ComparisonResultTextBlock.Text = result ? Strings.HashesMatch.GetLocalizedResource() : Strings.HashesDoNotMatch.GetLocalizedResource();
65+
}
66+
4967
private void MenuFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs e)
5068
{
5169
e.Cancel = _cancel;

0 commit comments

Comments
 (0)