private static void ParseAppCastXmlInfo(XmlNode item, UpdateInfoEventArgs info) { try { var versionNode = item.SelectSingleNode("version"); info.CurrentVersion = new Version(versionNode?.InnerText); } catch { info.CurrentVersion = null; } var appCastChangeLogNode = item.SelectSingleNode("changelog"); info.ChangelogURL = appCastChangeLogNode?.InnerText; var appCastUrlNode = item.SelectSingleNode("url"); info.DownloadURL = appCastUrlNode?.InnerText; var mandatoryNode = item.SelectSingleNode("mandatory"); bool mandatory; info.Mandatory = bool.TryParse(mandatoryNode?.InnerText, out mandatory) && mandatory; var appArgsNode = item.SelectSingleNode("args"); info.InstallerArgs = appArgsNode?.InnerText; var checksumNode = item.SelectSingleNode("checksum"); info.HashingAlgorithm = checksumNode?.Attributes?["algorithm"]?.InnerText; info.Checksum = checksumNode?.InnerText; }
private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args) { if (args != null) { if (args.IsUpdateAvailable) { var msg = "Update terbaru versi {0} sudah tersedia. Saat ini Anda sedang menggunakan Versi {1}\n\nApakah Anda ingin memperbarui aplikasi ini sekarang ?"; var installedVersion = string.Format("{0}.{1}.{2}", args.InstalledVersion.Major, args.InstalledVersion.Minor, args.InstalledVersion.Build); var currentVersion = string.Format("{0}.{1}.{2}", args.CurrentVersion.Major, args.CurrentVersion.Minor, args.CurrentVersion.Build); var dialogResult = MessageBox.Show(string.Format(msg, currentVersion, installedVersion), "Update Tersedia", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult.Equals(DialogResult.Yes)) { try { //You can use Download Update dialog used by AutoUpdater.NET to download the update. AutoUpdater.DownloadUpdate(); } catch (Exception exception) { MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
/// <summary> /// Opens the Download window that download the update and execute the installer when download completes. /// </summary> public static bool DownloadUpdate(UpdateInfoEventArgs args) { if (DownloadUpdateDialogType == null) { using (var downloadDialog = new DownloadUpdateDialog(args)) { try { return(downloadDialog.ShowDialog().Equals(DialogResult.OK)); } catch (TargetInvocationException) { } } return(false); } else { var form = (IForm)Activator.CreateInstance(DownloadUpdateDialogType, args); try { var ret = form.ShowDialog(); return(ret.HasValue && ret.Value == true); } catch (TargetInvocationException) { } return(false); } }
/// <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; } }
public static void Update(UpdateInfoEventArgs args) { UpdateManager updater = new UpdateManager(args); if (IsDownloadSuccessfully && DownloadedFileName != null) { updater._OnUpdateCompleted += Updater__OnUpdateCompleted; updater.Update(DownloadedFileName); } }
public DownloadUpdateDialog(UpdateInfoEventArgs args) { InitializeComponent(); _args = args; if (AutoUpdater.Mandatory && AutoUpdater.UpdateMode == Mode.ForcedDownload) { ControlBox = false; } }
/// <summary> /// Parses custom AppCast data /// </summary> /// <param name="appCastStream">Custom format of AppCast data</param> /// <returns>UpdateInfoEventArgs</returns> private static UpdateInfoEventArgs ParseAppCastCustom(Stream appCastStream) { UpdateInfoEventArgs args = null; using (var stream = new StreamReader(appCastStream)) { string appCastData = stream.ReadToEnd(); var parseArgs = new ParseUpdateInfoEventArgs(appCastData); ParseUpdateInfoEvent(parseArgs); args = parseArgs.UpdateInfo; } return(args); }
/// <summary> /// Shows standard update dialog. /// </summary> public static void ShowUpdateForm(UpdateInfoEventArgs args) { 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) { var downloadDialog = new DownloadUpdateDialog(args); try { return(downloadDialog.ShowDialog().Equals(DialogResult.OK)); } catch (TargetInvocationException) { } return(false); }
public UpdateForm(UpdateInfoEventArgs args) { _args = args; InitializeComponent(); var resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdateForm)); Text = string.Format(resources.GetString("$this.Text", CultureInfo.CurrentCulture), AutoUpdater.AppTitle, _args.CurrentVersion); labelUpdate.Text = string.Format(resources.GetString("labelUpdate.Text", CultureInfo.CurrentCulture), AutoUpdater.AppTitle); labelDescription.Text = string.Format(resources.GetString("labelDescription.Text", CultureInfo.CurrentCulture), AutoUpdater.AppTitle, _args.CurrentVersion, _args.InstalledVersion); }
/// <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 DownloadUpdateDialog(new DownloadManager(args), new UpdateManager(args))) { try { return(downloadDialog.ShowDialog().Equals(DialogResult.OK)); } catch (TargetInvocationException) { } } return(false); }
/// <summary> /// Parses known xml formatted AppCast data. /// </summary> /// <param name="appCastData">AppCast data</param> /// <returns>UpdateInfoEventArgs</returns> private static UpdateInfoEventArgs ParseAppCastXml(String appCastData) { UpdateInfoEventArgs args = null; try { XmlDocument receivedAppCastDocument = new XmlDocument(); receivedAppCastDocument.Load(appCastData); args = ParseAppCastXml(receivedAppCastDocument); } catch (Exception) { return(null); } return(args); }
public static bool DownloadSilently(UpdateInfoEventArgs args) { try { //Thread.Sleep(1000); DownloadManager downloader = new DownloadManager(args); downloader._OnDownloadFileCompleted += Downloader__OnDownloadFileCompleted; downloader.DownloadFileAsync(); return(true); } catch (TargetInvocationException) { } return(false); }
private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args) { if (args != null) { if (args.IsUpdateAvailable) { var dialogResult = MessageBox.Show( string.Format( "There is new version {0} avilable. You are using version {1}. Do you want to update the application now?", args.CurrentVersion, args.InstalledVersion), @"Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult.Equals(DialogResult.Yes)) { try { //You can use Download Update dialog used by AutoUpdater.NET to download the update. AutoUpdater.DownloadUpdate(); } catch (Exception exception) { MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(@"There is no update avilable please try again later.", @"No update available", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show( @"There is a problem reaching update server please check your internet connection and try again later.", @"Update check failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public UpdateForm(UpdateInfoEventArgs args) { _args = args; InitializeComponent(); UseLatestIE(); buttonSkip.Visible = AutoUpdater.ShowSkipButton; buttonRemindLater.Visible = AutoUpdater.ShowRemindLaterButton; var resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdateForm)); Text = string.Format(resources.GetString("$this.Text", CultureInfo.CurrentCulture), AutoUpdater.AppTitle, _args.CurrentVersion); labelUpdate.Text = string.Format(resources.GetString("labelUpdate.Text", CultureInfo.CurrentCulture), AutoUpdater.AppTitle); labelDescription.Text = string.Format(resources.GetString("labelDescription.Text", CultureInfo.CurrentCulture), AutoUpdater.AppTitle, _args.CurrentVersion, _args.InstalledVersion); if (AutoUpdater.Mandatory && AutoUpdater.UpdateMode == Mode.Forced) { ControlBox = false; } }
/// <summary> /// Gets update info. /// </summary> /// <returns>UpdateInfoEventArgs</returns> private static UpdateInfoEventArgs GetUpdateInfo() { UpdateInfoEventArgs ParseAppCast(string appCast) => ParseUpdateInfoEvent != null ? ParseAppCastCustom(appCast) : ParseAppCastXml(appCast); UpdateInfoEventArgs ParseAppCastStream(Stream appCast) => ParseUpdateInfoEvent != null ? ParseAppCastCustom(appCast) : ParseAppCastXml(appCast); UpdateInfoEventArgs args = null; if (!String.IsNullOrEmpty(AppCastData)) { args = ParseAppCast(AppCastData); } else { var webRequest = GetAppCastWebRequest(); if (webRequest != null) { try { using (var webResponse = webRequest.GetResponse()) using (var stream = webResponse.GetResponseStream()) { args = ParseAppCastStream(stream); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return(null); } } } return(args); }
/// <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 DownloadUpdateDialog(args)) { try { if (UseImpersonation) { DomainAuthentication domainAuthentication = new DomainAuthentication(ImpersonationUser, ImpersonationPassword, ImpersonationDomain); return(Impersonator.DoWorkUnderImpersonation(() => downloadDialog.ShowDialog().Equals(DialogResult.OK), domainAuthentication)); } else { return(downloadDialog.ShowDialog().Equals(DialogResult.OK)); } } catch (TargetInvocationException) { } } return(false); }
private void ExecuteUpdateXmlInfoParse(AppCast appCast, out UpdateInfoEventArgs info) { info = null; try { var appCastXmlDoc = new XmlDocument(); appCastXmlDoc.LoadXml(appCast.RemoteData); var appCastItems = appCastXmlDoc.SelectNodes("item"); if (appCastItems == null) { return; } info = new UpdateInfoEventArgs(); foreach (XmlNode item in appCastItems) { ParseAppCastXmlInfo(item, info); } Logger.Info(States.AppCastXmlInfoParseDone); } catch (Exception exc) { throw new UpdaterException(States.AppCastXmlInfoParseError, exception: exc); } }
private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { e.Cancel = true; Assembly mainAssembly = e.Argument as Assembly; var companyAttribute = (AssemblyCompanyAttribute)ApplicationHelper.GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); if (string.IsNullOrEmpty(AppTitle)) { var titleAttribute = (AssemblyTitleAttribute)ApplicationHelper.GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute)); AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name; } string appCompany = companyAttribute != null ? companyAttribute.Company : ""; RegistryLocation = !string.IsNullOrEmpty(appCompany) ? $@"Software\{appCompany}\{AppTitle}\AutoUpdater" : $@"Software\{AppTitle}\AutoUpdater"; //InstalledVersion = mainAssembly.GetName().Version; InstalledVersion = ApplicationHelper.GetInstallVersion(); var webRequest = WebRequest.Create(AppCastURL); webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); if (Proxy != null) { webRequest.Proxy = Proxy; } WebResponse webResponse; try { webResponse = webRequest.GetResponse(); } catch (Exception) { e.Cancel = false; return; } UpdateInfoEventArgs args; using (Stream appCastStream = webResponse.GetResponseStream()) { if (appCastStream != null) { if (ParseUpdateInfoEvent != null) { using (StreamReader streamReader = new StreamReader(appCastStream)) { string data = streamReader.ReadToEnd(); ParseUpdateInfoEventArgs parseArgs = new ParseUpdateInfoEventArgs(data); ParseUpdateInfoEvent(parseArgs); args = parseArgs.UpdateInfo; } } else { XmlDocument receivedAppCastDocument = new XmlDocument(); try { receivedAppCastDocument.Load(appCastStream); XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item"); args = new UpdateInfoEventArgs(); if (appCastItems != null) { foreach (XmlNode item in appCastItems) { XmlNode appCastVersion = item.SelectSingleNode("version"); try { CurrentVersion = new Version(appCastVersion?.InnerText); } catch (Exception) { CurrentVersion = null; } args.CurrentVersion = CurrentVersion; XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); args.ChangelogURL = appCastChangeLog?.InnerText; XmlNode appCastUrl = item.SelectSingleNode("url"); args.DownloadURL = appCastUrl?.InnerText; if (Mandatory.Equals(false)) { XmlNode mandatory = item.SelectSingleNode("mandatory"); Boolean.TryParse(mandatory?.InnerText, out Mandatory); } args.Mandatory = Mandatory; XmlNode appArgs = item.SelectSingleNode("args"); XmlNode restart = item.SelectSingleNode("restart"); if (restart != null && restart.InnerText.Equals("true", StringComparison.InvariantCultureIgnoreCase)) { NeedRestart = true; } args.InstallerArgs = appArgs?.InnerText; XmlNode checksum = item.SelectSingleNode("checksum"); args.HashingAlgorithm = checksum?.Attributes["algorithm"]?.InnerText; args.Checksum = checksum?.InnerText; } } } catch (XmlException) { e.Cancel = false; webResponse.Close(); return; } } } else { e.Cancel = false; webResponse.Close(); return; } } if (args.CurrentVersion == null || string.IsNullOrEmpty(args.DownloadURL)) { webResponse.Close(); if (ReportErrors) { throw new InvalidDataException(); } return; } CurrentVersion = args.CurrentVersion; ChangelogURL = args.ChangelogURL = WebHelper.GetURL(webResponse.ResponseUri, args.ChangelogURL); DownloadURL = args.DownloadURL = WebHelper.GetURL(webResponse.ResponseUri, args.DownloadURL); Mandatory = args.Mandatory; InstallerArgs = args.InstallerArgs ?? String.Empty; HashingAlgorithm = args.HashingAlgorithm ?? "MD5"; Checksum = args.Checksum ?? String.Empty; webResponse.Close(); if (Mandatory) { ShowRemindLaterButton = false; ShowSkipButton = false; } else { using (RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation)) { 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) { using (RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation)) { if (updateKeyWrite != null) { updateKeyWrite.SetValue("version", CurrentVersion.ToString()); updateKeyWrite.SetValue("skip", 0); } } } } object remindLaterTime = updateKey.GetValue("remindlater"); if (remindLaterTime != null) { DateTime remindLater = Convert.ToDateTime(remindLaterTime.ToString(), CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat); int compareResult = DateTime.Compare(DateTime.Now, remindLater); if (compareResult < 0) { e.Cancel = false; e.Result = remindLater; return; } } } } } args.IsUpdateAvailable = CurrentVersion > InstalledVersion; args.InstalledVersion = InstalledVersion; if (UpdateChanged != null && !args.IsUpdateAvailable) { UpdateChanged(args.IsUpdateAvailable); } e.Cancel = false; e.Result = args; }
/// <summary> /// Parses known xml formatted AppCast data. /// </summary> /// <param name="appCastXmlDoc">AppCast data xml document</param> /// <returns>UpdateInfoEventArgs</returns> private static UpdateInfoEventArgs ParseAppCastXml(XmlDocument appCastXmlDoc) { XmlNodeList appCastItems = appCastXmlDoc.SelectNodes("item"); var args = new UpdateInfoEventArgs(); if (appCastItems != null) { foreach (XmlNode item in appCastItems) { XmlNode appCastVersion = item.SelectSingleNode("version"); try { CurrentVersion = new Version(appCastVersion?.InnerText); } catch (Exception) { CurrentVersion = null; } args.CurrentVersion = CurrentVersion; XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); args.ChangelogURL = appCastChangeLog?.InnerText; XmlNode appCastUrl = item.SelectSingleNode("url"); args.DownloadURL = appCastUrl?.InnerText; if (Mandatory.Equals(false)) { XmlNode mandatory = item.SelectSingleNode("mandatory"); Boolean.TryParse(mandatory?.InnerText, out Mandatory); string mode = mandatory?.Attributes["mode"]?.InnerText; if (!string.IsNullOrEmpty(mode)) { UpdateMode = (Mode)Enum.Parse(typeof(Mode), mode); if (ReportErrors && !Enum.IsDefined(typeof(Mode), UpdateMode)) { throw new InvalidDataException( $"{UpdateMode} is not an underlying value of the Mode enumeration."); } } } args.Mandatory = Mandatory; args.UpdateMode = UpdateMode; XmlNode appArgs = item.SelectSingleNode("args"); args.InstallerArgs = appArgs?.InnerText; XmlNode checksum = item.SelectSingleNode("checksum"); args.HashingAlgorithm = checksum?.Attributes["algorithm"]?.InnerText; args.Checksum = checksum?.InnerText; } } return(args); }
public UpdateManager(UpdateInfoEventArgs args) { _args = args; }
private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { e.Cancel = true; Assembly mainAssembly = e.Argument as Assembly; var companyAttribute = (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); if (string.IsNullOrEmpty(AppTitle)) { 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) ? $@"Software\{appCompany}\{AppTitle}\AutoUpdater" : $@"Software\{AppTitle}\AutoUpdater"; InstalledVersion = mainAssembly.GetName().Version; WebRequest webRequest = WebRequest.Create(AppCastURL); webRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); if (Proxy != null) { webRequest.Proxy = Proxy; } var uri = new Uri(AppCastURL); WebResponse webResponse; try { if (uri.Scheme.Equals(Uri.UriSchemeFtp)) { var ftpWebRequest = (FtpWebRequest)webRequest; ftpWebRequest.Credentials = FtpCredentials; ftpWebRequest.UseBinary = true; ftpWebRequest.UsePassive = true; ftpWebRequest.KeepAlive = true; ftpWebRequest.Method = WebRequestMethods.Ftp.DownloadFile; webResponse = ftpWebRequest.GetResponse(); } else if (uri.Scheme.Equals(Uri.UriSchemeHttp) || uri.Scheme.Equals(Uri.UriSchemeHttps)) { HttpWebRequest httpWebRequest = (HttpWebRequest)webRequest; httpWebRequest.UserAgent = GetUserAgent(); if (BasicAuthXML != null) { httpWebRequest.Headers[HttpRequestHeader.Authorization] = BasicAuthXML.ToString(); } webResponse = httpWebRequest.GetResponse(); } else { webResponse = webRequest.GetResponse(); } } catch (Exception exception) { Debug.WriteLine(exception); e.Cancel = false; return; } UpdateInfoEventArgs args; using (Stream appCastStream = webResponse.GetResponseStream()) { if (appCastStream != null) { if (ParseUpdateInfoEvent != null) { using (StreamReader streamReader = new StreamReader(appCastStream)) { string data = streamReader.ReadToEnd(); ParseUpdateInfoEventArgs parseArgs = new ParseUpdateInfoEventArgs(data); ParseUpdateInfoEvent(parseArgs); args = parseArgs.UpdateInfo; } } else { XmlDocument receivedAppCastDocument = new XmlDocument(); try { receivedAppCastDocument.Load(appCastStream); XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item"); args = new UpdateInfoEventArgs(); if (appCastItems != null) { foreach (XmlNode item in appCastItems) { XmlNode appCastVersion = item.SelectSingleNode("version"); try { CurrentVersion = new Version(appCastVersion?.InnerText); } catch (Exception) { CurrentVersion = null; } args.CurrentVersion = CurrentVersion; XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); args.ChangelogURL = appCastChangeLog?.InnerText; XmlNode appCastUrl = item.SelectSingleNode("url"); args.DownloadURL = appCastUrl?.InnerText; if (Mandatory.Equals(false)) { XmlNode mandatory = item.SelectSingleNode("mandatory"); Boolean.TryParse(mandatory?.InnerText, out Mandatory); string mode = mandatory?.Attributes["mode"]?.InnerText; if (!string.IsNullOrEmpty(mode)) { UpdateMode = (Mode)Enum.Parse(typeof(Mode), mode); if (ReportErrors && !Enum.IsDefined(typeof(Mode), UpdateMode)) { throw new InvalidDataException( $"{UpdateMode} is not an underlying value of the Mode enumeration."); } } } args.Mandatory = Mandatory; args.UpdateMode = UpdateMode; XmlNode appArgs = item.SelectSingleNode("args"); args.InstallerArgs = appArgs?.InnerText; XmlNode checksum = item.SelectSingleNode("checksum"); args.HashingAlgorithm = checksum?.Attributes["algorithm"]?.InnerText; args.Checksum = checksum?.InnerText; } } } catch (XmlException) { e.Cancel = false; webResponse.Close(); return; } } } else { e.Cancel = false; webResponse.Close(); return; } } if (args.CurrentVersion == null || string.IsNullOrEmpty(args.DownloadURL)) { webResponse.Close(); if (ReportErrors) { throw new InvalidDataException(); } return; } CurrentVersion = args.CurrentVersion; ChangelogURL = args.ChangelogURL = GetURL(webResponse.ResponseUri, args.ChangelogURL); DownloadURL = args.DownloadURL = GetURL(webResponse.ResponseUri, args.DownloadURL); InstallerArgs = args.InstallerArgs ?? String.Empty; HashingAlgorithm = args.HashingAlgorithm ?? "MD5"; Checksum = args.Checksum ?? String.Empty; webResponse.Close(); if (Mandatory) { ShowRemindLaterButton = false; ShowSkipButton = false; } else { using (RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation)) { 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) { using (RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation)) { if (updateKeyWrite != null) { updateKeyWrite.SetValue("version", CurrentVersion.ToString()); updateKeyWrite.SetValue("skip", 0); } } } } object remindLaterTime = updateKey.GetValue("remindlater"); if (remindLaterTime != null) { DateTime remindLater = Convert.ToDateTime(remindLaterTime.ToString(), CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat); int compareResult = DateTime.Compare(DateTime.Now, remindLater); if (compareResult < 0) { e.Cancel = false; e.Result = remindLater; return; } } } } } args.IsUpdateAvailable = CurrentVersion > InstalledVersion; args.InstalledVersion = InstalledVersion; e.Cancel = false; e.Result = args; }
private bool GetTheAppCastInformation(string appCastUrl, IWebProxy proxy, ParseUpdateInfoHandler parseUpdateInfoHandler, out UpdateInfoEventArgs info) { info = null; var appCast = RetrieveTheAppCast(appCastUrl, proxy); Logger.Info(States.AppCastRetrievalDone, $"baseUri:[{appCast.BaseUri}]\nremoteData:{appCast.RemoteData}"); try { if (parseUpdateInfoHandler != null) { ExecuteUpdateCustomInfoParseEven(appCast, parseUpdateInfoHandler, out info); } else { ExecuteUpdateXmlInfoParse(appCast, out info); } } catch (Exception e) { throw new UpdaterException(States.AppCastInvalidDataError, exception: e); } if (info.CurrentVersion == null || string.IsNullOrEmpty(info.DownloadURL)) { throw new UpdaterException(States.AppCastInvalidDataError); } Logger.Info(States.AppCastDataValidationDone); info.DownloadURL = GetURL(appCast.BaseUri, info.DownloadURL); info.ChangelogURL = GetURL(appCast.BaseUri, info.ChangelogURL); return(true); }
private void ExecuteUpdateCustomInfoParseEven(AppCast appCast, ParseUpdateInfoHandler parseUpdateInfoHandler, out UpdateInfoEventArgs info) { info = null; try { var parseArgs = new ParseUpdateInfoEventArgs(appCast.RemoteData); CallSync(s => parseUpdateInfoHandler((ParseUpdateInfoEventArgs)s), parseArgs); info = parseArgs.UpdateInfo; Logger.Info(States.AppCastCustomInfoParseEventDone); } catch (Exception e) { throw new UpdaterException(States.AppCastCustomInfoParseEventError, exception: e); } }
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) { UpdateInfoEventArgs args = null; if (!runWorkerCompletedEventArgs.Cancelled) { if (runWorkerCompletedEventArgs.Result is DateTime remindLaterTime) { SetTimer(remindLaterTime); } else { args = runWorkerCompletedEventArgs.Result as UpdateInfoEventArgs; //if (CheckForUpdateEvent != null) //{ // CheckForUpdateEvent(args); //} // else { if (args != null) { if (args.IsUpdateAvailable) { if (!IsWinFormsApplication) { Application.EnableVisualStyles(); } if (Thread.CurrentThread.GetApartmentState().Equals(ApartmentState.STA)) { if (!RestartNecessary) { DownloadUpdate(); } else { ShowUpdateForm(); } } else { Thread thread = new Thread(ShowUpdateForm); thread.CurrentCulture = thread.CurrentUICulture = CultureInfo.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; if (CheckForUpdateEvent != null) { CheckForUpdateEvent(args); } }
private static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { e.Cancel = true; Assembly mainAssembly = e.Argument as Assembly; var companyAttribute = (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute)); if (string.IsNullOrEmpty(AppTitle)) { 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) ? $@"Software\{appCompany}\{AppTitle}\AutoUpdater" : $@"Software\{AppTitle}\AutoUpdater"; InstalledVersion = mainAssembly.GetName().Version; var webRequest = WebRequest.Create(AppCastURL); webRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); WebResponse webResponse; try { webResponse = webRequest.GetResponse(); } catch (Exception) { e.Cancel = false; return; } XmlDocument receivedAppCastDocument; using (Stream appCastStream = webResponse.GetResponseStream()) { receivedAppCastDocument = new XmlDocument(); if (appCastStream != null) { receivedAppCastDocument.Load(appCastStream); } else { e.Cancel = false; webResponse.Close(); 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) { webResponse.Close(); return; } } else { continue; } XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); ChangeLogURL = GetURL(webResponse.ResponseUri, appCastChangeLog); XmlNode appCastUrl = item.SelectSingleNode("url"); DownloadURL = GetURL(webResponse.ResponseUri, appCastUrl); XmlNode mandatory = item.SelectSingleNode("mandatory"); if (mandatory != null) { Mandatory = Boolean.Parse(mandatory.InnerText); if (Mandatory) { ShowRemindLaterButton = false; ShowSkipButton = false; } } if (IntPtr.Size.Equals(8)) { XmlNode appCastUrl64 = item.SelectSingleNode("url64"); var downloadURL64 = GetURL(webResponse.ResponseUri, appCastUrl64); if (!string.IsNullOrEmpty(downloadURL64)) { DownloadURL = downloadURL64; } } } } webResponse.Close(); if (!Mandatory) { using (RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(RegistryLocation)) { 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) { using (RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(RegistryLocation)) { if (updateKeyWrite != null) { updateKeyWrite.SetValue("version", CurrentVersion.ToString()); updateKeyWrite.SetValue("skip", 0); } } } } 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) { e.Cancel = false; e.Result = remindLater; return; } } } } } var args = new UpdateInfoEventArgs { DownloadURL = DownloadURL, ChangelogURL = ChangeLogURL, CurrentVersion = CurrentVersion, InstalledVersion = InstalledVersion, IsUpdateAvailable = CurrentVersion > InstalledVersion }; e.Cancel = false; e.Result = args; }
public DownloadManager(UpdateInfoEventArgs args) { _args = args; Init(); }
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); } 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 (IntPtr.Size.Equals(8)) { XmlNode appCastUrl64 = item.SelectSingleNode("url64"); var downloadURL64 = appCastUrl64 != null ? appCastUrl64.InnerText : ""; 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(); } if (CurrentVersion == null) return; 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); } }