/// <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; }
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; }