- [CLI] Added feature to search prebuild AssetMap to loaded filteded files only.
This commit is contained in:
@@ -505,6 +505,96 @@ namespace AssetStudio
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] ParseAssetMap(string mapName, ExportListType mapType, ClassIDType[] typeFilter, Regex[] nameFilter, Regex[] containerFilter)
|
||||
{
|
||||
var matches = new HashSet<string>();
|
||||
|
||||
switch (mapType)
|
||||
{
|
||||
case ExportListType.MessagePack:
|
||||
{
|
||||
using var stream = File.OpenRead(mapName);
|
||||
var assetMap = MessagePackSerializer.Deserialize<AssetMap>(stream, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
|
||||
foreach(var entry in assetMap.AssetEntries)
|
||||
{
|
||||
var isNameMatch = nameFilter.Length == 0 || nameFilter.Any(x => x.IsMatch(entry.Name));
|
||||
var isContainerMatch = containerFilter.Length == 0 || containerFilter.Any(x => x.IsMatch(entry.Container));
|
||||
var isTypeMatch = typeFilter.Length == 0 || typeFilter.Any(x => x == entry.Type);
|
||||
if (isNameMatch && isContainerMatch && isTypeMatch)
|
||||
{
|
||||
matches.Add(entry.Source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case ExportListType.XML:
|
||||
{
|
||||
using var stream = File.OpenRead(mapName);
|
||||
using var reader = XmlReader.Create(stream);
|
||||
reader.ReadToFollowing("Assets");
|
||||
reader.ReadToFollowing("Asset");
|
||||
do
|
||||
{
|
||||
reader.ReadToFollowing("Name");
|
||||
var name = reader.ReadInnerXml();
|
||||
|
||||
var isNameMatch = nameFilter.Length == 0 || nameFilter.Any(x => x.IsMatch(name));
|
||||
|
||||
reader.ReadToFollowing("Container");
|
||||
var container = reader.ReadInnerXml();
|
||||
|
||||
var isContainerMatch = containerFilter.Length == 0 || containerFilter.Any(x => x.IsMatch(container));
|
||||
|
||||
reader.ReadToFollowing("Type");
|
||||
var type = reader.ReadInnerXml();
|
||||
|
||||
var isTypeMatch = typeFilter.Length == 0 || typeFilter.Any(x => x.ToString().Equals(type, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
reader.ReadToFollowing("PathID");
|
||||
var pathID = reader.ReadInnerXml();
|
||||
|
||||
reader.ReadToFollowing("Source");
|
||||
var source = reader.ReadInnerXml();
|
||||
|
||||
if (isNameMatch && isContainerMatch && isTypeMatch)
|
||||
{
|
||||
matches.Add(source);
|
||||
}
|
||||
|
||||
reader.ReadEndElement();
|
||||
} while (reader.ReadToNextSibling("Asset"));
|
||||
}
|
||||
|
||||
break;
|
||||
case ExportListType.JSON:
|
||||
{
|
||||
using var stream = File.OpenRead(mapName);
|
||||
using var file = new StreamReader(stream);
|
||||
using var reader = new JsonTextReader(file);
|
||||
|
||||
var serializer = new JsonSerializer() { Formatting = Newtonsoft.Json.Formatting.Indented };
|
||||
serializer.Converters.Add(new StringEnumConverter());
|
||||
|
||||
var entries = serializer.Deserialize<List<AssetEntry>>(reader);
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
var isNameMatch = nameFilter.Length == 0 || nameFilter.Any(x => x.IsMatch(entry.Name));
|
||||
var isContainerMatch = containerFilter.Length == 0 || containerFilter.Any(x => x.IsMatch(entry.Container));
|
||||
var isTypeMatch = typeFilter.Length == 0 || typeFilter.Any(x => x == entry.Type);
|
||||
if (isNameMatch && isContainerMatch && isTypeMatch)
|
||||
{
|
||||
matches.Add(entry.Source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return matches.ToArray();
|
||||
}
|
||||
|
||||
private static void UpdateContainers(List<AssetEntry> assets, Game game)
|
||||
{
|
||||
if (game.Type.IsGISubGroup() && assets.Count > 0)
|
||||
|
||||
Reference in New Issue
Block a user