.exe更新demo
来源:互联网 发布:c linux ide工具 编辑:程序博客网 时间:2024/05/22 02:50
百度网盘源码加文件:http://pan.baidu.com/s/1qYe2Vgg
功能:通过网站更新用户的软件,需要联网,也可以通过本地网站更新局域网用户软件。
根本实现:1.一个网站(本地就可以)然后运行update.exe->通过update.xml获取网址,然后查看当前版本号和网站的server.xml最高版本号对比。然后判断是否更新。
2.更新就下载zip文件,解压替换并删除。
3.更新update.xml文档版本信息,跟新结束。
代码:解析xml文件:
/// <summary> /// 载入并解析XML /// </summary> private void LoadXml() { XmlDocument document = new XmlDocument(); try { document.Load(updateurl + "Server.xml"); XmlNode node = document.SelectSingleNode("//updates"); //获取最新版本号 version = Convert.ToInt32(node.Attributes["version"].Value); //所有需要升级文件大小,文件列表,sql列表 XmlNodeList updateList = document.SelectNodes("//updates//update"); foreach (XmlNode n in updateList) { long tempVersion = Convert.ToInt32(n.Attributes["version"].Value); long tempSize = Convert.ToInt64(n.Attributes["size"].Value); if (tempVersion > localversion && tempVersion <= version) { allsize += tempSize; versions.Add(tempVersion.ToString()); //获取升级文件列表 XmlNodeList fileList = n.SelectNodes("//update[@version='" + tempVersion + "']//files//file"); foreach (XmlNode n1 in fileList) { files.Add(n1.InnerText); } //获取执行的SQL语句列表 XmlNodeList sqlList = n.SelectNodes("//update[@version='" + tempVersion + "']//sqls//sql"); foreach (XmlNode n2 in sqlList) { sqls.Add(n2.InnerText); } //升级的提示信息 XmlNodeList msgList = n.SelectNodes("//update[@version='" + tempVersion + "']//msg"); foreach (XmlNode n3 in msgList) { msg += string.Format(CultureInfo.InvariantCulture, "版本【{0}】 {1}", new object[] { tempVersion, n3.InnerText.Replace("\r\n\t\t", "") }) + "\r\n"; } } } } catch (Exception e) { //Console.WriteLine(e.Message); MessageBox.Show("连接升级服务器失败,请重试!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 开始升级 /// </summary> private void StartUpdate() { if (localversion >= version) { UpdateCompleted(0); return; } this.downWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged); this.downWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted); if (this.allsize == 0L || files == null || files.Count == 0) { this.UpdateCompleted(0); } if (files != null && files.Count > 0) { DownloadFile(0); } }
public void DownloadProgressChanged(object wcsender, DownloadProgressChangedEventArgs ex) { PBNow.Text = "正在下载:" + filename + "[ " + ConvertSize(ex.BytesReceived) + "/" + ConvertSize(ex.TotalBytesToReceive) + " ]"; filesize = ex.TotalBytesToReceive; ftemp = ((float)(downedsize + ex.BytesReceived)) / ((float)allsize); PbAll.Value = Convert.ToInt32((float)(this.ftemp * 100f)); PBNow.Value = ex.ProgressPercentage; }
跟新效果:
更新前:
更新后:
一些代码图解:本地update.xml
网站server.xml
新手:代码粗糙,只是一个简单的demo,只能简单参考一下,有问题及时联系我。源码和全部文件都在网盘里面。
0 1
- .exe更新demo
- Tangram.exe.Config Demo文档
- Tangram.exe.Config Demo文档
- Tangram.exe.Config Demo文档
- TTProtect Demo (6.27)更新
- TTProtect Demo (7.2)更新
- 版本更新demo
- android增量更新demo
- 下拉更新demo
- 版本更新demo
- UI更新demo
- QT修改EXE资源,demo演示代码
- TTProtect Demo 1.02 (7.14)更新
- Android APP 增量更新demo
- ulua热更新小demo
- Android 2.3 - adb.exe版本更新
- C#如何更新EXE中和嵌入资源
- MKeyStudio_1.exe开发工具更新文档
- String(byte bytes[], String charsetName)
- vue-router,利用router.beforeEach未登录跳转到登录页
- (c语言)选择排序与冒泡排序
- 埃氏筛法
- 第三方App接入微信登录 解读 (微信开放平台)
- .exe更新demo
- jsp常用内置对象及其使用范围
- (c语言)在字符串中删除子串
- java高级实现文件流操作
- 初步认识React
- android 前后台流量监测
- Poj 2151 Check the difficulty of problems【概率dp+活用补集】
- session和cookie的区别
- 【敏捷开发每日一贴】代码走查