diff --git a/UndertaleModTool/MainWindow.xaml.cs b/UndertaleModTool/MainWindow.xaml.cs index 19f1a1d93..61c5bcb2f 100644 --- a/UndertaleModTool/MainWindow.xaml.cs +++ b/UndertaleModTool/MainWindow.xaml.cs @@ -502,6 +502,11 @@ private async void Window_Loaded(object sender, RoutedEventArgs e) RunGMSDebuggerItem.Visibility = Settings.Instance.ShowDebuggerOption ? Visibility.Visible : Visibility.Collapsed; + + if (Settings.Instance.CheckForUpdatesAtStartup) + { + _ = CheckForUpdates(isStartup: true); + } } public Dictionary childFiles = new Dictionary(); @@ -2878,7 +2883,12 @@ private void MenuItem_GitHub_Click(object sender, RoutedEventArgs e) OpenBrowser("https://github.com/UnderminersTeam/UndertaleModTool"); } - private async void MenuItem_CheckForUpdates_Click(object sender, RoutedEventArgs e) + private void MenuItem_CheckForUpdates_Click(object sender, RoutedEventArgs e) + { + _ = CheckForUpdates(); + } + + async Task CheckForUpdates(bool isStartup = false) { LoaderDialog loaderDialog = new("Check for updates", "Checking for updates..."); loaderDialog.Owner = this; @@ -2901,8 +2911,11 @@ private async void MenuItem_CheckForUpdates_Click(object sender, RoutedEventArgs if (response?.IsSuccessStatusCode != true) { - string errText = $"{(response is null ? "Check your internet connection." : $"HTTP error - {response.ReasonPhrase}.")}"; - loaderDialog.ShowError($"Failed to check for updates!\n{errText}"); + if (!isStartup) + { + string errText = $"{(response is null ? "Check your internet connection." : $"HTTP error - {response.ReasonPhrase}.")}"; + loaderDialog.ShowError($"Failed to check for updates!\n{errText}"); + } return; } @@ -2922,6 +2935,9 @@ private async void MenuItem_CheckForUpdates_Click(object sender, RoutedEventArgs $"\nCurrent version: {Version} ({currentDateTime})" + $"\nLatest version: {latestVersion} ({latestDateTime})" + "\n" + + (isStartup ? + "\nYou can disable checking for updates at startup in the settings." + + "\n" : "") + "\nDo you want to download the latest version?") == MessageBoxResult.Yes) { OpenBrowser((string)jsonResponse["html_url"]); @@ -2932,7 +2948,10 @@ private async void MenuItem_CheckForUpdates_Click(object sender, RoutedEventArgs } else { - loaderDialog.ShowMessage("UndertaleModTool is up to date."); + if (!isStartup) + { + loaderDialog.ShowMessage("UndertaleModTool is up to date."); + } } } finally diff --git a/UndertaleModTool/Settings.cs b/UndertaleModTool/Settings.cs index b20c8d1a9..b5aec15df 100644 --- a/UndertaleModTool/Settings.cs +++ b/UndertaleModTool/Settings.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using System.Text.Json; -using System.Threading.Tasks; using System.Windows; namespace UndertaleModTool @@ -54,6 +50,8 @@ public class Settings public bool EnableDarkMode { get; set; } = false; public bool ShowDebuggerOption { get; set; } = false; + public bool CheckForUpdatesAtStartup { get; set; } = true; + public static Settings Instance; public static JsonSerializerOptions JsonOptions = new JsonSerializerOptions diff --git a/UndertaleModTool/Windows/SettingsWindow.xaml b/UndertaleModTool/Windows/SettingsWindow.xaml index 76b2e7c5d..b7dba5fc5 100644 --- a/UndertaleModTool/Windows/SettingsWindow.xaml +++ b/UndertaleModTool/Windows/SettingsWindow.xaml @@ -39,62 +39,64 @@ - - + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - + - + + - - - + - - - + + + - - - + + + - + + + - + - - + - - + + - - + + - - Open application data folder - Update app to latest commit + + + + + Open application data folder + Update app to latest commit diff --git a/UndertaleModTool/Windows/SettingsWindow.xaml.cs b/UndertaleModTool/Windows/SettingsWindow.xaml.cs index dd4cb7c1b..8fd30fdab 100644 --- a/UndertaleModTool/Windows/SettingsWindow.xaml.cs +++ b/UndertaleModTool/Windows/SettingsWindow.xaml.cs @@ -1,18 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; +using System.Windows; namespace UndertaleModTool { @@ -209,6 +195,16 @@ public static bool ShowDebuggerOption } } + public static bool CheckForUpdatesAtStartup + { + get => Settings.Instance.CheckForUpdatesAtStartup; + set + { + Settings.Instance.CheckForUpdatesAtStartup = value; + Settings.Save(); + } + } + public bool UpdateButtonEnabled { get => UpdateAppButton.IsEnabled;