From 70ad15e118c8a0fb3f0c227f527d2a08bbed0dbb Mon Sep 17 00:00:00 2001 From: Naser Date: Sat, 11 Mar 2023 08:21:24 +0330 Subject: [PATCH] Fix bug in read file for hashing --- src/nHash/Features/HashAlgorithmFeature.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nHash/Features/HashAlgorithmFeature.cs b/src/nHash/Features/HashAlgorithmFeature.cs index 8c9f80f..e5cf180 100644 --- a/src/nHash/Features/HashAlgorithmFeature.cs +++ b/src/nHash/Features/HashAlgorithmFeature.cs @@ -15,7 +15,7 @@ public class HashAlgorithmFeature : IFeature public HashAlgorithmFeature() { _algorithmType = new Argument("type", "Algorithm type"); - _textArgument = new Argument("text", "Text for calculate fingerprint"); + _textArgument = new Argument("text", GetDefaultString, "Text for calculate fingerprint"); _fileName = new Option(name: "--file", description: "File name for calculate hash"); _lowerCase = new Option(name: "--lower", description: "Generate lower case"); } @@ -46,6 +46,12 @@ private static void CalculateText(string text, AlgorithmType algorithmType, bool if (!string.IsNullOrWhiteSpace(fileName)) { + if (!File.Exists(fileName)) + { + Console.WriteLine($"File {fileName} does not exists!"); + return; + } + var fileBytes = File.ReadAllBytes(fileName); CalculateHash(fileBytes, algorithmType, lowerCase); } @@ -73,4 +79,6 @@ private static void CalculateHash(byte[] inputBytes, AlgorithmType algorithmType Console.WriteLine(hashedText); } + + private static string GetDefaultString() => string.Empty; } \ No newline at end of file