Ejemplo n.º 1
0
 public static void ShowGUI()
 {
     // show the form
     using (var form = new DriverDialog()) {
         form.ShowDialog();
     }
 }
Ejemplo n.º 2
0
        public static string ShowGUI()
        {
            // show the form
            using (DriverDialog form = new DriverDialog()) {
                form.ShowDialog();
            }

            return(null);
        }
Ejemplo n.º 3
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);
            }
        }