private static void UpdateRootAssets(RootAssetCollection rootAssetCollection, Dictionary <Guid, Tuple <Guid, UFile> > idRemap, Dictionary <UFile, UFile> locationRemap) { foreach (var rootAsset in rootAssetCollection.ToArray()) { var location = (UFile)rootAsset.Location; var id = rootAsset.Id; Tuple <Guid, UFile> newId; UFile newLocation; bool changed = false; if (idRemap.TryGetValue(id, out newId)) { id = newId.Item1; location = newId.Item2; changed = true; } if (!changed && locationRemap.TryGetValue(location, out newLocation)) { location = newLocation; changed = true; } if (changed) { var newRootAsset = new AssetReference <Asset>(id, location); rootAssetCollection.Remove(rootAsset.Id); rootAssetCollection.Add(newRootAsset); } } }
/// <summary> /// Fix and/or remove invalid RootAssets entries. /// Note: at some point, we might want to make IReference be part of the same workflow as standard asset references. /// </summary> /// <param name="rootAssets">The root assets to check.</param> /// <param name="referencedPackage">The package where to look for root reference.</param> /// <param name="log">The logger.</param> private void ProcessRootAssetReferences(RootAssetCollection rootAssets, Package referencedPackage, ILogger log) { foreach (var rootAsset in rootAssets.ToArray()) { // Update Asset references (AssetReference, AssetBase, reference) var id = rootAsset.Id; var newItemReference = referencedPackage.Assets.Find(id); // If asset was not found by id try to find by its location if (newItemReference == null) { newItemReference = referencedPackage.Assets.Find(rootAsset.Location); if (newItemReference != null) { // If asset was found by its location, just emit a warning log.Warning(package, rootAsset, AssetMessageCode.AssetReferenceChanged, rootAsset, newItemReference.Id); } } // If asset was not found, remove the reference if (newItemReference == null) { log.Warning(package, rootAsset, AssetMessageCode.AssetForPackageNotFound, rootAsset, package.FullPath.GetFileName()); rootAssets.Remove(rootAsset.Id); package.IsDirty = true; continue; } // Only update location that are actually different var newLocationWithoutExtension = newItemReference.Location; if (newLocationWithoutExtension != rootAsset.Location || newItemReference.Id != rootAsset.Id) { rootAssets.Remove(rootAsset.Id); rootAssets.Add(new AssetReference(newItemReference.Id, newLocationWithoutExtension)); package.IsDirty = true; } } }
private static void UpdateRootAssets(RootAssetCollection rootAssetCollection, IReadOnlyDictionary <AssetId, Tuple <AssetId, UFile> > idRemap) { foreach (var rootAsset in rootAssetCollection.ToArray()) { var id = rootAsset.Id; Tuple <AssetId, UFile> remap; if (idRemap.TryGetValue(id, out remap) && IsNewReference(remap, rootAsset)) { var newRootAsset = new AssetReference(remap.Item1, remap.Item2); rootAssetCollection.Remove(rootAsset.Id); rootAssetCollection.Add(newRootAsset); } } }
private static void UpdateRootAssets(RootAssetCollection rootAssetCollection, IReadOnlyDictionary<AssetId, Tuple<AssetId, UFile>> idRemap) { foreach (var rootAsset in rootAssetCollection.ToArray()) { var id = rootAsset.Id; Tuple<AssetId, UFile> remap; if (idRemap.TryGetValue(id, out remap) && IsNewReference(remap, rootAsset)) { var newRootAsset = new AssetReference(remap.Item1, remap.Item2); rootAssetCollection.Remove(rootAsset.Id); rootAssetCollection.Add(newRootAsset); } } }
/// <summary> /// Fix and/or remove invalid RootAssets entries. /// Note: at some point, we might want to make IContentReference be part of the same workflow as standard asset references. /// </summary> /// <param name="rootAssets">The root assets to check.</param> /// <param name="referencedPackage">The package where to look for root reference.</param> /// <param name="log">The logger.</param> private void ProcessRootAssetReferences(RootAssetCollection rootAssets, Package referencedPackage, ILogger log) { foreach (var rootAsset in rootAssets.ToArray()) { // Update Asset references (AssetReference, AssetBase, ContentReference) var id = rootAsset.Id; var newItemReference = referencedPackage.Assets.Find(id); // If asset was not found by id try to find by its location if (newItemReference == null) { newItemReference = referencedPackage.Assets.Find(rootAsset.Location); if (newItemReference != null) { // If asset was found by its location, just emit a warning log.Warning(package, rootAsset, AssetMessageCode.AssetReferenceChanged, rootAsset, newItemReference.Id); } } // If asset was not found, remove the reference if (newItemReference == null) { log.Warning(package, rootAsset, AssetMessageCode.AssetNotFound, rootAsset); rootAssets.Remove(rootAsset.Id); package.IsDirty = true; continue; } // Only update location that are actually different var newLocationWithoutExtension = newItemReference.Location; if (newLocationWithoutExtension != rootAsset.Location || newItemReference.Id != rootAsset.Id) { rootAssets.Remove(rootAsset.Id); rootAssets.Add(new AssetReference<Asset>(newItemReference.Id, newLocationWithoutExtension)); package.IsDirty = true; } } }
private static void UpdateRootAssets(RootAssetCollection rootAssetCollection, Dictionary<Guid, Tuple<Guid, UFile>> idRemap, Dictionary<UFile, UFile> locationRemap) { foreach (var rootAsset in rootAssetCollection.ToArray()) { var location = (UFile)rootAsset.Location; var id = rootAsset.Id; Tuple<Guid, UFile> newId; UFile newLocation; bool changed = false; if (idRemap.TryGetValue(id, out newId)) { id = newId.Item1; location = newId.Item2; changed = true; } if (!changed && locationRemap.TryGetValue(location, out newLocation)) { location = newLocation; changed = true; } if (changed) { var newRootAsset = new AssetReference<Asset>(id, location); rootAssetCollection.Remove(rootAsset.Id); rootAssetCollection.Add(newRootAsset); } } }