add automatic driver installing

This commit is contained in:
Jakob 2023-08-29 14:37:36 +02:00
parent 8f26383166
commit 15202c9dfd
13 changed files with 331 additions and 16 deletions

View file

@ -8,7 +8,6 @@ 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
@ -363,11 +362,13 @@ namespace EnvyUpdate
File.Delete(Path.Combine(GlobalVars.exedirectory, onlineDriv + "-nvidia-installer.exe.downloading"));
}
Thread thread = new Thread(() => {
WebClient client = new WebClient();
client.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.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, onlineDriv + "-nvidia-installer.exe.downloading"));
using (WebClient client = new WebClient())
{
client.Headers["User-Agent"] = GlobalVars.useragent;
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri(Util.GetDirectDownload(gpuURL)), Path.Combine(GlobalVars.exedirectory, onlineDriv + "-nvidia-installer.exe.downloading"));
}
});
thread.Start();
Debug.LogToFile("INFO Started installer download.");
@ -391,7 +392,7 @@ namespace EnvyUpdate
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);
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;
Debug.LogToFile("INFO Download successful.");
@ -404,17 +405,73 @@ namespace EnvyUpdate
{
File.Delete(Path.Combine(GlobalVars.exedirectory, onlineDriv + "-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);
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Danger, Wpf.Ui.Common.SymbolRegular.ErrorCircle24, Properties.Resources.info_download_error, Properties.Resources.info_download_error_title);
Debug.LogToFile("INFO Download NOT successful. Error: " + e.Error.ToString());
}));
}
}
private void buttonInstall_Click(object sender, RoutedEventArgs e)
{
string sevenZipPath = Util.GetSevenZip();
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Info, Wpf.Ui.Common.SymbolRegular.FolderZip24, Properties.Resources.info_extracting, Properties.Resources.info_extracting_title);
string filePath = Path.Combine(GlobalVars.exedirectory, onlineDriv + "-nvidia-installer.exe");
string destinationDir = Path.Combine(GlobalVars.exedirectory, onlineDriv + "-extracted");
if (!Directory.Exists(destinationDir))
Directory.CreateDirectory(destinationDir);
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Minimized,
WorkingDirectory = destinationDir,
FileName = sevenZipPath,
Arguments = "x -aoa -y " + filePath + " Display.Driver Display.Nview Display.Optimus HDAudio MSVCR NVI2 NVPCF PhysX PPC ShieldWirelessController EULA.txt ListDevices.txt setup.cfg setup.exe"
};
process.EnableRaisingEvents = true;
process.StartInfo = startInfo;
process.Exited += new EventHandler(ExtractionFinished);
process.Start();
}
private void showSnackbar (Wpf.Ui.Common.ControlAppearance appearance, Wpf.Ui.Common.SymbolRegular icon, string message = "", string title = "")
private void ExtractionFinished(object sender, EventArgs e)
{
string extractedPath = Path.Combine(GlobalVars.exedirectory, onlineDriv + "-extracted");
Application.Current.Dispatcher.Invoke(new Action(() => {
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Success, Wpf.Ui.Common.SymbolRegular.FolderZip24, Properties.Resources.info_extract_complete, Properties.Resources.info_extract_complete_title);
}));
File.Delete(Path.Combine(GlobalVars.exedirectory, "7zr.exe"));
Util.CleanInstallConfig(Path.Combine(extractedPath, "setup.cfg"));
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
WorkingDirectory = extractedPath,
FileName = "setup.exe",
Arguments = "-passive -noreboot -noeula"
};
process.EnableRaisingEvents = true;
process.StartInfo = startInfo;
process.Exited += new EventHandler(InstallFinished);
process.Start();
}
private void InstallFinished(object sender, EventArgs e)
{
Application.Current.Dispatcher.Invoke(new Action(() => {
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Success, Wpf.Ui.Common.SymbolRegular.FolderZip24, Properties.Resources.info_install_complete, Properties.Resources.info_install_complete_title);
}));
File.Delete(Path.Combine(GlobalVars.exedirectory, onlineDriv + "-nvidia-installer.exe"));
Directory.Delete(Path.Combine(GlobalVars.exedirectory, onlineDriv + "-extracted"), true);
}
private void ShowSnackbar(Wpf.Ui.Common.ControlAppearance appearance, Wpf.Ui.Common.SymbolRegular icon, string message = "", string title = "")
{
snackbarInfo.Appearance = appearance;
snackbarInfo.Icon = icon;

View file

@ -240,7 +240,7 @@
<Version>4.1.0</Version>
</PackageReference>
<PackageReference Include="Fody">
<Version>6.6.4</Version>
<Version>6.8.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
@ -251,10 +251,10 @@
<Version>2.2.0</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>7.0.1</Version>
<Version>7.0.3</Version>
</PackageReference>
<PackageReference Include="WPF-UI">
<Version>2.0.3</Version>
<Version>2.1.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View file

@ -12,5 +12,6 @@ namespace EnvyUpdate
public static readonly string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\envyupdate\\";
public static readonly string startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
public static bool monitoringInstall = false;
public static readonly string useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Firefox/115.0";
}
}

