From 726adc71936c01a8ca75e2ee97d410e85da27773 Mon Sep 17 00:00:00 2001 From: Jakob Date: Fri, 14 Jul 2023 21:52:27 +0200 Subject: [PATCH] finish downloader --- EnvyUpdate/DashboardPage.xaml | 129 ++++++++++---------- EnvyUpdate/DashboardPage.xaml.cs | 31 ++++- EnvyUpdate/Properties/Resources.Designer.cs | 36 ++++++ EnvyUpdate/Properties/Resources.de.resx | 12 ++ EnvyUpdate/Properties/Resources.resx | 12 ++ EnvyUpdate/Util.cs | 5 +- 6 files changed, 159 insertions(+), 66 deletions(-) diff --git a/EnvyUpdate/DashboardPage.xaml b/EnvyUpdate/DashboardPage.xaml index 3170e4b..eb0757b 100644 --- a/EnvyUpdate/DashboardPage.xaml +++ b/EnvyUpdate/DashboardPage.xaml @@ -11,75 +11,78 @@ Title="DashboardPage"> - - - - - - - - - - - - - + + + + + + + + - - - + + + + + + + + + - - - - - - + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/EnvyUpdate/DashboardPage.xaml.cs b/EnvyUpdate/DashboardPage.xaml.cs index a72a329..45f7af0 100644 --- a/EnvyUpdate/DashboardPage.xaml.cs +++ b/EnvyUpdate/DashboardPage.xaml.cs @@ -8,6 +8,8 @@ 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 { @@ -352,7 +354,7 @@ namespace EnvyUpdate 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")); + client.DownloadFileAsync(new Uri(Util.GetDirectDownload(gpuURL)), Path.Combine(GlobalVars.exedirectory, "nvidia-installer.exe.downloading")); }); thread.Start(); } @@ -369,9 +371,34 @@ namespace EnvyUpdate void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { Application.Current.Dispatcher.Invoke(new Action(() => { + buttonDownload.IsEnabled = true; progressbarDownload.Visibility = Visibility.Collapsed; - buttonDownload.Icon = Wpf.Ui.Common.SymbolRegular.CheckmarkCircle24; })); + 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); + })); + 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 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/Properties/Resources.Designer.cs b/EnvyUpdate/Properties/Resources.Designer.cs index c17e88a..e0ed7b3 100644 --- a/EnvyUpdate/Properties/Resources.Designer.cs +++ b/EnvyUpdate/Properties/Resources.Designer.cs @@ -78,6 +78,42 @@ namespace EnvyUpdate.Properties { } } + /// + /// Looks up a localized string similar to There was a problem downloading the driver installer. Please try again.. + /// + public static string info_download_error { + get { + return ResourceManager.GetString("info_download_error", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Error while downloading. + /// + public static string info_download_error_title { + get { + return ResourceManager.GetString("info_download_error_title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Driver installer successfully downloaded.. + /// + public static string info_download_success { + get { + return ResourceManager.GetString("info_download_success", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Download successful. + /// + public static string info_download_success_title { + get { + return ResourceManager.GetString("info_download_success_title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Preference reset.. /// diff --git a/EnvyUpdate/Properties/Resources.de.resx b/EnvyUpdate/Properties/Resources.de.resx index eace543..13bfb43 100644 --- a/EnvyUpdate/Properties/Resources.de.resx +++ b/EnvyUpdate/Properties/Resources.de.resx @@ -123,6 +123,18 @@ EnvyUpdate schließen? + + Fehler beim Herunterladen der Treiber-Installationsdatei. Bitte versuchen Sie es erneut. + + + Fehler beim Herunterladen + + + Treiber-Installationsdatei erfolgreich heruntergeladen. + + + Herunterladen erfolgreich abgeschlossen + Einstellung zurückgesetzt. diff --git a/EnvyUpdate/Properties/Resources.resx b/EnvyUpdate/Properties/Resources.resx index bb5275a..308ba4e 100644 --- a/EnvyUpdate/Properties/Resources.resx +++ b/EnvyUpdate/Properties/Resources.resx @@ -123,6 +123,18 @@ Exit EnvyUpdate? + + There was a problem downloading the driver installer. Please try again. + + + Error while downloading + + + Driver installer successfully downloaded. + + + Download successful + Preference reset. diff --git a/EnvyUpdate/Util.cs b/EnvyUpdate/Util.cs index 94c5f9b..5cd3410 100644 --- a/EnvyUpdate/Util.cs +++ b/EnvyUpdate/Util.cs @@ -1,4 +1,5 @@ -using IWshRuntimeLibrary; +using EnvyUpdate.Properties; +using IWshRuntimeLibrary; using Microsoft.Win32; using System; using System.Diagnostics; @@ -7,7 +8,9 @@ using System.Linq; using System.Management; using System.Net; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows; +using System.Windows.Controls; using System.Xml.Linq; namespace EnvyUpdate