<?xml version="1.0"?> //xml版本号 <AutoUpdater> <URLAddres URL="http://192.168.198.113/vbroker/log/"/>//升级文件所在服务器端的网址 <UpdateInfo> <UpdateTime Date = "2005-02-02"/> //升级文件的更新日期 <Version Num = "1.0.0.1"/> //升级文件的版本号 </UpdateInfo> <UpdateFileList> //升级文件列表 <UpdateFile FileName = "aa.txt"/> //共有三个文件需升级 <UpdateFile FileName = "VB40.rar"/> <UpdateFile FileName = "VB4-1.CAB"/> </UpdateFileList> <RestartApp> <ReStart Allow = "Yes"/> //允许重新启动应用程序 <AppName Name = "TIMS.exe"/> //启动的应用程序名 </RestartApp> </AutoUpdater>
private string GetTheLastUpdateTime(string Dir)
{
string LastUpdateTime = "";
string AutoUpdaterFileName = Dir + @"\AutoUpdater.xml";
if(!File.Exists(AutoUpdaterFileName))
return LastUpdateTime;
//打开xml文件
FileStream myFile = new FileStream(AutoUpdaterFileName,FileMode.Open);
//xml文件阅读器
XmlTextReader xml = new XmlTextReader(myFile);
while(xml.Read())
{
if(xml.Name == "UpdateTime")
{
//获取升级文档的最后一次更新日期
LastUpdateTime = xml.GetAttribute("Date");
break;
}
}
xml.Close();
myFile.Close();
return LastUpdateTime;
}
//获取客户端指定路径下的应用程序最近一次更新时间 string thePreUpdateDate = GetTheLastUpdateTime(Application.StartupPath); Application.StartupPath指客户端应用程序所在的路径。 //获得从服务器端已下载文档的最近一次更新日期 string theLastsUpdateDate = GetTheLastUpdateTime(theFolder.FullName); theFolder.FullName指在升级文档下载到客户机上的临时文件夹所在的路径。
//获得已下载文档的最近一次更新日期
string theLastsUpdateDate = GetTheLastUpdateTime(theFolder.FullName);
if(thePreUpdateDate != "")
{
//如果客户端将升级的应用程序的更新日期大于服务器端升级的应用程序的更新日期
if(Convert.ToDateTime(thePreUpdateDate)>=Convert.ToDateTime(theLastsUpdateDate))
{
MessageBox.Show("当前软件已经是最新的,无需更新!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
}
}
this.labDownFile.Text = "下载更新文件";
this.labFileName.Refresh();
this.btnCancel.Enabled = true;
this.progressBar.Position = 0;
this.progressBarTotal.Position = 0;
this.progressBarTotal.Refresh();
this.progressBar.Refresh();
//通过动态数组获取下载文件的列表
ArrayList List = GetDownFileList(GetTheUpdateURL(),theFolder.FullName);
string[] urls = new string[List.Count];
List.CopyTo(urls, 0);
private void BatchDownload(object data)
{
this.Invoke(this.activeStateChanger, new object[]{true, false});
try
{
DownloadInstructions instructions = (DownloadInstructions) data;
//批量下载
using(BatchDownloader bDL = new BatchDownloader())
{
bDL.CurrentProgressChanged += new DownloadProgressHandler(this.SingleProgressChanged);
bDL.StateChanged += new DownloadProgressHandler(this.StateChanged);
bDL.FileChanged += new DownloadProgressHandler(bDL_FileChanged);
bDL.TotalProgressChanged += new DownloadProgressHandler(bDL_TotalProgressChanged);
bDL.Download(instructions.URLs, instructions.Destination, (ManualResetEvent) this.cancelEvent);
}
}
catch(Exception ex)
{
ShowErrorMessage(ex);
}
this.Invoke(this.activeStateChanger, new object[]{false, false});
this.labFileName.Text = "";
//更新程序
if(this._Update)
{
//关闭原有的应用程序
this.labDownFile.Text = "正在关闭程序....";
System.Diagnostics.Process[]proc=System.Diagnostics.Process.GetProcessesByName("TIMS");
//关闭原有应用程序的所有进程
foreach(System.Diagnostics.Process pro in proc)
{
pro.Kill();
}
DirectoryInfo theFolder=new DirectoryInfo(Path.GetTempPath()+"JurassicUpdate");
if(theFolder.Exists)
{
foreach(FileInfo theFile in theFolder.GetFiles())
{
//如果临时文件夹下存在与应用程序所在目录下的文件同名的文件,则删除应用程序目录下的文件
if(File.Exists(Application.StartupPath + \\"+Path.GetFileName(theFile.FullName)))
File.Delete(Application.StartupPath + "\\"+Path.GetFileName(theFile.FullName));
//将临时文件夹的文件移到应用程序所在的目录下
File.Move(theFile.FullName,Application.StartupPath + \\"+Path.GetFileName(theFile.FullName));
}
}
//启动安装程序
this.labDownFile.Text = "正在启动程序....";
System.Diagnostics.Process.Start(Application.StartupPath + "\\" + "TIMS.exe");
this.Close();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有