Пример #1
0
        private void CopyLocalResource(Stream outputStream, IResourceBlock resourceBlock, ResourcePointer address,
                                       int length, int index = 0)
        {
            //  the resource has already been copied
            if (address < GetFilePosition( ))
            {
                //  if this is true then we've already handled this resource so use the
                //  new address
                ResourcePointer newAddress;
                if (ShiftData.TryGetValue(address, out newAddress))
                {
                    resourceBlock.SetResourcePointer(newAddress, index);
                    return;
                }
                //  has the resource already been copied? Has it been moved?
                //  well, shit.
                System.Diagnostics.Debug.WriteLineIf(address < GetFilePosition( ),
                                                     "Warning: address < GetFilePosition()");
                this.Seek(address);
            }
            //  this is not strictly an error but it should be treated as such
            if (address > GetFilePosition( ))
            {
                System.Diagnostics.Debug.WriteLineIf(address > GetFilePosition( ),
                                                     "Warning: address > GetFilePosition()");
                this.Seek(address);
            }
            System.Diagnostics.Debug.WriteLineIf(address % 512 != 0, "Warning: address % 512 != 0");
            if (outputStream.Position % 512 != 0)
            {
                System.Diagnostics.Debug.WriteLineIf(outputStream.Position % 512 != 0,
                                                     "Warning: output address % 512 != 0");
            }


            var position = outputStream.Position;

            ShiftData[address] = ( int )position;
            resourceBlock.SetResourcePointer(( int )position, index);

            var size = Padding.Align(length, 512);

            this.BufferedCopyBytesTo(size, outputStream);
        }