当前位置:文档之家› 系统自动更新AutoUpdate

系统自动更新AutoUpdate

系统自动更新分为插件更新和系统主程序更新,其中插件更新需要用户手动检查,系统主程序更新在程序启动时检查。

系统主程序更新1.可更新除AutoUpdate.exe外的所有文件。

一般情况下不更新主程序配置文件,因为主程序配置文件里包含了用户个性化配置,如果更新主程序配置文件就会清空用户配置。

2.更新的前提条件如下:(1)需要配置IIS服务器提供Web服务,供AutoUpdate.exe从服务器上下载更新文件。

(2)在程序中设置配置文件的路径:http://192.168.1.100/UFVideo/CSFiles/UpdateXMLFile.xml配置文件的内容如下:<?xml version="1.0" encoding="utf-8"?><UpdateTable><Ver>13</Ver><Path>http://192.168.1.100//UFVideo/CSFiles/UpdateMainFiles.zip</Path> </UpdateTable>配置文件提供了两个值一是最新的版本号<Ver>13</Ver>,二是更新文件的下载路径<Path>http://192.168.1.100//UFVideo/CSFiles/UpdateMainFiles.zip</Path>3.AutoUpdate.exe的工作流程(1)系统登录时主程序检查版本,主程序根据设置配置文件的服务器XML路径检查比较自身版本和服务器提供版本是否一致,如果低于服务器版本就提示用户更新。

(2)用户根据提示同意更新后由主程序启动AutoUpdate.exe,并且在启动时提供三个参数:最新的版本号、主程序名称、下载文件路径。

(3)AutoUpdate.exe启动后就开始根据提供的下载路径参数下载更新文件。

(4)更新文件下载完成后解压到自身的启动目录中,完成文件更新。

(5)更新主程序配置文件中的版本号。

(6)重新启动主程序,完成更新任务。

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using DevExpress.XtraEditors;using System.Threading;using Shell32;using System.Configuration;namespace AutoUpdate{public partial class XtraFormUpdate : DevExpress.XtraEditors.XtraForm{public XtraFormUpdate(string[] agr)InitializeComponent();this.ShowInTaskbar = false;this.MaximizeBox = false;this.MinimizeBox = false;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;}public XtraFormUpdate(){InitializeComponent();this.ShowInTaskbar = false;this.MaximizeBox = false;this.MinimizeBox = false;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;}static string HttpPath = "";static string Ver = "";static string strProcName = "";static class Program{[STAThread]static void Main(string[] agr){if (agr.Length == 1){string [] a = agr[0].ToString().Split('|');HttpPath = a[0].ToString();Ver = a[1].ToString();strProcName = a[2].ToString();XtraFormUpdate form = new XtraFormUpdate(agr);Application.Run(form);}else{Application.Run(new XtraFormUpdate());}}}///<summary>///关闭主进程///</summary>///<param name="ProcessName">主进程名称</param>public void KillProcess(string ProcessName){System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcesses();foreach (System.Diagnostics.Process p in ps){//MessageBox.Show(p.ProcessName);if (p.ProcessName.ToString() == ProcessName){p.Kill();break;}}public void DownFile(string UpdateHttpPath){try{string TempPath = System.IO.Path.GetTempPath() + "GFK";if (System.IO.Directory.Exists(TempPath) == true){System.IO.Directory.Delete(TempPath, true);}if (System.IO.Directory.Exists(TempPath) == false){ System.IO.Directory.CreateDirectory(TempPath); }if (UpdateHttpPath != null && UpdateHttpPath != ""){string FilePath = TempPath + "\\" +HttpPath.Substring(stIndexOf("/") + 1);NewHttpDown nhd = new NewHttpDown();nhd.Dock = DockStyle.Top;// SystemNewVer = int.Parse(NewVer);for (int i = 0; i < panelControl1.Controls.Count; i++){ nhd.Top = 150 + i * 30; } //新增控件布局nhd.RemoveControls += new NewHttpDown.RemoveControlsdelegate(下载完执行);nhd.scFileName = FilePath;nhd.scUrl = HttpPath;panelControl1.Controls.Add(nhd);}else{DevExpress.XtraEditors.XtraMessageBox.Show("更新地址不正确,请咨询IT部获取正确的更新地址。

", "操作提示");}}catch { }}public delegate void下载delegate(DevExpress.XtraEditors.XtraUserControl b);下载delegate下载OK;public void下载完执行(DevExpress.XtraEditors.XtraUserControl b){try{if (InvokeRequired){Invoke(new下载delegate(下载完执行), b);}else{try{// simpleButton3.Enabled = true;string Text = b.Tag.ToString();if (Text != "labelControl2"){string PPath = Text.Replace("文件保存路径:", "");string FileName = PPath.Substring(stIndexOf("\\") + 1);UpdateSys(PPath);string Path = PPath.Replace(FileName, "");DevExpress.XtraEditors.SimpleButton bt = newDevExpress.XtraEditors.SimpleButton();bt.Text = PPath;bt.Tag = Path;bt.ToolTip = Text + "\r\n" + "本次升级任务下载的文件";bt.Dock = DockStyle.Top;bt.Appearance.ForeColor = System.Drawing.Color.Blue;eFont = true;eForeColor = true;bt.Appearance.TextOptions.HAlignment =DevExpress.Utils.HorzAlignment.Near;bt.Click += new System.EventHandler(link);for (int i = 0; i < panelControl1.Controls.Count; i++){ bt.Top = i * 30; } //生成一个类似超链接的按钮,打开文件下载的位置panelControl1.Controls.Add(bt);}panelControl1.Controls.Remove(b);// DevExpress.XtraEditors.XtraMessageBox.Show("本次升级任务完成,自动重启主程序。

相关主题