public static Pack LoadBinary(string path) { Pack pack = new Pack(path); using (FileStream fileStream = File.OpenRead(path)) { using (BinaryDataReader binaryReader = new BinaryDataReader(fileStream, true)) { binaryReader.ByteOrder = ByteOrder.BigEndian; uint nextChunkAbsoluteOffset = 0; do { fileStream.Seek(nextChunkAbsoluteOffset, SeekOrigin.Begin); nextChunkAbsoluteOffset = binaryReader.ReadUInt32(); uint fileCount = binaryReader.ReadUInt32(); for (uint i = 0; i < fileCount; ++i) { AssetRef file = AssetRef.LoadBinary(pack, fileStream); pack.assetLookupCache[file.Name] = file; pack.Assets.Add(file); } } while (nextChunkAbsoluteOffset != 0); } return(pack); } }
public static AssetRef LoadBinary(Pack pack, Stream stream) { AssetRef assetRef; using (BinaryDataReader reader = new BinaryDataReader(stream, true)) { reader.ByteOrder = ByteOrder.BigEndian; assetRef = new AssetRef(pack); uint count = reader.ReadUInt32(); assetRef.Name = new string(reader.ReadChars((int)count)); assetRef.DisplayName = assetRef.Name + " (" + pack.Name + ')'; assetRef.AbsoluteOffset = reader.ReadUInt32(); assetRef.Size = reader.ReadUInt32(); assetRef.Crc32 = reader.ReadUInt32(); // Set the type of the asset based on the extension { // First get the extension without the leading '.' string extension = Path.GetExtension(assetRef.Name).Substring(1); try { assetRef.AssetType = (AssetType)Enum.Parse(typeof(AssetType), extension, true); } catch (ArgumentException) { // This extension isn't mapped in the enum Debug.LogWarning("Unknown Forgelight File Type: " + extension); assetRef.AssetType = AssetType.Unknown; } } } return(assetRef); }