public Form1(string path) { InitializeComponent(); if (path != string.Empty) { if ((Path.GetExtension(path).ToLower() == ".qmk" || (Path.GetExtension(path).ToLower() == ".hex") || (Path.GetExtension(path).ToLower() == ".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(richTextBox1); flasher = new Flashing(printer); usb = new USB(flasher, printer); flasher.usb = usb; backgroundWorker1 = new BackgroundWorker(); backgroundWorker1.DoWork += backgroundWorker1_DoWork; backgroundWorker1.WorkerReportsProgress = true; }
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); } } }