public static Pack LoadBinary(string path) { Pack pack = new Pack(path); using (FileStream fileStream = File.OpenRead(path)) { BinaryReaderBigEndian binaryReader = new BinaryReaderBigEndian(fileStream); 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, binaryReader.BaseStream); pack.assetLookupCache[file.Name] = file; pack.Assets.Add(file); } } while (nextChunkAbsoluteOffset != 0); return(pack); } }
public static AssetRef LoadBinary(Pack pack, Stream stream) { BinaryReaderBigEndian reader = new BinaryReaderBigEndian(stream); AssetRef assetRef = new AssetRef(pack); uint count = reader.ReadUInt32(); assetRef.Name = new string(reader.ReadChars((int)count)); 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.Type = (Types)Enum.Parse(typeof(Types), extension, true); } catch (ArgumentException) { // This extension isn't mapped in the enum Debug.LogWarning("Unknown Forgelight File Type: " + extension); assetRef.Type = Types.Unknown; } } return(assetRef); }