Exemplo n.º 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
            };
        }
Exemplo n.º 2
0
        public Flashing(Printing printer)
        {
            this.printer = printer;

            foreach (string resource in resources)
            {
                ExtractResource(resource);
            }

            System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver");
            query.Condition = "Name = 'libusb0'";
            System.Management.ManagementObjectSearcher 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);

                int  size    = 0;
                bool success = Program.SetupCopyOEMInf(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2", "atmel_usb_dfu.inf"), "", Program.OemSourceMediaType.SPOST_NONE, Program.OemCopyStyle.SP_COPY_NEWER, 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 System.Diagnostics.Process();
            //process.EnableRaisingEvents = true;
            //process.OutputDataReceived += OnOutputDataReceived;
            //process.ErrorDataReceived += OnErrorDataReceived;
            startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardError  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardInput  = true;
            startInfo.CreateNoWindow         = true;
        }
Exemplo n.º 3
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
            };
        }
Exemplo n.º 4
0
        public Flashing(Form1 form, Printing printer)
        {
            this.f       = form;
            this.printer = printer;

            foreach (string resource in resources)
            {
                ExtractResource(resource);
            }

            process   = new System.Diagnostics.Process();
            startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardError  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow         = true;
        }
Exemplo n.º 5
0
        public Flashing(Printing printer)
        {
            this.printer = printer;

            foreach (string resource in resources)
            {
                ExtractResource(resource);
            }

            process = new System.Diagnostics.Process();
            //process.EnableRaisingEvents = true;
            //process.OutputDataReceived += OnOutputDataReceived;
            //process.ErrorDataReceived += OnErrorDataReceived;
            startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardError  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardInput  = true;
            startInfo.CreateNoWindow         = true;
        }
