public static Package Open(string strPackPath) { Package pakPackage = null; if (strPackPath != null) { if (!File.Exists(strPackPath)) { strPackPath = null; } string strManifestPath = Path.ChangeExtension(strPackPath, ".PAK.MAN"); if (strPackPath != null && !File.Exists(strManifestPath)) { MessageBox.Show("Unable to locate the coresponding\r\n" + "manifest for this package", "TL2MH", MessageBoxButtons.OK, MessageBoxIcon.Error); strManifestPath = null; } if (strPackPath != null && strManifestPath != null) { List<PackageEntry> lstEntries = ReadManifest(strManifestPath); Dictionary<string, FolderEntry> dctMap = new Dictionary<string, FolderEntry>(); FolderEntry feRoot = new FolderEntry(Path.GetDirectoryName(lstEntries[0].Name), lstEntries[0]); dctMap[lstEntries[0].Name] = feRoot; for (int nCurrEntry = 1; nCurrEntry < lstEntries.Count; nCurrEntry++) { PackageEntry entCurr = lstEntries[nCurrEntry]; if (entCurr.Type == FileType.Directory) { FolderEntry feSubFolder = new FolderEntry(Path.GetDirectoryName(entCurr.Name), entCurr); dctMap[entCurr.GroupName].SubFolders.Add(feSubFolder); dctMap[entCurr.GroupName + entCurr.Name] = feSubFolder; } else { FileEntry feFile = new FileEntry(Path.GetFileName(entCurr.Name), entCurr); dctMap[entCurr.GroupName].Files.Add(feFile); } } pakPackage = new Package(strPackPath, feRoot); } } return pakPackage; }
public byte[] GetContent(FileEntry fileEntry) { var entry = (PackageEntry)fileEntry.Tag; this._packageStream.Seek(entry.Offset, SeekOrigin.Begin); byte[] sizeBytes = new byte[sizeof(int)]; // Uncompressed size this._packageStream.Read(sizeBytes, 0, sizeof(int)); if (BitConverter.ToInt32(sizeBytes, 0) > 0) { this._packageStream.Seek(entry.Offset + 10, SeekOrigin.Begin); byte[] content = new byte[0]; using (DeflateStream dfsDecompressor = new DeflateStream(this._packageStream, CompressionMode.Decompress, true)) { byte[] buffer = new byte[4096]; int read = dfsDecompressor.Read(buffer, 0, 4096); int pos; while (read > 0) { pos = content.Length; Array.Resize(ref content, content.Length + read); Array.Copy(buffer, 0, content, pos, read); read = dfsDecompressor.Read(buffer, 0, 4096); } } return content; } return new byte[0]; }