Esempio n. 1
0
        private void BackgroundWorker1DoWork(object sender, DoWorkEventArgs e)
        {
            _abort = false;
            _sw    = Stopwatch.StartNew();
            if (!(e.Argument is BWArgs))
            {
                return;
            }
            var args = e.Argument as BWArgs;

            try
            {
                #region XSVF

                if (args.Operation == BWArgs.Operations.XSVF)
                {
                    try {
                        _xsvfFlasher           = Main.GetXSVFFlasher();
                        _xsvfFlasher.Error    += MainOnError;
                        _xsvfFlasher.Status   += MainOnError;
                        _xsvfFlasher.Progress += MainOnProgress;
                        _xsvfFlasher.WriteXSVF(args.File);
                        e.Result = true;
                    }
                    catch (DeviceError ex) {
                        if (ex.ErrorLevel == DeviceError.ErrorLevels.IncompatibleDevice)
                        {
                            MessageBox.Show(Resources.IncompatibleXSVF);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                #endregion
                else if (args.Device == BWArgs.Devices.MMC)
                {
                    if (args.MMCDevice == null)
                    {
                        throw new Exception("Something went horribly wrong here!!");
                    }
                    _mmcFlasher = Main.GetMMCFlasher(args.MMCDevice);
                    if (_mmcFlasher == null)
                    {
                        e.Result = false;
                        return;
                    }
                    _mmcFlasher.Error    += MainOnError;
                    _mmcFlasher.Status   += MainOnError;
                    _mmcFlasher.Progress += MainOnProgress;
                    e.Result              = true;
                    switch (args.Operation)
                    {
                    case BWArgs.Operations.Read:
                        _mmcFlasher.Read(args.File, (long)mmcoffsetbox.Value, (long)mmccountbox.Value);
                        break;

                    case BWArgs.Operations.Erase:
                        _mmcFlasher.ZeroData((long)mmcoffsetbox.Value, (long)mmccountbox.Value);
                        break;

                    case BWArgs.Operations.Write:
                        _mmcFlasher.Write(args.File, (long)mmcoffsetbox.Value, (long)mmccountbox.Value, args.Verify);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    _spiFlasher = Main.GetSPIFlasher();
                    if (_spiFlasher == null)
                    {
                        e.Result = false;
                        return;
                    }
                    _spiFlasher.Error    += MainOnError;
                    _spiFlasher.Status   += MainOnError;
                    _spiFlasher.Progress += MainOnProgress;
                    e.Result              = true;
                    switch (args.Operation)
                    {
                    case BWArgs.Operations.Read:
                        _spiFlasher.Read((uint)spiblockbox.Value, (uint)spicountbox.Value, args.File, 1);
                        break;

                    case BWArgs.Operations.Erase:
                        _spiFlasher.Erase((uint)spiblockbox.Value, (uint)spicountbox.Value, 1);
                        break;

                    case BWArgs.Operations.Write:
                        var mode = SPIWriteModes.None;
                        if (args.AddSpare)
                        {
                            mode |= SPIWriteModes.AddSpare;
                        }
                        else if (args.CorrectSpare)
                        {
                            mode |= SPIWriteModes.CorrectSpare;
                        }
                        if (args.EraseFirst)
                        {
                            mode |= SPIWriteModes.EraseFirst;
                        }
                        if (args.Verify)
                        {
                            mode |= SPIWriteModes.VerifyAfter;
                        }
                        _spiFlasher.Write((uint)spiblockbox.Value, (uint)spicountbox.Value, args.File, mode, 1);
                        break;

                    default:
                        throw new Exception("Unkown Operation");
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(string.Format("Internal Exception: {0}{1}", Environment.NewLine, ex));
            }
            finally {
                switch (args.Device)
                {
                case BWArgs.Devices.SPI:
                    if (_spiFlasher != null)
                    {
                        _spiFlasher.Error    -= MainOnError;
                        _spiFlasher.Status   -= MainOnError;
                        _spiFlasher.Progress -= MainOnProgress;
                    }
                    _spiFlasher = null;
                    break;

                case BWArgs.Devices.MMC:
                    if (_mmcFlasher != null)
                    {
                        _mmcFlasher.Error    -= MainOnError;
                        _mmcFlasher.Status   -= MainOnError;
                        _mmcFlasher.Progress -= MainOnProgress;
                    }
                    _mmcFlasher = null;
                    break;
                }
                if (args.Operation == BWArgs.Operations.XSVF)
                {
                    if (_xsvfFlasher != null)
                    {
                        _xsvfFlasher.Error    -= MainOnError;
                        _xsvfFlasher.Status   -= MainOnError;
                        _xsvfFlasher.Progress -= MainOnProgress;
                    }
                    _xsvfFlasher = null;
                }
            }
        }
Esempio n. 2
0
        private void BackgroundWorker1DoWork(object sender, DoWorkEventArgs e)
        {
            _abort = false;
            _sw = Stopwatch.StartNew();
            if(!(e.Argument is BWArgs))
                return;
            var args = e.Argument as BWArgs;
            try
            {
                #region XSVF

                if (args.Operation == BWArgs.Operations.XSVF) {
                    try {
                        _xsvfFlasher = Main.GetXSVFFlasher();
                        _xsvfFlasher.Error += MainOnError;
                        _xsvfFlasher.Status += MainOnError;
                        _xsvfFlasher.Progress += MainOnProgress;
                        _xsvfFlasher.WriteXSVF(args.File);
                        e.Result = true;
                    }
                    catch(DeviceError ex) {
                        if(ex.ErrorLevel == DeviceError.ErrorLevels.IncompatibleDevice)
                            MessageBox.Show(Resources.IncompatibleXSVF);
                        else
                            throw;
                    }
                }

                #endregion
                else if(args.Device == BWArgs.Devices.MMC) {
                    if (args.MMCDevice == null)
                        throw new Exception("Something went horribly wrong here!!");
                    _mmcFlasher = Main.GetMMCFlasher(args.MMCDevice);
                    if (_mmcFlasher == null) {
                        e.Result = false;
                        return;
                    }
                    _mmcFlasher.Error += MainOnError;
                    _mmcFlasher.Status += MainOnError;
                    _mmcFlasher.Progress += MainOnProgress;
                    e.Result = true;
                    switch(args.Operation) {
                        case BWArgs.Operations.Read:
                            _mmcFlasher.Read(args.File, (long)mmcoffsetbox.Value, (long)mmccountbox.Value);
                            break;
                        case BWArgs.Operations.Erase:
                            _mmcFlasher.ZeroData((long)mmcoffsetbox.Value, (long)mmccountbox.Value);
                            break;
                        case BWArgs.Operations.Write:
                            _mmcFlasher.Write(args.File, (long)mmcoffsetbox.Value, (long)mmccountbox.Value, args.Verify);
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                else {
                    _spiFlasher = Main.GetSPIFlasher();
                    if(_spiFlasher == null) {
                        e.Result = false;
                        return;
                    }
                    _spiFlasher.Error += MainOnError;
                    _spiFlasher.Status += MainOnError;
                    _spiFlasher.Progress += MainOnProgress;
                    e.Result = true;
                    switch(args.Operation) {
                        case BWArgs.Operations.Read:
                            _spiFlasher.Read((uint) spiblockbox.Value, (uint) spicountbox.Value, args.File, 1);
                            break;
                        case BWArgs.Operations.Erase:
                            _spiFlasher.Erase((uint) spiblockbox.Value, (uint) spicountbox.Value, 1);
                            break;
                        case BWArgs.Operations.Write:
                            var mode = SPIWriteModes.None;
                            if(args.AddSpare)
                                mode |= SPIWriteModes.AddSpare;
                            else if(args.CorrectSpare)
                                mode |= SPIWriteModes.CorrectSpare;
                            if(args.EraseFirst)
                                mode |= SPIWriteModes.EraseFirst;
                            if(args.Verify)
                                mode |= SPIWriteModes.VerifyAfter;
                            _spiFlasher.Write((uint) spiblockbox.Value, (uint) spicountbox.Value, args.File, mode, 1);
                            break;
                        default:
                            throw new Exception("Unkown Operation");
                    }
                }
            }
                catch (Exception ex) {
                    MessageBox.Show(string.Format("Internal Exception: {0}{1}", Environment.NewLine, ex));
                }
            finally {
                switch(args.Device) {
                    case BWArgs.Devices.SPI:
                        if(_spiFlasher != null) {
                            _spiFlasher.Error -= MainOnError;
                            _spiFlasher.Status -= MainOnError;
                            _spiFlasher.Progress -= MainOnProgress;
                        }
                        _spiFlasher = null;
                        break;
                    case BWArgs.Devices.MMC:
                        if(_mmcFlasher != null)
                        {
                            _mmcFlasher.Error -= MainOnError;
                            _mmcFlasher.Status -= MainOnError;
                            _mmcFlasher.Progress -= MainOnProgress;
                        }
                        _mmcFlasher = null;
                        break;
                }
                if (args.Operation == BWArgs.Operations.XSVF) {
                    if (_xsvfFlasher != null) {
                        _xsvfFlasher.Error -= MainOnError;
                        _xsvfFlasher.Status -= MainOnError;
                        _xsvfFlasher.Progress -= MainOnProgress;
                    }
                    _xsvfFlasher = null;
                }
            }
        }