public static bool CheckUpdateLoad() { bool result = false; try { AutoVersionInfo app = AutoVersionInfo.CheckIsUpdate(StaticUtil.VERSION); //Console.WriteLine("Application.StartupPath=>" + Application.StartupPath); if (app.IsUpdate && MessageBoxEx.Show("检查到新版本,是否更新?", "版本检查", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string path = Application.StartupPath.Replace(Path.DirectorySeparatorChar + "Print" + Path.DirectorySeparatorChar + "Print" + Path.DirectorySeparatorChar, Path.DirectorySeparatorChar + "Print" + Path.DirectorySeparatorChar + "AutoUpdate" + Path.DirectorySeparatorChar); Ini ini = new Ini(path + Path.DirectorySeparatorChar + "version.ini"); ini.Write("version", "name", app.SoftName); ini.Write("version", "version", app.Version); ini.Write("version", "description", app.Description); ini.Write("version", "forced", app.Forced.ToString()); ini.Write("version", "url", app.Url); ini.Write("version", "md5", app.Md5); ini.Write("version", "size", app.Size.ToString()); System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.WorkingDirectory = path; process.StartInfo.FileName = "AutoUpdate.exe"; //process.StartInfo.Arguments = JsonConvert.SerializeObject(app); process.Start(); result = true; } else { result = false; } } catch (Exception ex) { MessageBoxEx.Show(ex.Message); result = false; } return(result); }
private void UpdateForm_Load(object sender, EventArgs e) { string file = Application.StartupPath + Path.DirectorySeparatorChar + "version.ini"; if (File.Exists(file)) { Ini ini = new Ini(file); app = new AutoVersionInfo(); app.SoftName = ini.Read("version", "name", 256); app.Version = ini.Read("version", "version", 256); app.Description = ini.Read("version", "description", 256); app.Forced = StaticUtil.ToInt(ini.Read("version", "forced", 256)); app.Url = ini.Read("version", "url", 256); app.Md5 = ini.Read("version", "md5", 256); app.Size = StaticUtil.ToInt(ini.Read("version", "size", 256)); if (!CheckTools.isPoint(StaticUtil.VERSION)) { throw new Exception("系统版本号设置有误!"); } if (!CheckTools.isPoint(app.Version)) { throw new Exception("远程版本号设置有误!"); } if (float.Parse(app.Version) > float.Parse(StaticUtil.VERSION)) { app.IsUpdate = true; } } else { this.progress_file.Text = "正在检测版本号..."; app = AutoVersionInfo.CheckIsUpdate(StaticUtil.VERSION); } UpdateApp(); }