public void RemoveReplacer(AssetsFileInstance forFile, AssetsReplacer replacer, bool closePreviewStream = true) { AssetID assetId = new AssetID(forFile.name, replacer.GetPathID()); if (NewAssets.ContainsKey(assetId)) { NewAssets.Remove(assetId); } if (NewAssetDatas.ContainsKey(assetId)) { if (closePreviewStream) { NewAssetDatas[assetId].Close(); } NewAssetDatas.Remove(assetId); } if (ItemUpdated != null) { ItemUpdated(assetId); } if (NewAssets.Count == 0) { Modified = false; } }
public void AddReplacer(AssetsReplacer replacer, MemoryStream previewStream = null) { if (replacer == null) { return; } var forInstance = LoadedFiles[replacer.GetFileID()]; var assetId = new AssetID(forInstance.path, replacer.GetPathID()); var index = LoadedAssets.FindIndex(i => i.FileID == replacer.GetFileID() && i.PathID == replacer.GetPathID()); var item = LoadedAssets[index]; if (NewAssets.ContainsKey(assetId)) { RemoveReplacer(replacer); } NewAssets[assetId] = replacer; if (previewStream == null) { var newStream = new MemoryStream(); var newWriter = new AssetsFileWriter(newStream); replacer.Write(newWriter); newStream.Position = 0; previewStream = newStream; } NewAssetDatas[assetId] = previewStream; if (replacer is AssetsRemover) { LoadedContainers.Remove(assetId); } else { var cont = MakeAssetContainer(item, NewAssetDatas[assetId]); UpdateAssetInfo(cont, assetId, index); } Modified = true; }
public void AddReplacer(AssetsFileInstance forFile, AssetsReplacer replacer, Stream? previewStream = null) { AssetsFile assetsFile = forFile.file; AssetID assetId = new AssetID(forFile.path, replacer.GetPathID()); if (NewAssets.ContainsKey(assetId)) RemoveReplacer(forFile, NewAssets[assetId], true); NewAssets[assetId] = replacer; //make stream to use as a replacement to the one from file if (previewStream == null) { MemoryStream newStream = new MemoryStream(); AssetsFileWriter newWriter = new AssetsFileWriter(newStream); replacer.Write(newWriter); newStream.Position = 0; previewStream = newStream; } NewAssetDatas[assetId] = previewStream; if (!(replacer is AssetsRemover)) { AssetsFileReader reader = new AssetsFileReader(previewStream); AssetContainer cont = new AssetContainer( reader, 0, replacer.GetPathID(), (uint)replacer.GetClassID(), replacer.GetMonoScriptID(), (uint)previewStream.Length, forFile); LoadedAssets[assetId] = cont; } else { LoadedAssets.Remove(assetId); } if (ItemUpdated != null) ItemUpdated(forFile, assetId); Modified = true; }