Beispiel #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);
            }
        }
Beispiel #2
0
 public void Close()
 {
     if (handle != IntPtr.Zero)
     {
         StormLib.SFileCloseArchive(handle);
         handle = IntPtr.Zero;
     }
 }
Beispiel #3
0
 public sealed override void Close()
 {
     base.Close();
     if (handle != IntPtr.Zero)
     {
         StormLib.SFileCloseFile(handle);
         handle = IntPtr.Zero;
     }
 }
Beispiel #4
0
        public bool Close()
        {
            bool r = StormLib.SFileCloseArchive(handle);

            if (r)
            {
                handle = IntPtr.Zero;
            }
            return(r);
        }
Beispiel #5
0
        private bool Open(string file, uint Prio, OpenArchiveFlags Flags)
        {
            bool r = StormLib.SFileOpenArchive(file, Prio, Flags, out handle);

            if (r)
            {
                OpenPatch(file);
            }
            return(r);
        }
Beispiel #6
0
        public bool ExtractFile(string from, string to, OpenFile dwSearchScope)
        {
            var dir = Path.GetDirectoryName(to);

            if (!Directory.Exists(dir) && !String.IsNullOrEmpty(dir))
            {
                Directory.CreateDirectory(dir);
            }

            return(StormLib.SFileExtractFile(handle, from, to, dwSearchScope));
        }
Beispiel #7
0
 public MpqArchive(string filename)
 {
     if (!File.Exists(filename))
     {
         throw new FileNotFoundException(filename);
     }
     if (!StormLib.SFileOpenArchive(filename, 0, OpenArchiveFlags.READ_ONLY, out handle))
     {
         throw new IOException("SFileOpenArchive failed");
     }
 }
Beispiel #8
0
        public unsafe MpqFile OpenFile(string szFileName, OpenFileFlags dwSearchScope)
        {
            IntPtr h;
            IntPtr hp = (IntPtr)(&h);
            bool   r  = StormLib.SFileOpenFileEx(handle, szFileName, dwSearchScope, hp);

            if (!r)
            {
                return(null);
            }
            return(new MpqFile(this, h));
        }
Beispiel #9
0
        private unsafe bool Open(string file, uint Prio, OpenArchiveFlags Flags)
        {
            IntPtr h;
            IntPtr hp = (IntPtr)(&h);
            bool   r  = StormLib.SFileOpenArchive(file, Prio, Flags, hp);

            if (r)
            {
                handle = h;
                OpenPatch(file);
            }
            return(r);
        }
Beispiel #10
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);
            }
        }
Beispiel #11
0
        public MpqFileStream OpenFile(string filename)
        {
            if (!HasFile(filename))
            {
                throw new FileNotFoundException();
            }

            IntPtr fileHandle;

            if (!StormLib.SFileOpenFileEx(handle, filename, OpenFileFlags.FROM_MPQ, out fileHandle))
            {
                throw new IOException("SFileOpenFileEx failed");
            }

            return(new MpqFileStream(fileHandle));
        }
Beispiel #12
0
        private void OpenPatch(string file)
        {
            var patches = Directory.GetFiles(MpqArchiveSet.GetGameDirFromReg(), "Data\\wow-update-*.mpq");

            var prefix = MpqLocale.GetPrefix(file);

            foreach (var patch in patches)
            {
                // hack due to multiple variants of game world in current client (world.mpq + oldworld.mpq), which can't be used at same time
                if (patch.Contains("oldworld"))
                {
                    continue;
                }

                bool r = StormLib.SFileOpenPatchArchive(handle, patch, prefix, 0);
            }
        }
Beispiel #13
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            MoveMethod moveMethod = MoveMethod.Begin;

            switch (origin)
            {
            case SeekOrigin.Begin: moveMethod = MoveMethod.Begin; break;

            case SeekOrigin.Current: moveMethod = MoveMethod.Current; break;

            case SeekOrigin.End: moveMethod = MoveMethod.End; break;
            }

            var result = StormLib.SFileSetFilePointer(handle, offset, IntPtr.Zero, moveMethod);

            if (result == StormLib.SFILE_INVALID_SIZE)
            {
                throw new IOException("SFileSetFilePointer failed");
            }
            position = result;
            return(position);
        }
Beispiel #14
0
        private void OpenPatch(string file)
        {
            var gamedir = MpqArchiveSet.GetGameDirFromReg();

            var patches = Directory.GetFiles(gamedir, "Data\\wow-update-*.mpq").ToList();

            var prefix = MpqLocale.GetPrefix(file);

            if (prefix != "base")
            {
                patches.RemoveAll(s => s.Contains("base"));

                var localePatches = Directory.GetFiles(gamedir, String.Format("Data\\{0}\\wow-update-*.mpq", prefix));

                patches.AddRange(localePatches);
            }

            foreach (var patch in patches)
            {
                prefix = MpqLocale.GetPrefix(file);
                var pref = MpqLocale.GetPrefixForPatch(patch);

                if (pref != "locale")
                {
                    prefix = String.Empty;
                }

                Console.WriteLine("Adding patch: {0} with prefix {1}", Path.GetFileName(patch), prefix != String.Empty ? "\"" + prefix + "\"" : "\"\"");
                bool r = StormLib.SFileOpenPatchArchive(handle, patch, prefix, 0);
                if (!r)
                {
                    Console.WriteLine("Failed to add patch: {0}", Path.GetFileName(patch));
                }
                else
                {
                    Console.WriteLine("Added patch: {0}", Path.GetFileName(patch));
                }
            }
        }
Beispiel #15
0
        public uint GetSize()
        {
            uint high;

            return(StormLib.SFileGetFileSize(handle, out high));
        }
Beispiel #16
0
 public bool HasFile(string name)
 {
     return(StormLib.SFileHasFile(handle, name));
 }
Beispiel #17
0
 public bool ExtractFile(string from, string to)
 {
     return(StormLib.SFileExtractFile(handle, from, to));
 }