Ejemplo n.º 1
0
        /// <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();

            string FULL_PATH_DIRECTORY = savePath + OnlineGPUVersion + @"\";
            string 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 (WebClient webClient = new WebClient()) {
                        var  notifier = new AutoResetEvent(false);
                        var  progress = new ProgressBar();
                        bool error    = false;

                        webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e) {
                            progress.Report((double)e.ProgressPercentage / 100);

                            if (e.BytesReceived >= e.TotalBytesToReceive)
                            {
                                notifier.Set();
                            }
                        };

                        webClient.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e) {
                            if (e.Cancelled)
                            {
                                File.Delete(FULL_PATH_DRIVER);
                            }
                        };

                        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("Running installer . . . ");
                if (SettingManager.ReadSettingBool("Minimal install"))
                {
                    Process.Start(FULL_PATH_DIRECTORY + "setup.exe", "/s").WaitForExit();
                }
                else
                {
                    if (minimized)
                    {
                        Process.Start(FULL_PATH_DRIVER, "/s").WaitForExit();
                    }
                    else
                    {
                        Process.Start(FULL_PATH_DRIVER, "/noeula").WaitForExit();
                    }
                }

                Console.Write("OK!");
            } catch {
                Console.WriteLine("Could not run driver installer!");
            }

            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);
            }
        }
Ejemplo n.º 3
0
        /// <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}");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Downloads the driver and some other stuff
        /// </summary>
        private static void DownloadDriver()
        {
            int    DateDiff = (DateTime.Now - releaseDate).Days; // how many days between the two dates
            string theDate  = null;

            if (DateDiff == 1)
            {
                theDate = DateDiff + " day ago";
            }
            else if (DateDiff < 1)
            {
                theDate = "today"; // we only have the date and not time :/
            }
            else
            {
                theDate = DateDiff + " days ago";
            }

            string message = "Graphics card drivers are available, do you want to update now?" + Environment.NewLine + Environment.NewLine;

            string key = "Show Driver Description";
            string val = null;

            // loop
            while (val != "true" & val != "false")
            {
                val = SettingManager.ReadSetting(key); // refresh value each time

                if (val == "true")
                {
                    message = message + "Description: " + releaseDesc + Environment.NewLine + Environment.NewLine;
                }
                else if (val == "false")
                {
                    break;
                }
                else
                {
                    // invalid value
                    SettingManager.SetupSetting(key);
                }
            }

            message += "Driver version: " + OnlineGPUVersion + " (you're running " + OfflineGPUVersion + ")" + Environment.NewLine +
                       "Driver released: " + theDate + " (" + releaseDate.ToShortDateString() + ")";

            DialogResult dialog = MessageBox.Show(message, "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dialog == DialogResult.Yes)
            {
                Console.WriteLine();

                bool error = false;
                driverFileName = downloadURL.Split('/').Last(); // retrives file name from url

                try {
                    message = "Where do you want to save the drivers?";

                    key = "Minimal install";
                    val = null; // reset value

                    // loop
                    while (val != "true" & val != "false")
                    {
                        val = SettingManager.ReadSetting(key); // refresh value each time
                        if (val == "true")
                        {
                            message += " (you should select a empty folder)";
                        }
                        else if (val == "false")
                        {
                            break;
                        }
                        else
                        {
                            // invalid value
                            SettingManager.SetupSetting(key);
                        }
                    }

                    DialogResult result;
                    using (FolderBrowserDialog folderDialog = new FolderBrowserDialog()) {
                        folderDialog.Description = message;

                        result = folderDialog.ShowDialog(); // show dialog and get status (will wait for input)
                        switch (result)
                        {
                        case DialogResult.OK:
                            savePath = folderDialog.SelectedPath;
                            break;

                        default:
                            Console.WriteLine("User closed dialog!");
                            return;
                        }
                    }

                    // 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 ProgressBar();

                            webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e)
                            {
                                progress.Report((double)e.ProgressPercentage / 100);

                                if (e.BytesReceived >= e.TotalBytesToReceive)
                                {
                                    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))
                    {
                        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!");
                    LogManager.Log(ex.Message, LogManager.Level.ERROR);
                    Console.WriteLine();
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine();
                }

                if (error == false)
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug == true)
                {
                    Console.WriteLine("savePath: " + savePath);
                }

                dialog = MessageBox.Show("Do you want view the release PDF?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.Yes)
                {
                    try {
                        Process.Start(pdfURL);
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex.StackTrace);
                    }
                }

                key = "Minimal install";
                val = null; // reset value
                // loop
                while (val != "true" & val != "false")
                {
                    val = SettingManager.ReadSetting(key); // refresh value each time
                    if (val == "true")
                    {
                        MakeInstaller();
                    }
                    else if (val == "false")
                    {
                        break;
                    }
                    else
                    {
                        // invalid value
                        SettingManager.SetupSetting(key);
                    }
                }

                dialog = MessageBox.Show("Do you wish to run the driver installer?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.Yes)
                {
                    try {
                        if (val == "true")
                        {
                            // extracted
                            Process.Start(savePath + @"\setup.exe");
                        }
                        else
                        {
                            Process.Start(savePath + @"\" + driverFileName);
                        }
                    } catch (Exception ex) {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }