示例#1
0
        public Flashing(Printing printer)
        {
            _printer = printer;
            EmbeddedResourceHelper.ExtractResources(_resources);

            var query = new System.Management.SelectQuery("Win32_SystemDriver")
            {
                Condition = "Name = 'libusb0'"
            };
            var searcher = new System.Management.ManagementObjectSearcher(query);
            var drivers  = searcher.Get();

            if (drivers.Count > 0)
            {
                printer.Print("libusb0 driver found on system", MessageType.Info);
            }
            else
            {
                printer.Print("libusb0 driver not found - attempting to install", MessageType.Info);

                if (Directory.Exists(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2")))
                {
                    Directory.Delete(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2"), true);
                }
                ZipFile.ExtractToDirectory(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2.zip"), Application.LocalUserAppDataPath);

                var size    = 0;
                var success = Program.SetupCopyOEMInf(Path.Combine(Application.LocalUserAppDataPath,
                                                                   "dfu-prog-usb-1.2.2",
                                                                   "atmel_usb_dfu.inf"),
                                                      "",
                                                      Program.OemSourceMediaType.SpostNone,
                                                      Program.OemCopyStyle.SpCopyNewer,
                                                      null,
                                                      0,
                                                      ref size,
                                                      null);
                if (!success)
                {
                    var errorCode   = Marshal.GetLastWin32Error();
                    var errorString = new Win32Exception(errorCode).Message;
                    printer.Print("Error: " + errorString, MessageType.Error);
                }
            }

            _process = new Process();
            //process.EnableRaisingEvents = true;
            //process.OutputDataReceived += OnOutputDataReceived;
            //process.ErrorDataReceived += OnErrorDataReceived;
            _startInfo = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                CreateNoWindow         = true
            };
        }
示例#2
0
        public Flashing(Printing printer)
        {
            _printer = printer;
            EmbeddedResourceHelper.ExtractResources(_resources);

            _process   = new Process();
            _startInfo = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                CreateNoWindow         = true
            };
        }
示例#3
0
        private static bool InstallDrivers()
        {
            const string drivers   = "drivers.txt";
            const string installer = "qmk_driver_installer.exe";

            var driversPath   = Path.Combine(Application.LocalUserAppDataPath, drivers);
            var installerPath = Path.Combine(Application.LocalUserAppDataPath, installer);

            if (!File.Exists(driversPath))
            {
                EmbeddedResourceHelper.ExtractResources(drivers);
            }
            if (!File.Exists(installerPath))
            {
                EmbeddedResourceHelper.ExtractResources(installer);
            }

            var process = new Process
            {
                StartInfo = new ProcessStartInfo(installerPath, $"--all --force \"{driversPath}\"")
                {
                    Verb = "runas"
                }
            };

            try
            {
                process.Start();
                Settings.Default.driversInstalled = true;
                Settings.Default.Save();
                return(true);
            }
            catch (Win32Exception)
            {
                var tryAgain = MessageBox.Show("This action requires administrator rights, do you want to try again?", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry;
                return(tryAgain && InstallDrivers());
            }
        }