|
@@ -0,0 +1,61 @@
|
|
|
+// See https://aka.ms/new-console-template for more information
|
|
|
+
|
|
|
+
|
|
|
+using System.Runtime.InteropServices;
|
|
|
+using System.Security.Cryptography;
|
|
|
+
|
|
|
+
|
|
|
+[DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]
|
|
|
+static extern bool CreateHardLink(
|
|
|
+ string lpFileName,
|
|
|
+ string lpExistingFileName,
|
|
|
+ IntPtr lpSecurityAttributes
|
|
|
+);
|
|
|
+
|
|
|
+
|
|
|
+Console.WriteLine("Installer is suck");
|
|
|
+
|
|
|
+
|
|
|
+if (args.Length == 0)
|
|
|
+{
|
|
|
+ Console.WriteLine("Usage: <inDir> <outDir>");
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+var files = Directory.GetFiles(args[0]);
|
|
|
+foreach (var file in files)
|
|
|
+{
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Console.WriteLine($"> {file}");
|
|
|
+ var info = new FileInfo(file);
|
|
|
+ Console.WriteLine($" Len: {info.Length:N0}");
|
|
|
+ Console.Write(" SHA256...");
|
|
|
+ string hexHash;
|
|
|
+ {
|
|
|
+ using var inputStream = info.OpenRead();
|
|
|
+ using var sha256 = SHA256.Create();
|
|
|
+ var hash = sha256.ComputeHash(inputStream);
|
|
|
+ hexHash = Convert.ToHexString(hash);
|
|
|
+ }
|
|
|
+ Console.WriteLine($" {hexHash}");
|
|
|
+
|
|
|
+ var targetPath = Path.Combine(args[1], $"{info.Length:0-000-000-000}_{hexHash}{info.Extension}");
|
|
|
+ if (File.Exists(targetPath))
|
|
|
+ {
|
|
|
+ File.Delete(file);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ File.Move(file, targetPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ CreateHardLink(file, targetPath, nint.Zero);
|
|
|
+ Console.WriteLine($" Collapse to {targetPath} <");
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine($"Error:{e.Message}");
|
|
|
+ }
|
|
|
+ Console.WriteLine();
|
|
|
+}
|