public static ApplicationRelease CheckForUpdates(Version currentVersion, bool dontIgnore = false) { if (!dontIgnore) { if (GlobalSettings.Default.AlwaysCheckForUpdates.HasValue && !GlobalSettings.Default.AlwaysCheckForUpdates.Value) { return(null); } #if DEBUG // Skip the load check, as it may take a few seconds during development. if (Debugger.IsAttached) { return(null); } #endif } // Accessing GitHub API directly for updates. GitHubClient client = new GitHubClient(new ProductHeaderValue("SEToolbox-Updater")); Release latest = client.Repository.Release.GetLatest("midspace", "SEToolbox").Result; var item = new ApplicationRelease { Name = latest.Name, Link = latest.HtmlUrl, Version = GetVersion(latest.TagName) }; Version ignoreVersion; Version.TryParse(GlobalSettings.Default.IgnoreUpdateVersion, out ignoreVersion); if (item.Version > currentVersion && item.Version != ignoreVersion || dontIgnore) { return(item); } return(null); }
public static ApplicationRelease CheckForUpdates(CodeRepositoryType repositoryType, string updatesUrl) { if (GlobalSettings.Default.AlwaysCheckForUpdates.HasValue && !GlobalSettings.Default.AlwaysCheckForUpdates.Value) { return(null); } #if DEBUG // Skip the load check, as it may take a few seconds during development. if (Debugger.IsAttached) { return(null); } #endif var currentVersion = GlobalSettings.GetAppVersion(); string webContent; string link; // Create the WebClient with Proxy Credentials. using (var webclient = new MyWebClient()) { try { if (webclient.Proxy != null) { // For Proxy servers on Corporate networks. webclient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials; } } catch { // Reading from the Proxy may cause a network releated error. // Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section. } webclient.Headers.Add(HttpRequestHeader.UserAgent, string.Format("Mozilla/5.0 ({0}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36", Environment.OSVersion)); // Crude useragent. try { webContent = webclient.DownloadString(updatesUrl); } catch { // Ignore any errors. // If it cannot connect, then there may be an intermittant connection issue, either with the internet, or the website itself. return(null); } if (string.IsNullOrEmpty(webContent)) { return(null); } // link should be in the form "http://setoolbox.codeplex.com/releases/view/120855" link = webclient.ResponseUri == null ? null : webclient.ResponseUri.AbsoluteUri; } string pattern = ""; if (repositoryType == CodeRepositoryType.CodePlex) { pattern = CodePlexPattern; } if (repositoryType == CodeRepositoryType.GitHub) { pattern = GitHubPattern; } var match = Regex.Match(webContent, pattern); if (!match.Success) { return(null); } var item = new ApplicationRelease { Link = link, Version = GetVersion(match.Groups["version"].Value) }; Version ignoreVersion; Version.TryParse(GlobalSettings.Default.IgnoreUpdateVersion, out ignoreVersion); if (item.Version > currentVersion && item.Version != ignoreVersion) { return(item); } return(null); }
public static ApplicationRelease CheckForUpdates(CodeRepositoryType repositoryType, string updatesUrl) { if (GlobalSettings.Default.AlwaysCheckForUpdates.HasValue && !GlobalSettings.Default.AlwaysCheckForUpdates.Value) return null; #if DEBUG // Skip the load check, as it may take a few seconds during development. if (Debugger.IsAttached) return null; #endif var currentVersion = GlobalSettings.GetAppVersion(); string webContent; string link; // Create the WebClient with Proxy Credentials. using (var webclient = new MyWebClient()) { try { if (webclient.Proxy != null) { // For Proxy servers on Corporate networks. webclient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials; } } catch { // Reading from the Proxy may cause a network releated error. // Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section. } webclient.Headers.Add(HttpRequestHeader.UserAgent, string.Format("Mozilla/5.0 ({0}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36", Environment.OSVersion)); // Crude useragent. try { webContent = webclient.DownloadString(updatesUrl); } catch { // Ignore any errors. // If it cannot connect, then there may be an intermittant connection issue, either with the internet, or the website itself. return null; } if (string.IsNullOrEmpty(webContent)) return null; // link should be in the form "http://setoolbox.codeplex.com/releases/view/120855" link = webclient.ResponseUri == null ? null : webclient.ResponseUri.AbsoluteUri; } string pattern = ""; if (repositoryType == CodeRepositoryType.CodePlex) pattern = CodePlexPattern; if (repositoryType == CodeRepositoryType.GitHub) pattern = GitHubPattern; var match = Regex.Match(webContent, pattern); if (!match.Success) return null; var item = new ApplicationRelease { Link = link, Version = GetVersion(match.Groups["version"].Value) }; Version ignoreVersion; Version.TryParse(GlobalSettings.Default.IgnoreUpdateVersion, out ignoreVersion); if (item.Version > currentVersion && item.Version != ignoreVersion) return item; return null; }