4 using System.Collections.Generic;
7 using SiliconStudio.Core.IO;
8 using SiliconStudio.Core.Serialization;
10 namespace SiliconStudio.Assets.Analysis
31 if (inputItems == null)
throw new ArgumentNullException(
"inputItems");
32 if (outputItems == null)
throw new ArgumentNullException(
"outputItems");
33 if (assetResolver == null)
throw new ArgumentNullException(
"assetResolver");
36 if (inputItems.Any(item => item == null))
38 throw new ArgumentException(
"List cannot contain null items",
"inputItems");
41 var items = inputItems;
44 items = inputItems.Select(item => item.Clone()).ToList();
48 var locationConflicts =
new Dictionary<AssetItem, UFile>();
49 foreach (var item
in items)
52 if (assetResolver.RegisterLocation(item.Location, out newLocation))
54 locationConflicts[item] = newLocation;
59 var idConflicts =
new Dictionary<AssetItem, Guid>();
60 foreach (var item
in items)
63 if (assetResolver.RegisterId(item.Id, out newGuid))
65 idConflicts[item] = newGuid;
71 var idRemap =
new Dictionary<Guid, Tuple<Guid, UFile>>();
72 var locationRemap =
new Dictionary<UFile, UFile>();
74 foreach (var item
in items)
76 if (outputItems.Contains(item))
81 outputItems.Add(item);
84 if (!idConflicts.TryGetValue(item, out newGuid))
90 if (locationConflicts.TryGetValue(item, out newLocation) && !locationRemap.ContainsKey(item.Location))
92 locationRemap.Add(item.Location, newLocation);
95 if (!idRemap.ContainsKey(item.Id))
97 idRemap.Add(item.Id,
new Tuple<Guid, UFile>(newGuid, newLocation ?? item.Location));
102 foreach (var item
in outputItems)
106 if (idConflicts.TryGetValue(item, out newGuid))
108 item.Asset.Id = newGuid;
113 if (locationConflicts.ContainsKey(item))
115 item.Location = locationConflicts[item];
123 var links = AssetReferenceAnalysis.Visit(item.Asset).Where(link => link.Reference is
IContentReference).ToList();
125 foreach (var assetLink
in links)
129 var newId = assetReference.Id;
130 var newLocation = assetReference.Location;
132 bool requireUpdate =
false;
134 if (idRemap.ContainsKey(newId))
136 var newRemap = idRemap[newId];
137 newId = newRemap.Item1;
138 newLocation = newRemap.Item2;
139 requireUpdate =
true;
142 if (!requireUpdate && locationRemap.ContainsKey(newLocation))
144 newLocation = locationRemap[newLocation];
145 requireUpdate =
true;
150 assetLink.UpdateReference(newId, newLocation);
Helper to find available new asset locations and identifiers.
static void Clean(ICollection< AssetItem > inputItems, ICollection< AssetItem > outputItems, AssetResolver assetResolver, bool cloneInput)
Cleans the specified input items.
An interface that provides a reference to an asset.
Defines a normalized file path. See UPath for details. This class cannot be inherited.