2023年11月26日发(作者:)using System;
using c;
using ;
using ;
using ;
using ;
namespace AutoUpdate
{
public class AutoUpdateConfig
{
public string autoUpdateUrl { get; set; }
public string Version { get; set; }
public string Description { get; set; }
public int fileCount { get; set; }
public string filePath { get; set; }
public List
}
public class AutoUpdateFile
{
///
/// 文件名
///
public string fileName { get; set; }
///
/// 文件大小
///
public string fileSize { get; set; }
///
/// true 表示成功下载
///
public string status { get; set; }
}
public class AutoUpdate
{
public AutoUpdateConfig GetAutoUpdateConfig(string autoUpdateUrl)
{
AutoUpdateConfig model = null;
XmlDocument doc = new XmlDocument();
try
{
(new WebClient().OpenRead(autoUpdateUrl));
}
catch(Exception ex)
{
(e);
return model;
}
model = new AutoUpdateConfig();
XmlElement root = ntElement;
n = SingleNode("version").();
ption = SingleNode("description").InnerText;
dateUrl = autoUpdateUrl;
List
foreach (XmlNode node in SingleNode("filelist").ChildNodes)
{
AutoUpdateFile item = new AutoUpdateFile();
me = utes["name"].InnerText;
ze = utes["size"].InnerText;
= "";
(item);
}
st = list;
unt = ;
return model;
}
public void formatVersion(ref string ver1, ref string ver2)
{
ver1 = e(".", "");
ver2 = e(".", "");
if ( < )
{
ver1 = ht(, '0');
}
else
{
ver2 = ht(, '0');
}
}
}
}
using System;
using c;
using entModel;
using ;
using g;
using ;
using ;
using ;
using ;
using ;
using stics;
using tio
n;
namespace AutoUpdate
{
public partial class frmMain : rm
{
AutoUpdate dal = new AutoUpdate();
AutoUpdateConfig model;
string autoUpdateurl { get; set; }
string processName { get; set; }
public frmMain(string autoUpdateUrl, string processName)
{
InitializeComponent();
dateurl = autoUpdateUrl;
sName = processName;
}
private void frmMain_Load(object sender, EventArgs e)
{
e = true;
e = false;
= "下一步";
model = oUpdateConfig(autoUpdateurl);
if (model == null)
{
d = false;
= autoUpdateurl+"
远程服务器错误";
}
else
{
= ption;
string version = cutingAssembly().GetName().ng();
string ver1 = version;
string ver2 = n;
Version(ref ver1, ref ver2);
if (32(ver1) >= 32(ver2))
{
("当前已是最新版本无需更新", "提示");
}
if (model != null)
{
urce = st;
}
}
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
AutoUpdateFile item = (AutoUpdateFile)ate;
if ( != null)
{
= "下载失败";
hData();
}
else
{
//rDefault(u => me == me).status = "成功";
= "成功";
hData();
if (rDefault(u => != "成功") == null)
{
("已经成功升级到" + n + ",请重新打开wms系统", "提示");
= "已经成功升级到" + n ;
e = false;
}
}
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
AutoUpdateFile item = (AutoUpdateFile)ate;
= (eceived / mal(ytesToReceive)).ToString("P");
hData();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
if (e)
{
if (cessesByName(sName).Length > 0)
{
("请关闭wms主系统", "警告");
return;
}
e = true;
e = false;
= "升级";
}
else
{
for (int i = 0; i < nt; i++)
{
AutoUpdateFile item = (AutoUpdateFile)(i);
using (WebClient client = new WebClient())
{
string fileName = me;
adFileAsync(new Uri(new Uri(dateUrl), fileName), fileName, item);
adProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
adFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
}
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
();
}
}
}
============================================xml 文件


发布评论