private static void ClearTmpPathFiles() { try { if (Directory.GetFiles(PathEx.TmpPath).Length > 0) { DirectoryEx.DeleteC(PathEx.TmpPath, true); Directory.CreateDirectory(PathEx.TmpPath); } } catch (Exception e) { Log.Exception(e); } }
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; } }