/// <summary> /// Shows standard update dialog. /// </summary> public static void ShowUpdateForm(UpdateInfoEventArgs args) { if (UpdateFormType == null) { using (var updateForm = new UpdateForm(args)) { if (UpdateFormSize.HasValue) { updateForm.Size = UpdateFormSize.Value; } if (updateForm.ShowDialog().Equals(DialogResult.OK)) { Exit(); } } } else { var form = (IForm)Activator.CreateInstance(UpdateFormType, args); var ret = form.ShowDialog(); if (ret.HasValue && ret.Value == true) { Exit(); } Running = false; } }
private static void ShowUI() { var updateForm = new UpdateForm(); CultureInfo ci = Thread.CurrentThread.CurrentUICulture; updateForm.ShowDialog(); }
private static void ShowUpdateForm() { var updateForm = new UpdateForm(); if (updateForm.ShowDialog().Equals(DialogResult.OK)) { Exit(); } }
private static void ShowUI() { Task.Run(() => { var updateForm = new UpdateForm(); updateForm.ShowDialog(); updateForm.Dispose(); }); }
/// <summary> /// Shows standard update dialog. /// </summary> public static void ShowUpdateForm() { var updateForm = new UpdateForm(); if (UpdateFormSize.HasValue) { updateForm.Size = UpdateFormSize.Value; } if (updateForm.ShowDialog().Equals(DialogResult.OK)) { Exit(); } }
/// <summary> /// Shows standard update dialog. /// </summary> public static void ShowUpdateForm(UpdateInfoEventArgs args) { using (var updateForm = new UpdateForm(args)) { if (UpdateFormSize.HasValue) { updateForm.Size = UpdateFormSize.Value; } if (updateForm.ShowDialog().Equals(DialogResult.OK)) { Exit(); } } }
/// <summary> /// Opens the Download window that download the update and execute the installer when download completes. /// </summary> public static bool DownloadUpdate(UpdateInfoEventArgs args) { using (var downloadDialog = new UpdateForm(args)) { try { return(downloadDialog.ShowDialog().Equals(DialogResult.OK)); } catch (TargetInvocationException) { } } return(false); }
public static void ShowUpdateForm() { var updateForm = new UpdateForm(); var dialogResult = updateForm.ShowDialog(); if (UpdateFormClosedEvent != null) { UpdateFormClosedEvent(new UpdateFormClosedEventArgs(dialogResult)); } if (dialogResult.Equals(DialogResult.OK)) { Exit(); } }
/// <summary> /// Shows standard update dialog. /// <paramref name="updateOK">Download result.</paramref> /// </summary> public static void ShowUpdateForm(ref bool updateOK) { using (var updateForm = new UpdateForm()) { if (UpdateFormSize.HasValue) { updateForm.Size = UpdateFormSize.Value; } if (updateForm.ShowDialog().Equals(DialogResult.OK)) { updateOK = true; Exit(); return; } updateOK = false; } }
private static void ShowUpdateForm() { if (Mandatory) { if (DownloadUpdate()) { if (NeedRestart) { Exit(); } } } else { var updateForm = new UpdateForm(); if (updateForm.ShowDialog().Equals(DialogResult.OK)) { if (NeedRestart) { Exit(); } } } }
private static void ShowUI() { var updateForm = new UpdateForm(); updateForm.ShowDialog(); }
private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { int compareResult; AutoUpdateEventArgs args = new AutoUpdateEventArgs(); TraceWriteLine("Beginning AutoUpdater worker"); Thread.CurrentThread.CurrentUICulture = CurrentCulture; var mainAssembly = Assembly.GetEntryAssembly(); var companyAttribute = (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); var titleAttribute = (AssemblyTitleAttribute)GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute)); AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name; var appCompany = companyAttribute != null ? companyAttribute.Company : ""; int days = (int)e.Argument; RegistryLocation = string.Format(@"Software\{0}\{1}\AutoUpdater", appCompany, AppTitle); RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation, true) ?? Registry.CurrentUser.CreateSubKey(RegistryLocation); object remindLaterTime = updateKey.GetValue("remindlater"); if (remindLaterTime == null && days > 0) { string lastcheck = updateKey.GetValue("lastcheck", "").ToString(); if (!String.IsNullOrEmpty(lastcheck)) { try { DateTime lastcheckDate = Convert.ToDateTime(lastcheck, CultureInfo.InvariantCulture); compareResult = DateTime.Compare(DateTime.Now, lastcheckDate.AddDays(days)); if (compareResult < 0) { args.Status = AutoUpdateEventArgs.StatusCodes.delayed; args.Text = string.Format(Strings.sLastCheck, lastcheckDate.ToString("D", CurrentCulture)); OnUpdateStatus(args); return; } } catch (Exception ex) { TraceWriteLine("AutoUpdater(175)::" + ex.Message); } } } if (remindLaterTime != null && days > 0) { try { DateTime remindLater = Convert.ToDateTime(remindLaterTime.ToString(), CultureInfo.InvariantCulture); compareResult = DateTime.Compare(DateTime.Now, remindLater); if (compareResult < 0) { var updateForm = new UpdateForm(true); updateForm.SetTimer(remindLater); return; } } catch (Exception ex) { TraceWriteLine("AutoUpdater(198)::" + ex.Message); } } if (remindLaterTime != null) { updateKey.DeleteValue("remindlater"); } InstalledVersion = mainAssembly.GetName().Version; args.Status = AutoUpdateEventArgs.StatusCodes.checking; args.Text = Strings.sCheckingForUpdates; OnUpdateStatus(args); WebRequest webRequest = WebRequest.Create(AppCastURL); webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); WebResponse webResponse; try { webResponse = webRequest.GetResponse(); } catch (Exception ex) { args.Status = AutoUpdateEventArgs.StatusCodes.error; args.Text = ex.Message; OnUpdateStatus(args); return; } Stream appCastStream = webResponse.GetResponseStream(); var receivedAppCastDocument = new XmlDocument(); if (appCastStream != null) { receivedAppCastDocument.Load(appCastStream); } else { TraceWriteLine("AutoUpdater(234)::return"); return; } XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("channel/item"); if (appCastItems != null) { foreach (XmlNode item in appCastItems) { XmlNode appCastVersion = item.SelectSingleNode("version"); if (appCastVersion != null) { String appVersion = appCastVersion.InnerText; AvailableVersion = new Version(appVersion); XmlNode appCastTitle = item.SelectSingleNode("title"); DialogTitle = appCastTitle != null ? appCastTitle.InnerText : ""; XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); ChangeLogURL = appCastChangeLog != null ? appCastChangeLog.InnerText : ""; XmlNode appCastUrl = item.SelectSingleNode("url"); DownloadURL = appCastUrl != null ? appCastUrl.InnerText : ""; } } } object skip = updateKey.GetValue("skip"); object applicationVersion = updateKey.GetValue("version"); if (skip != null && applicationVersion != null) { string skipValue = skip.ToString(); var skipVersion = new Version(applicationVersion.ToString()); if (skipValue.Equals("1") && InstalledVersion == skipVersion) { args.Status = AutoUpdateEventArgs.StatusCodes.noUpdateAvailable; args.Text = Strings.sSkipping; OnUpdateStatus(args); return; } if (InstalledVersion > skipVersion) { RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation); if (updateKeyWrite != null) { updateKeyWrite.SetValue("version", InstalledVersion.ToString()); updateKeyWrite.SetValue("skip", 0); } } } updateKey.SetValue("lastcheck", DateTime.Now.ToString(CultureInfo.InvariantCulture)); updateKey.Close(); RunBrowserThread(versionURL); #if DEBUG if (force) { args.Status = AutoUpdateEventArgs.StatusCodes.updateAvailable; args.Text = Strings.sUpdateAvailable; OnUpdateStatus(args); var thread = new Thread(ShowUI); thread.CurrentCulture = thread.CurrentUICulture = CurrentCulture ?? Application.CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); return; } #endif if (InstalledVersion >= AvailableVersion) { args.Status = AutoUpdateEventArgs.StatusCodes.noUpdateAvailable; args.Text = Strings.sLatestVersion; OnUpdateStatus(args); return; } args.Status = AutoUpdateEventArgs.StatusCodes.updateAvailable; args.Text = Strings.sUpdateAvailable; OnUpdateStatus(args); if (days == 0) { var thread = new Thread(ShowUI); thread.CurrentCulture = thread.CurrentUICulture = CurrentCulture ?? Application.CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); } }
private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { Assembly mainAssembly = Assembly.GetEntryAssembly(); var companyAttribute = (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); var titleAttribute = (AssemblyTitleAttribute)GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute)); AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name; string appCompany = companyAttribute != null ? companyAttribute.Company : ""; RegistryLocation = !string.IsNullOrEmpty(appCompany) ? string.Format(@"Software\{0}\{1}\AutoUpdater", appCompany, AppTitle) : string.Format(@"Software\{0}\AutoUpdater", AppTitle); RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation); if (updateKey != null) { object remindLaterTime = updateKey.GetValue("remindlater"); if (remindLaterTime != null) { DateTime remindLater = Convert.ToDateTime(remindLaterTime.ToString(), CultureInfo.CreateSpecificCulture("en-US")); int compareResult = DateTime.Compare(DateTime.Now, remindLater); if (compareResult < 0) { var updateForm = new UpdateForm(true); updateForm.SetTimer(remindLater); return; } } } InstalledVersion = mainAssembly.GetName().Version; WebRequest webRequest = WebRequest.Create(AppCastURL); webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); WebResponse webResponse; try { webResponse = webRequest.GetResponse(); } catch (Exception) { if (CheckForUpdateEvent != null) { CheckForUpdateEvent(null); } return; } Stream appCastStream = webResponse.GetResponseStream(); var receivedAppCastDocument = new XmlDocument(); if (appCastStream != null) { receivedAppCastDocument.Load(appCastStream); } else { if (CheckForUpdateEvent != null) { CheckForUpdateEvent(null); } return; } XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item"); if (appCastItems != null) { foreach (XmlNode item in appCastItems) { XmlNode appCastVersion = item.SelectSingleNode("version"); if (appCastVersion != null) { String appVersion = appCastVersion.InnerText; CurrentVersion = new Version(appVersion); if (CurrentVersion == null) { return; } } else { continue; } XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); ChangeLogURL = GetURL(webResponse.ResponseUri, appCastChangeLog); XmlNode appCastUrl = item.SelectSingleNode("url"); DownloadURL = GetURL(webResponse.ResponseUri, appCastUrl); if (IntPtr.Size.Equals(8)) { XmlNode appCastUrl64 = item.SelectSingleNode("url64"); var downloadURL64 = GetURL(webResponse.ResponseUri, appCastUrl64); if (!string.IsNullOrEmpty(downloadURL64)) { DownloadURL = downloadURL64; } } } } if (updateKey != null) { object skip = updateKey.GetValue("skip"); object applicationVersion = updateKey.GetValue("version"); if (skip != null && applicationVersion != null) { string skipValue = skip.ToString(); var skipVersion = new Version(applicationVersion.ToString()); if (skipValue.Equals("1") && CurrentVersion <= skipVersion) { return; } if (CurrentVersion > skipVersion) { RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation); if (updateKeyWrite != null) { updateKeyWrite.SetValue("version", CurrentVersion.ToString()); updateKeyWrite.SetValue("skip", 0); } } } updateKey.Close(); } var args = new UpdateInfoEventArgs { DownloadURL = DownloadURL, ChangelogURL = ChangeLogURL, CurrentVersion = CurrentVersion, InstalledVersion = InstalledVersion, IsUpdateAvailable = false, }; if (CurrentVersion > InstalledVersion) { args.IsUpdateAvailable = true; if (CheckForUpdateEvent == null) { var thread = new Thread(ShowUI); thread.CurrentCulture = thread.CurrentUICulture = CurrentCulture ?? Application.CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); } } if (CheckForUpdateEvent != null) { CheckForUpdateEvent(args); } }
private static void BackgroundWorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) { if (!runWorkerCompletedEventArgs.Cancelled) { if (runWorkerCompletedEventArgs.Result is DateTime) { var remindLaterTime = (DateTime)runWorkerCompletedEventArgs.Result; SetTimer(remindLaterTime); } else { var args = runWorkerCompletedEventArgs.Result as UpdateInfoEventArgs; if (CheckForUpdateEvent != null) { CheckForUpdateEvent(args); } else { if (args != null) { if (args.IsUpdateAvailable) { if (!IsWinFormsApplication) { Application.EnableVisualStyles(); } Thread thread = new Thread(new ThreadStart(delegate { var updateForm = new UpdateForm(); if (updateForm.ShowDialog().Equals(DialogResult.OK)) { Exit(); } })); thread.CurrentCulture = thread.CurrentUICulture = CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); return; } else { if (ReportErrors) { MessageBox.Show(Resources.UpdateUnavailableMessage, Resources.UpdateUnavailableCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { if (ReportErrors) { MessageBox.Show( Resources.UpdateCheckFailedMessage, Resources.UpdateCheckFailedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } Running = false; } } }
private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { var mainAssembly = Assembly.GetEntryAssembly(); var companyAttribute = (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); var titleAttribute = (AssemblyTitleAttribute)GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute)); AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name; var appCompany = companyAttribute != null ? companyAttribute.Company : ""; RegistryLocation = !string.IsNullOrEmpty(appCompany) ? string.Format(@"Software\{0}\{1}\AutoUpdater", appCompany, AppTitle) : string.Format(@"Software\{0}\AutoUpdater", AppTitle); RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation); if (updateKey != null && ForceCheck == false) { object remindLaterTime = updateKey.GetValue("remindlater"); if (remindLaterTime != null) { DateTime remindLater = Convert.ToDateTime(remindLaterTime.ToString(), CultureInfo.CreateSpecificCulture("en-US")); int compareResult = DateTime.Compare(DateTime.Now, remindLater); if (compareResult < 0) { var updateForm = new UpdateForm(true); updateForm.SetTimer(remindLater); return; } } } var fileVersionAttribute = (AssemblyFileVersionAttribute)GetAttribute(mainAssembly, typeof(AssemblyFileVersionAttribute)); InstalledVersion = new Version(fileVersionAttribute.Version); WebRequest webRequest = WebRequest.Create(AppCastURL); webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); WebResponse webResponse; try { webResponse = webRequest.GetResponse(); } catch (Exception) { return; } Stream appCastStream = webResponse.GetResponseStream(); var receivedAppCastDocument = new XmlDocument(); if (appCastStream != null) { receivedAppCastDocument.Load(appCastStream); } else { return; } XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item"); if (appCastItems != null) { foreach (XmlNode item in appCastItems) { XmlNode appCastVersion = item.SelectSingleNode("version"); if (appCastVersion != null) { String appVersion = appCastVersion.InnerText; var version = new Version(appVersion); if (version <= InstalledVersion) { continue; } CurrentVersion = version; } else { continue; } XmlNode appCastTitle = item.SelectSingleNode("title"); DialogTitle = appCastTitle != null ? appCastTitle.InnerText : ""; XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); ChangeLogURL = appCastChangeLog != null ? appCastChangeLog.InnerText : ""; XmlNode appCastUrl = item.SelectSingleNode("url"); DownloadURL = appCastUrl != null ? appCastUrl.InnerText : ""; } } if (updateKey != null) { object skip = updateKey.GetValue("skip"); object applicationVersion = updateKey.GetValue("version"); if (skip != null && applicationVersion != null) { string skipValue = skip.ToString(); var skipVersion = new Version(applicationVersion.ToString()); if (skipValue.Equals("1") && CurrentVersion <= skipVersion) { return; } if (CurrentVersion > skipVersion) { RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation); if (updateKeyWrite != null) { updateKeyWrite.SetValue("version", CurrentVersion.ToString()); updateKeyWrite.SetValue("skip", 0); } } } updateKey.Close(); } if (CurrentVersion != null && CurrentVersion > InstalledVersion) { var thread = new Thread(ShowUI); thread.CurrentCulture = thread.CurrentUICulture = CurrentCulture ?? System.Windows.Forms.Application.CurrentCulture; thread.SetApartmentState(ApartmentState.STA); thread.Start(); } else if (ForceCheck == true) { System.Windows.Forms.MessageBox.Show(Properties.Resources.updateLatest, Properties.Resources.updateTitle, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } }
private static void ShowUi() { var updateForm = new UpdateForm(_title, _appCastUrl, _appTitle, _currentVersion, _installedVersion, _changeLogUrl, _downloadUrl, _registryLocation, _remindLaterAt, _remindLaterFormat, _letUserSelectRemindLater); updateForm.ShowDialog(); }