public void RemoveBundleArchive(AssetBundleArchive bundle) { lock (_lock) { bundle.ArchiveContainer = null; this.bundles.Remove(bundle); } }
public static AssetBundleArchive Load(string path) { using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { AssetBundleArchive bundle = Load(fileStream); bundle.Path = path; return(bundle); } }
public AssetArchive(AssetBundleArchive bundle, string name, long fileStreamOffset, long fileStreamSize, ArchiveType type) { this.Bundle = bundle; this.Name = name; this.Type = type; this.fileStreamOffset = fileStreamOffset; this.fileStreamSize = fileStreamSize; }
public ObjectArchive(AssetBundleArchive bundle, string name, long fileStreamOffset, long fileStreamSize, ArchiveType type) : base(bundle, name, fileStreamOffset, fileStreamSize, type) { this.archiveRefs.Add(new ArchiveRef(0, this.Name, 0, new Hash128(new byte[16]), this.Name)); this.extractor = new FeatureExtractor(); using (Stream stream = this.GetDataStream()) { using (ArchiveBinaryReader reader = new ArchiveBinaryReader(stream)) { this.Load(reader); } } }
public void AddBundleArchive(AssetBundleArchive bundle) { lock (_lock) { if (bundle == null) { throw new ArgumentNullException("bundle"); } if (this.bundles.Contains(bundle)) { return; } bundle.ArchiveContainer = this; this.bundles.Add(bundle); } }
public static AssetBundleArchive Load(Stream stream) { using (var reader = new ArchiveBinaryReader(stream)) { var signature = reader.ReadCString(); var formatVersion = reader.ReadInt32(true); var mainVersion = reader.ReadCString(); var buildVersion = reader.ReadCString(); if (signature != SIGNATURE_FS && signature != SIGNATURE_WEB) { throw new NotSupportedException("Not supported signature : " + signature); } if (formatVersion != 6) { throw new NotSupportedException("Not supported format version : " + formatVersion); } AssetBundleArchive bundle = new AssetBundleArchive(formatVersion, mainVersion, buildVersion); bundle.FileSize = reader.ReadInt64(true); var compressedBlockSize = reader.ReadInt32(true); var uncompressedBlockSize = reader.ReadInt32(true); var flags = reader.ReadInt32(true); var compressionType = (CompressionType)(flags & 0x3f); byte[] buffer = null; if ((flags & 0x80) > 0) { var currentPos = reader.BaseStream.Position; reader.BaseStream.Seek(-compressedBlockSize, SeekOrigin.End); buffer = reader.ReadBytes(compressedBlockSize); reader.BaseStream.Seek(currentPos, SeekOrigin.Begin); } else { buffer = reader.ReadBytes(compressedBlockSize); } switch (compressionType) { case CompressionType.NONE: break; case CompressionType.LZ4: case CompressionType.LZ4HC: buffer = LZ4.LZ4Codec.Decode(buffer, 0, compressedBlockSize, uncompressedBlockSize); break; default: throw new NotSupportedException("Not supported compression type : " + compressionType); } List <BlockInfo> blocks = new List <BlockInfo>(); List <AssetInfo> assets = new List <AssetInfo>(); using (var metaReader = new ArchiveBinaryReader(new MemoryStream(buffer))) { bundle.GUID = metaReader.ReadHash128(); int blockCount = metaReader.ReadInt32(true); for (int i = 0; i < blockCount; i++) { BlockInfo block; block.uncompressedSize = metaReader.ReadUInt32(true); block.compressedSize = metaReader.ReadUInt32(true); block.flag = metaReader.ReadInt16(true); blocks.Add(block); } var assetCount = metaReader.ReadInt32(true); for (int i = 0; i < assetCount; i++) { AssetInfo asset; asset.offset = metaReader.ReadInt64(true); asset.size = metaReader.ReadInt64(true); asset.flag = metaReader.ReadInt32(true); var name = metaReader.ReadCString(); name = string.IsNullOrEmpty(name) ? "" : name.ToLower(); asset.name = name; assets.Add(asset); } } var totalDataSize = blocks.Sum(b => b.uncompressedSize); var dataFilename = string.Format("{0}/{1}", ArchiveUtil.GetTemporaryCachePath(), Guid.NewGuid().ToString()); FileInfo file = new FileInfo(dataFilename); if (!file.Directory.Exists) { file.Directory.Create(); } bundle.dataFilename = file.FullName; using (Stream dataStream = new FileStream(file.FullName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 8192)) { foreach (var block in blocks) { switch (block.CompressionType) { case CompressionType.NONE: { buffer = reader.ReadBytes((int)block.compressedSize); dataStream.Write(buffer, 0, buffer.Length); break; } case CompressionType.LZMA: { var properties = reader.ReadBytes(5); var decoder = new SevenZip.Compression.LZMA.Decoder(); decoder.SetDecoderProperties(properties); decoder.Code(reader.BaseStream, dataStream, block.compressedSize - 5, block.uncompressedSize, null); break; } case CompressionType.LZ4: case CompressionType.LZ4HC: { buffer = reader.ReadBytes((int)block.compressedSize); var data = LZ4.LZ4Codec.Decode(buffer, 0, (int)block.compressedSize, (int)block.uncompressedSize); dataStream.Write(data, 0, data.Length); break; } default: throw new NotSupportedException("Not supported compression type : " + block.CompressionType); } } } foreach (var assetInfo in assets) { switch (assetInfo.flag) { case 4: { ObjectArchive asset = new ObjectArchive(bundle, assetInfo.name, assetInfo.offset, assetInfo.size, assetInfo.Type); bundle.AddAssetArchive(asset); break; } default: { ResourceArchive asset = new ResourceArchive(bundle, assetInfo.name, assetInfo.offset, assetInfo.size, assetInfo.Type); bundle.AddAssetArchive(asset); break; } } //switch (assetInfo.Type) //{ // case ArchiveType.CAB: // case ArchiveType.BUILD_PLAYER: // case ArchiveType.SHARED_DATA: // { // ObjectArchive asset = new ObjectArchive(bundle, assetInfo.name, assetInfo.offset, assetInfo.size, assetInfo.Type); // bundle.AddAssetArchive(asset); // break; // } // default: // { // ResourceArchive asset = new ResourceArchive(bundle, assetInfo.name, assetInfo.offset, assetInfo.size, assetInfo.Type); // bundle.AddAssetArchive(asset); // break; // } //} } return(bundle); } }
public ResourceArchive(AssetBundleArchive bundle, string name, long fileStreamOffset, long fileStreamSize, ArchiveType type) : base(bundle, name, fileStreamOffset, fileStreamSize, type) { }