/// <summary> /// Do all operation that checks for new version, brings up the change /// dialog, allows downloading etc. UI can just call this method to /// do it all. /// </summary> /// <param name="force">Forces the version check even if it was done recently. Otherwise LastChecked and Interval is used to decide if to hit the server</param> /// <param name="closeApplication">It trye forces MM to be shutdown after downloading</param> /// <param name="failTimeout">Max time to for the HTTP check to take before considering failed</param> /// <returns></returns> public static bool CheckForNewVersion(bool force, bool closeApplication = true, int failTimeout = 2000) { var updater = new ApplicationUpdater(typeof(MainWindow)); bool isNewVersion = updater.IsNewVersionAvailable(!force, timeout: failTimeout); if (isNewVersion) { var res = MessageBox.Show(updater.VersionInfo.Detail + "\r\n\r\n" + "Do you want to download and install this version?", updater.VersionInfo.Title, MessageBoxButton.YesNo, MessageBoxImage.Information); if (res == MessageBoxResult.Yes) { ShellUtils.GoUrl(mmApp.Urls.InstallerDownloadUrl); if (closeApplication) { mmApp.Model.Window.Close(); } } } return(isNewVersion); }
bool CheckForNewVersion(bool force, bool closeForm = true) { var updater = new ApplicationUpdater(typeof(MainWindow)); bool isNewVersion = updater.IsNewVersionAvailable(!force); if (isNewVersion) { var res = MessageBox.Show(updater.VersionInfo.Detail + "\r\n\r\n" + "Do you want to download and install this version?", updater.VersionInfo.Title, MessageBoxButton.YesNo, MessageBoxImage.Information); if (res == MessageBoxResult.Yes) { updater.DownloadProgressChanged += (sender, e) => { WindowUtilities.DoEvents(); ShowStatus("Downloading Update: " + (e.BytesReceived / 1000).ToString("n0") + "kb of " + (e.TotalBytesToReceive / 1000).ToString("n0") + "kb"); }; ShowStatus("Downloading Update..."); WindowUtilities.DoEvents(); if (!updater.Download() || !updater.ExecuteDownloadedFile()) { MessageBox.Show("Failed to download the update file. Please install the update " + "manually from http://markdownmonster.west-wind.com/.\r\n\r\n" + updater.ErrorMessage, "Update Failed", MessageBoxButton.OK, MessageBoxImage.Exclamation); ShellUtils.GoUrl("http://markdownmonster.west-wind.com/download.aspx"); ShowStatus("Update failed...", 4000); return(false); } ShowStatus("Update download completed..."); if (closeForm) { Close(); } } } mmApp.Configuration.ApplicationUpdates.LastUpdateCheck = DateTime.UtcNow.Date; return(isNewVersion); }
/// <summary> /// Do all operation that checks for new version, brings up the change /// dialog, allows downloading etc. UI can just call this method to /// do it all. /// </summary> /// <param name="force">Forces the version check even if it was done recently. Otherwise LastChecked and Interval is used to decide if to hit the server</param> /// <param name="closeApplication">It trye forces MM to be shutdown after downloading</param> /// <param name="failTimeout">Max time to for the HTTP check to take before considering failed</param> /// <returns></returns> public static bool CheckForNewVersion(bool force, bool closeApplication = true, int failTimeout = 2000) { var updater = new ApplicationUpdater(typeof(MainWindow)); bool isNewVersion = updater.IsNewVersionAvailable(!force, timeout: failTimeout); if (isNewVersion) { var res = MessageBox.Show(updater.VersionInfo.Detail + "\r\n\r\n" + "Do you want to download and install this version?", updater.VersionInfo.Title, MessageBoxButton.YesNo, MessageBoxImage.Information); if (res == MessageBoxResult.Yes) { try { ShellUtils.GoUrl(mmApp.Urls.InstallerDownloadUrl); } catch (Exception ex) { mmApp.Log("Couldn't access update Url: " + mmApp.Urls.InstallerDownloadUrl, ex, false, logLevel: LogLevels.Error); mmApp.Model.Window.ShowStatusError( $"Unable to access update url: {mmApp.Urls.InstallerDownloadUrl}. {ex.Message}"); } if (closeApplication) { mmApp.Model.Window.Close(); } } } return(isNewVersion); }