Skip to content

Commit bb53df1

Browse files
Restructure Archive and SerializedFile code into their own libraries
For consistency with the other command implementations - it didn't make much sense that some commands were implemented directly inside UnityDataTool and others as separate libraries.
1 parent 3308843 commit bb53df1

13 files changed

Lines changed: 149 additions & 38 deletions

File tree

AGENTS.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,22 @@ UnityDataTool find-refs database.db -n "ObjectName" -t "Texture2D"
9090

9191
### Component Hierarchy
9292
```
93-
UnityDataTool (CLI executable)
93+
UnityDataTool (CLI executable) — wires the feature libraries into commands
9494
├── Analyzer → SQLite database generation
9595
├── TextDumper → Human-readable text output
96-
├── ReferenceFinder → Object reference chain tracing
97-
└── UnityFileSystem → C# wrapper for native library
98-
└── UnityFileSystemApi (native .dll/.dylib/.so)
96+
├── ReferenceFinder → Object reference chain tracing (queries the Analyzer database)
97+
├── Archive → inspect / extract Unity Archives (the `archive` command)
98+
├── SerializedFile → inspect SerializedFile header/metadata/objects (the `serialized-file` command)
99+
└── (base libraries, used by the feature libraries above)
100+
├── UnityBinaryFormat → C# parsers & helpers for Archives / SerializedFiles
101+
├── UnityDataModels → schemas for JSON build-report formats
102+
└── UnityFileSystem → C# wrapper for native library
103+
└── UnityFileSystemApi (native .dll/.dylib/.so)
99104
```
100105

106+
The feature libraries each build on UnityBinaryFormat and UnityFileSystem. See the
107+
"Repository content" section of `README.md` for a diagram of the dependencies.
108+
101109
### Key Architectural Patterns
102110

103111
**Native Interop**: UnityFileSystem wraps UnityFileSystemApi (native library from Unity Editor) via P/Invoke in `DllWrapper.cs`. The native library reads Unity Archive and SerializedFile formats.

Archive/Archive.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ApplicationIcon />
7+
<StartupObject />
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
12+
<PlatformTarget>AnyCPU</PlatformTarget>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="System.IO.Packaging" Version="7.0.0" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\UnityBinaryFormat\UnityBinaryFormat.csproj" />
25+
<ProjectReference Include="..\UnityFileSystem\UnityFileSystem.csproj" />
26+
</ItemGroup>
27+
28+
</Project>
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
using UnityDataTools.BinaryFormat;
66
using UnityDataTools.FileSystem;
77

8-
namespace UnityDataTools.UnityDataTool;
8+
namespace UnityDataTools.Archive;
99

