Exemplo n.º 1
0
        /// <summary>
        /// Seeks to a position within the stream
        /// </summary>
        /// <param name="offset">offset to seek</param>
        /// <param name="origin">seek origin</param>
        /// <returns>Returns the new position</returns>
        public override long Seek(long offset, SeekOrigin origin)
        {
            if (fileStream == null)
            {
                throw new ObjectDisposedException("fileStream", "storage stream no longer available");
            }
            long     l        = 0;
            object   local    = l;
            GCHandle gCHandle = new GCHandle();

            try
            {
                gCHandle = GCHandle.Alloc(local, GCHandleType.Pinned);
                IntPtr i = gCHandle.AddrOfPinnedObject();
                fileStream.Seek(offset, (int)origin, i);
                l = (long)local;
            }
            finally
            {
                if (gCHandle.IsAllocated)
                {
                    gCHandle.Free();
                }
            }
            return(l);
        }
Exemplo n.º 2
0
 public override long Seek(long offset, SeekOrigin origin)
 {
     using (var buffer = new SafeStructureInOutBuffer <long>())
     {
         _stm.Seek(0, (int)origin, buffer.DangerousGetHandle());
         return(buffer.Result);
     }
 }
Exemplo n.º 3
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            IntPtr newPosPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long)));

            _baseStream.Seek(offset, (int)origin, newPosPtr);
            long newPos = newPosPtr.ToInt64();

            Marshal.FreeHGlobal(newPosPtr);
            _currentPosition = newPos;
            return(newPos);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Move the current pointer in the strea relative to the seek origin
        /// </summary>
        /// <param name="offset">The number of bytes to move from origin</param>
        /// <param name="origin">Move from begging, current cursor, or end of file</param>
        /// <returns></returns>
        public override long Seek(long offset, SeekOrigin origin)
        {
            int dwOrigin = 0;

            switch (origin)
            {
            case SeekOrigin.Begin:
                dwOrigin = 0;
                break;

            case SeekOrigin.Current:
                dwOrigin = 1;
                break;

            case SeekOrigin.End:
                dwOrigin = 2;
                break;

            default:
                throw new ArgumentException("Invalid seek origin");
            }

            //ensure not seeking while reading
            lock (this)
            {
                unsafe
                {
                    // getting casting errors is unlikely as that would be millions of terrabytes for a single file
                    // This memory will be fixed due to it being declared in unsafe and allow taking the address
                    ulong ulongPosition = (ulong)m_position;

                    m_cachedIstream.Seek(offset, dwOrigin, new IntPtr(&ulongPosition));

                    m_position = (long)ulongPosition;
                }
            }
            return(m_position);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Create the optical disk image.
        /// </summary>
        /// <returns></returns>
        public COMTypes.IStream CreateImageStream(IFileSystemImageResult fsres)
        {
            var ppos = IntPtr.Zero;

            COMTypes.IStream imagestream = null;
            try
            {
                _fsres      = fsres;
                imagestream = fsres.ImageStream;
                ppos        = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long)));
                imagestream.Seek(0, 0, ppos);
                if (Marshal.ReadInt64(ppos) != 0)
                {
                    throw new IOException("Can't reset the stream position");
                }

                //IDiscFormat2Data idf = this as IDiscFormat2Data;
                //idf.Write(imagestream);
            }
            catch (Exception exc)
            {
                if (!string.IsNullOrEmpty(OutputFileName))
                {
                    File.Delete(OutputFileName);
                }
                Debug.WriteLine(exc.ToString());
            }
            finally
            {
                if (ppos != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(ppos);
                }
            }
            return(imagestream);
        }