Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit 61ff13f

Browse files
committed
- [CLI] Added feature to search prebuild AssetMap to loaded filteded files only.
1 parent 5597235 commit 61ff13f

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

AssetStudio.CLI/Program.cs

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public static void Run(Options o)
147147
{
148148
if (o.MapOp.HasFlag(MapOpType.Load))
149149
{
150+
files = AssetsHelper.ParseAssetMap(o.MapName, o.MapType, classTypeFilter, o.NameFilter, o.ContainerFilter);
150151
}
151152
else
152153
{

AssetStudio/AssetsHelper.cs

+90
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,96 @@ private static void BuildAssetMap(string file, List<AssetEntry> assets, ClassIDT
505505
}
506506
}
507507

508+
public static string[] ParseAssetMap(string mapName, ExportListType mapType, ClassIDType[] typeFilter, Regex[] nameFilter, Regex[] containerFilter)
509+
{
510+
var matches = new HashSet<string>();
511+
512+
switch (mapType)
513+
{
514+
case ExportListType.MessagePack:
515+
{
516+
using var stream = File.OpenRead(mapName);
517+
var assetMap = MessagePackSerializer.Deserialize<AssetMap>(stream, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
518+
foreach(var entry in assetMap.AssetEntries)
519+
{
520+
var isNameMatch = nameFilter.Length == 0 || nameFilter.Any(x => x.IsMatch(entry.Name));
521+
var isContainerMatch = containerFilter.Length == 0 || containerFilter.Any(x => x.IsMatch(entry.Container));
522+
var isTypeMatch = typeFilter.Length == 0 || typeFilter.Any(x => x == entry.Type);
523+
if (isNameMatch && isContainerMatch && isTypeMatch)
524+
{
525+
matches.Add(entry.Source);
526+
}
527+
}
528+
}
529+
530+
break;
531+
case ExportListType.XML:
532+
{
533+
using var stream = File.OpenRead(mapName);
534+
using var reader = XmlReader.Create(stream);
535+
reader.ReadToFollowing("Assets");
536+
reader.ReadToFollowing("Asset");
537+
do
538+
{
539+
reader.ReadToFollowing("Name");
540+
var name = reader.ReadInnerXml();
541+
542+
var isNameMatch = nameFilter.Length == 0 || nameFilter.Any(x => x.IsMatch(name));
543+
544+
reader.ReadToFollowing("Container");
545+
var container = reader.ReadInnerXml();
546+
547+
var isContainerMatch = containerFilter.Length == 0 || containerFilter.Any(x => x.IsMatch(container));
548+
549+
reader.ReadToFollowing("Type");
550+
var type = reader.ReadInnerXml();
551+
552+
var isTypeMatch = typeFilter.Length == 0 || typeFilter.Any(x => x.ToString().Equals(type, StringComparison.OrdinalIgnoreCase));
553+
554+
reader.ReadToFollowing("PathID");
555+
var pathID = reader.ReadInnerXml();
556+
557+
reader.ReadToFollowing("Source");
558+
var source = reader.ReadInnerXml();
559+
560+
if (isNameMatch && isContainerMatch && isTypeMatch)
561+
{
562+
matches.Add(source);
563+
}
564+
565+
reader.ReadEndElement();
566+
} while (reader.ReadToNextSibling("Asset"));
567+
}
568+
569+
break;
570+
case ExportListType.JSON:
571+
{
572+
using var stream = File.OpenRead(mapName);
573+
using var file = new StreamReader(stream);
574+
using var reader = new JsonTextReader(file);
575+
576+
var serializer = new JsonSerializer() { Formatting = Newtonsoft.Json.Formatting.Indented };
577+
serializer.Converters.Add(new StringEnumConverter());
578+
579+
var entries = serializer.Deserialize<List<AssetEntry>>(reader);
580+
foreach (var entry in entries)
581+
{
582+
var isNameMatch = nameFilter.Length == 0 || nameFilter.Any(x => x.IsMatch(entry.Name));
583+
var isContainerMatch = containerFilter.Length == 0 || containerFilter.Any(x => x.IsMatch(entry.Container));
584+
var isTypeMatch = typeFilter.Length == 0 || typeFilter.Any(x => x == entry.Type);
585+
if (isNameMatch && isContainerMatch && isTypeMatch)
586+
{
587+
matches.Add(entry.Source);
588+
}
589+
}
590+
}
591+
592+
break;
593+
}
594+
595+
return matches.ToArray();
596+
}
597+
508598
private static void UpdateContainers(List<AssetEntry> assets, Game game)
509599
{
510600
if (game.Type.IsGISubGroup() && assets.Count > 0)

AssetStudio/TypeFlags.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace AssetStudio;
45
public static class TypeFlags
@@ -44,3 +45,12 @@ public static bool CanExport(this ClassIDType type)
4445
return false;
4546
}
4647
}
48+
49+
[Flags]
50+
public enum TypeFlag
51+
{
52+
None,
53+
Parse,
54+
Export,
55+
Both = Parse | Export,
56+
}

0 commit comments

Comments
 (0)