Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing checksum comparison issue (#396) #406

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dev/DevToys.Startup/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>

<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
Expand Down
1 change: 1 addition & 0 deletions src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Messages\PinToolToStartMessage.cs" />
<Compile Include="Messages\OpenToolInNewWindowMessage.cs" />
<Compile Include="Messages\ChangeSelectedMenuItemMessage.cs" />
<Compile Include="Models\HashComparisonResult.cs" />
<Compile Include="Models\HashingAlgorithm.cs" />
<Compile Include="Models\HashingAlgorithmDisplayPair.cs" />
<Compile Include="Models\HashingProgress.cs" />
Expand Down
10 changes: 10 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ public class CheckSumGeneratorStrings : ObservableObject
/// Gets the resource SearchKeywords.
/// </summary>
public string SearchKeywords => _resources.GetString("SearchKeywords");

/// <summary>
/// Gets the resource HashesMatch.
/// </summary>
public string HashesMatch => _resources.GetString("HashesMatch");

/// <summary>
/// Gets the resource HashesMismatch.
/// </summary>
public string HashesMismatch => _resources.GetString("HashesMismatch");
}

public class ColorBlindnessSimulatorStrings : ObservableObject
Expand Down
38 changes: 38 additions & 0 deletions src/dev/impl/DevToys/Models/HashComparisonResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#nullable enable

using Microsoft.UI.Xaml.Controls;

namespace DevToys.Models
{
/// <summary>
/// Contains information regarding the result of the hash comparison.
/// </summary>
internal sealed class HashComparisonResult
{
/// <summary>
/// Initializes a new instance of the <see cref="HashComparisonResult"/> class.
/// </summary>
/// <param name="severity">The severity of the comparison result message</param>
/// <param name="message">The message that can be shown to the user</param>
internal HashComparisonResult(InfoBarSeverity severity, string message)
{
Severity = severity;
Message = message;
}

/// <summary>
/// Gets a value that represents the severity of the comparison result message
/// </summary>
public InfoBarSeverity Severity { get; }

/// <summary>
/// Gets a value that represents the message can be shown to the user
/// </summary>
public string Message { get; }

/// <summary>
/// Gets the default-empty comparison result.
/// </summary>
public static HashComparisonResult? None { get; }
}
}
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/cs-CZ/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/de-DE/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/en-US/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/es-AR/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/es-ES/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/fr-FR/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
26 changes: 16 additions & 10 deletions src/dev/impl/DevToys/Strings/hu-HU/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -118,42 +118,48 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AccessibleName" xml:space="preserve">
<value>Checksum Generator tool</value>
<value>Checksum Generátor eszköz</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
<value>Mégsem</value>
</data>
<data name="Configuration" xml:space="preserve">
<value>Configuration</value>
<value>Beállítások</value>
</data>
<data name="Description" xml:space="preserve">
<value>Generate a hash with Checksum based on a file</value>
<value>Hash készítése fájl alapján</value>
</data>
<data name="HashingAlgorithmDescription" xml:space="preserve">
<value>Select which hashing algorithm you want to use</value>
<value>Válassza ki a használni kívánt hash függvényt</value>
</data>
<data name="HashingAlgorithmTitle" xml:space="preserve">
<value>Hashing Algorithm</value>
<value>Hash függvény</value>
</data>
<data name="Input" xml:space="preserve">
<value>Input</value>
<value>Bemenet</value>
</data>
<data name="MenuDisplayName" xml:space="preserve">
<value>Checksum</value>
</data>
<data name="Output" xml:space="preserve">
<value>Output</value>
<value>Kimenet</value>
</data>
<data name="OutputComparer" xml:space="preserve">
<value>Output Comparer</value>
<value>Összehasonlító eredmény</value>
</data>
<data name="SearchDisplayName" xml:space="preserve">
<value>Checksum Generator</value>
</data>
<data name="Uppercase" xml:space="preserve">
<value>Uppercase</value>
<value>Nagybetűs</value>
</data>
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>A hashek megegyeznek.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>A hashek nem egyeznek meg.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/id-ID/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/it-IT/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/ja-JP/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value>Checksum</value>
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/ko-KR/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value>Checksum</value>
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/pl-PL/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/pt-PT/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/ru-RU/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/zh-Hans/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/dev/impl/DevToys/Strings/zh-Hant/CheckSumGenerator.resw
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,10 @@
<data name="SearchKeywords" xml:space="preserve">
<value />
</data>
<data name="HashesMatch" xml:space="preserve">
<value>The hashes are the same.</value>
</data>
<data name="HashesMismatch" xml:space="preserve">
<value>The hashes are different.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using DevToys.Views.Tools.CheckSumGenerator;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;

Expand Down Expand Up @@ -61,6 +62,7 @@ private static readonly SettingDefinition<HashingAlgorithm> HashingAlgorithmSett
private bool _toolSuccessfullyWorked;
private bool _hasCancelledCalculation;
private bool _shouldDisplayProgress;
private HashComparisonResult? _hashComparisonResult;
private HashingAlgorithmDisplayPair? _outputHashingAlgorithm;
private readonly Queue<Task> _computationTaskQueue = new();

Expand Down Expand Up @@ -132,13 +134,27 @@ internal bool ShouldDisplayProgress
internal string? Output
{
get => _output;
set => SetProperty(ref _output, value);
set
{
SetProperty(ref _output, value);
HashComparisonResult = EvaluateOutputComparisonResult(value, OutputComparer);
}
}

internal string? OutputComparer
{
get => _outputComparer;
set => SetProperty(ref _outputComparer, value);
set
{
SetProperty(ref _outputComparer, value);
HashComparisonResult = EvaluateOutputComparisonResult(Output, value);
}
}

internal HashComparisonResult? HashComparisonResult
{
get => _hashComparisonResult;
private set => SetProperty(ref _hashComparisonResult, value);
}

/// <summary>
Expand Down Expand Up @@ -343,5 +359,22 @@ private HashAlgorithm CreateHashAlgorithm(HashingAlgorithm hashingAlgorithm) =>
HashingAlgorithm.SHA512 => SHA512.Create(),
_ => throw new ArgumentException("Hash Algorithm not supported", nameof(HashingAlgorithm))
};

/// <summary>
/// Evaluates the Output Comparison.
/// </summary>
private HashComparisonResult? EvaluateOutputComparisonResult(string? output, string? comparerOutput)
{
if (!string.IsNullOrEmpty(output) && !string.IsNullOrEmpty(comparerOutput))
{
return string.Equals(output, comparerOutput, StringComparison.OrdinalIgnoreCase)
? new HashComparisonResult(InfoBarSeverity.Success, Strings.HashesMatch)
: new HashComparisonResult(InfoBarSeverity.Error, Strings.HashesMismatch);
}
else
{
return HashComparisonResult.None;
}
}
}
}
Loading