Skip to content

Commit 58753bf

Browse files
authored
Merge pull request #21 from Unity-Technologies/mac_arm64
Migrating to MSSql for mac-arm64 compatability
2 parents 819be10 + ce9d8bf commit 58753bf

34 files changed

Lines changed: 395 additions & 269 deletions

Analyzer.Tests/Analyzer.Tests.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>disable</Nullable>
77

88
<IsPackable>false</IsPackable>
9+
10+
<LangVersion>latest</LangVersion>
11+
</PropertyGroup>
12+
13+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
14+
<PlatformTarget>AnyCPU</PlatformTarget>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
919
</PropertyGroup>
1020

1121
<ItemGroup>

Analyzer.Tests/ExpectedDataGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
14
using UnityDataTools.Analyzer.SerializedObjects;
25
using UnityDataTools.FileSystem;
36
using UnityDataTools.FileSystem.TypeTreeReaders;

Analyzer.Tests/SerializedObjectsTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
14
using NUnit.Framework;
25
using UnityDataTools.FileSystem;
36
using UnityDataTools.FileSystem.TypeTreeReaders;

Analyzer/Analyzer.csproj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<LangVersion>latest</LangVersion>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
9+
<PlatformTarget>AnyCPU</PlatformTarget>
10+
</PropertyGroup>
11+
12+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
13+
<PlatformTarget>AnyCPU</PlatformTarget>
514
</PropertyGroup>
615

716
<ItemGroup>
8-
<PackageReference Include="System.Data.SQLite" Version="1.0.116" />
17+
<PackageReference Include="Microsoft.Data.SQLite" Version="9.0.1" />
918
</ItemGroup>
1019

1120
<ItemGroup>

Analyzer/AnalyzerTool.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
3030
int lastLength = 0;
3131
foreach (var file in files)
3232
{
33+
// Automatically ignore these annoying OS X style files meta files.
34+
if (Path.GetFileName(file) == ".DS_Store")
35+
continue;
36+
3337
try
3438
{
3539
UnityArchive archive = null;
@@ -44,9 +48,11 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
4448

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

47-
Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");
48-
4951
writer.WriteSerializedFile(relativePath, file, Path.GetDirectoryName(file));
52+
53+
var message = $"Processing {i * 100 / files.Length}% ({i}/{files.Length}) {file}";
54+
Console.Write($"\rProcessing {i * 100 / files.Length}% ({i}/{files.Length}) {file}");
55+
lastLength = message.Length;
5056
}
5157

5258
if (archive != null)
@@ -71,23 +77,29 @@ public int Analyze(string path, string databaseName, string searchPattern, bool
7177
}
7278
catch (Exception e)
7379
{
74-
Console.Error.WriteLine();
75-
Console.Error.WriteLine($"Error processing {node.Path} in archive {file}");
80+
Console.Error.WriteLine($"\rError processing {node.Path} in archive {file}{new string(' ', Math.Max(0, lastLength - message.Length))}");
81+
Console.Error.WriteLine(e);
82+
Console.WriteLine();
7683
}
7784
}
7885
}
7986
}
8087
finally
8188
{
89+
Console.Write($"\r{new string(' ', lastLength)}");
8290
writer.EndAssetBundle();
8391
archive.Dispose();
8492
}
8593
}
8694
}
87-
catch (Exception e)
95+
catch(NotSupportedException) {
96+
Console.Error.WriteLine();
97+
//Console.Error.WriteLine($"File not supported: {file}"); // This is commented out because another codepath will output "failed to load"
98+
}
99+
catch (Exception e)
88100
{
89101
Console.Error.WriteLine();
90-
Console.Error.WriteLine($"Error processing file {file}!");
102+
Console.Error.WriteLine($"Error processing file: {file}");
91103
Console.Write($"{e.GetType()}: ");
92104
Console.WriteLine(e.Message);
93105
Console.WriteLine(e.StackTrace);

Analyzer/PPtrAndCrcProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private void ProcessManagedReferenceRegistry(TypeTreeNode node)
290290
}
291291
else
292292
{
293-
throw new Exception("Unsupported ManagedReferenceRegistry version");
293+
throw new Exception($"Unsupported ManagedReferenceRegistry version {version}");
294294
}
295295
}
296296

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Data;
4-
using System.Data.SQLite;
2+
using Microsoft.Data.Sqlite;
53
using UnityDataTools.Analyzer.SerializedObjects;
64
using UnityDataTools.FileSystem.TypeTreeReaders;
75

86
namespace UnityDataTools.Analyzer.SQLite.Handlers;
97

