public AssetStream(PackedAssetBundle bundle, string path) { this.bundle = bundle; if (!bundle.index.TryGetValue(AssetPath.CorrectSlashes(path), out descriptor)) { throw new Exception("Can't open asset: {0}", path); } stream = bundle.AllocStream(); Seek(0, SeekOrigin.Begin); }
public void ApplyPatch(PackedAssetBundle patchBundle) { var manifest = Manifest.Create(this); var patchManifest = Manifest.Create(patchBundle); if (patchManifest.BaseBundleVersion.HasValue) { if (manifest.BundleVersion.HasValue && patchManifest.BaseBundleVersion != manifest.BundleVersion) { throw new InvalidOperationException("Patch base version should be equal patched bundle version"); } else if (patchManifest.BundleVersion.HasValue) { manifest.BundleVersion = patchManifest.BundleVersion; } } foreach (var file in patchBundle.EnumerateFiles()) { manifest.DeletedAssets.Remove(file); if (FileExists(file)) { DeleteFile(file); } using (var stream = patchBundle.OpenFileRaw(file)) { ImportFileRaw( file, stream, 0, patchBundle.GetSourceExtension(file), patchBundle.GetFileLastWriteTime(file), patchBundle.GetAttributes(file), patchBundle.GetCookingRulesSHA1(file) ); } } foreach (var file in patchManifest.DeletedAssets) { if (FileExists(file)) { DeleteFile(file); if (!manifest.DeletedAssets.Contains(file)) { manifest.DeletedAssets.Add(file); } } } manifest.Write(this); }