10-
public static class Archive
10+
public static class ArchiveTool
1111
{
12+
public enum OutputFormat
13+
{
14+
Text,
15+
Json
16+
}
17+
1218
public static int HandleExtract(FileInfo filename, DirectoryInfo outputFolder, string filter = null)
1319
{
1420
try

Archive/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Archive
2+
3+
See [Documentation/command-archive.md](../Documentation/command-archive.md)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Text;
77
using System.Text.Json;
88

9-
namespace UnityDataTools.UnityDataTool;
9+
namespace UnityDataTools.Archive;
1010

1111
public static class WebBundleHelper
1212
{
@@ -50,14 +50,14 @@ public static void Extract(FileInfo filename, DirectoryInfo outputFolder, string
5050
Console.WriteLine($"Extracted {extracted} out of {total} files.");
5151
}
5252

53-
public static void List(FileInfo filename, OutputFormat format)
53+
public static void List(FileInfo filename, ArchiveTool.OutputFormat format)
5454
{
5555
using var fileStream = File.Open(filename.ToString(), FileMode.Open);
5656
using var stream = GetStream(filename, fileStream);
5757
using var reader = new BinaryReader(stream, Encoding.UTF8);
5858
var fileDescriptions = ParseWebBundleHeader(reader);
5959

60-
if (format == OutputFormat.Json)
60+
if (format == ArchiveTool.OutputFormat.Json)
6161
{
6262
var jsonArray = new object[fileDescriptions.Count];
6363
for (int i = 0; i < fileDescriptions.Count; i++)

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ all of that functionality to users.
4444

4545
```mermaid
4646
flowchart TD
47-
CLI["<b>UnityDataTool</b><br/>command-line tool<br/>(+ archive / serialized-file commands)"]
47+
CLI["<b>UnityDataTool</b><br/>command-line tool"]
4848
4949
Analyzer["<b>Analyzer</b><br/>SQLite database"]
5050
TextDumper["<b>TextDumper</b><br/>human-readable dump"]
5151
ReferenceFinder["<b>ReferenceFinder</b><br/>reference chains"]
52+
Archive["<b>Archive</b><br/>inspect / extract archives"]
53+
SerializedFile["<b>SerializedFile</b><br/>inspect SerializedFiles"]
5254
5355
UnityFileSystem["<b>UnityFileSystem</b><br/>C# wrapper +<br/>UnityFileSystemApi (native)"]
5456
UnityBinaryFormat["<b>UnityBinaryFormat</b><br/>C# parsers &amp; helpers<br/>for Archives / SerializedFiles"]
@@ -57,25 +59,27 @@ flowchart TD
5759
CLI --> Analyzer
5860
CLI --> TextDumper
5961
CLI --> ReferenceFinder
60-
CLI --> UnityBinaryFormat
61-
CLI --> UnityFileSystem
62+
CLI --> Archive
63+
CLI --> SerializedFile
6264
6365
Analyzer --> UnityFileSystem
6466
Analyzer --> UnityBinaryFormat
6567
Analyzer --> UnityDataModels
6668
TextDumper --> UnityFileSystem
6769
TextDumper --> UnityBinaryFormat
70+
Archive --> UnityFileSystem
71+
Archive --> UnityBinaryFormat
72+
SerializedFile --> UnityFileSystem
73+
SerializedFile --> UnityBinaryFormat
6874
UnityBinaryFormat --> UnityFileSystem
6975
7076
ReferenceFinder -. "reads the SQLite database" .-> Analyzer
7177
```
7278

7379
**Command-line tool**
7480
* [UnityDataTool](Documentation/unitydatatool.md): the command-line tool. It wires the feature
75-
libraries together and exposes them as commands (`analyze`, `dump`, `find-refs`, and more), so most
76-
users only ever interact with this executable. It also directly contains the implementation of the
77-
`archive` and `serialized-file` commands — critical features for working with the file formats,
78-
built mostly on top of UnityBinaryFormat.
81+
libraries together and exposes them as commands (`analyze`, `dump`, `find-refs`, `archive`,
82+
`serialized-file`, and more), so most users only ever interact with this executable.
7983

8084
**Feature libraries**
8185
* [Analyzer](Documentation/analyzer.md): extracts key information from Unity data files into a SQLite
@@ -84,6 +88,10 @@ flowchart TD
8488
(similar to Unity's binary2text).
8589
* [ReferenceFinder](Documentation/referencefinder.md): finds reference chains from one object to
8690
another by querying a database produced by the Analyzer (a data dependency rather than a code one).
91+
* [Archive](Documentation/command-archive.md): inspects and extracts the contents of Unity Archives
92+
(AssetBundles and web platform `.data` files) — the `archive` command.
93+
* [SerializedFile](Documentation/command-serialized-file.md): inspects the header, metadata, object
94+
list, and external references of a SerializedFile — the `serialized-file` command.
8795

8896
**Base libraries**
8997
* UnityFileSystem: a .NET class library, with source and binaries, that wraps the native

SerializedFile/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SerializedFile
2+
3+
See [Documentation/command-serialized-file.md](../Documentation/command-serialized-file.md)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ApplicationIcon />
7+
<StartupObject />
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
12+
<PlatformTarget>AnyCPU</PlatformTarget>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\UnityBinaryFormat\UnityBinaryFormat.csproj" />
21+
<ProjectReference Include="..\UnityFileSystem\UnityFileSystem.csproj" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
using UnityDataTools.BinaryFormat;
66
using UnityDataTools.FileSystem;
77

8-
namespace UnityDataTools.UnityDataTool;
8+
namespace UnityDataTools.SerializedFile;
99

10-
public static class SerializedFileCommands
10+
public static class SerializedFileTool
1111
{
12+
public enum OutputFormat
13+
{
14+
Text,
15+
Json
16+
}
17+
1218
public static int HandleExternalRefs(FileInfo filename, OutputFormat format)
1319
{
1420
// External references are read directly from the parsed metadata rather than via UnityFileSystemApi.

UnityDataTool.Tests/WebBundleSupportTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Threading.Tasks;
77
using NUnit.Framework;
8+
using UnityDataTools.Archive;
89
using UnityDataTools.FileSystem;
910

1011
namespace UnityDataTools.UnityDataTool.Tests;

0 commit comments

Comments
 (0)