108
public class AnimationClipHandler : ISQLiteHandler
119
{
12-
SQLiteCommand m_InsertCommand;
10+
SqliteCommand m_InsertCommand;
1311

14-
public void Init(SQLiteConnection db)
12+
public void Init(SqliteConnection db)
1513
{
16-
using var command = new SQLiteCommand(db);
17-
14+
using var command = db.CreateCommand();
1815
command.CommandText = Properties.Resources.AnimationClip;
1916
command.ExecuteNonQuery();
20-
21-
m_InsertCommand = new SQLiteCommand(db);
17+
18+
m_InsertCommand = db.CreateCommand();
2219
m_InsertCommand.CommandText = "INSERT INTO animation_clips(id, legacy, events) VALUES(@id, @legacy, @events)";
23-
m_InsertCommand.Parameters.Add("@id", DbType.Int64);
24-
m_InsertCommand.Parameters.Add("@legacy", DbType.Int32);
25-
m_InsertCommand.Parameters.Add("@events", DbType.Int32);
20+
m_InsertCommand.Parameters.Add("@id", SqliteType.Integer);
21+
m_InsertCommand.Parameters.Add("@legacy", SqliteType.Integer);
22+
m_InsertCommand.Parameters.Add("@events", SqliteType.Integer);
2623
}
2724

2825
public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
2926
{
3027
var animationClip = AnimationClip.Read(reader);
31-
28+
m_InsertCommand.Transaction = ctx.Transaction;
3229
m_InsertCommand.Parameters["@id"].Value = objectId;
3330
m_InsertCommand.Parameters["@legacy"].Value = animationClip.Legacy;
3431
m_InsertCommand.Parameters["@events"].Value = animationClip.Events;
@@ -38,12 +35,12 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
3835
streamDataSize = 0;
3936
}
4037

41-
public void Finalize(SQLiteConnection db)
38+
public void Finalize(SqliteConnection db)
4239
{
4340
}
4441

4542
void IDisposable.Dispose()
4643
{
47-
m_InsertCommand.Dispose();
44+
m_InsertCommand?.Dispose();
4845
}
4946
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
using System;
2-
using System.Data;
3-
using System.Data.SQLite;
42
using System.Text.RegularExpressions;
3+
using Microsoft.Data.Sqlite;
54
using UnityDataTools.Analyzer.SerializedObjects;
65
using UnityDataTools.FileSystem.TypeTreeReaders;
76

87
namespace UnityDataTools.Analyzer.SQLite.Handlers;
98

109
public class AssetBundleHandler : ISQLiteHandler
1110
{
12-
SQLiteCommand m_InsertCommand;
13-
private SQLiteCommand m_InsertDepCommand;
11+
SqliteCommand m_InsertCommand;
12+
private SqliteCommand m_InsertDepCommand;
1413
private Regex m_SceneNameRegex = new Regex(@"([^//]+)\.unity");
1514

16-
public void Init(SQLiteConnection db)
15+
public void Init(SqliteConnection db)
1716
{
18-
using var command = new SQLiteCommand(db);
19-
17+
using var command = db.CreateCommand();
2018
command.CommandText = Properties.Resources.AssetBundle;
2119
command.ExecuteNonQuery();
2220

23-
m_InsertCommand = new SQLiteCommand(db);
21+
m_InsertCommand = db.CreateCommand();
22+
2423
m_InsertCommand.CommandText = "INSERT INTO assets(object, name) VALUES(@object, @name)";
25-
m_InsertCommand.Parameters.Add("@object", DbType.Int64);
26-
m_InsertCommand.Parameters.Add("@name", DbType.String);
24+
m_InsertCommand.Parameters.Add("@object", SqliteType.Integer);
25+
m_InsertCommand.Parameters.Add("@name", SqliteType.Text);
26+
27+
m_InsertDepCommand = db.CreateCommand();
2728

28-
m_InsertDepCommand = new SQLiteCommand(db);
2929
m_InsertDepCommand.CommandText = "INSERT INTO asset_dependencies(object, dependency) VALUES(@object, @dependency)";
30-
m_InsertDepCommand.Parameters.Add("@object", DbType.Int64);
31-
m_InsertDepCommand.Parameters.Add("@dependency", DbType.Int64);
30+
m_InsertDepCommand.Parameters.Add("@object", SqliteType.Integer);
31+
m_InsertDepCommand.Parameters.Add("@dependency", SqliteType.Integer);
3232
}
3333

3434
public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
@@ -41,7 +41,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
4141
{
4242
var fileId = ctx.LocalToDbFileId[asset.PPtr.FileId];
4343
var objId = ctx.ObjectIdProvider.GetId((fileId, asset.PPtr.PathId));
44-
44+
m_InsertCommand.Transaction = ctx.Transaction;
4545
m_InsertCommand.Parameters["@object"].Value = objId;
4646
m_InsertCommand.Parameters["@name"].Value = asset.Name;
4747
m_InsertCommand.ExecuteNonQuery();
@@ -51,7 +51,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
5151
var dependency = assetBundle.PreloadTable[i];
5252
var depFileId = ctx.LocalToDbFileId[dependency.FileId];
5353
var depId = ctx.ObjectIdProvider.GetId((depFileId, dependency.PathId));
54-
54+
m_InsertDepCommand.Transaction = ctx.Transaction;
5555
m_InsertDepCommand.Parameters["@object"].Value = objId;
5656
m_InsertDepCommand.Parameters["@dependency"].Value = depId;
5757
m_InsertDepCommand.ExecuteNonQuery();
@@ -65,7 +65,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
6565
{
6666
var sceneName = match.Groups[1].Value;
6767
var objId = ctx.ObjectIdProvider.GetId((ctx.SerializedFileIdProvider.GetId(sceneName), 0));
68-
68+
m_InsertCommand.Transaction = ctx.Transaction;
6969
m_InsertCommand.Parameters["@object"].Value = objId;
7070
m_InsertCommand.Parameters["@name"].Value = asset.Name;
7171
m_InsertCommand.ExecuteNonQuery();
@@ -77,10 +77,10 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
7777
streamDataSize = 0;
7878
}
7979

80-
public void Finalize(SQLiteConnection db)
80+
public void Finalize(SqliteConnection db)
8181
{
82-
using var command = new SQLiteCommand(db);
83-
82+
using var command = new SqliteCommand();
83+
command.Connection = db;
8484
command.CommandText = "CREATE INDEX asset_dependencies_object ON asset_dependencies(object)";
8585
command.ExecuteNonQuery();
8686

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

9191
void IDisposable.Dispose()
9292
{
93-
m_InsertCommand.Dispose();
94-
m_InsertDepCommand.Dispose();
93+
m_InsertCommand?.Dispose();
94+
m_InsertDepCommand?.Dispose();
9595
}
9696
}
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
using System;
2-
using System.Collections.Generic;
2+
using Microsoft.Data.Sqlite;
33
using System.Data;
4-
using System.Data.SQLite;
54
using UnityDataTools.Analyzer.SerializedObjects;
65
using UnityDataTools.FileSystem.TypeTreeReaders;
76

87
namespace UnityDataTools.Analyzer.SQLite.Handlers;
98

109
public class AudioClipHandler : ISQLiteHandler
1110
{
12-
SQLiteCommand m_InsertCommand;
11+
private SqliteCommand m_InsertCommand;
1312

14-
public void Init(SQLiteConnection db)
13+
public void Init(SqliteConnection db)
1514
{
16-
using var command = new SQLiteCommand(db);
17-
15+
using var command = db.CreateCommand();
1816
command.CommandText = Properties.Resources.AudioClip;
1917
command.ExecuteNonQuery();
2018

21-
m_InsertCommand = new SQLiteCommand(db);
19+
m_InsertCommand = db.CreateCommand();
2220
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)";
23-
m_InsertCommand.Parameters.Add("@id", DbType.Int64);
24-
m_InsertCommand.Parameters.Add("@bits_per_sample", DbType.Int32);
25-
m_InsertCommand.Parameters.Add("@frequency", DbType.Int32);
26-
m_InsertCommand.Parameters.Add("@channels", DbType.Int32);
27-
m_InsertCommand.Parameters.Add("@load_type", DbType.Int32);
28-
m_InsertCommand.Parameters.Add("@format", DbType.Int32);
21+
m_InsertCommand.Parameters.Add("@id", SqliteType.Integer);
22+
m_InsertCommand.Parameters.Add("@bits_per_sample", SqliteType.Integer);
23+
m_InsertCommand.Parameters.Add("@frequency", SqliteType.Integer);
24+
m_InsertCommand.Parameters.Add("@channels", SqliteType.Integer);
25+
m_InsertCommand.Parameters.Add("@load_type", SqliteType.Integer);
26+
m_InsertCommand.Parameters.Add("@format", SqliteType.Integer);
2927
}
3028

3129
public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
3230
{
3331
var audioClip = AudioClip.Read(reader);
34-
32+
m_InsertCommand.Transaction = ctx.Transaction;
3533
m_InsertCommand.Parameters["@id"].Value = objectId;
3634
m_InsertCommand.Parameters["@bits_per_sample"].Value = audioClip.BitsPerSample;
3735
m_InsertCommand.Parameters["@frequency"].Value = audioClip.Frequency;
@@ -45,12 +43,12 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
4543
name = audioClip.Name;
4644
}
4745

48-
public void Finalize(SQLiteConnection db)
46+
public void Finalize(SqliteConnection db)
4947
{
5048
}
5149

5250
void IDisposable.Dispose()
5351
{
54-
m_InsertCommand.Dispose();
52+
m_InsertCommand?.Dispose();
5553
}
5654
}

Analyzer/SQLite/Handlers/ISQLiteHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Data.SQLite;
3+
using Microsoft.Data.Sqlite;
44
using UnityDataTools.FileSystem.TypeTreeReaders;
55

66
namespace UnityDataTools.Analyzer.SQLite.Handlers;
@@ -13,11 +13,12 @@ public class Context
1313
public Util.ObjectIdProvider ObjectIdProvider { get; init; }
1414
public Util.IdProvider<string> SerializedFileIdProvider { get; init; }
1515
public Dictionary<int, int> LocalToDbFileId { get; init; }
16+
public SqliteTransaction Transaction { get; set; }
1617
}
1718

1819
public interface ISQLiteHandler : IDisposable
1920
{
20-
void Init(SQLiteConnection db);
21+
void Init(Microsoft.Data.Sqlite.SqliteConnection db);
2122
void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize);
22-
void Finalize(SQLiteConnection db);
23+
void Finalize(Microsoft.Data.Sqlite.SqliteConnection db);
2324
}

0 commit comments

Comments
 (0)