private static bool CheckUpdatePackageMD5(string filePath, string md5Code, out MD5Helper.FileMD5ErrorMode errCode) { string currentMD5Code; errCode = MD5Helper.CreateMD5(filePath, out currentMD5Code); if (errCode != MD5Helper.FileMD5ErrorMode.OK) { System.Console.WriteLine("Calculation file md5 error,Err:" + errCode.ToString()); try { File.Delete(filePath); } catch { } return(false); } if (md5Code.ToLower() != currentMD5Code.ToLower()) { System.Console.WriteLine("File md5 is not match!"); try { File.Delete(filePath); } catch { } return(false); } else { return(true); } }
/// <summary> /// 校验更新包MD5码 /// </summary> /// <param name="filePath"></param> /// <param name="md5Code"></param> /// <param name="errCode"></param> /// <returns>是否校验成功</returns> private static bool FileMD5Check(string filePath, string md5Code, out MD5Helper.FileMD5ErrorMode errCode) { string currentMD5Code; errCode = MD5Helper.CreateMD5(filePath, out currentMD5Code); if (errCode != MD5Helper.FileMD5ErrorMode.OK) { System.Console.WriteLine("Calculation file md5 error,Err:" + errCode.ToString()); if (_sw != null) { _sw.WriteLine("(UTC:" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "): Calculation file md5 error,Err:" + errCode.ToString()); } try { File.Delete(filePath); } catch { } return(false); } if (md5Code.ToLower() != currentMD5Code.ToLower()) { System.Console.WriteLine("File md5 is not match!"); if (_sw != null) { _sw.WriteLine("(UTC:" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "): File md5 is not match!"); } try { File.Delete(filePath); } catch { } return(false); } else { return(true); } }
public static bool IsMD5Equal(string firstFileName, string secondFileName) { string firstMD5 = ""; MD5Helper.FileMD5ErrorMode errorMode = MD5Helper.CreateMD5(firstFileName, out firstMD5); if (errorMode != MD5Helper.FileMD5ErrorMode.OK) { return(false); } string secondMD5 = ""; errorMode = MD5Helper.CreateMD5(secondFileName, out secondMD5); if (errorMode != MD5Helper.FileMD5ErrorMode.OK) { return(false); } if (firstMD5 != secondMD5) { return(false); } return(true); }