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 RemoveReplacer(AssetsReplacer replacer, bool closePreviewStream = true) { if (replacer == null) { return; } var forInstance = LoadedFiles[replacer.GetFileID()]; var assetId = new AssetID(forInstance.path, replacer.GetPathID()); NewAssets.Remove(assetId); if (NewAssetDatas.ContainsKey(assetId)) { if (closePreviewStream) { NewAssetDatas[assetId].Close(); } NewAssetDatas.Remove(assetId); } Modified = NewAssets.Count != 0; }