系统自动更新AutoUpdate
- 格式:docx
- 大小:28.11 KB
- 文档页数:7
系统自动更新分为插件更新和系统主程序更新,其中插件更新需要用户手动检查,系统主程序更新在程序启动时检查。
系统主程序更新
1.可更新除AutoUpdate.exe外的所有文件。
一般情况下不更新主程序配置文件,因为主程序配置文件里包含了用户个性化配置,如果更新主程序配置文件就会清空用户配置。
2.更新的前提条件如下:
(1)需要配置IIS服务器提供Web服务,供AutoUpdate.exe从服务器上下载更
新文件。
(2)在程序中设置配置文件的路径:
http://192.168.1.100/UFVideo/CSFiles/UpdateXMLFile.xml
配置文件的内容如下:
配置文件提供了两个值一是最新的版本号
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());
}
}
}
///
///关闭主进程
///
///主进程名称
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;
}
}