Close() public méthode

public Close ( ) : void
Résultat void
Exemple #1
0
        public void DoAction(Actions action, Stream file)
        {
            _abort = false;

            reader = new FirmwareReader(file);
            flashRanges = new GetFlashSizeResponse[MAX_FLASH_ARRAYS];

            try
            {
                EnterBootloaderResponse blInfo = this.EnterBootloader();
                if (blInfo.SiliconId != reader.SiliconId || blInfo.SiliconRev != reader.SiliconRev)
                    throw new UnsupportedDeviceException(blInfo.SiliconId, blInfo.SiliconRev, reader.SiliconId, reader.SiliconRev);
                if ((blInfo.Version & BOOTLOADER_VERSION_MASK) != SUPPORTED_BOOTLOADER)
                    throw new UnsupportedBootloaderException(blInfo.Version);

                for (FirmwareReader.Row row = reader.ReadRow(); row != null; row = reader.ReadRow())
                {
                    if (_abort) break;

                    ValidateRow(row.ArrayId, row.RowNumber);

                    switch (action)
                    {
                        case Actions.PROGRAM:
                            this.ProgramRow(row.ArrayId, row.RowNumber, row.Data);
                            goto case Actions.VERIFY;
                        case Actions.VERIFY:
                            byte checksum2 = (byte)(row.Checksum + row.ArrayId + row.RowNumber + (row.RowNumber >> 8) + row.Data.Length + (row.Data.Length >> 8));
                            VerifyRowResponse verify = this.VerifyRow(row.ArrayId, row.RowNumber);
                            if (verify.Checksum != checksum2)
                                throw new InvalidChecksumException(row.ArrayId, row.RowNumber);
                            break;
                        case Actions.ERASE:
                            this.EraseRow(row.ArrayId, row.RowNumber);
                            break;
                    }
                    if (this.Progress != null)
                        this.Progress((int)((reader.Position * 100) / reader.Length), row.ArrayId, row.RowNumber);
                }

                if (action != Actions.ERASE)
                {
                    VerifyChecksumResponse appVerify = this.VerifyChecksum();
                    if (!appVerify.ChecksumValid)
                        throw new InvalidChecksumException();
                }
            }
            finally
            {
                reader.Close();
                reader = null;
            }
        }
Exemple #2
0
        public void DoAction(Actions action, Stream file)
        {
            _abort = false;

            reader      = new FirmwareReader(file);
            flashRanges = new GetFlashSizeResponse[MAX_FLASH_ARRAYS];

            try
            {
                EnterBootloaderResponse blInfo = this.EnterBootloader();
                if (blInfo.SiliconId != reader.SiliconId || blInfo.SiliconRev != reader.SiliconRev)
                {
                    throw new UnsupportedDeviceException(blInfo.SiliconId, blInfo.SiliconRev, reader.SiliconId, reader.SiliconRev);
                }
                if ((blInfo.Version & BOOTLOADER_VERSION_MASK) != SUPPORTED_BOOTLOADER)
                {
                    throw new UnsupportedBootloaderException(blInfo.Version);
                }

                for (FirmwareReader.Row row = reader.ReadRow(); row != null; row = reader.ReadRow())
                {
                    if (_abort)
                    {
                        break;
                    }

                    ValidateRow(row.ArrayId, row.RowNumber);

                    switch (action)
                    {
                    case Actions.PROGRAM:
                        this.ProgramRow(row.ArrayId, row.RowNumber, row.Data);
                        goto case Actions.VERIFY;

                    case Actions.VERIFY:
                        byte checksum2           = (byte)(row.Checksum + row.ArrayId + row.RowNumber + (row.RowNumber >> 8) + row.Data.Length + (row.Data.Length >> 8));
                        VerifyRowResponse verify = this.VerifyRow(row.ArrayId, row.RowNumber);
                        if (verify.Checksum != checksum2)
                        {
                            throw new InvalidChecksumException(row.ArrayId, row.RowNumber);
                        }
                        break;

                    case Actions.ERASE:
                        this.EraseRow(row.ArrayId, row.RowNumber);
                        break;
                    }
                    if (this.Progress != null)
                    {
                        this.Progress((int)((reader.Position * 100) / reader.Length), row.ArrayId, row.RowNumber);
                    }
                }

                if (action != Actions.ERASE)
                {
                    VerifyChecksumResponse appVerify = this.VerifyChecksum();
                    if (!appVerify.ChecksumValid)
                    {
                        throw new InvalidChecksumException();
                    }
                }
            }
            finally
            {
                reader.Close();
                reader = null;
            }
        }