private static string GetExeFileNameFromConfigFile() { var exeFn = string.Empty; try { var path = InstalledVersionManager.StartUpPathOfExe + "Config.ini"; using (var reader = new StreamReader(path)) { string fullVersion = reader.ReadToEnd().Trim(); if (fullVersion.StartsWith("v")) { fullVersion = fullVersion.Substring(1); string[] subVs = fullVersion.Split('.'); int version = Convert.ToInt32(subVs[0]) * 10000; version += Convert.ToInt32(subVs[1]) * 100; version += Convert.ToInt32(subVs[2]); exeFn = InstalledVersionManager.GetExistPathByVersion(version) + "\\Bot.exe"; } } if (!string.IsNullOrEmpty(exeFn) && !File.Exists(exeFn)) { exeFn = null; } } catch { exeFn = null; } return(exeFn); }
private static string GetMaxVersionPath(int v = 0) { string path = null; var newestVer = InstalledVersionManager.GetNewestVersion(); if (newestVer != null && newestVer.Version >= v) { path = newestVer.Path; } return(path); }
public static InstalledVersion GetNewestVersion() { InstalledVersion newestVersion = null; var allInstalledVersions = InstalledVersionManager.GetAllInstalledVersionAndSortByVersionDesc(); if (allInstalledVersions != null && allInstalledVersions.Count() > 0) { newestVersion = allInstalledVersions[0]; } return(newestVersion); }
public static string GetExeFileName() { var fn = InstalledVersionManager.GetExeFileNameFromConfigFile(); if (string.IsNullOrEmpty(fn)) { fn = InstalledVersionManager.GetReleaseVersionExeFileNameForTest(); } if (string.IsNullOrEmpty(fn)) { fn = InstalledVersionManager.GetMaxVersionExeFileName(); } return(fn); }
private static string GetMaxVersionExeFileName() { var fn = string.Empty; var newestVersion = InstalledVersionManager.GetNewestVersion(); if (newestVersion != null) { fn = newestVersion.Path + "\\Bot.exe"; } if (!string.IsNullOrEmpty(fn) && !File.Exists(fn)) { fn = string.Empty; } return(fn); }
private static string GetExistPathByVersion(int version) { var path = string.Empty; var allInstalledVersions = InstalledVersionManager.GetAllInstalledVersionAndSortByVersionDesc(); if (allInstalledVersions != null && allInstalledVersions.Count() > 0) { InstalledVersion installedVersion = allInstalledVersions.SingleOrDefault(k => k.Version == version); if (installedVersion != null) { path = installedVersion.Path; } } return(path); }
private static void Update(UpdateDownloadEntity updtEt) { if (!_isUpdating) { _isUpdating = true; try { Log.Info(string.Format("开始升级,补丁={0}", Util.SerializeWithTypeName(updtEt))); var newVerDir = PathEx.ParentOfExePath + ShareUtil.ConvertVersionToString(updtEt.PatchVersion); NetUtil.DownFile(updtEt.PatchUrl, _patchFn, updtEt.PatchSize); DirectoryEx.DeleteC(newVerDir, true); CopyBaseFile(newVerDir); Zip.UnZipFile(_patchFn, newVerDir, null); File.Delete(_patchFn); //DeleteOldVersion(ent.DeleteVersions, ent.DeleteVersionLessThan, ent.PatchVersion); InstalledVersionManager.SaveVersionToConfigFile(updtEt.PatchVersion); if (updtEt.IsForceUpdate) { var msg = string.Format("{0}已升级到版本{1},{0}将自动重启。\r\n\r\n升级信息:{2}", "软件", ShareUtil.ConvertVersionToString(updtEt.PatchVersion), updtEt.Tip); MsgBox.ShowTrayTip(msg, "软件升级", 30, null, () => Reboot()); } else { var msg = string.Format("{0}已升级到版本{1},是否立即重启软件,使用新版本?", "软件", ShareUtil.ConvertVersionToString(updtEt.PatchVersion)); if (MsgBox.ShowDialog(msg, "提示", null, null, null)) { Reboot(); } } } catch (Exception ex) { Log.Exception(ex); DispatcherEx.xInvoke(() => MsgBox.ShowErrDialog(string.Format("升级失败,原因={0}", ex.Message))); } Log.Info("结束升级补丁"); _isUpdating = false; } }
public static List <InstalledVersion> GetAllInstalledVersionAndSortByVersionDesc() { var installedVersions = new List <InstalledVersion>(); var dirts = Directory.GetDirectories(PathEx.ParentOfExePath, "v*"); if (dirts != null && dirts.Length != 0) { foreach (string dir in dirts) { var versionFromDir = InstalledVersionManager.GetVersionFromDir(dir); if (versionFromDir > 0) { installedVersions.Add(new InstalledVersion { Path = dir, Version = versionFromDir }); } } } installedVersions = installedVersions.OrderByDescending(k => k.Version).ToList(); return(installedVersions); }