Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Analyzer.Tests/Analyzer.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>

<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Analyzer.Tests/ExpectedDataGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.IO;
using System.Linq;
using UnityDataTools.Analyzer.SerializedObjects;
using UnityDataTools.FileSystem;
using UnityDataTools.FileSystem.TypeTreeReaders;
Expand Down
3 changes: 3 additions & 0 deletions Analyzer.Tests/SerializedObjectsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using UnityDataTools.FileSystem;
using UnityDataTools.FileSystem.TypeTreeReaders;
Expand Down
13 changes: 11 additions & 2 deletions Analyzer/Analyzer.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Data.SQLite" Version="1.0.116" />
<PackageReference Include="Microsoft.Data.SQLite" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 18 additions & 6 deletions Analyzer/AnalyzerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
int lastLength = 0;
foreach (var file in files)
{
// Automatically ignore these annoying OS X style files meta files.
if (Path.GetFileName(file) == ".DS_Store")
continue;

try
{
UnityArchive archive = null;
Expand All @@ -44,9 +48,11 @@ public int Analyze(string path, string databaseName, string searchPattern, bool

var relativePath = Path.GetRelativePath(path, file);

Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");

writer.WriteSerializedFile(relativePath, file, Path.GetDirectoryName(file));

var message = $"Processing {i * 100 / files.Length}% ({i}/{files.Length}) {file}";
Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");
lastLength = message.Length;
}

if (archive != null)
Expand All @@ -71,23 +77,29 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
}
catch (Exception e)
{
Console.Error.WriteLine();
Console.Error.WriteLine($"Error processing {node.Path} in archive {file}");
Console.Error.WriteLine($"\rError processing {node.Path} in archive {file}{new string(' ', Math.Max(0, lastLength - message.Length))}");
Console.Error.WriteLine(e);
Console.WriteLine();
}
}
}
}
finally
{
Console.Write($"\r{new string(' ', lastLength)}");
writer.EndAssetBundle();
archive.Dispose();
}
}
}
catch (Exception e)
catch(NotSupportedException) {
Console.Error.WriteLine();
//Console.Error.WriteLine($"File not supported: {file}"); // This is commented out because another codepath will output "failed to load"
}
catch (Exception e)
{
Console.Error.WriteLine();
Console.Error.WriteLine($"Error processing file {file}!");
Console.Error.WriteLine($"Error processing file: {file}");
Console.Write($"{e.GetType()}: ");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
Expand Down
2 changes: 1 addition & 1 deletion Analyzer/PPtrAndCrcProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void ProcessManagedReferenceRegistry(TypeTreeNode node)
}
else
{
throw new Exception("Unsupported ManagedReferenceRegistry version");
throw new Exception($"Unsupported ManagedReferenceRegistry version {version}");
}
}

Expand Down
27 changes: 12 additions & 15 deletions Analyzer/SQLite/Handlers/AnimationClipHandler.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;
using UnityDataTools.Analyzer.SerializedObjects;
using UnityDataTools.FileSystem.TypeTreeReaders;

namespace UnityDataTools.Analyzer.SQLite.Handlers;

public class AnimationClipHandler : ISQLiteHandler
{
SQLiteCommand m_InsertCommand;
SqliteCommand m_InsertCommand;

public void Init(SQLiteConnection db)
public void Init(SqliteConnection db)
{
using var command = new SQLiteCommand(db);

using var command = db.CreateCommand();
command.CommandText = Properties.Resources.AnimationClip;
command.ExecuteNonQuery();

m_InsertCommand = new SQLiteCommand(db);
m_InsertCommand = db.CreateCommand();
m_InsertCommand.CommandText = "INSERT INTO animation_clips(id, legacy, events) VALUES(@id, @legacy, @events)";
m_InsertCommand.Parameters.Add("@id", DbType.Int64);
m_InsertCommand.Parameters.Add("@legacy", DbType.Int32);
m_InsertCommand.Parameters.Add("@events", DbType.Int32);
m_InsertCommand.Parameters.Add("@id", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@legacy", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@events", SqliteType.Integer);
}

public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
{
var animationClip = AnimationClip.Read(reader);

m_InsertCommand.Transaction = ctx.Transaction;
m_InsertCommand.Parameters["@id"].Value = objectId;
m_InsertCommand.Parameters["@legacy"].Value = animationClip.Legacy;
m_InsertCommand.Parameters["@events"].Value = animationClip.Events;
Expand All @@ -38,12 +35,12 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = 0;
}

public void Finalize(SQLiteConnection db)
public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand.Dispose();
m_InsertCommand?.Dispose();
}
}
42 changes: 21 additions & 21 deletions Analyzer/SQLite/Handlers/AssetBundleHandler.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
using System;
using System.Data;
using System.Data.SQLite;
using System.Text.RegularExpressions;
using Microsoft.Data.Sqlite;
using UnityDataTools.Analyzer.SerializedObjects;
using UnityDataTools.FileSystem.TypeTreeReaders;

