From b4d03a97d96537fc259564ffa2d97befb773f21c Mon Sep 17 00:00:00 2001 From: Attila Steger Date: Wed, 16 Feb 2022 22:06:49 +0100 Subject: [PATCH 1/2] Fixing checksum comparison issue (#396) --- src/dev/DevToys.Startup/Package.appxmanifest | 2 +- src/dev/impl/DevToys/DevToys.csproj | 1 + src/dev/impl/DevToys/LanguageManager.cs | 10 ++++++ .../DevToys/Models/HashComparisonResult.cs | 19 +++++++++++ .../Strings/cs-CZ/CheckSumGenerator.resw | 6 ++++ .../Strings/de-DE/CheckSumGenerator.resw | 6 ++++ .../Strings/en-US/CheckSumGenerator.resw | 6 ++++ .../Strings/es-AR/CheckSumGenerator.resw | 6 ++++ .../Strings/es-ES/CheckSumGenerator.resw | 6 ++++ .../Strings/fr-FR/CheckSumGenerator.resw | 6 ++++ .../Strings/hu-HU/CheckSumGenerator.resw | 26 ++++++++------ .../Strings/id-ID/CheckSumGenerator.resw | 6 ++++ .../Strings/it-IT/CheckSumGenerator.resw | 6 ++++ .../Strings/ja-JP/CheckSumGenerator.resw | 6 ++++ .../Strings/ko-KR/CheckSumGenerator.resw | 6 ++++ .../Strings/pl-PL/CheckSumGenerator.resw | 6 ++++ .../Strings/pt-PT/CheckSumGenerator.resw | 6 ++++ .../Strings/ru-RU/CheckSumGenerator.resw | 6 ++++ .../Strings/zh-Hans/CheckSumGenerator.resw | 6 ++++ .../Strings/zh-Hant/CheckSumGenerator.resw | 6 ++++ .../CheckSumGeneratorToolViewModel.cs | 34 +++++++++++++++++-- .../CheckSumGeneratorToolPage.xaml | 9 ++++- src/dev/shared/SharedAssemblyInfo.cs | 2 +- 23 files changed, 178 insertions(+), 15 deletions(-) create mode 100644 src/dev/impl/DevToys/Models/HashComparisonResult.cs diff --git a/src/dev/DevToys.Startup/Package.appxmanifest b/src/dev/DevToys.Startup/Package.appxmanifest index 3bec993557..c7b45eb3be 100644 --- a/src/dev/DevToys.Startup/Package.appxmanifest +++ b/src/dev/DevToys.Startup/Package.appxmanifest @@ -1,4 +1,4 @@ - + + diff --git a/src/dev/impl/DevToys/LanguageManager.cs b/src/dev/impl/DevToys/LanguageManager.cs index 731ffd521d..ba2ed3efe1 100644 --- a/src/dev/impl/DevToys/LanguageManager.cs +++ b/src/dev/impl/DevToys/LanguageManager.cs @@ -412,6 +412,16 @@ public class CheckSumGeneratorStrings : ObservableObject /// Gets the resource SearchKeywords. /// public string SearchKeywords => _resources.GetString("SearchKeywords"); + + /// + /// Gets the resource HashesMatch. + /// + public string HashesMatch => _resources.GetString("HashesMatch"); + + /// + /// Gets the resource HashesMismatch. + /// + public string HashesMismatch => _resources.GetString("HashesMismatch"); } public class ColorBlindnessSimulatorStrings : ObservableObject diff --git a/src/dev/impl/DevToys/Models/HashComparisonResult.cs b/src/dev/impl/DevToys/Models/HashComparisonResult.cs new file mode 100644 index 0000000000..9c25083adf --- /dev/null +++ b/src/dev/impl/DevToys/Models/HashComparisonResult.cs @@ -0,0 +1,19 @@ +using Microsoft.UI.Xaml.Controls; + +namespace DevToys.Models +{ + internal class HashComparisonResult + { + internal HashComparisonResult(InfoBarSeverity severity, string message) + { + Severity = severity; + Message = message; + } + + public InfoBarSeverity Severity { get; } + + public string Message { get; } + + public static HashComparisonResult None { get; } + } +} diff --git a/src/dev/impl/DevToys/Strings/cs-CZ/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/cs-CZ/CheckSumGenerator.resw index f43258230e..7de31d954e 100644 --- a/src/dev/impl/DevToys/Strings/cs-CZ/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/cs-CZ/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/de-DE/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/de-DE/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/de-DE/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/de-DE/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/en-US/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/en-US/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/en-US/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/en-US/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/es-AR/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/es-AR/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/es-AR/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/es-AR/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/es-ES/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/es-ES/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/es-ES/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/es-ES/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/fr-FR/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/fr-FR/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/fr-FR/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/fr-FR/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/hu-HU/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/hu-HU/CheckSumGenerator.resw index 0e31a46529..5ea141a466 100644 --- a/src/dev/impl/DevToys/Strings/hu-HU/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/hu-HU/CheckSumGenerator.resw @@ -118,42 +118,48 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Checksum Generator tool + Checksum Generátor eszköz - Cancel + Mégsem - Configuration + Beállítások - Generate a hash with Checksum based on a file + Hash készítése fájl alapján - Select which hashing algorithm you want to use + Válassza ki a használni kívánt hash függvényt - Hashing Algorithm + Hash függvény - Input + Bemenet Checksum - Output + Kimenet - Output Comparer + Összehasonlító eredmény Checksum Generator - Uppercase + Nagybetűs + + A hashek megegyeznek. + + + A hashek nem egyeznek meg. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/id-ID/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/id-ID/CheckSumGenerator.resw index 9ee25ec691..de92a49d95 100644 --- a/src/dev/impl/DevToys/Strings/id-ID/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/id-ID/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/it-IT/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/it-IT/CheckSumGenerator.resw index bf272cacac..c6c6bd987b 100644 --- a/src/dev/impl/DevToys/Strings/it-IT/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/it-IT/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/ja-JP/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/ja-JP/CheckSumGenerator.resw index 46adebfe82..71ab71e7bf 100644 --- a/src/dev/impl/DevToys/Strings/ja-JP/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/ja-JP/CheckSumGenerator.resw @@ -156,4 +156,10 @@ Checksum + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/ko-KR/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/ko-KR/CheckSumGenerator.resw index 22986da1ed..83fa9345ff 100644 --- a/src/dev/impl/DevToys/Strings/ko-KR/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/ko-KR/CheckSumGenerator.resw @@ -156,4 +156,10 @@ Checksum + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/pl-PL/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/pl-PL/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/pl-PL/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/pl-PL/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/pt-PT/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/pt-PT/CheckSumGenerator.resw index 504fb5d979..075d40aa2e 100644 --- a/src/dev/impl/DevToys/Strings/pt-PT/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/pt-PT/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/ru-RU/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/ru-RU/CheckSumGenerator.resw index 0e31a46529..0430af8b0d 100644 --- a/src/dev/impl/DevToys/Strings/ru-RU/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/ru-RU/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/zh-Hans/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/zh-Hans/CheckSumGenerator.resw index 5a1998bb69..b37611000e 100644 --- a/src/dev/impl/DevToys/Strings/zh-Hans/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/zh-Hans/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/Strings/zh-Hant/CheckSumGenerator.resw b/src/dev/impl/DevToys/Strings/zh-Hant/CheckSumGenerator.resw index 7da99f9b0a..6f409fc5ff 100644 --- a/src/dev/impl/DevToys/Strings/zh-Hant/CheckSumGenerator.resw +++ b/src/dev/impl/DevToys/Strings/zh-Hant/CheckSumGenerator.resw @@ -156,4 +156,10 @@ + + The hashes are the same. + + + The hashes are different. + \ No newline at end of file diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs index ce067605cf..6ed42e8179 100644 --- a/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs +++ b/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs @@ -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; @@ -61,6 +62,7 @@ public sealed class CheckSumGeneratorToolViewModel : ObservableRecipient, IToolV private bool _toolSuccessfullyWorked; private bool _hasCancelledCalculation; private bool _shouldDisplayProgress; + private HashComparisonResult? _hashComparisonResult; private HashingAlgorithmDisplayPair? _outputHashingAlgorithm; private readonly Queue _computationTaskQueue = new(); @@ -132,13 +134,27 @@ internal bool ShouldDisplayProgress internal string? Output { get => _output; - set => SetProperty(ref _output, value); + set + { + SetProperty(ref _output, value); + EvaluateOutputComparisonResult(); + } } internal string? OutputComparer { get => _outputComparer; - set => SetProperty(ref _outputComparer, value); + set + { + SetProperty(ref _outputComparer, value); + EvaluateOutputComparisonResult(); + } + } + + internal HashComparisonResult? HashComparisonResult + { + get => _hashComparisonResult; + private set => SetProperty(ref _hashComparisonResult, value); } /// @@ -343,5 +359,19 @@ hashingAlgorithm switch HashingAlgorithm.SHA512 => SHA512.Create(), _ => throw new ArgumentException("Hash Algorithm not supported", nameof(HashingAlgorithm)) }; + + private void EvaluateOutputComparisonResult() + { + if (!string.IsNullOrEmpty(OutputComparer) && !string.IsNullOrEmpty(Output)) + { + HashComparisonResult = string.Equals(OutputComparer, Output, StringComparison.OrdinalIgnoreCase) + ? new HashComparisonResult(InfoBarSeverity.Success, Strings.HashesMatch) + : new HashComparisonResult(InfoBarSeverity.Error, Strings.HashesMismatch); + } + else + { + HashComparisonResult = HashComparisonResult.None; + } + } } } diff --git a/src/dev/impl/DevToys/Views/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolPage.xaml b/src/dev/impl/DevToys/Views/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolPage.xaml index 2563b9cd16..725bb4c023 100644 --- a/src/dev/impl/DevToys/Views/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolPage.xaml +++ b/src/dev/impl/DevToys/Views/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolPage.xaml @@ -13,6 +13,7 @@ + @@ -80,8 +81,14 @@ + + + diff --git a/src/dev/shared/SharedAssemblyInfo.cs b/src/dev/shared/SharedAssemblyInfo.cs index 10b703abb9..6f8c30f649 100644 --- a/src/dev/shared/SharedAssemblyInfo.cs +++ b/src/dev/shared/SharedAssemblyInfo.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // From a62afad7be1e7de8efc1e5316b64e335a06ce57d Mon Sep 17 00:00:00 2001 From: Attila Steger Date: Fri, 18 Feb 2022 22:04:04 +0100 Subject: [PATCH 2/2] - Fixing warning message - Changes on the comparison evaluator method to support unit testing --- .../DevToys/Models/HashComparisonResult.cs | 25 ++++++++++++++++--- .../CheckSumGeneratorToolViewModel.cs | 15 ++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/dev/impl/DevToys/Models/HashComparisonResult.cs b/src/dev/impl/DevToys/Models/HashComparisonResult.cs index 9c25083adf..83131bf5e7 100644 --- a/src/dev/impl/DevToys/Models/HashComparisonResult.cs +++ b/src/dev/impl/DevToys/Models/HashComparisonResult.cs @@ -1,19 +1,38 @@ -using Microsoft.UI.Xaml.Controls; +#nullable enable + +using Microsoft.UI.Xaml.Controls; namespace DevToys.Models { - internal class HashComparisonResult + /// + /// Contains information regarding the result of the hash comparison. + /// + internal sealed class HashComparisonResult { + /// + /// Initializes a new instance of the class. + /// + /// The severity of the comparison result message + /// The message that can be shown to the user internal HashComparisonResult(InfoBarSeverity severity, string message) { Severity = severity; Message = message; } + /// + /// Gets a value that represents the severity of the comparison result message + /// public InfoBarSeverity Severity { get; } + /// + /// Gets a value that represents the message can be shown to the user + /// public string Message { get; } - public static HashComparisonResult None { get; } + /// + /// Gets the default-empty comparison result. + /// + public static HashComparisonResult? None { get; } } } diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs index 6ed42e8179..11c8079b1f 100644 --- a/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs +++ b/src/dev/impl/DevToys/ViewModels/Tools/Generators/CheckSumGenerator/CheckSumGeneratorToolViewModel.cs @@ -137,7 +137,7 @@ internal bool ShouldDisplayProgress set { SetProperty(ref _output, value); - EvaluateOutputComparisonResult(); + HashComparisonResult = EvaluateOutputComparisonResult(value, OutputComparer); } } @@ -147,7 +147,7 @@ internal bool ShouldDisplayProgress set { SetProperty(ref _outputComparer, value); - EvaluateOutputComparisonResult(); + HashComparisonResult = EvaluateOutputComparisonResult(Output, value); } } @@ -360,17 +360,20 @@ hashingAlgorithm switch _ => throw new ArgumentException("Hash Algorithm not supported", nameof(HashingAlgorithm)) }; - private void EvaluateOutputComparisonResult() + /// + /// Evaluates the Output Comparison. + /// + private HashComparisonResult? EvaluateOutputComparisonResult(string? output, string? comparerOutput) { - if (!string.IsNullOrEmpty(OutputComparer) && !string.IsNullOrEmpty(Output)) + if (!string.IsNullOrEmpty(output) && !string.IsNullOrEmpty(comparerOutput)) { - HashComparisonResult = string.Equals(OutputComparer, Output, StringComparison.OrdinalIgnoreCase) + return string.Equals(output, comparerOutput, StringComparison.OrdinalIgnoreCase) ? new HashComparisonResult(InfoBarSeverity.Success, Strings.HashesMatch) : new HashComparisonResult(InfoBarSeverity.Error, Strings.HashesMismatch); } else { - HashComparisonResult = HashComparisonResult.None; + return HashComparisonResult.None; } } }