纯粹为了记录,方便以后拷贝
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace CompareBytesMd5
{
class Program
{
public static string CalculateMD5(string filePath)
{
try
{
var stream = File.OpenRead(filePath);
var res = CalculateMD5(stream);
stream.Close();
return res;
}
catch (Exception ex)
{
Console.WriteLine("xxxxxxxxxxxxxxxxx Error");
}
return "";
}
public static string CalculateMD5(Stream stream)
{
using (var md5Obj = System.Security.Cryptography.MD5.Create())
{
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
string s = sr.ReadToEnd();
sr.Close();
sr.Dispose();
s = s.Replace("\r\n", "\n");
byte[] bytes = Encoding.UTF8.GetBytes(s);
var hash = md5Obj.ComputeHash(bytes);
var strMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
return strMD5;
}
}
static void Main(string[] args)
{
string srcPath = "E:/Workspace/ro/config/Table/ServerBytes";
string dstPath = "E:/Workspace/ro/config/Assets/Editor/Table";
// string dstPath = "E:/Workspace/ro/config/Assets/Resources/Table";
var srcFiles = Directory.GetFiles(srcPath, "*.bytes");
var dstFiles = Directory.GetFiles(dstPath, "*.bytes");
Dictionary<string, string> fileName2Md54Src = new Dictionary<string, string>();
Dictionary<string, string> fileName2Md54Dst = new Dictionary<string, string>();
foreach (var file in srcFiles)
{
if (!file.EndsWith(".bytes")) continue;
var pureName = Path.GetFileNameWithoutExtension(file);
var md5 = CalculateMD5(file);
fileName2Md54Src.Add(pureName, md5);
}
foreach (var file in dstFiles)
{
if (!file.EndsWith(".bytes")) continue;
var pureName = Path.GetFileNameWithoutExtension(file);
var md5 = CalculateMD5(file);
fileName2Md54Dst.Add(pureName, md5);
}
List<string> notExistItems = new List<string>();
List<string> notMatchItems = new List<string>();
foreach (var pairItem in fileName2Md54Src)
{
if (!fileName2Md54Dst.ContainsKey(pairItem.Key))
{
notExistItems.Add(pairItem.Key);
continue;
}
if (pairItem.Value != fileName2Md54Dst[pairItem.Key])
{
notMatchItems.Add(pairItem.Key);
}
}
//if (notExistItems.Count > 0)
//{
// Console.WriteLine("xxxxxxxxxxxxxxxxxx notExistItems:");
// foreach (var item in notExistItems)
// {
// Console.WriteLine(item);
// }
//}
if (notMatchItems.Count > 0)
{
Console.WriteLine("xxxxxxxxxxxxxxxxxx notMatchItems:");
foreach (var item in notMatchItems)
{
Console.WriteLine($"fileName:{item} srcMd5:{fileName2Md54Src[item]}, dstMd5:{fileName2Md54Dst[item]}");
}
}
Console.WriteLine("Hello");
}
}
}