public UpdateWindow(UpdateViewModel viewModel) { InitializeComponent(); viewModel.InvokeWindow = (x) => this.Dispatcher.Invoke(x); this.DataContext = viewModel; Global.Dialogs.Register(this, viewModel); }
public async void CheckForUpdates() { if (m_checkingUpdates) return; m_checkingUpdates = true; bool newVersion = false; string link = string.Empty; string execute = string.Empty; string files = string.Empty; await Task.Run(() => { HttpWebRequest request = Requests.CreateDefaultRequest(Global.UpdateVersionLink); string result = Requests.ReadResponseString(request); XElement rootElement = XElement.Parse(result); XElement versionElement = rootElement.Element("version"); if (versionElement == null) return; XElement downloadElement = rootElement.Element("download"); if (downloadElement == null) return; XElement executeElement = rootElement.Element("execute"); if (executeElement == null) return; XElement filesElement = rootElement.Element("files"); if (filesElement == null) return; Version version; if (!Version.TryParse(versionElement.Value, out version)) return; Version currentVersion = Version.Parse(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion); link = downloadElement.Value; if (version > currentVersion) newVersion = true; execute = executeElement.Value; files = filesElement.Value; }); if (newVersion && Global.MessageBox(this, Global.GetStringResource("StringUpdateAvailable"), MessageBoxExPredefinedButtons.YesNo) == MessageBoxExButton.Yes) { UpdateViewModel dialogViewModel = new UpdateViewModel(link); Global.Dialogs.ShowDialog(this, dialogViewModel); string basePath = Global.AppDataPath + Path.DirectorySeparatorChar + Global.UpdateExtractDirectory; string appDir = AppDomain.CurrentDomain.BaseDirectory; while (appDir.EndsWith("\\")) appDir = appDir.Remove(appDir.Length - 1); Process.Start(basePath + Path.DirectorySeparatorChar + execute, "\"" + basePath + Path.DirectorySeparatorChar + files + "\" \"" + appDir + "\""); NeedClose(); } m_checkingUpdates = false; }
public async void CheckForUpdates(bool raisedManually = false) { if (m_checkingUpdates) { return; } m_checkingUpdates = true; bool newVersion = false; NewVersionInfo?info = null; try { info = await NewVersionInfo.RequestInfoAsync(Global.UpdateVersionLink); } catch { try { info = await NewVersionInfo.RequestInfoAsync(Global.AdditionalUpdateVersionLink); } catch { if (raisedManually) { Global.MessageBox(this, Global.GetStringResource("StringCheckUpdatesError"), MessageBoxExPredefinedButtons.Ok); } } } Version currentVersion = Version.Parse(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion); if (info != null && info.Value.Version > currentVersion) { newVersion = true; } if (raisedManually && !newVersion) { Global.MessageBox(this, Global.GetStringResource("StringNoUpdatesFound"), MessageBoxExPredefinedButtons.Ok); } if (newVersion && Global.MessageBox(this, Global.GetStringResource("StringUpdateAvailable"), MessageBoxExPredefinedButtons.YesNo) == MessageBoxExButton.Yes) { UpdateViewModel dialogViewModel = new UpdateViewModel(info.Value.Link); Global.Dialogs.ShowDialog(this, dialogViewModel); if (!dialogViewModel.DownloadSuccessful) { Global.MessageBox(this, Global.GetStringResource("StringUpdateDownloadError"), MessageBoxExPredefinedButtons.Ok); } else if (!dialogViewModel.ExtractSuccessful) { Global.MessageBox(this, Global.GetStringResource("StringUpdateExtractError"), MessageBoxExPredefinedButtons.Ok); } if (dialogViewModel.DownloadSuccessful && dialogViewModel.ExtractSuccessful) { string basePath = Global.AppDataPath + Path.DirectorySeparatorChar + Global.UpdateExtractDirectory; string appDir = AppDomain.CurrentDomain.BaseDirectory; while (appDir.EndsWith("\\")) { appDir = appDir.Remove(appDir.Length - 1); } Process.Start($"{basePath}{Path.DirectorySeparatorChar}{info.Value.Execute}", $"\"{basePath}{Path.DirectorySeparatorChar}{info.Value.Files}\" \"{appDir}\""); NeedClose(); } } m_checkingUpdates = false; }