Compare commits

...

2 Commits

Author SHA1 Message Date
21fc686d17 Update Program.cs
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-02-17 22:55:29 +07:00
522f2f827b Update Program.cs
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-02-16 18:24:22 +07:00

View File

@@ -8,6 +8,8 @@ namespace file_hash_checker
{ {
internal class Program internal class Program
{ {
private static readonly string regexHash = @"[a-zA-Z0-9]{32,}";
/*static int ReadBlock(Stream s, byte[] block) /*static int ReadBlock(Stream s, byte[] block)
{ {
int position = 0; int position = 0;
@@ -84,8 +86,11 @@ namespace file_hash_checker
Console.WriteLine(message); Console.WriteLine(message);
Console.Write("> "); Console.Write("> ");
string data = Console.ReadLine().Trim(); string data = Console.ReadLine().Trim();
if (string.IsNullOrWhiteSpace(data)) if (string.IsNullOrWhiteSpace(data) || !File.Exists(data))
InputData(message); {
Console.WriteLine("Файл не найден!");
return InputData(message);
}
return data; return data;
} }
@@ -97,13 +102,13 @@ namespace file_hash_checker
string hash = CalculateMD5(source); string hash = CalculateMD5(source);
bool result = false; bool result = false;
if (Regex.Match(toCompare, @"[a-zA-Z0-9]{32,}").Success) if (Regex.Match(toCompare, regexHash).Success)
result = hash == toCompare.ToLower(); result = hash == toCompare.ToLower();
else if (File.Exists(toCompare)) else if (File.Exists(toCompare))
if (toCompare.EndsWith(".md5")) if (toCompare.EndsWith(".md5"))
{ {
var fileData = File.ReadAllText(toCompare); var fileData = File.ReadAllText(toCompare);
Match match = Regex.Match(fileData, @"[a-zA-Z0-9]{32,}"); Match match = Regex.Match(fileData, regexHash);
if (match.Success) if (match.Success)
result = hash == match.Value; result = hash == match.Value;
} }