Exemplo n.º 6
0
        public MainWindow(string path) : this()
        {
            if (path != string.Empty)
            {
                var extension = Path.GetExtension(path)?.ToLower();
                if (extension == ".qmk" || extension == ".hex" || extension == ".bin")
                {
                    _filePassedIn = path;
                }
                else
                {
                    MessageBox.Show("QMK Toolbox doesn't support this kind of file", "File Type Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            _printer     = new Printing(logTextBox);
            _flasher     = new Flashing(_printer);
            _usb         = new Usb(_flasher, _printer);
            _flasher.Usb = _usb;

            _usb.StartListeningForDeviceEvents(DeviceEvent);
        }
Exemplo n.º 7
0
 public Usb(Flashing flasher, Printing printer)
 {
     _flasher = flasher;
     _printer = printer;
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                AttachConsole(ATTACH_PARENT_PROCESS);

                Printing printer = new Printing();
                if (args.Length < 3)
                {
                    printer.print("QMK Toolbox (http://qmk.fm/toolbox)", MessageType.Info);
                    printer.printResponse("Supporting following bootloaders:\n", MessageType.Info);
                    printer.printResponse(" - DFU (Atmel, LUFA) via dfu-programmer (http://dfu-programmer.github.io/)\n", MessageType.Info);
                    printer.printResponse(" - Caterina (Arduino, Pro Micro) via avrdude (http://nongnu.org/avrdude/)\n", MessageType.Info);
                    printer.printResponse(" - Halfkay (Teensy, Ergodox EZ) via teensy_loader_cli (https://pjrc.com/teensy/loader_cli.html)\n", MessageType.Info);
                    printer.printResponse(" - STM32 (ARM) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
                    printer.printResponse(" - Kiibohd (ARM) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
                    printer.printResponse("And the following ISP flasher protocols:\n", MessageType.Info);
                    printer.printResponse(" - USBTiny (AVR Pocket)\n", MessageType.Info);
                    printer.printResponse(" - AVRISP (Arduino ISP)\n", MessageType.Info);
                    printer.printResponse("usage: qmk_toolbox.exe <mcu> <filepath>", MessageType.Info);
                }
                else
                {
                    printer.print("QMK Toolbox (http://qmk.fm/toolbox)", MessageType.Info);
                    Flashing flasher = new Flashing(printer);
                    USB      usb     = new USB(flasher, printer);
                    flasher.usb = usb;

                    ManagementObjectCollection collection;
                    using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity where DeviceID Like ""USB%"""))
                        collection = searcher.Get();

                    usb.DetectBootloaderFromCollection(collection);

                    if (args[0].Equals("flash"))
                    {
                        var mcu      = args[1];
                        var filepath = args[2];
                        flasher.flash(mcu, filepath);
                    }
                    else if (args[0].Equals("list"))
                    {
                    }
                    else if (args[0].Equals("eepromReset"))
                    {
                    }
                }

                FreeConsole();
            }
            else
            {
                if (mutex.WaitOne(TimeSpan.Zero, true))
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(args.Length == 0 ? new Form1(string.Empty) : new Form1(args[0]));
                    mutex.ReleaseMutex();
                }
                else
                {
                    // send our Win32 message to make the currently running instance
                    // jump on top of all the other windows
                    if (args.Length > 0)
                    {
                        using (StreamWriter sw = new StreamWriter(Path.Combine(Path.GetTempPath(), "qmk_toolbox/file_passed_in.txt"))) {
                            sw.WriteLine(args[0]);
                        }
                    }
                    NativeMethods.PostMessage(
                        (IntPtr)NativeMethods.HWND_BROADCAST,
                        NativeMethods.WM_SHOWME,
                        IntPtr.Zero,
                        IntPtr.Zero);
                }
            }
        }
Exemplo n.º 9
0
 public USB(Flashing flasher, Printing printer)
 {
     this.flasher = flasher;
     this.printer = printer;
 }
Exemplo n.º 10
0
        private static void Main(string[] args)
        {
            if (Mutex.WaitOne(TimeSpan.Zero, true) && args.Length > 0)
            {
                AttachConsole(AttachParentProcess);

                var printer = new Printing();
                if (args[0].Equals("list"))
                {
                    var flasher = new Flashing(printer);
                    var usb     = new Usb(flasher, printer);
                    flasher.Usb = usb;

                    ManagementObjectCollection collection;
                    using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE ""USB%"""))
                        collection = searcher.Get();

                    usb.DetectBootloaderFromCollection(collection);
                    FreeConsole();
                    Environment.Exit(0);
                }

                if (args[0].Equals("flash"))
                {
                    var flasher = new Flashing(printer);
                    var usb     = new Usb(flasher, printer);
                    flasher.Usb = usb;

                    ManagementObjectCollection collection;
                    using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE ""USB%"""))
                        collection = searcher.Get();

                    usb.DetectBootloaderFromCollection(collection);

                    if (usb.AreDevicesAvailable())
                    {
                        var mcu      = args[1];
                        var filepath = args[2];
                        printer.Print("Attempting to flash, please don't remove device", MessageType.Bootloader);
                        flasher.Flash(mcu, filepath);
                        FreeConsole();
                        Environment.Exit(0);
                    }
                    else
                    {
                        printer.Print("There are no devices available", MessageType.Error);
                        FreeConsole();
                        Environment.Exit(1);
                    }
                }

                if (args[0].Equals("help"))
                {
                    printer.Print("QMK Toolbox (http://qmk.fm/toolbox)", MessageType.Info);
                    printer.PrintResponse("Supported bootloaders:\n", MessageType.Info);
                    printer.PrintResponse(" - Atmel/LUFA/QMK DFU via dfu-programmer (http://dfu-programmer.github.io/)\n", MessageType.Info);
                    printer.PrintResponse(" - Caterina (Arduino, Pro Micro) via avrdude (http://nongnu.org/avrdude/)\n", MessageType.Info);
                    printer.PrintResponse(" - Halfkay (Teensy, Ergodox EZ) via Teensy Loader (https://pjrc.com/teensy/loader_cli.html)\n", MessageType.Info);
                    printer.PrintResponse(" - ARM DFU (STM32, Kiibohd) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
                    printer.PrintResponse(" - Atmel SAM-BA (Massdrop) via Massdrop Loader (https://github.com/massdrop/mdloader)\n", MessageType.Info);
                    printer.PrintResponse(" - BootloadHID (Atmel, PS2AVRGB) via bootloadHID (https://www.obdev.at/products/vusb/bootloadhid.html)\n", MessageType.Info);
                    printer.PrintResponse("Supported ISP flashers:\n", MessageType.Info);
                    printer.PrintResponse(" - USBTiny (AVR Pocket)\n", MessageType.Info);
                    printer.PrintResponse(" - AVRISP (Arduino ISP)\n", MessageType.Info);
                    printer.PrintResponse(" - USBasp (AVR ISP)\n", MessageType.Info);
                    printer.PrintResponse("usage: qmk_toolbox.exe <mcu> <filepath>", MessageType.Info);
                    FreeConsole();
                    Environment.Exit(0);
                }

                printer.Print("Command not found - use \"help\" for all commands", MessageType.Error);
                FreeConsole();
                Environment.Exit(1);
            }
            else
            {
                if (Mutex.WaitOne(TimeSpan.Zero, true))
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(args.Length == 0 ? new MainWindow(string.Empty) : new MainWindow(args[0]));
                    Mutex.ReleaseMutex();
                }
                else
                {
                    // send our Win32 message to make the currently running instance
                    // jump on top of all the other windows
                    if (args.Length > 0)
                    {
                        using (var sw = new StreamWriter(Path.Combine(Path.GetTempPath(), "qmk_toolbox/file_passed_in.txt")))
                        {
                            sw.WriteLine(args[0]);
                        }
                    }
                    NativeMethods.PostMessage(
                        (IntPtr)NativeMethods.HwndBroadcast,
                        NativeMethods.WmShowme,
                        IntPtr.Zero,
                        IntPtr.Zero);
                }
            }
        }