Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Security.Cryptography;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace HashFiles
- {
- class Program
- {
- static string Paths = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- static void Main(string[] args)
- {
- CreateFile();
- Console.WriteLine("Attempting to Hash your Files!");
- string filepath = Paths + "/files/";
- Console.WriteLine("Path: "+filepath);
- string[] localfilelist = Directory.GetFiles(filepath, "*", SearchOption.AllDirectories);
- string[] localfilenames = new string[localfilelist.Length];
- string[] md5 = new string[localfilelist.Length];
- for (int i = 0;i<localfilelist.Length;i++)
- {
- md5[i] = CalculateMD5(localfilelist[i]);
- Console.WriteLine("Hashing "+localfilelist[i]+" Hash: "+md5[i]);
- }
- for (int i = 0; i < localfilenames.Length; i++)
- {
- localfilenames[i] = localfilelist[i].Replace(filepath, "");
- }
- using (StreamWriter sw = new StreamWriter("manifest.txt", true))
- {
- for (int i = 0; i < localfilelist.Length; i++)
- {
- string[] split = Regex.Split(localfilelist[i], "/files/");
- sw.WriteLine(split[1]+"="+localfilenames[i]+"="+md5[i]);
- }
- sw.Close();
- Console.WriteLine("Finished");
- Console.ReadLine();
- }
- }
- public static void CreateFile()
- {
- if (!File.Exists("manifest.txt"))
- {
- File.Create("manifest.txt");
- }
- }
- public static string CalculateMD5(string filename) //calculate MD5s the same way HashMyFiles does it
- {
- using (var md5 = MD5.Create())
- {
- using (var stream = File.OpenRead(filename))
- {
- var hash = md5.ComputeHash(stream);
- return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement