系统自动更新AutoUpdate.doc_第1页
系统自动更新AutoUpdate.doc_第2页
系统自动更新AutoUpdate.doc_第3页
系统自动更新AutoUpdate.doc_第4页
系统自动更新AutoUpdate.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

系统自动更新分为插件更新和系统主程序更新,其中插件更新需要用户手动检查,系统主程序更新在程序启动时检查。系统主程序更新1.可更新除AutoUpdate.exe外的所有文件。一般情况下不更新主程序配置文件,因为主程序配置文件里包含了用户个性化配置,如果更新主程序配置文件就会清空用户配置。2.更新的前提条件如下:(1)需要配置IIS服务器提供Web服务,供AutoUpdate.exe从服务器上下载更新文件。(2)在程序中设置配置文件的路径:00/UFVideo/CSFiles/UpdateXMLFile.xml配置文件的内容如下: 13 00/UFVideo/CSFiles/UpdateMainFiles.zip配置文件提供了两个值一是最新的版本号13,二是更新文件的下载路径00/UFVideo/CSFiles/UpdateMainFiles.zip3.AutoUpdate.exe的工作流程(1)系统登录时主程序检查版本,主程序根据设置配置文件的服务器XML路径 检查比较自身版本和服务器提供版本是否一致,如果低于服务器版本就提示用户更新。(2)用户根据提示同意更新后由主程序启动AutoUpdate.exe,并且在启动时提供三个参数:最新的版本号、主程序名称、下载文件路径。(3)AutoUpdate.exe启动后就开始根据提供的下载路径参数下载更新文件。(4)更新文件下载完成后解压到自身的启动目录中,完成文件更新。(5)更新主程序配置文件中的版本号。(6)重新启动主程序,完成更新任务。using System;using System.Collections.Generic;using System.ComponentModel;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 = agr0.ToString().Split(|); HttpPath = a0.ToString(); Ver = a1.ToString(); strProcName = a2.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; 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(HttpPath.LastIndexOf(/) + 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(PPath.LastIndexOf() + 1); UpdateSys(PPath); string Path = PPath.Replace(FileName, ); DevExpress.XtraEditors.SimpleButton bt = new DevExpress.XtraEditors.SimpleButton(); bt.Text = PPath; bt.Tag = Path; bt.ToolTip = Text + rn + 本次升级任务下载的文件; bt.Dock = DockStyle.Top; bt.Appearance.ForeColor = System.Drawing.Color.Blue; bt.Appearance.Options.UseFont = true; bt.Appearance.Options.UseForeColor = 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(本次升级任务完成,自动重启主程序。, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); WriteConfig(Application.StartupPath + + strProcName + .exe, Version, Ver); System.Diagnostics.Process.Start(Application.StartupPath + + strProcName + .exe); KillProcess(AutoUpdate); catch catch DevExpress.XtraEditors.XtraMessageBox.Show(尚有未完成的下载任务,下次可继续下载。, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); public void link(object sender, EventArgs e) string path = (DevExpress.XtraEditors.SimpleButton)sender).Tag.ToString(); System.Diagnostics.Process.Start(explorer.exe, path); / / 解压文件 / / public void UpdateSys(string TempPath) try FileInfo fio = new FileInfo(TempPath); if (fio.Exists) UnZip(TempPath, Application.StartupPath); catch private void UnZip(string SourcePath, string DestinationPath) try if (System.IO.Directory.Exists(DestinationPath) = false) System.IO.Directory.CreateDirectory(DestinationPath); try Shell32.ShellClass sc = new Shell32.ShellClass(); Shell32.Folder SrcFolder = sc.NameSpace(SourcePath); Shell32.Folder DestFolder = sc.NameSpace(DestinationPath); Shell32.FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); finally /FileInfo fo = new FileInfo(SourcePath); /if (fo.Exists) / fo.Delete(); catch public string ReadXML(string Filepath, string Attribute) string value = ; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Filepath); /加载Xml文件 System.Xml.XmlElement root = doc.DocumentElement; /获取根节点 foreach (System.Xml.XmlNode node in root) if (node.Name = Attribute) value = node.InnerText; return value; public bool UpdateXML(string Filepath, string Attribute, string value) System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(Filepath); /加载Xml文件 System.Xml.XmlElement root = doc.DocumentElement; /获取根节点 bool b = false; foreach (System.Xml.XmlNode node in root) if (node.Name = Attribute) node.InnerText = value; b = true; doc.Save(Filepath); return b; private void XtraFormUpdate_Load(object sender, EventArgs e) if (!string.IsNullOrEmpty(Ver) & !string.IsNullOrEmpty(strProcName) & !string.IsNullOrEmpty(Http

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论