From cdcfccd87c492ca4632df99a0049d5cfd59073bc Mon Sep 17 00:00:00 2001 From: Jakob Date: Fri, 14 Jul 2023 00:16:57 +0200 Subject: [PATCH 01/64] complete UI rewrite --- EnvyUpdate/App.xaml | 8 +- EnvyUpdate/DashboardPage.xaml | 85 ++++ EnvyUpdate/DashboardPage.xaml.cs | 415 ++++++++++++++++++ EnvyUpdate/EnvyUpdate.csproj | 36 +- EnvyUpdate/InfoWindow.xaml | 26 -- EnvyUpdate/MainWindow.xaml | 88 ++-- EnvyUpdate/MainWindow.xaml.cs | 377 +--------------- EnvyUpdate/Properties/Licenses.Designer.cs | 153 +++++++ EnvyUpdate/Properties/Licenses.resx | 190 ++++++++ EnvyUpdate/Properties/Resources.Designer.cs | 99 +++++ EnvyUpdate/Properties/Resources.de.resx | 33 ++ EnvyUpdate/Properties/Resources.resx | 33 ++ EnvyUpdate/SettingsPage.xaml | 61 +++ ...nfoWindow.xaml.cs => SettingsPage.xaml.cs} | 38 +- README.md | 4 +- 15 files changed, 1207 insertions(+), 439 deletions(-) create mode 100644 EnvyUpdate/DashboardPage.xaml create mode 100644 EnvyUpdate/DashboardPage.xaml.cs delete mode 100644 EnvyUpdate/InfoWindow.xaml create mode 100644 EnvyUpdate/Properties/Licenses.Designer.cs create mode 100644 EnvyUpdate/Properties/Licenses.resx create mode 100644 EnvyUpdate/SettingsPage.xaml rename EnvyUpdate/{InfoWindow.xaml.cs => SettingsPage.xaml.cs} (58%) diff --git a/EnvyUpdate/App.xaml b/EnvyUpdate/App.xaml index 414c0d4..de53160 100644 --- a/EnvyUpdate/App.xaml +++ b/EnvyUpdate/App.xaml @@ -2,8 +2,14 @@ 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/DashboardPage.xaml b/EnvyUpdate/DashboardPage.xaml new file mode 100644 index 0000000..b9572ba --- /dev/null +++ b/EnvyUpdate/DashboardPage.xaml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/EnvyUpdate/DashboardPage.xaml.cs b/EnvyUpdate/DashboardPage.xaml.cs new file mode 100644 index 0000000..abb0b90 --- /dev/null +++ b/EnvyUpdate/DashboardPage.xaml.cs @@ -0,0 +1,415 @@ +using Microsoft.Build.Framework.XamlTypes; +using Microsoft.Toolkit.Uwp.Notifications; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.RegularExpressions; +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.Navigation; +using System.Windows.Threading; +using Windows.ApplicationModel.VoiceCommands; + +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; + private string[] arguments = null; + + public DashboardPage() + { + InitializeComponent(); + + // Try to get command line arguments + try + { + arguments = Environment.GetCommandLineArgs(); + } + catch (IndexOutOfRangeException) + { + // This is necessary, since .NET throws an exception if you check for a non-existant arg. + } + + // Delete installed legacy versions + if (Directory.Exists(GlobalVars.appdata)) + { + Debug.LogToFile("INFO Found old appdata installation, uninstalling."); + UninstallAll(); + } + + 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); + } + else + { + if (arguments.Contains("/fake")) + { + Debug.isFake = true; + Debug.LogToFile("WARN Faking GPU with debug info."); + } + else + { + Debug.LogToFile("FATAL No supported GPU found, terminating."); + MessageBox.Show(Properties.Resources.no_compatible_gpu); + Environment.Exit(255); + } + } + + Debug.LogToFile("INFO Detecting driver type."); + + if (Util.IsDCH()) + textblockLocalType.Text = "DCH"; + else if (Debug.isFake) + textblockLocalType.Text = "DCH (Debug)"; + 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."); + } + + 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 mode on systems without an Nvidia GPU. + 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 buttonDL_Click(object sender, RoutedEventArgs e) + { + Debug.LogToFile("INFO Opening download page."); + Process.Start(gpuURL); + } + + public void UninstallAll() + { + if (File.Exists(GlobalVars.startup + "\\EnvyUpdate.lnk")) + { + Debug.LogToFile("INFO Deleted startup entry."); + File.Delete(GlobalVars.startup + "\\EnvyUpdate.lnk"); + } + + if (File.Exists(GlobalVars.startmenu + "\\EnvyUpdate.lnk")) + { + Debug.LogToFile("INFO Deleted start menu entry."); + File.Delete(GlobalVars.startmenu + "\\EnvyUpdate.lnk"); + } + if ((GlobalVars.exedirectory == GlobalVars.appdata) && File.Exists(GlobalVars.appdata + "EnvyUpdate.exe")) + { + Debug.LogToFile("INFO Deleting EnvyUpdate appdata and self."); + MessageBox.Show(Properties.Resources.uninstall_legacy_message); + Util.SelfDelete(); + } + else if (Directory.Exists(GlobalVars.appdata)) + { + Debug.LogToFile("INFO Deleting EnvyUpdate appdata folder"); + Directory.Delete(GlobalVars.appdata, true); + } + } + + private void radioGRD_Checked(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 radioSD_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 buttonSkip_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; + } + } + } +} diff --git a/EnvyUpdate/EnvyUpdate.csproj b/EnvyUpdate/EnvyUpdate.csproj index b3e717f..ef59029 100644 --- a/EnvyUpdate/EnvyUpdate.csproj +++ b/EnvyUpdate/EnvyUpdate.csproj @@ -100,21 +100,25 @@ - - InfoWindow.xaml - + + DashboardPage.xaml + + + True + True + Licenses.resx + Resources.de.resx True True + + SettingsPage.xaml + - - Designer - MSBuild:Compile - MSBuild:Compile Designer @@ -127,6 +131,14 @@ MainWindow.xaml Code + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + @@ -142,6 +154,10 @@ Settings.settings True + + ResXFileCodeGenerator + Licenses.Designer.cs + PublicResXFileCodeGenerator Resources.de.Designer.cs @@ -197,9 +213,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - 1.1.0 - 7.1.3 @@ -209,6 +222,9 @@ 7.0.1 + + 2.0.3 + \ No newline at end of file diff --git a/EnvyUpdate/InfoWindow.xaml b/EnvyUpdate/InfoWindow.xaml deleted file mode 100644 index e9d09c5..0000000 --- a/EnvyUpdate/InfoWindow.xaml +++ /dev/null @@ -1,26 +0,0 @@ - - -