/// <summary> /// 升级 /// </summary> /// <param name="currentVersion">当前版本号</param> /// <param name="newVersion">新的版本号</param> /// <returns></returns> public static void Upgrade(MUpgrade upgrade) { if (upgrade == null || upgrade.Files == null || upgrade.Files.Count == 0) { return; } RaiseBeginUpgrade(); var index = 0; foreach (var file in upgrade.Files) { RaiseFileBeginDownload(file.Name, index); try { Down(upgrade.BaseUrl, file); RaiseFileEndDownload(file.Name, index); index++; } catch (Exception ex) { RaiseUpgradeError(ex.Message); return; } } RaiseEndUpgrade(); }
public static bool Check(string url, out MUpgrade upgrade) { try { var request = new WebClient(); request.Encoding = Encoding.UTF8; var content = request.DownloadString(url); var formatter = new XmlSerializer(typeof(MUpgrade)); using (var reader = new StringReader(content)) { object obj = formatter.Deserialize(reader); upgrade = obj as MUpgrade; } using (var fs = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "upgrade.xml"), FileMode.Create)) { formatter.Serialize(fs, upgrade); } } catch { upgrade = null; } return(upgrade != null); }