public void Update() { AutoUpdateVer oldVer = AutoUpdateVer.ReadVer(); lblVer.Text = "当前版本:" + oldVer.Version; lblVerInfo.Text = oldVer.VerInfo; SetStatusMessage("程序正在检查是否有新版本..."); if (HttpDownload(oldVer.Url + "ver.dll", "dll/ver.dll")) { AutoUpdateVer newVer = AutoUpdateVer.ReadVer(); lblVer.Text = "当前版本:" + oldVer.Version + "——>新版本:" + newVer.Version; lblVerInfo.Text = newVer.VerInfo; SetStatusMessage("发现新版本,正在更新..."); File.Delete("dll/ver.dll"); int allCount = newVer.DLLs.Count; int count = 1; foreach (string dll in newVer.DLLs.Keys) { SetStatusMessage("正在更新第" + count + "个(" + dll + ")/总共" + allCount + "个..."); if (!oldVer.DLLs.ContainsKey(dll) || newVer.DLLs[dll] != oldVer.DLLs[dll]) //更新文件 { HttpDownload(newVer.Url + dll, "dll/" + dll); } count++; } HttpDownload(oldVer.Url + "ver.dll", "dll/ver.dll"); } else { SetStatusMessage("连接更新主机出错,更新中断!"); } }
public static AutoUpdateVer ReadVer() { AutoUpdateVer autoUpVer = new AutoUpdateVer(); if (!Directory.Exists("dll")) { Directory.CreateDirectory("dll"); } if (File.Exists("dll/ver.dll")) { XDocument document = XDocument.Load("dll/ver.dll"); XElement root = document.Root; XElement vers = root.Element("vers"); autoUpVer.Version = vers.Attribute("ver").Value; autoUpVer.Url = vers.Attribute("url").Value; autoUpVer.VerInfo = vers.Value; autoUpVer.DLLs = new Dictionary <string, string>(); foreach (XElement ele in root.Element("dlls").Elements()) { autoUpVer.DLLs.Add(ele.Name.ToString(), ele.Attribute("ver").Value); } } return(autoUpVer); }