add support for system 7zip installations

This commit is contained in:
Jakob 2023-08-29 15:30:11 +02:00
parent 3fb5799b00
commit 6233a5d88e
2 changed files with 38 additions and 9 deletions

View file

@ -383,6 +383,7 @@ namespace EnvyUpdate
progressbarDownload.Value = int.Parse(Math.Truncate(percentage).ToString());
}));
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Application.Current.Dispatcher.Invoke(new Action(() => {
@ -412,6 +413,7 @@ namespace EnvyUpdate
}
private void buttonInstall_Click(object sender, RoutedEventArgs e)
{
buttonInstall.IsEnabled = false;
string sevenZipPath = Util.GetSevenZip();
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Info, Wpf.Ui.Common.SymbolRegular.FolderZip24, Properties.Resources.info_extracting, Properties.Resources.info_extracting_title);
@ -470,6 +472,9 @@ namespace EnvyUpdate
{
Application.Current.Dispatcher.Invoke(new Action(() => {
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Success, Wpf.Ui.Common.SymbolRegular.CheckmarkCircle24, Properties.Resources.info_install_complete, Properties.Resources.info_install_complete_title);
buttonInstall.IsEnabled = true;
buttonInstall.Visibility = Visibility.Collapsed;
buttonDownload.Visibility = Visibility.Visible;
}));
Debug.LogToFile("INFO Driver setup complete. Cleaning up setup files.");

View file

@ -576,17 +576,21 @@ namespace EnvyUpdate
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");
string path;
if (ExistsOnPath("7zg.exe"))
{
path = "7zg.exe";
}
else
{
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);
}
Debug.LogToFile("INFO Downloaded 7-zip.");
}
return path;
}
@ -644,5 +648,25 @@ namespace EnvyUpdate
Debug.LogToFile("INFO Finished removing GFE content from installer config.");
}
private static bool ExistsOnPath(string fileName)
{
return GetFullPath(fileName) != null;
}
private static string GetFullPath(string fileName)
{
if (System.IO.File.Exists(fileName))
return Path.GetFullPath(fileName);
var values = Environment.GetEnvironmentVariable("PATH");
foreach (var path in values.Split(Path.PathSeparator))
{
var fullPath = Path.Combine(path, fileName);
if (System.IO.File.Exists(fullPath))
return fullPath;
}
return null;
}
}
}