/// <summary> /// Downloads the driver and some other stuff /// </summary> private static void DownloadDriver() { DriverDialog.ShowGUI(); if (DriverDialog.selectedBtn == DriverDialog.SelectedBtn.DLEXTRACT) { // download and save (and extract) Console.WriteLine(); bool error = false; driverFileName = downloadURL.Split('/').Last(); // retrives file name from url try { string message = "Where do you want to save the drivers?"; if (SettingManager.ReadSettingBool("Minimal install")) { message += " (you should select a empty folder)"; } var folderSelectDialog = new FolderSelectDialog(); folderSelectDialog.Title = message; if (folderSelectDialog.Show()) { savePath = folderSelectDialog.FileName + @"\"; } else { Console.WriteLine("User closed dialog!"); return; } if (File.Exists(savePath + driverFileName) && !DoesDriverFileSizeMatch(savePath + driverFileName)) { LogManager.Log($"Deleting {savePath}{driverFileName} because its length doesn't match!", LogManager.Level.INFO); File.Delete(savePath + driverFileName); } // don't download driver if it already exists Console.Write("Downloading the driver . . . "); if (showUI && !File.Exists(savePath + driverFileName)) { using (WebClient webClient = new WebClient()) { var notifier = new AutoResetEvent(false); var progress = new Handlers.ProgressBar(); webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e) { progress.Report((double)e.ProgressPercentage / 100); }; // Only set notifier here! webClient.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { File.Delete(savePath + driverFileName); } else { notifier.Set(); } }; webClient.DownloadFileAsync(new Uri(downloadURL), savePath + driverFileName); notifier.WaitOne(); // sync with the above progress.Dispose(); // get rid of the progress bar } } // show the progress bar gui else if (!showUI && !File.Exists(savePath + driverFileName)) { using (DownloaderForm dlForm = new DownloaderForm()) { dlForm.Show(); dlForm.Focus(); dlForm.DownloadFile(new Uri(downloadURL), savePath + driverFileName); dlForm.Close(); } } else { LogManager.Log("Driver is already downloaded", LogManager.Level.INFO); } } catch (Exception ex) { error = true; Console.Write("ERROR!"); Console.WriteLine(); Console.WriteLine(ex.ToString()); Console.WriteLine(); } if (!error) { Console.Write("OK!"); Console.WriteLine(); } if (debug) { Console.WriteLine($"savePath: {savePath}"); } if (SettingManager.ReadSettingBool("Minimal install")) { MakeInstaller(false); } } else if (DriverDialog.selectedBtn == DriverDialog.SelectedBtn.DLINSTALL) { DownloadDriverQuiet(false); } }
/// <summary> /// Downloads and installs the driver without user interaction /// </summary> private static void DownloadDriverQuiet(bool minimized) { driverFileName = downloadURL.Split('/').Last(); // retrives file name from url savePath = Path.GetTempPath(); var FULL_PATH_DIRECTORY = savePath + OnlineGPUVersion + @"\"; var FULL_PATH_DRIVER = FULL_PATH_DIRECTORY + driverFileName; savePath = FULL_PATH_DIRECTORY; Directory.CreateDirectory(FULL_PATH_DIRECTORY); if (File.Exists(FULL_PATH_DRIVER) && !DoesDriverFileSizeMatch(FULL_PATH_DRIVER)) { LogManager.Log($"Deleting {FULL_PATH_DRIVER} because its length doesn't match!", LogManager.Level.INFO); File.Delete(savePath + driverFileName); } if (!File.Exists(FULL_PATH_DRIVER)) { Console.Write("Downloading the driver . . . "); if (showUI || confirmDL) { using (var webClient = new WebClient()) { var notifier = new AutoResetEvent(false); var progress = new Handlers.ProgressBar(); var error = false; webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e) { progress.Report((double)e.ProgressPercentage / 100); }; webClient.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { File.Delete(savePath + driverFileName); } else { notifier.Set(); } }; try { webClient.DownloadFileAsync(new Uri(downloadURL), FULL_PATH_DRIVER); notifier.WaitOne(); } catch (Exception ex) { error = true; Console.Write("ERROR!"); Console.WriteLine(); Console.WriteLine(ex.ToString()); Console.WriteLine(); } progress.Dispose(); // dispone the progress bar if (!error) { Console.Write("OK!"); Console.WriteLine(); } } } else { using (DownloaderForm dlForm = new DownloaderForm()) { dlForm.Show(); dlForm.Focus(); dlForm.DownloadFile(new Uri(downloadURL), FULL_PATH_DRIVER); dlForm.Close(); } } } if (SettingManager.ReadSettingBool("Minimal install")) { MakeInstaller(minimized); } try { Console.WriteLine(); Console.Write("Executing driver installer . . . "); var minimalInstaller = SettingManager.ReadSettingBool("Minimal install"); var arguments = minimized ? "/s /noreboot" : "/nosplash"; Process.Start(SettingManager.ReadSettingBool("Minimal install") ? FULL_PATH_DIRECTORY + "setup.exe" : FULL_PATH_DRIVER, arguments).WaitForExit(); Console.Write("OK!"); } catch { Console.WriteLine("An error occurred preventing the driver installer to execute!"); } Console.WriteLine(); try { Directory.Delete(FULL_PATH_DIRECTORY, true); Console.WriteLine($"Cleaned up: {FULL_PATH_DIRECTORY}"); } catch { Console.WriteLine($"Could not cleanup: {FULL_PATH_DIRECTORY}"); } }