- [CLI] Added feature to search prebuild AssetMap to loaded filteded files only.
This commit is contained in:
@@ -147,6 +147,7 @@ namespace AssetStudio.CLI
|
|||||||
{
|
{
|
||||||
if (o.MapOp.HasFlag(MapOpType.Load))
|
if (o.MapOp.HasFlag(MapOpType.Load))
|
||||||
{
|
{
|
||||||
|
files = AssetsHelper.ParseAssetMap(o.MapName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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)
|
private static void UpdateContainers(List<AssetEntry> assets, Game game)
|
||||||
{
|
{
|
||||||
if (game.Type.IsGISubGroup() && assets.Count > 0)
|
if (game.Type.IsGISubGroup() && assets.Count > 0)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AssetStudio;
|
namespace AssetStudio;
|
||||||
public static class TypeFlags
|
public static class TypeFlags
|
||||||
@@ -44,3 +45,12 @@ public static class TypeFlags
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum TypeFlag
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Parse,
|
||||||
|
Export,
|
||||||
|
Both = Parse | Export,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user