namespace UnityDataTools.Analyzer.SQLite.Handlers;

public class AssetBundleHandler : ISQLiteHandler
{
SQLiteCommand m_InsertCommand;
private SQLiteCommand m_InsertDepCommand;
SqliteCommand m_InsertCommand;
private SqliteCommand m_InsertDepCommand;
private Regex m_SceneNameRegex = new Regex(@"([^//]+)\.unity");

public void Init(SQLiteConnection db)
public void Init(SqliteConnection db)
{
using var command = new SQLiteCommand(db);

using var command = db.CreateCommand();
command.CommandText = Properties.Resources.AssetBundle;
command.ExecuteNonQuery();

m_InsertCommand = new SQLiteCommand(db);
m_InsertCommand = db.CreateCommand();

m_InsertCommand.CommandText = "INSERT INTO assets(object, name) VALUES(@object, @name)";
m_InsertCommand.Parameters.Add("@object", DbType.Int64);
m_InsertCommand.Parameters.Add("@name", DbType.String);
m_InsertCommand.Parameters.Add("@object", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@name", SqliteType.Text);

m_InsertDepCommand = db.CreateCommand();

m_InsertDepCommand = new SQLiteCommand(db);
m_InsertDepCommand.CommandText = "INSERT INTO asset_dependencies(object, dependency) VALUES(@object, @dependency)";
m_InsertDepCommand.Parameters.Add("@object", DbType.Int64);
m_InsertDepCommand.Parameters.Add("@dependency", DbType.Int64);
m_InsertDepCommand.Parameters.Add("@object", SqliteType.Integer);
m_InsertDepCommand.Parameters.Add("@dependency", SqliteType.Integer);
}

public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
Expand All @@ -41,7 +41,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
{
var fileId = ctx.LocalToDbFileId[asset.PPtr.FileId];
var objId = ctx.ObjectIdProvider.GetId((fileId, asset.PPtr.PathId));

m_InsertCommand.Transaction = ctx.Transaction;
m_InsertCommand.Parameters["@object"].Value = objId;
m_InsertCommand.Parameters["@name"].Value = asset.Name;
m_InsertCommand.ExecuteNonQuery();
Expand All @@ -51,7 +51,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
var dependency = assetBundle.PreloadTable[i];
var depFileId = ctx.LocalToDbFileId[dependency.FileId];
var depId = ctx.ObjectIdProvider.GetId((depFileId, dependency.PathId));

m_InsertDepCommand.Transaction = ctx.Transaction;
m_InsertDepCommand.Parameters["@object"].Value = objId;
m_InsertDepCommand.Parameters["@dependency"].Value = depId;
m_InsertDepCommand.ExecuteNonQuery();
Expand All @@ -65,7 +65,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
{
var sceneName = match.Groups[1].Value;
var objId = ctx.ObjectIdProvider.GetId((ctx.SerializedFileIdProvider.GetId(sceneName), 0));

m_InsertCommand.Transaction = ctx.Transaction;
m_InsertCommand.Parameters["@object"].Value = objId;
m_InsertCommand.Parameters["@name"].Value = asset.Name;
m_InsertCommand.ExecuteNonQuery();
Expand All @@ -77,10 +77,10 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = 0;
}

public void Finalize(SQLiteConnection db)
public void Finalize(SqliteConnection db)
{
using var command = new SQLiteCommand(db);
using var command = new SqliteCommand();
command.Connection = db;
command.CommandText = "CREATE INDEX asset_dependencies_object ON asset_dependencies(object)";
command.ExecuteNonQuery();

Expand All @@ -90,7 +90,7 @@ public void Finalize(SQLiteConnection db)

void IDisposable.Dispose()
{
m_InsertCommand.Dispose();
m_InsertDepCommand.Dispose();
m_InsertCommand?.Dispose();
m_InsertDepCommand?.Dispose();
}
}
30 changes: 14 additions & 16 deletions Analyzer/SQLite/Handlers/AudioClipHandler.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
using System;
using System.Collections.Generic;
using Microsoft.Data.Sqlite;
using System.Data;
using System.Data.SQLite;
using UnityDataTools.Analyzer.SerializedObjects;
using UnityDataTools.FileSystem.TypeTreeReaders;

namespace UnityDataTools.Analyzer.SQLite.Handlers;

public class AudioClipHandler : ISQLiteHandler
{
SQLiteCommand m_InsertCommand;
private SqliteCommand m_InsertCommand;

public void Init(SQLiteConnection db)
public void Init(SqliteConnection db)
{
using var command = new SQLiteCommand(db);

using var command = db.CreateCommand();
command.CommandText = Properties.Resources.AudioClip;
command.ExecuteNonQuery();

m_InsertCommand = new SQLiteCommand(db);
m_InsertCommand = db.CreateCommand();
m_InsertCommand.CommandText = "INSERT INTO audio_clips(id, bits_per_sample, frequency, channels, load_type, format) VALUES(@id, @bits_per_sample, @frequency, @channels, @load_type, @format)";
m_InsertCommand.Parameters.Add("@id", DbType.Int64);
m_InsertCommand.Parameters.Add("@bits_per_sample", DbType.Int32);
m_InsertCommand.Parameters.Add("@frequency", DbType.Int32);
m_InsertCommand.Parameters.Add("@channels", DbType.Int32);
m_InsertCommand.Parameters.Add("@load_type", DbType.Int32);
m_InsertCommand.Parameters.Add("@format", DbType.Int32);
m_InsertCommand.Parameters.Add("@id", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@bits_per_sample", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@frequency", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@channels", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@load_type", SqliteType.Integer);
m_InsertCommand.Parameters.Add("@format", SqliteType.Integer);
}

public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
{
var audioClip = AudioClip.Read(reader);

m_InsertCommand.Transaction = ctx.Transaction;
m_InsertCommand.Parameters["@id"].Value = objectId;
m_InsertCommand.Parameters["@bits_per_sample"].Value = audioClip.BitsPerSample;
m_InsertCommand.Parameters["@frequency"].Value = audioClip.Frequency;
Expand All @@ -45,12 +43,12 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
name = audioClip.Name;
}

public void Finalize(SQLiteConnection db)
public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand.Dispose();
m_InsertCommand?.Dispose();
}
}
7 changes: 4 additions & 3 deletions Analyzer/SQLite/Handlers/ISQLiteHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using Microsoft.Data.Sqlite;
using UnityDataTools.FileSystem.TypeTreeReaders;

namespace UnityDataTools.Analyzer.SQLite.Handlers;
Expand All @@ -13,11 +13,12 @@ public class Context
public Util.ObjectIdProvider ObjectIdProvider { get; init; }
public Util.IdProvider<string> SerializedFileIdProvider { get; init; }
public Dictionary<int, int> LocalToDbFileId { get; init; }
public SqliteTransaction Transaction { get; set; }
}

public interface ISQLiteHandler : IDisposable
{
void Init(SQLiteConnection db);
void Init(Microsoft.Data.Sqlite.SqliteConnection db);
void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize);
void Finalize(SQLiteConnection db);
void Finalize(Microsoft.Data.Sqlite.SqliteConnection db);
}
Loading