//forceSearch = true if should search for updates even if Last Checked is not longer than 1 Day ago public static async Task <bool> CheckForUpdates(MainWindow window, bool forceSearch) { try { //Last update Check DateTime lastChecked = ConfigHelper.LastChecked; //Update Available? bool updateAvailable = ConfigHelper.UpdateAvailable; //Last Update Content for Label window.SetProgressStatus(string.Format(strings.updateLast, $"{lastChecked:dd.MM.yyyy HH:mm}")); //If AutoUpdate is disabled and the User does not manually search, exit Method if (!ConfigHelper.AutoUpdate && !forceSearch) { return(false); } //Update Loading Indicator window.SetProgressStatus(strings.checkingUpdate); //Check for Update, if last update is longer than 1 Day ago if (forceSearch || DateTime.Now - lastChecked > TimeSpan.FromDays(1) || updateAvailable) { //Retrieve info from github GitHubClient github = new GitHubClient(new ProductHeaderValue("ImgurSniper")); IReadOnlyList <GitHubCommit> commitsRaw = await github.Repository.Commit.GetAll("mrousavy", "ImgurSniper"); //All Commits where a new ImgurSniper Version is available start with "R:" Commits = new List <GitHubCommit>(commitsRaw.Where(c => c.Commit.Message.StartsWith("R:"))); TotalCommits = commitsRaw.Count; ConfigHelper.TotalCommits = TotalCommits; ConfigHelper.LastChecked = DateTime.Now; ConfigHelper.Save(); //Last Update Content for Label window.SetProgressStatus(string.Format(strings.updateLast, $"{DateTime.Now:dd.MM.yyyy HH:mm}")); int currentCommits = ConfigHelper.CurrentCommits; //999 = value is unset if (currentCommits == 999) { ConfigHelper.CurrentCommits = Commits.Count; ConfigHelper.Save(); } else if (updateAvailable || Commits.Count > currentCommits) { //Newer Version is available ConfigHelper.UpdateAvailable = true; ConfigHelper.Save(); window.SuccessToast.Show(string.Format(strings.updateAvailable, currentCommits, Commits.Count), TimeSpan.FromSeconds(4)); return(true); } else { //No Update available ConfigHelper.UpdateAvailable = false; ConfigHelper.Save(); } } } catch { window.ErrorToast.Show(strings.failedUpdate, TimeSpan.FromSeconds(3)); } //Any other way than return true = no update return(false); }