From 0760600d4735b168f9a6f315e26899fc5a268a13 Mon Sep 17 00:00:00 2001 From: Jakob Date: Fri, 14 Jul 2023 21:04:54 +0200 Subject: [PATCH] add download for driver --- EnvyUpdate/DashboardPage.xaml | 4 +-- EnvyUpdate/DashboardPage.xaml.cs | 55 ++++++++++++++++++++------------ EnvyUpdate/MainWindow.xaml.cs | 11 +------ EnvyUpdate/SettingsPage.xaml.cs | 11 ------- EnvyUpdate/Util.cs | 11 +++++-- README.md | 2 +- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/EnvyUpdate/DashboardPage.xaml b/EnvyUpdate/DashboardPage.xaml index a9a1d8d..3170e4b 100644 --- a/EnvyUpdate/DashboardPage.xaml +++ b/EnvyUpdate/DashboardPage.xaml @@ -46,10 +46,10 @@ - + - + diff --git a/EnvyUpdate/DashboardPage.xaml.cs b/EnvyUpdate/DashboardPage.xaml.cs index e88ea01..a72a329 100644 --- a/EnvyUpdate/DashboardPage.xaml.cs +++ b/EnvyUpdate/DashboardPage.xaml.cs @@ -1,24 +1,13 @@ -using Microsoft.Build.Framework.XamlTypes; -using Microsoft.Toolkit.Uwp.Notifications; -using System; -using System.Collections.Generic; +using System; +using System.ComponentModel; 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.Threading; 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 { @@ -261,12 +250,6 @@ namespace EnvyUpdate } } - private void buttonDL_Click(object sender, RoutedEventArgs e) - { - Debug.LogToFile("INFO Opening download page."); - Process.Start(gpuURL); - } - private void switchStudioDriver_Unchecked(object sender, RoutedEventArgs e) { if (File.Exists(GlobalVars.exedirectory + "sd.envy")) @@ -358,5 +341,37 @@ namespace EnvyUpdate 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")); + }); + 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(() => { + progressbarDownload.Visibility = Visibility.Collapsed; + buttonDownload.Icon = Wpf.Ui.Common.SymbolRegular.CheckmarkCircle24; + })); + } } } diff --git a/EnvyUpdate/MainWindow.xaml.cs b/EnvyUpdate/MainWindow.xaml.cs index 1f6b74d..6efb4fc 100644 --- a/EnvyUpdate/MainWindow.xaml.cs +++ b/EnvyUpdate/MainWindow.xaml.cs @@ -1,17 +1,8 @@ -using Microsoft.Build.Framework.XamlTypes; -using Microsoft.Toolkit.Uwp.Notifications; +using Microsoft.Toolkit.Uwp.Notifications; using System; -using System.Diagnostics; using System.IO; using System.Linq; -using System.Management; -using System.Net; -using System.Runtime.Remoting.Messaging; -using System.Text.RegularExpressions; using System.Windows; -using System.Windows.Media; -using System.Windows.Threading; -using Wpf.Ui.Controls.Interfaces; namespace EnvyUpdate { diff --git a/EnvyUpdate/SettingsPage.xaml.cs b/EnvyUpdate/SettingsPage.xaml.cs index 5e5d838..28fe8b7 100644 --- a/EnvyUpdate/SettingsPage.xaml.cs +++ b/EnvyUpdate/SettingsPage.xaml.cs @@ -1,17 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; -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.Navigation; namespace EnvyUpdate { diff --git a/EnvyUpdate/Util.cs b/EnvyUpdate/Util.cs index 91e3124..94c5f9b 100644 --- a/EnvyUpdate/Util.cs +++ b/EnvyUpdate/Util.cs @@ -573,10 +573,15 @@ namespace EnvyUpdate } } - public static void DownloadFile(string fileURL, string savePath) + public static string GetDirectDownload(string gpuUrl) { - //TODO Implement downloading - //TODO implement progress bar + string webcontent; + using (var wc = new WebClient()) + webcontent = wc.DownloadString(gpuUrl); + + string directUrl = Regex.Match(webcontent, "\\/Windows\\/\\d+\\.\\d+\\/[\\w\\d\\/\\-\\.]*exe").Value; + directUrl = "https://us.download.nvidia.com" + directUrl; + return directUrl; } } } diff --git a/README.md b/README.md index d1a58b5..2b6a970 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ If you want to help me develop EnvyUpdate, you can start by creating issues with * [TinyNvidiaUpdateChecker](https://github.com/ElPumpo/TinyNvidiaUpdateChecker) - a command line update checker and installer. Inspired EnvyUpdate to begin with. * [nvidia-update](https://github.com/ZenitH-AT/nvidia-update) - a Powershell script to check for driver updates -* [Disable-Nvidia-Telemtry](https://github.com/NateShoffner/Disable-Nvidia-Telemetry) - does pretty much what the name says. It disables Nvidia Telemetry. +* [Disable-Nvidia-Telemetry](https://github.com/NateShoffner/Disable-Nvidia-Telemetry) - does pretty much what the name says. It disables Nvidia Telemetry. * [NVCleanInstall](https://www.techpowerup.com/nvcleanstall/) - a closed-source application by TechPowerUp which does quite a lot of cool things. EnvyUpdate is not a replacement for any of these tools. I will still try to implement as many features in EnvyUpdate as possible while keeping the simple interface and as little settings as possible.