Example #1
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            string fileName;

            using (var op = new OpenFileDialog {
                Title = @"Select encrypted or decrypted firmware file ...", Filter = Consts.FirmwareFilter
            })
            {
                if (op.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                fileName = op.FileName;
            }

            try
            {
                var firmware = m_loader.LoadFile(fileName);
                if (FirmwareLoader.FindByteArray(firmware, Encoding.UTF8.GetBytes(m_connectedDeviceProductId)) == -1)
                {
                    InfoBox.Show("Selected firmware file is not suitable for the connected device.");
                    return;
                }
                m_worker.RunWorkerAsync(firmware);
            }
            catch (Exception ex)
            {
                InfoBox.Show("An exception occured during firmware update.\n" + ex.Message);
            }
        }
        private void UpdateFirmware(Func <byte[]> firmwareFunc)
        {
            var skipValidation = ModifierKeys.HasFlag(Keys.Control) && ModifierKeys.HasFlag(Keys.Alt);

            try
            {
                var firmware = firmwareFunc();
                if (!skipValidation && FirmwareLoader.FindByteArray(firmware, Encoding.UTF8.GetBytes(m_connectedDeviceProductId)) == -1)
                {
                    InfoBox.Show("Opened firmware file is not suitable for the connected device.");
                    return;
                }
                m_worker.RunWorkerAsync(new AsyncProcessWrapper(worker => UpdateFirmwareAsyncWorker(worker, firmware)));
            }
            catch (Exception ex)
            {
                InfoBox.Show("An error occured during firmware update.\n" + ex.Message);
            }
        }