http://hi.baidu.com/xingziyong/blog/item/d68905e91347dc3eb80e2d85.html
最近单位开发一个项目,其中需要用到自动升级功能。因为自动升级是一个比较常用的功能,可能会在很多程序中用到,于是,我就想写一个自动升级的组件,在应用程序中,只需要引用这个自动升级组件,并添加少量代码,即可实现自动升级功能。因为我们的程序中可能包含多个exe或者dll文件,所以要支持多文件的更新。
首先,要确定程序应该去哪里下载需要升级的文件。我选择了到指定的网站上去下载,这样比较简单,也通用一些。在这个网站上,需要放置一个当前描述最新文件列表的文件,我们估且叫它服务器配置文件。这个文件保存了当前最新文件的版本号(lastver),大小(size),下载地址(url),本地文件的保存路径(path),还有当更新了这个文件后,程序是否需要重新启动(needRestart)。这个文件大致如下:
updateservice.xml
<?xml version="1.0" encoding="utf-8"
?>
< updateFiles >
< file path= "AutoUpdater.dll" url= "http://update.iyond.com/CompanyClientApplication/AutoUpdater.zip" lastver= "1.0.0.0" size= "28672" needRestart= "true" />
< file path= "CompanyClient.exe" url= "http://update.iyond.com/CompanyClientApplication/CompanyClient.zip" lastver= "1.1.0.0" size= "888832 " needRestart= "true" />
< file path= "HappyFenClient.dll" url= "http://update.iyond.com/CompanyClientApplication/HappyFenClient.zip" lastver= "1.0.0.0" size= "24576" needRestart= "true" />
< file path= "NetworkProvider.dll" url= "http://update.iyond.com/CompanyClientApplication/NetworkProvider.zip" lastver= "1.0.0.0" size= "32768" needRestart= "true" />
< file path= "Utility.dll" url= "http://update.iyond.com/CompanyClientApplication/Utility.zip" lastver= "1.0.0.0" size= "20480" needRestart= "true" />
< file path= "Wizard.dll" url= "http://update.iyond.com/CompanyClientApplication/Wizard.zip" lastver= "1.0.0.0"
< updateFiles >
< file path= "AutoUpdater.dll" url= "http://update.iyond.com/CompanyClientApplication/AutoUpdater.zip" lastver= "1.0.0.0" size= "28672" needRestart= "true" />
< file path= "CompanyClient.exe" url= "http://update.iyond.com/CompanyClientApplication/CompanyClient.zip" lastver= "1.1.0.0" size= "888832 " needRestart= "true" />
< file path= "HappyFenClient.dll" url= "http://update.iyond.com/CompanyClientApplication/HappyFenClient.zip" lastver= "1.0.0.0" size= "24576" needRestart= "true" />
< file path= "NetworkProvider.dll" url= "http://update.iyond.com/CompanyClientApplication/NetworkProvider.zip" lastver= "1.0.0.0" size= "32768" needRestart= "true" />
< file path= "Utility.dll" url= "http://update.iyond.com/CompanyClientApplication/Utility.zip" lastver= "1.0.0.0" size= "20480" needRestart= "true" />
< file path= "Wizard.dll" url= "http://update.iyond.com/CompanyClientApplication/Wizard.zip" lastver= "1.0.0.0"