View file

@ -120,6 +120,21 @@ namespace EnvyUpdate.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to MIT License
///
///Copyright (c) 2017 Alexander Selishchev
///
///Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
///
///The above copyrigh [rest of string was truncated]&quot;;.
/// </summary>
internal static string SevenZipExtractor {
get {
return ResourceManager.GetString("SevenZipExtractor", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to # Windows Community Toolkit
///

View file

@ -159,6 +159,17 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</value>
</data>
<data name="SevenZipExtractor" xml:space="preserve">
<value>MIT License
Copyright (c) 2017 Alexander Selishchev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</value>
</data>
<data name="WindowsCommunityToolkit" xml:space="preserve">

View file

@ -69,6 +69,15 @@ namespace EnvyUpdate.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to An error occurred attempting to install the new version. Please enable logging in the settings and report the issue on GitHub!.
/// </summary>
public static string error_installing {
get {
return ResourceManager.GetString("error_installing", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Exit EnvyUpdate?.
/// </summary>
@ -114,6 +123,60 @@ namespace EnvyUpdate.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to The driver files have finished extracting..
/// </summary>
public static string info_extract_complete {
get {
return ResourceManager.GetString("info_extract_complete", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extraction complete.
/// </summary>
public static string info_extract_complete_title {
get {
return ResourceManager.GetString("info_extract_complete_title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The driver files are being extracted. This could take a few minutes..
/// </summary>
public static string info_extracting {
get {
return ResourceManager.GetString("info_extracting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extracting driver files.
/// </summary>
public static string info_extracting_title {
get {
return ResourceManager.GetString("info_extracting_title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The installation of the new driver version was completed..
/// </summary>
public static string info_install_complete {
get {
return ResourceManager.GetString("info_install_complete", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Update finished.
/// </summary>
public static string info_install_complete_title {
get {
return ResourceManager.GetString("info_install_complete_title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Preference reset..
/// </summary>

View file

@ -120,6 +120,9 @@
<data name="app_description" xml:space="preserve">
<value>NVIDIA Aktualisierungsanwendung.</value>
</data>
<data name="error_installing" xml:space="preserve">
<value>Ein Fehler ist bei der Installation aufgetreten. Bitte aktivieren Sie den Log und melden Sie den Fehler auf GitHub!</value>
</data>
<data name="exit_confirm" xml:space="preserve">
<value>EnvyUpdate schließen?</value>
</data>
@ -135,6 +138,24 @@
<data name="info_download_success_title" xml:space="preserve">
<value>Herunterladen erfolgreich abgeschlossen</value>
</data>
<data name="info_extracting" xml:space="preserve">
<value>Die Treiberdateien werden nun extrahiert. Dies könnte einige Minuten dauern.</value>
</data>
<data name="info_extracting_title" xml:space="preserve">
<value>Dateien werden extrahiert</value>
</data>
<data name="info_extract_complete" xml:space="preserve">
<value>Die Treiberdateien wurden vollständig extrahiert.</value>
</data>
<data name="info_extract_complete_title" xml:space="preserve">
<value>Extrahierung abgeschlossen</value>
</data>
<data name="info_install_complete" xml:space="preserve">
<value>Die Installation der neuen Treiberversion wurde abgeschlossen.</value>
</data>
<data name="info_install_complete_title" xml:space="preserve">
<value>Update abgeschlossen</value>
</data>
<data name="info_reset_caption" xml:space="preserve">
<value>Einstellung zurückgesetzt.</value>
</data>

View file

@ -120,6 +120,9 @@
<data name="app_description" xml:space="preserve">
<value>NVIDIA Updater Application.</value>
</data>
<data name="error_installing" xml:space="preserve">
<value>An error occurred attempting to install the new version. Please enable logging in the settings and report the issue on GitHub!</value>
</data>
<data name="exit_confirm" xml:space="preserve">
<value>Exit EnvyUpdate?</value>
</data>
@ -135,6 +138,24 @@
<data name="info_download_success_title" xml:space="preserve">
<value>Download successful</value>
</data>
<data name="info_extracting" xml:space="preserve">
<value>The driver files are being extracted. This could take a few minutes.</value>
</data>
<data name="info_extracting_title" xml:space="preserve">
<value>Extracting driver files</value>
</data>
<data name="info_extract_complete" xml:space="preserve">
<value>The driver files have finished extracting.</value>
</data>
<data name="info_extract_complete_title" xml:space="preserve">
<value>Extraction complete</value>
</data>
<data name="info_install_complete" xml:space="preserve">
<value>The installation of the new driver version was completed.</value>
</data>
<data name="info_install_complete_title" xml:space="preserve">
<value>Update finished</value>
</data>
<data name="info_reset_caption" xml:space="preserve">
<value>Preference reset.</value>
</data>

View file

@ -49,6 +49,9 @@
<Expander Margin="0,4,0,0" Header="ResourceEmbedder">
<TextBox x:Name="textBoxLicResourceembedder" IsReadOnly="True" TextWrapping="Wrap"/>
</Expander>
<Expander Margin="0,4,0,0" Header="SevenZipExtractor">
<TextBox x:Name="textBoxLic7z" IsReadOnly="True" TextWrapping="Wrap"/>
</Expander>
<Expander Margin="0,4,0,0" Header="Windows Community Toolkit">
<TextBox x:Name="textBoxLicWindowscommunitytoolkit" IsReadOnly="True" TextWrapping="Wrap"/>
</Expander>

View file

@ -28,6 +28,7 @@ namespace EnvyUpdate
textBoxLicFody.Text = Properties.Licenses.Fody;
textBoxLicCostura.Text = Properties.Licenses.CosturaFody;
textBoxLicResourceembedder.Text = Properties.Licenses.ResourceEmbedder;
textBoxLic7z.Text = Properties.Licenses.SevenZipExtractor;
textBoxLicWindowscommunitytoolkit.Text = Properties.Licenses.WindowsCommunityToolkit;
textBoxLicWpfui.Text = Properties.Licenses.wpfui;
}

View file

@ -1,5 +1,4 @@
using EnvyUpdate.Properties;
using IWshRuntimeLibrary;
using IWshRuntimeLibrary;
using Microsoft.Win32;
using System;
using System.Diagnostics;
@ -8,9 +7,7 @@ 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
@ -576,5 +573,74 @@ namespace EnvyUpdate
directUrl = "https://us.download.nvidia.com" + directUrl;
return directUrl;
}
public static string GetSevenZip()
{
// Note: This download happens on the main thread. I believe spinning up a whole thread to
// download a single 600kb file is less efficient than just doing it on the main thread.
// At 1Mbit/s, this download takes 5 seconds, in most cases internet should be faster than that.
string path = Path.Combine(GlobalVars.exedirectory, "7zr.exe");
using (WebClient client = new WebClient())
{
client.Headers["User-Agent"] = GlobalVars.useragent;
client.DownloadFile(new Uri("https://www.7-zip.org/a/7zr.exe"), path);
}
return path;
}
public static Process ExtractWithSevenZip(string sevenZipPath, string filePath, string destinationDir)
{
if (!Directory.Exists(destinationDir))
Directory.CreateDirectory(destinationDir);
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Minimized,
WorkingDirectory = destinationDir,
FileName = sevenZipPath,
Arguments = "x -aoa -y " + filePath + " Display.Driver Display.Nview Display.Optimus HDAudio MSVCR NVI2 NVPCF PhysX PPC ShieldWirelessController EULA.txt ListDevices.txt setup.cfg setup.exe"
};
process.EnableRaisingEvents = true;
process.StartInfo = startInfo;
return process;
}
public static void CleanInstallConfig(string filePath)
{
if (!System.IO.File.Exists(filePath))
{
Debug.LogToFile("FATAL Driver installer config not found, terminating.");
MessageBox.Show(Properties.Resources.error_installing);
Environment.Exit(17);
}
Debug.LogToFile("INFO Removing GFE content from installer config.");
string outfile = filePath + ".out";
StreamReader sr = new StreamReader(filePath);
StreamWriter sw = new StreamWriter(outfile);
string line;
while ((line = sr.ReadLine()) != null)
{
if (new[] { "EulaHtmlFile", "FunctionalConsentFile", "PrivacyPolicyFile" }.Any(c => line.Contains(c)))
{
continue;
}
sw.WriteLine(line);
}
sw.Close();
sr.Close();
System.IO.File.Delete(filePath);
System.IO.File.Move(outfile, filePath);
Debug.LogToFile("INFO Finished removing GFE content from installer config.");
}
}
}