Ejemplo n.º 1
0
        public IEnumerable <FfuFileBlock> EnumerateBlocks()
        {
            var block = new byte[_file.BlockSizeInBytes];

            for (int i = 0; i < _descriptors.Count; i++)
            {
                // move to block #i
                _file.SeekBegin(PayloadPosition + i * _file.BlockSizeInBytes);

                if (!_file.TryRead(block))
                {
                    throw new InvalidDataException();
                }

                var desc = _descriptors[i];
                foreach (var location in desc.Locations)
                {
                    var bl = new FfuFileBlock
                    {
                        DescriptorIndex = i,
                        Data            = block
                    };
                    switch (location.dwDiskAccessMethod)
                    {
                    case FfuFile.DISK_ACCESS_METHOD.DISK_BEGIN:
                        bl.TargetSeekOrigin = SeekOrigin.Begin;
                        bl.TargetSeekOffset = location.dwBlockIndex * (long)_file.BlockSizeInBytes;
                        break;

                    case FfuFile.DISK_ACCESS_METHOD.DISK_END:
                        bl.TargetSeekOrigin = SeekOrigin.End;
                        bl.TargetSeekOffset = -((location.dwBlockIndex + 1) * (long)_file.BlockSizeInBytes);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    yield return(bl);
                }
            }
        }
Ejemplo n.º 2
0
 private void OnProgressChanged(FfuFileBlock block)
 {
     ProgressChanged?.Invoke(this, new ProgressChangedEventArgs((100 * block.DescriptorIndex) / _descriptors.Count, block));
 }