From b4b90920ca75c3c93b2ffc47d20e6d3a021004ed Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Tue, 7 Dec 2021 16:59:16 +0300 Subject: [PATCH 1/4] test --- Test2/Test2/MD5.cs | 105 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Test2/Test2/MD5.cs diff --git a/Test2/Test2/MD5.cs b/Test2/Test2/MD5.cs new file mode 100644 index 0000000..137776c --- /dev/null +++ b/Test2/Test2/MD5.cs @@ -0,0 +1,105 @@ +using System; +using System.IO; +using System.Security.Cryptography; +using System.Text; +using System.Threading; + +namespace Test2 +{ + public class MD5 + { + public static string CheckSum(string path) + { + var dir = new DirectoryInfo(path); + var otherdir = dir.GetDirectories(); + var files = dir.GetFiles(); + var md5 = new MD5CryptoServiceProvider(); + string hash = BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(dir.Name))); + hash += MD5Single(otherdir); + return hash; + } + + public static string CheckSumMulti(string path) + { + var dir = new DirectoryInfo(path); + var otherdir = dir.GetDirectories(); + var files = dir.GetFiles(); + var md5 = new MD5CryptoServiceProvider(); + string hash = BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(dir.Name))); + hash += MD5Multi(otherdir); + return hash; + } + + private static string MD5Single(DirectoryInfo[] dirs) + { + var md5 = new MD5CryptoServiceProvider(); + string hash = null; + foreach (var d in dirs) + { + var byteDirHash = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(d.Name)); + hash += BitConverter.ToString(byteDirHash); + var files = d.GetFiles(); + foreach (var f in files) + { + hash += FileHash(f, md5); + } + MD5Single(d.GetDirectories()); + } + return hash; + } + + private static string FileHash(FileInfo file, MD5CryptoServiceProvider md5) + { + var fileStream = File.OpenRead(file.FullName); + byte[] hashByte = md5.ComputeHash(fileStream); + return BitConverter.ToString(hashByte); + } + + private static string FindHash(DirectoryInfo dir) + { + var size = dir.GetFiles().Length < Environment.ProcessorCount + ? dir.GetFiles().Length + : Environment.ProcessorCount; + var threads = new Thread[size]; + var chunkSize = dir.GetFiles().Length / threads.Length + 1; + var md5 = new MD5CryptoServiceProvider(); + var bytedir = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(dir.Name)); + var hash = BitConverter.ToString(bytedir); + var files = dir.GetFiles(); + for (int i = 0; i < dir.GetFiles().Length; i++) + { + var localI = i; + threads[i] = new Thread(() => + { + for (var l = localI * chunkSize; l < (localI + 1) * chunkSize && l < files.Length; ++l) + { + hash += FileHash(files[l], md5); + } + }); + } + foreach (var thread in threads) + { + thread.Start(); + } + + foreach (var thread in threads) + { + thread.Join(); + } + + return hash; + } + + + private static string MD5Multi(DirectoryInfo[] dirs) + { + string hash = null; + for (int i = 0; i < dirs.Length; ++i) + { + hash += FindHash(dirs[i]); + } + + return hash; + } + } +} \ No newline at end of file From 5aef47eee342029e7a19f3dcacb20472b50add64 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Tue, 7 Dec 2021 17:00:58 +0300 Subject: [PATCH 2/4] test --- Test2/Test2/Program.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Test2/Test2/Program.cs diff --git a/Test2/Test2/Program.cs b/Test2/Test2/Program.cs new file mode 100644 index 0000000..17e0062 --- /dev/null +++ b/Test2/Test2/Program.cs @@ -0,0 +1,16 @@ +using System; + +namespace Test2 +{ + class Program + { + static void Main(string[] args) + { + var hash = MD5.CheckSum("C:\\Users\\89803\\Files\\MatMech\\Algebra"); + Console.WriteLine(hash); + Console.WriteLine("\n"); + hash = MD5.CheckSumMulti("C:\\Users\\89803\\Files\\MatMech\\Algebra"); + Console.WriteLine(hash); + } + } +} \ No newline at end of file From cc2717fcdc8ed8aaa2e04514bdfbd8697732dd3b Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Tue, 7 Dec 2021 17:01:18 +0300 Subject: [PATCH 3/4] test --- Test1.1/Test1.1.Tests/Test1.1.Tests.csproj | 21 +++++++++++++++++++++ Test2/Test2.sln | 16 ++++++++++++++++ Test2/Test2/Test2.csproj | 9 +++++++++ 3 files changed, 46 insertions(+) create mode 100644 Test1.1/Test1.1.Tests/Test1.1.Tests.csproj create mode 100644 Test2/Test2.sln create mode 100644 Test2/Test2/Test2.csproj diff --git a/Test1.1/Test1.1.Tests/Test1.1.Tests.csproj b/Test1.1/Test1.1.Tests/Test1.1.Tests.csproj new file mode 100644 index 0000000..641f3b5 --- /dev/null +++ b/Test1.1/Test1.1.Tests/Test1.1.Tests.csproj @@ -0,0 +1,21 @@ + + + + net5.0 + Test1._1.Tests + + false + + + + + + + + + + + + + + diff --git a/Test2/Test2.sln b/Test2/Test2.sln new file mode 100644 index 0000000..a2d1c6d --- /dev/null +++ b/Test2/Test2.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test2", "Test2\Test2.csproj", "{C4E4D325-036A-4937-A6B9-4B54D4A6B5B0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C4E4D325-036A-4937-A6B9-4B54D4A6B5B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C4E4D325-036A-4937-A6B9-4B54D4A6B5B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C4E4D325-036A-4937-A6B9-4B54D4A6B5B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C4E4D325-036A-4937-A6B9-4B54D4A6B5B0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Test2/Test2/Test2.csproj b/Test2/Test2/Test2.csproj new file mode 100644 index 0000000..a184b89 --- /dev/null +++ b/Test2/Test2/Test2.csproj @@ -0,0 +1,9 @@ + + + + Exe + net5.0 + Windows + + + From 15bef2164b3bf4501affc4981892caeb70633e9d Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Tue, 7 Dec 2021 17:02:32 +0300 Subject: [PATCH 4/4] delete file --- Test1.1/Test1.1.Tests/Test1.1.Tests.csproj | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 Test1.1/Test1.1.Tests/Test1.1.Tests.csproj diff --git a/Test1.1/Test1.1.Tests/Test1.1.Tests.csproj b/Test1.1/Test1.1.Tests/Test1.1.Tests.csproj deleted file mode 100644 index 641f3b5..0000000 --- a/Test1.1/Test1.1.Tests/Test1.1.Tests.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net5.0 - Test1._1.Tests - - false - - - - - - - - - - - - - -