Example #1
0
        public bool ExtractTo(string to)
        {
            uint dwSize = GetSize();

            if (dwSize == 0)
            {
                return(false);
            }

            // hope we won't run OOM
            byte[] szBuffer = new byte[dwSize];

            using (FileStream file = File.Create(to))
            {
                int dwBytes;

                bool r = StormLib.SFileReadFile(handle, szBuffer, szBuffer.Length, out dwBytes, IntPtr.Zero);

                if (dwBytes != szBuffer.Length)
                {
                    throw new IOException(String.Format("Can't extract {0} properly!", to));
                }

                if (dwBytes > 0)
                {
                    file.Write(szBuffer, 0, dwBytes);
                }

                return(r);
            }
        }
Example #2
0
        public unsafe override int Read(byte[] buffer, int offset, int count)
        {
            fixed(byte *bufferPointer = buffer)
            {
                long bytesRead;

                if (!StormLib.SFileReadFile(handle, bufferPointer + offset, count, out bytesRead))
                {
                    throw new IOException("SFileReadFile failed");
                }
                position += bytesRead;
                return((int)bytesRead);
            }
        }