mirror of
https://github.com/JDM170/file_hash_checker
synced 2025-12-10 16:17:18 +07:00
Compare commits
2 Commits
5ebc893513
...
21fc686d17
| Author | SHA1 | Date | |
|---|---|---|---|
|
21fc686d17
|
|||
|
522f2f827b
|
13
Program.cs
13
Program.cs
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user