public string CheckUpdate(string oldVersion, ref List <MDownloadfile> fileList) { MMessage <string> msg = new MMessage <string>(); bool update = false; string newVersion; try { string _path = @"\Updates"; string ss = Server.MapPath(_path); if (File.Exists(Server.MapPath(_path + @"\POS.exe"))) { newVersion = FileVersionInfo.GetVersionInfo(Server.MapPath(_path + @"\POS.exe")).FileVersion; //判断版本号 string[] oldVers = oldVersion.Split('.'); string[] newVers = newVersion.Split('.'); for (int i = 0; i < 4; i++) { //逐位比较版本号 if (int.Parse(oldVers[i]) == int.Parse(newVers[i])) { //旧版本号等于新版本号 update = false; continue; } if (int.Parse(oldVers[i]) > int.Parse(newVers[i])) { //旧版本号大于新版本号 throw new Exception("本地版本比服务器版本高"); } if (int.Parse(oldVers[i]) < int.Parse(newVers[i])) { //旧版本号小于新版本号 update = true; break; } } if (update) { #region 生成配置文件 //写配置文件 using (StreamWriter wt = new StreamWriter(Server.MapPath(_path + @"\Version.inf"), false)) { wt.WriteLine(newVersion); wt.Close(); } #endregion DirectoryInfo updateFolder = new DirectoryInfo(Server.MapPath(_path)); fileList = new List <MDownloadfile>(); foreach (FileInfo file in updateFolder.GetFiles()) { fileList.Add(new MDownloadfile(file.Name, ZipClass.ZipFileToBytes(file.FullName))); } msg.Flag = true; //msg.Content = fileList; return(Converter.Serialize(msg)); } else { msg.Flag = false; msg.Text = "已是最新程序"; return(Converter.Serialize(msg)); } } else { msg.Flag = false; msg.Text = "更新文件不存在"; return(Converter.Serialize(msg)); } } catch (Exception ex) { WriteLog("Update", false, ex.Message); msg.Flag = false; msg.Text = ex.Message; msg.Content = null; return(Converter.Serialize(msg)); } }