通过web对.exe程序进行更新和修改
实现功能:通过网站更新用户的软件,需要联网,也可以通过本地网站更新局域网用户软件。
根本实现:1.一个网站(我用的是自己的www.aq36.xyz ,本地就可以,可以用localhost)然后运行update.exe->{通过update.xml获取网址,然后查看当前版本号和网站的server.xml最高版本号对比。然后判断是否更新}。
2.更新就下载zip文件,解压替换并删除。
3.更新update.xml文档版本信息,跟新结束。
主要代码:
1.解析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);
}
}
2.下载文件:
private void DownloadFile(int index)
{
try
{
downindex++;
filename = files[index];
//LabelNow.Text = "开始下载版本【" + versions[index] + "】" + filename;
LabelAll.Text = string.Format(CultureInfo.InvariantCulture, "升级进度 {0}/{1} [ {2} ]", new object[] { downindex, files.Count, this.ConvertSize(allsize) });
PBNow.Value = ;
downWebClient.DownloadFileAsync(new Uri(updateurl + filename), Application.StartupPath + "/temp/" + filename); }
catch (WebException exception)
{
MessageBox.Show(exception.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
3.开始升级:
private void StartUpdate()
{
if (localversion >= version)
{
UpdateCompleted();
return;
}
this.downWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
this.downWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
if (this.allsize == 0L || files == null || files.Count == )
{
this.UpdateCompleted();
}
if (files != null && files.Count > )
{
DownloadFile();
} }
4.下载完成并更改update.xml
private void DownloadFileCompleted(object wcsender, AsyncCompletedEventArgs ex)
{
if (ex.Error != null)
{
MessageBox.Show(ex.Error.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
if (File.Exists(Application.StartupPath + @"\" + this.filename))
{
File.Delete(Application.StartupPath + @"\" + this.filename);
}
File.Move(Application.StartupPath + @"\temp\" + this.filename, Application.StartupPath + @"\" + this.filename);
new FastZip().ExtractZip(Application.StartupPath + @"\" + this.filename, Application.StartupPath + @"\", "");
File.Delete(Application.StartupPath + @"\" + this.filename);
this.downedsize += this.filesize;
if (this.files.Count > this.downindex)
{
this.DownloadFile(this.downindex);
}
else
{
XmlTextWriter writer = new XmlTextWriter(Application.StartupPath + @"\update.xml", null)
{
Formatting = Formatting.Indented,
Indentation =
};
writer.WriteStartDocument();
writer.WriteStartElement("update");
writer.WriteStartElement("ProcessName");
writer.WriteString(this.ProcessName);
writer.WriteEndElement();
writer.WriteStartElement("version");
writer.WriteString(this.version.ToString());
writer.WriteEndElement();
writer.WriteStartElement("url");
writer.WriteString(this.updateurl);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
if (!string.IsNullOrEmpty(this.msg))
{
MessageBox.Show(this.msg, "升级提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
this.UpdateCompleted();
}
}
}
跟新进度条效果图:
更新前:
更新后:
一些文档代码图解:
1.本地update.xml
2.网站server.xml
代码粗糙,只是一个简单的demo,简单参考一下,有错误及时联系我。
百度网盘源码加文件:http://pan.baidu.com/s/1qYe2Vgg。
通过web对.exe程序进行更新和修改的更多相关文章
- nw.js桌面程序自动更新(node.js表白记)
Hello Google Node.js 一个基于Google V8 的JavaScript引擎. 一个伟大的端至端语言,或许我对你的热爱源自于web这门极富情感的技术吧! 注: 光阴似水,人生若梦, ...
- .Net桌面程序自动更新NAppUpdate
自动更新介绍 我们做了程序,不免会有版本升级,这就需要程序有自动版本升级的功能.应用程序自动更新是由客户端应用程序自身负责从一个已知服务器下载并安装更新,用户唯一需要进行干预的是决定是否愿意现在或以后 ...
- Python编写的桌面图形界面程序实现更新检测和下载安装
在Python中我们有很多种方案来编写桌面图形用户界面程序,譬如内置的 Tkinter .强大的 PyQt5 和 PySide2 ,还有 wxPython .借助这些或内置或第三方的模块,我们可以轻松 ...
- Docker容器环境下ASP.NET Core Web API应用程序的调试
本文主要介绍通过Visual Studio 2015 Tools for Docker – Preview插件,在Docker容器环境下,对ASP.NET Core Web API应用程序进行调试.在 ...
- 在docker中运行ASP.NET Core Web API应用程序
本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过程中,也会对docker的使用进行一些简单的描述.对于.NET Cor ...
- <转>exe & dll自我更新
exe & dll自我更新 分类: c/c++ 2008-10-16 22:07 756人阅读 评论(1) 收藏 举报 exedlldelayapi游戏 exe与dll的自我更新 在改 ...
- 本地json文件的编辑器,node-webkit开发的exe程序
首发:个人博客,更新&纠错&回复 在昨天的dota契合度计算器中,用到了dota英雄数据和dota玩家数据这两个数据库,为了便于网页应用使用,这两个数据库的存储格式是json,即her ...
- HTML5 Web缓存&运用程序缓存&cookie,session
在介绍HTML5 web缓存前,来认识一下cookie和session: session: 由于HTTP是无状态的,你是谁?你干了什么?抱歉服务器都是不知道的. 因此session(会话)出现了,它会 ...
- Linux,在不使用U盘的情况下使用wubi.exe程序在Win7上安装ubuntu-14.04.3版系统
本文介绍如何在不使用U盘的情况下使用wubi.exe程序在Win7上安装ubuntu-14.04.3版系统. 花了一天的时间终于安装上了Ubuntu14.04,过程坎坷,是血泪史,开始报“cannot ...
随机推荐
- 走进 Redis 的世界
NoSQL(Not Only SQL) 在现今已经应用非常普遍了,尤其是 Redis 和 MongoDB.我们现在来说说 Redis. 前世 Redis 是一个意大利人 Salvatore Sanfi ...
- 通过 Composer Github Packagist制作发布共享PHP包
参考来源: https://laravel-china.org/topics/1002 https://rivsen.github.io/post/how-to-publish-package-to- ...
- mtime,ctime,atime
mtime,ctime,atime是linux三个主要的变动时间. 这三个时间比较容易理解,但是不容易记忆,也容易搞混. mtime (modification time) 文件内容数据更改时,会更 ...
- 基于Spring-WS的Restful API的集成测试
在很多Java企业级应用中,Spring占据了非常重要的位置,这就导致了基本上的技术选型都是围绕着Spring来, 比方说笔者最近的项目需要开发一个Restful的API接口,选型的时候就说,客户架构 ...
- 一个服务器启动多个tomcat(详细图解)
1.官网下载一个tomcat,复制一个副本(第二个tomcat) 2.添加2个环境变量(右键单击我的电脑->选择属性->选择高级->选择环境变量),是2个tomcat的位置,环境变量 ...
- Robot Framework 关键字自定义
关键字自定义有三种方法: 1.在自动化目录中右键-->New User Keyword 2.选中case中的步骤(可选多行),右键-->Extract Keyword 3.自己写模块,自定 ...
- burpsuite+sqlmap跨登录验证SQL注入
(我操作的系统是kali linux) 1.利用burpsuite代理设置拦截浏览器请求(具体操作步骤可参考:http://www.cnblogs.com/hito/p/4495432.html) 2 ...
- 初用Linux, 安装Ubuntu16.04+NVIDIA387+CUDA8.0+cudnn5.1+TensorFlow1.0.1
因为最近Deep Learning十分热门, 装一下TensorFlow学习一下. 本文主要介绍安装流程, 将自己遇到的问题说明出来, 并记录自己如何处理, 原理方面并没有能力解释. 由于本人之前从来 ...
- 腾讯.NET面试题
在整个面试过程中,作为面试者的你,角色就是小怪兽,面试官的角色则是奥特曼,更不幸的是,作为小怪兽的你是孤身一人,而奥特曼却往往有好几个~ 以下是网友发的关于腾讯的.NET面试题,不得不说还是有一定的难 ...
- linux 根分区扩展
linux根分区扩容 今天网站上传图片出问题了,一开始还以为是程序问题,后来发现原来是服务器存储空间不够,明明有200G的磁盘空间,没理由这么快就用完,查了一下分区情况,原来有两块磁盘,根分区只挂载在 ...