public MPQFile(string fileName) { lock (mAccessLock) { FileName = fileName; foreach (KeyValuePair <string, IntPtr> hArchive in MPQArchiveLoader.Instance.Archives) { bool ret = MPQArchiveLoader.SFileOpenFileEx(hArchive.Value, fileName, 0, ref fileHandle); if (ret) { break; } else { fileHandle = IntPtr.Zero; } } if (fileHandle == IntPtr.Zero) { throw new System.IO.FileNotFoundException("No MPQ-Archive contains the file!", fileName); } Load(fileHandle); } }
public static bool Exists(string fileName) { foreach (var val in MPQArchiveLoader.Instance.Archives) { if (MPQArchiveLoader.SFileHasFile(val.Value, fileName)) { return(true); } } return(false); }
internal void Load(IntPtr hFile) { uint sizeHigh = 0; uint fileSize = MPQArchiveLoader.SFileGetFileSize(hFile, ref sizeHigh); if (fileSize == 0) { throw new System.IO.FileNotFoundException("No MPQ-Archive contains the file with valid size!", FileName); } fileData = new byte[fileSize]; int bytesRead = 0; FileSize = fileSize; Position = 0; MPQArchiveLoader.SFileReadFile(hFile, fileData, (int)fileSize, ref bytesRead, IntPtr.Zero); MPQArchiveLoader.SFileCloseFile(hFile); }
public string[] GetFiles() { IntPtr lf = IntPtr.Zero; bool ret = MPQArchiveLoader.SFileOpenFileEx(mHandle, "(listfile)", 0, ref lf); if (ret == false) { return new string[] { } } ; MPQFile file = new MPQFile(); file.Load(lf); var bytes = file.Read(file.FileSize); string fullStr = Encoding.UTF8.GetString(bytes); return(fullStr.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); }