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); } }
public void Close() { if (handle != IntPtr.Zero) { StormLib.SFileCloseArchive(handle); handle = IntPtr.Zero; } }
public sealed override void Close() { base.Close(); if (handle != IntPtr.Zero) { StormLib.SFileCloseFile(handle); handle = IntPtr.Zero; } }
public bool Close() { bool r = StormLib.SFileCloseArchive(handle); if (r) { handle = IntPtr.Zero; } return(r); }
private bool Open(string file, uint Prio, OpenArchiveFlags Flags) { bool r = StormLib.SFileOpenArchive(file, Prio, Flags, out handle); if (r) { OpenPatch(file); } return(r); }
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)); }
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"); } }
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)); }
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); }
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); } }
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)); }
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); } }
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); }
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)); } } }
public uint GetSize() { uint high; return(StormLib.SFileGetFileSize(handle, out high)); }
public bool HasFile(string name) { return(StormLib.SFileHasFile(handle, name)); }
public bool ExtractFile(string from, string to) { return(StormLib.SFileExtractFile(handle, from, to)); }