Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
- namespace verify_redm
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Reading cache list...");
- var inputFile = File.ReadAllLines("cache.sha1");
- var cacheList = new Dictionary<string, string>();
- foreach (var line in inputFile)
- {
- var line2 = line.Trim();
- line2 = line2.Replace("\"", "");
- line2 = line2.Replace("{", "");
- line2 = line2.Replace("}", "");
- if (String.IsNullOrWhiteSpace(line2))
- continue;
- var split = line2.Split(',');
- var path = split[0].Trim();
- var hash = split[1].Trim();
- cacheList[path] = hash;
- }
- Console.WriteLine($"Got {cacheList.Keys.Count} file keys to check.");
- var targetDir = @"D:\RedM\cache\game";
- foreach (var entry in cacheList)
- {
- Console.ForegroundColor = ConsoleColor.Gray;
- var checkPath = Path.Combine(targetDir, entry.Key);
- Console.Write($"{checkPath} ...");
- if (File.Exists(checkPath))
- {
- var hash = Hash(checkPath);
- if (String.Equals(hash, entry.Value, StringComparison.InvariantCultureIgnoreCase))
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(" -> OK!");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($" -> Expected {entry.Value}, got {hash}!");
- }
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(" -> File missing!");
- }
- }
- Console.WriteLine("Checks done.");
- Console.ReadKey(true);
- }
- static string Hash(string path)
- {
- using (FileStream fs = new FileStream(path, FileMode.Open))
- using (BufferedStream bs = new BufferedStream(fs))
- {
- using (SHA1Managed sha1 = new SHA1Managed())
- {
- byte[] hash = sha1.ComputeHash(bs);
- StringBuilder formatted = new StringBuilder(2 * hash.Length);
- foreach (byte b in hash)
- {
- formatted.AppendFormat("{0:X2}", b);
- }
- return formatted.ToString();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement