Exemplo n.º 1
0
        /// <summary>
        /// Moves the current location within the stream to the specified location.
        /// </summary>
        /// <param name="offset">The offset relative to the seek origin.</param>
        /// <param name="origin">The seek origin.</param>
        /// <returns>The new position in the file.</returns>
        public override long Seek(long offset, SeekOrigin origin)
        {
            long newPos = LateBoundStormDllApi.SFileSetFilePointer(m_hFile, offset, origin);

            m_pos = newPos;
            return(m_pos);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads data from the underlying stream into the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer that will receive the data.</param>
        /// <param name="offset">The starting location in the buffer to get the data.</param>
        /// <param name="count">The amount of data to be read.</param>
        /// <remarks>
        /// <para>Rather than throwing an exception, if the buffer is too small to return the requested amount of
        /// data, only as much data as the buffer can hold is returned.</para>
        /// </remarks>
        /// <returns>The number of bytes read.</returns>
        public override int Read(byte[] buffer, int offset, int count)
        {
            checkDisposed();

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", "The read buffer cannot be null.");
            }

            int maxLen = count - offset;

            if (maxLen > buffer.Length)
            {
                maxLen = buffer.Length;
            }

            int bytesToCopy = (int)(Length - Position);

            if (bytesToCopy > maxLen)
            {
                bytesToCopy = maxLen;
            }

            byte[] tmpBuffer = new byte[maxLen];

            int amount = LateBoundStormDllApi.SFileReadFile(m_hFile, tmpBuffer, bytesToCopy);

            Buffer.BlockCopy(tmpBuffer, 0, buffer, offset, amount);

            m_pos += amount;

            return(amount);
        }
Exemplo n.º 3
0
        private MpqServices()
        {
            m_path = Path.GetTempFileName();
            //Console.WriteLine(m_path);
            FileStream fs = new FileStream(m_path, FileMode.Open, FileAccess.Write, FileShare.None);

            byte[] storm_dll;
            if (NativeMethods.Is64BitProcess)
            {
                storm_dll = Resources.StormLib64;
            }
            else
            {
                storm_dll = Resources.StormLib32;
            }

            fs.Write(storm_dll, 0, storm_dll.Length);
            fs.Close();

            m_hMod = NativeMethods.LoadLibrary(m_path);
            if (m_hMod == IntPtr.Zero)
            {
                int win32err = Marshal.GetLastWin32Error();
                File.Delete(m_path);
                throw new Win32Exception(win32err);
            }

            LateBoundStormDllApi.Initialize(m_hMod);

            m_archives = new List <MpqArchive>();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Cleans up unmanaged resources used by this archive.
        /// </summary>
        /// <param name="disposing"><c>true</c> if the object is being disposed; <c>false</c> if it is being finalized.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (m_disposed)
            {
                return;
            }

            if (disposing)
            {
                foreach (MpqFileStream mfs in m_files)
                {
                    mfs.Dispose();
                }

                m_files.Clear();
                m_files = null;
            }

            if (m_hMPQ != IntPtr.Zero)
            {
                LateBoundStormDllApi.SFileCloseArchive(m_hMPQ);
            }

            m_disposed = true;

            MpqServices.NotifyArchiveDisposed(this);
        }
Exemplo n.º 5
0
        internal MpqFileStream(string internalPath, MpqArchive parent)
        {
            m_owner = parent;

            IntPtr hFile = LateBoundStormDllApi.SFileOpenFileEx(parent.Handle, internalPath, SearchType.CurrentOnly);

            m_path  = internalPath;
            m_hFile = hFile;
        }
Exemplo n.º 6
0
        internal MpqArchive(string path)
        {
            m_files = new List <MpqFileStream>();

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(Resources.fileNotFound, path);
            }

            m_hMPQ = LateBoundStormDllApi.SFileOpenArchive(path, 1, 0);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Cleans up unmanaged resources in use.
        /// </summary>
        /// <param name="disposing"><c>true</c> if the object is being disposed; <c>false</c> if it is being finalized.</param>
        protected override void Dispose(bool disposing)
        {
            if (m_disposed)
            {
                return;
            }

            if (m_hFile != IntPtr.Zero)
            {
                LateBoundStormDllApi.SFileCloseFile(m_hFile);
                m_hFile = IntPtr.Zero;

                m_owner.FileIsDisposed(this);
                m_owner = null;
                m_path  = null;
            }

            m_disposed = true;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Determines whether the archive contains the specified file.
 /// </summary>
 /// <param name="fileName">The path to the file relative to the MPQ root.</param>
 /// <returns><b>True</b> if the file is contained within the MPQ; otherwise <b>false</b>.</returns>
 public bool ContainsFile(string fileName)
 {
     return(LateBoundStormDllApi.SFileHasFile(m_hMPQ, fileName));
 }