예제 #1
0
        private MpqServices()
        {
            m_path = Path.GetTempFileName();
            byte[] storm_dll;
            if (NativeMethods.Is64BitProcess)
            {
                storm_dll = Resources.StormLib64;
            }
            else
            {
                storm_dll = Resources.StormLib32;
            }

            File.WriteAllBytes(m_path, storm_dll);

            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>();
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #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;
        }
예제 #6
0
        internal MpqArchive(string path)
        {
            m_files = new List <MpqFileStream>();

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

            m_hMPQ = LateBoundStormDllApi.SFileOpenArchive(path, 1, 0);
        }
예제 #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;
        }
예제 #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 virtual bool ContainsFile(string fileName)
 {
     return(LateBoundStormDllApi.SFileHasFile(m_hMPQ, fileName));
 }