diff --git a/EnvyUpdate.sln b/EnvyUpdate.sln index d7abf71..5225e06 100644 --- a/EnvyUpdate.sln +++ b/EnvyUpdate.sln @@ -1,32 +1,23 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.6.33829.357 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29411.108 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EnvyUpdate", "EnvyUpdate\EnvyUpdate.csproj", "{1BF2468D-9579-462D-9153-4836E9C8721F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug - ignoregpu|Any CPU = Debug - ignoregpu|Any CPU - Debug - ignoregpu|x86 = Debug - ignoregpu|x86 Debug|Any CPU = Debug|Any CPU - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug - ignoregpu|Any CPU.ActiveCfg = Debug - ignoregpu|Any CPU {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug - ignoregpu|Any CPU.Build.0 = Debug - ignoregpu|Any CPU - {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug - ignoregpu|x86.ActiveCfg = Debug - ignoregpu|x86 - {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug - ignoregpu|x86.Build.0 = Debug - ignoregpu|x86 {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|x86.ActiveCfg = Debug|x86 - {1BF2468D-9579-462D-9153-4836E9C8721F}.Debug|x86.Build.0 = Debug|x86 {1BF2468D-9579-462D-9153-4836E9C8721F}.Release|Any CPU.ActiveCfg = Release|Any CPU {1BF2468D-9579-462D-9153-4836E9C8721F}.Release|Any CPU.Build.0 = Release|Any CPU - {1BF2468D-9579-462D-9153-4836E9C8721F}.Release|x86.ActiveCfg = Release|x86 - {1BF2468D-9579-462D-9153-4836E9C8721F}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/EnvyUpdate/App.xaml b/EnvyUpdate/App.xaml index de53160..414c0d4 100644 --- a/EnvyUpdate/App.xaml +++ b/EnvyUpdate/App.xaml @@ -2,14 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:EnvyUpdate" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" StartupUri="MainWindow.xaml"> - - - - - - + diff --git a/EnvyUpdate/App.xaml.cs b/EnvyUpdate/App.xaml.cs index 2d0e158..3bd4437 100644 --- a/EnvyUpdate/App.xaml.cs +++ b/EnvyUpdate/App.xaml.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; using Windows.Foundation.Collections; -using Wpf.Ui.Markup; namespace EnvyUpdate { @@ -19,28 +18,26 @@ namespace EnvyUpdate { protected override void OnStartup(StartupEventArgs e) { - // Remove placeholder light theme and apply system app theme - Wpf.Ui.Appearance.Accent.ApplySystemAccent(); - Application.Current.Resources.MergedDictionaries.RemoveAt(0); - ThemesDictionary themedict = new ThemesDictionary(); - if (Util.IsDarkTheme()) - themedict.Theme = Wpf.Ui.Appearance.ThemeType.Dark; - else - themedict.Theme = Wpf.Ui.Appearance.ThemeType.Light; - Application.Current.Resources.MergedDictionaries.Add(themedict); - // TODO: Watch for theme changes and dynamically update - // Listen to notification activation - ToastNotificationManagerCompat.OnActivated += ToastNotificationManagerCompat_OnActivated; - } - - private void ToastNotificationManagerCompat_OnActivated(ToastNotificationActivatedEventArgsCompat e) - { - // Need to dispatch to UI thread if performing UI operations - Application.Current.Dispatcher.Invoke(delegate + ToastNotificationManagerCompat.OnActivated += toastArgs => { - Util.ShowMain(); - }); + // Obtain the arguments from the notification + ToastArguments args = ToastArguments.Parse(toastArgs.Argument); + + // Need to dispatch to UI thread if performing UI operations + Application.Current.Dispatcher.Invoke(delegate + { + switch (args.Get("action")) + { + case "download": + Process.Start(Util.GetGpuUrl()); + break; + default: + Util.ShowMain(); + break; + } + }); + }; } } } diff --git a/EnvyUpdate/DashboardPage.xaml b/EnvyUpdate/DashboardPage.xaml deleted file mode 100644 index dc9d964..0000000 --- a/EnvyUpdate/DashboardPage.xaml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/EnvyUpdate/DashboardPage.xaml.cs b/EnvyUpdate/DashboardPage.xaml.cs deleted file mode 100644 index f7e4f1d..0000000 --- a/EnvyUpdate/DashboardPage.xaml.cs +++ /dev/null @@ -1,410 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net; -using System.Text.RegularExpressions; -using System.Threading; -using System.Windows; -using System.Windows.Threading; -using Wpf.Ui.Controls; -using MessageBox = System.Windows.MessageBox; - -namespace EnvyUpdate -{ - /// - /// Interaction logic for Dashboard.xaml - /// - public partial class DashboardPage - { - private string localDriv = null; - private string onlineDriv = null; - private string gpuURL = null; - private string skippedVer = null; - - public DashboardPage() - { - InitializeComponent(); - - if (Debug.isFake) - localDriv = Debug.LocalDriv(); - else - localDriv = Util.GetLocDriv(); - - Debug.LogToFile("INFO Local driver version: " + localDriv); - - if (localDriv != null) - { - Debug.LogToFile("INFO Local driver version already known, updating info without reloading."); - UpdateLocalVer(false); - } - - Debug.LogToFile("INFO Detecting driver type."); - - if (Debug.isFake) - textblockLocalType.Text = "DCH (Debug)"; - else if (Util.IsDCH()) - textblockLocalType.Text = "DCH"; - else - textblockLocalType.Text = "Standard"; - - Debug.LogToFile("INFO Done detecting driver type: " + textblockLocalType.Text); - - // Check for startup shortcut - if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk"))) - { - Debug.LogToFile("INFO Autostart is enabled."); - switchAutostart.IsChecked = true; - switchAutostart_Click(null, null); //Automatically recreate shortcut to account for moved EXE. - } - - DispatcherTimer Dt = new DispatcherTimer(); - Dt.Tick += new EventHandler(Dt_Tick); - // Check for new updates every 5 hours. - Dt.Interval = new TimeSpan(5, 0, 0); - Dt.Start(); - Debug.LogToFile("INFO Started check timer."); - - string watchDirPath = Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"), "NVIDIA Corporation\\Installer2\\InstallerCore"); - if (Directory.Exists(watchDirPath)) - { - GlobalVars.monitoringInstall = true; - - var driverFileChangedWatcher = new FileSystemWatcher(watchDirPath); - driverFileChangedWatcher.NotifyFilter = NotifyFilters.Attributes - | NotifyFilters.CreationTime - | NotifyFilters.FileName - | NotifyFilters.LastAccess - | NotifyFilters.LastWrite - | NotifyFilters.Size; - driverFileChangedWatcher.Changed += DriverFileChanged; - - driverFileChangedWatcher.Filter = "*.dll"; - driverFileChangedWatcher.IncludeSubdirectories = false; - driverFileChangedWatcher.EnableRaisingEvents = true; - Debug.LogToFile("INFO Started update file system watcher."); - } - else - Debug.LogToFile("WARN Could not start update file system watcher. Path not found: " + watchDirPath); - - Load(); - } - - private void Dt_Tick(object sender, EventArgs e) - { - Load(); - } - - private void Load() - { - if (Util.GetDTID() == 18) - { - Debug.LogToFile("INFO Found studio driver."); - switchStudioDriver.IsChecked = true; - } - else - { - Debug.LogToFile("INFO Found standard driver."); - switchStudioDriver.IsChecked = false; - } - - if (File.Exists(GlobalVars.exedirectory + "skip.envy")) - { - Debug.LogToFile("INFO Found version skip config."); - skippedVer = File.ReadLines(GlobalVars.exedirectory + "skip.envy").First(); - } - - // This little bool check is necessary for debug fake mode. - if (Debug.isFake) - { - localDriv = Debug.LocalDriv(); - cardLocal.Header = localDriv; - textblockGPUName.Text = Debug.GPUname(); - } - - try - { - Debug.LogToFile("INFO Trying to get GPU update URL."); - gpuURL = Util.GetGpuUrl(); - } - catch (ArgumentException) - { - Debug.LogToFile("WARN Could not get GPU update URL, trying again with non-studio driver."); - try - { - // disable SD and try with GRD - if (File.Exists(GlobalVars.exedirectory + "sd.envy")) - { - File.Delete(GlobalVars.exedirectory + "sd.envy"); - } - - gpuURL = Util.GetGpuUrl(); //try again with GRD - MessageBox.Show(Properties.Resources.ui_studionotsupported); - switchStudioDriver.IsChecked = false; - } - catch (ArgumentNullException) - { - MessageBox.Show("ERROR: Could not get list of GPU models from Nvidia, please check your network connection.\nOtherwise, please report this issue on GitHub."); - Environment.Exit(11); - } - catch (ArgumentException e) - { - // Now we have a problem. - Debug.LogToFile("FATAL Invalid API response from Nvidia. Attempted API call: " + e.Message); - MessageBox.Show("ERROR: Invalid API response from Nvidia. Please file an issue on GitHub.\nAttempted API call:\n" + e.Message); - Environment.Exit(10); - } - } - - using (var c = new WebClient()) - { - Debug.LogToFile("INFO Trying to get newest driver version."); - string pContent = c.DownloadString(gpuURL); - var pattern = @"Windows\/\d{3}\.\d{2}"; - Regex rgx = new Regex(pattern); - var matches = rgx.Matches(pContent); - onlineDriv = Regex.Replace(Convert.ToString(matches[0]), "Windows/", ""); - cardOnline.Header = onlineDriv; - Debug.LogToFile("INFO Got online driver version: " + onlineDriv); - } - - try - { - if (float.Parse(localDriv) < float.Parse(onlineDriv)) - { - Debug.LogToFile("INFO Local version is older than online. Setting UI..."); - SetInfoBar(false); - buttonDownload.Visibility = Visibility.Visible; - if (skippedVer == null) - { - buttonSkipVersion.ToolTip = Properties.Resources.ui_skipversion; - buttonSkipVersion.IsEnabled = true; - buttonSkipVersion.Visibility = Visibility.Visible; - } - else - { - buttonSkipVersion.IsEnabled = true; - buttonSkipVersion.ToolTip = Properties.Resources.ui_skipped; - } - - Debug.LogToFile("INFO UI set."); - - if (skippedVer != onlineDriv) - { - Debug.LogToFile("INFO Showing update popup notification."); - Notify.ShowDrivUpdatePopup(); - } - } - else - { - Debug.LogToFile("INFO Local version is up to date."); - buttonSkipVersion.Visibility = Visibility.Collapsed; - SetInfoBar(true); - } - } - catch (FormatException) - { - Debug.LogToFile("INFO Caught FormatException, assuming locale workaround is necessary."); - //Thank you locales. Some languages need , instead of . for proper parsing - string cLocalDriv = localDriv.Replace('.', ','); - string cOnlineDriv = onlineDriv.Replace('.', ','); - if (float.Parse(cLocalDriv) < float.Parse(cOnlineDriv)) - { - Debug.LogToFile("INFO Local version is older than online. Setting UI..."); - SetInfoBar(false); - buttonDownload.Visibility = Visibility.Visible; - if (skippedVer == null) - { - buttonSkipVersion.IsEnabled = true; - buttonSkipVersion.Visibility = Visibility.Visible; - } - else - { - buttonSkipVersion.IsEnabled = false; - buttonSkipVersion.ToolTip = Properties.Resources.ui_skipped; - } - - if (skippedVer != onlineDriv) - { - Debug.LogToFile("INFO Showing update popup notification."); - Notify.ShowDrivUpdatePopup(); - } - } - else - { - Debug.LogToFile("INFO Local version is up to date."); - buttonSkipVersion.Visibility = Visibility.Collapsed; - SetInfoBar(true); - } - } - - //Check for different version than skipped version - if (skippedVer != null && skippedVer != onlineDriv) - { - Debug.LogToFile("INFO Skipped version is surpassed, deleting setting."); - skippedVer = null; - if (File.Exists(GlobalVars.exedirectory + "skip.envy")) - File.Delete(GlobalVars.exedirectory + "skip.envy"); - buttonSkipVersion.ToolTip = Properties.Resources.ui_skipversion; - buttonSkipVersion.IsEnabled = true; - buttonSkipVersion.Visibility = Visibility.Visible; - } - } - - private void switchStudioDriver_Unchecked(object sender, RoutedEventArgs e) - { - if (File.Exists(GlobalVars.exedirectory + "sd.envy")) - { - Debug.LogToFile("INFO Switching to game ready driver."); - File.Delete(GlobalVars.exedirectory + "sd.envy"); - Load(); - } - } - - private void switchStudioDriver_Checked(object sender, RoutedEventArgs e) - { - if (!File.Exists(GlobalVars.exedirectory + "sd.envy")) - { - Debug.LogToFile("INFO Switching to studio driver."); - File.Create(GlobalVars.exedirectory + "sd.envy").Close(); - Load(); - } - } - - private void switchAutostart_Click(object sender, RoutedEventArgs e) - { - if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk"))) - { - Debug.LogToFile("INFO Removing autostart entry."); - File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EnvyUpdate.lnk")); - } - if (switchAutostart.IsChecked == true) - { - Debug.LogToFile("INFO Creating autostart entry."); - Util.CreateShortcut("EnvyUpdate", Environment.GetFolderPath(Environment.SpecialFolder.Startup), GlobalVars.exeloc, "NVidia Update Checker", "/minimize"); - } - } - - private void buttonSkipVersion_Click(object sender, RoutedEventArgs e) - { - Debug.LogToFile("INFO Skipping version."); - skippedVer = onlineDriv; - File.WriteAllText(GlobalVars.exedirectory + "skip.envy", onlineDriv); - buttonSkipVersion.IsEnabled = false; - buttonSkipVersion.ToolTip = Properties.Resources.ui_skipped; - MessageBox.Show(Properties.Resources.skip_confirm); - } - - private void UpdateLocalVer(bool reloadLocalDriv = true) - { - Debug.LogToFile("INFO Updating local driver version in UI."); - if (reloadLocalDriv) - { - Debug.LogToFile("INFO Reloading local driver version."); - localDriv = Util.GetLocDriv(); - } - cardLocal.Header = localDriv; - if (GlobalVars.isMobile) - textblockGPUName.Text = Util.GetGPUName(false) + " (mobile)"; - else - textblockGPUName.Text = Util.GetGPUName(false); - } - - void DriverFileChanged(object sender, FileSystemEventArgs e) - { - Debug.LogToFile("INFO Watched driver file changed! Reloading data."); - System.Threading.Thread.Sleep(10000); - Application.Current.Dispatcher.Invoke(delegate - { - UpdateLocalVer(); - Load(); - }); - } - - private void CardOnline_Click(object sender, RoutedEventArgs e) - { - Debug.LogToFile("INFO Opening download page."); - Process.Start(gpuURL); - } - - private void SetInfoBar (bool good) - { - if (good) - { - infoBarStatus.Severity = Wpf.Ui.Controls.InfoBarSeverity.Success; - infoBarStatus.Title = Properties.Resources.ui_info_uptodate; - infoBarStatus.Message = Properties.Resources.ui_message_good; - } - else - { - infoBarStatus.Severity = Wpf.Ui.Controls.InfoBarSeverity.Warning; - infoBarStatus.Title = Properties.Resources.ui_info_outdated; - infoBarStatus.Message = Properties.Resources.ui_message_update; - } - } - - private void buttonDownload_Click(object sender, RoutedEventArgs e) - { - progressbarDownload.Visibility = Visibility.Visible; - buttonDownload.IsEnabled = false; - - Thread thread = new Thread(() => { - WebClient client = new WebClient(); - client.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0"; - client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); - client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); - client.DownloadFileAsync(new Uri(Util.GetDirectDownload(gpuURL)), Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe.downloading")); - }); - thread.Start(); - } - - void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) - { - double bytesIn = double.Parse(e.BytesReceived.ToString()); - double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); - double percentage = bytesIn / totalBytes * 100; - Application.Current.Dispatcher.Invoke(new Action(() => { - progressbarDownload.Value = int.Parse(Math.Truncate(percentage).ToString()); - })); - } - void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) - { - Application.Current.Dispatcher.Invoke(new Action(() => { - buttonDownload.IsEnabled = true; - progressbarDownload.Visibility = Visibility.Collapsed; - })); - if (e.Error == null) - { - Application.Current.Dispatcher.Invoke(new Action(() => { - showSnackbar(Wpf.Ui.Common.ControlAppearance.Success, Wpf.Ui.Common.SymbolRegular.CheckmarkCircle24, Properties.Resources.info_download_success, Properties.Resources.info_download_success_title); - buttonDownload.Visibility = Visibility.Collapsed; - buttonInstall.Visibility = Visibility.Visible; - })); - if (File.Exists(Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe"))) - File.Delete(Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe")); - File.Move(Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe.downloading"), Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe")); - } - else - { - File.Delete(Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe.downloading")); - Application.Current.Dispatcher.Invoke(new Action(() => { - showSnackbar(Wpf.Ui.Common.ControlAppearance.Danger, Wpf.Ui.Common.SymbolRegular.ErrorCircle24, Properties.Resources.info_download_error, Properties.Resources.info_download_error_title); - })); - } - } - private void buttonInstall_Click(object sender, RoutedEventArgs e) - { - - } - - private void showSnackbar (Wpf.Ui.Common.ControlAppearance appearance, Wpf.Ui.Common.SymbolRegular icon, string message = "", string title = "") - { - snackbarInfo.Appearance = appearance; - snackbarInfo.Icon = icon; - snackbarInfo.Title = title; - snackbarInfo.Message = message; - snackbarInfo.Show(); - } - } -} diff --git a/EnvyUpdate/EnvyUpdate.csproj b/EnvyUpdate/EnvyUpdate.csproj index 29dd347..b3e717f 100644 --- a/EnvyUpdate/EnvyUpdate.csproj +++ b/EnvyUpdate/EnvyUpdate.csproj @@ -72,37 +72,6 @@ app.manifest - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - 7.3 - prompt - true - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - 7.3 - prompt - true - - - true - bin\x86\Debug - ignoregpu\ - DEBUG;TRACE - full - x86 - 7.3 - prompt - MinimumRecommendedRules.ruleset - true - @@ -131,25 +100,21 @@ + + InfoWindow.xaml + - - DashboardPage.xaml - - - True - True - Licenses.resx - Resources.de.resx True True - - SettingsPage.xaml - + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -162,14 +127,6 @@ MainWindow.xaml Code - - Designer - MSBuild:Compile - - - Designer - MSBuild:Compile - @@ -185,10 +142,6 @@ Settings.settings True - - ResXFileCodeGenerator - Licenses.Designer.cs - PublicResXFileCodeGenerator Resources.de.Designer.cs @@ -244,6 +197,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + 1.1.0 + 7.1.3 @@ -253,9 +209,6 @@ 7.0.1 - - 2.0.3 - \ No newline at end of file diff --git a/EnvyUpdate/InfoWindow.xaml b/EnvyUpdate/InfoWindow.xaml new file mode 100644 index 0000000..e9d09c5 --- /dev/null +++ b/EnvyUpdate/InfoWindow.xaml @@ -0,0 +1,26 @@ + + +