Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version support/assetdatabase #31

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
Binary file added native/libspreads_lmdb.dylib
Binary file not shown.
5 changes: 5 additions & 0 deletions src/Unity.Cli/Commands_RunAssetDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ void DumpTables(AssetLmdb db, IEnumerable<TableDumpSpec> specs)

foreach (var spec in specs)
{

if (!config.OptCombined)
{
var path = outDir.Combine($"{db.Name}-{spec.TableName}");
dump = new DumpContext(path, config);
}

// Data size in tables can vary with DbVersions. We filter them out here
if (spec.VersionCompatibliity != null && !spec.VersionCompatibliity.Contains(db.DbVersion))
continue;

db.DumpTable(dump!, db, spec);

if (!config.OptCombined)
Expand Down
6 changes: 6 additions & 0 deletions src/Unity.Cli/Unity.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@
<ProjectReference Include="$(OkSrcRoot)Unity\Unity.csproj" />
</ItemGroup>

<ItemGroup>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check your formatting

<None Include="$(OkSrcRoot)/../native/libspreads_lmdb.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Unity/AssetDb/AssetLmdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AssetLmdb(NPath dbPath, params uint[] supportedVersions) : base(dbPath)
var supportedVersionsText = supportedVersions
.Select(NiceUint)
.StringJoin(", ");
throw new InvalidOperationException($"Unsupported {Name} version {NiceUint(DbVersion)} (supported: {supportedVersionsText})");
throw new InvalidOperationException($"Unsupported {Name} version {NiceUint(DbVersion)} ({DbVersion}) (supported: {supportedVersionsText})");
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public void DumpTable(DumpContext dump, AssetLmdb db, TableDumpSpec spec)
[UsedImplicitly]
public record AssetLmdbInfo(string Name, string Version, string[] TableNames);

public record TableDumpSpec(string TableName, string CsvFields, bool UniqueKeys, Action<DumpContext, DirectBuffer, DirectBuffer> Dump);
public record TableDumpSpec(string TableName, string CsvFields, bool UniqueKeys, uint[]? VersionCompatibliity, Action<DumpContext, DirectBuffer, DirectBuffer> Dump);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spleliing


public struct DumpConfig
{
Expand Down
4 changes: 3 additions & 1 deletion src/Unity/AssetDb/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public AssetLmdbTableAttribute(string tableName, string csvFields)

public bool UniqueKeys { get; set; }

public uint[]? VersionCompatibility { get; set; }

public static TableDumpSpec[] CreateTableDumpSpecs(Type type)
{
var expected = new[] { typeof(DumpContext), typeof(DirectBuffer), typeof(DirectBuffer) };
Expand All @@ -32,7 +34,7 @@ public static TableDumpSpec[] CreateTableDumpSpecs(Type type)
throw new InvalidOperationException($"Method {m.DeclaringType}.{m.Name} is not `void {m.Name}(DumpContext, DirectBuffer, DirectBuffer)`");

return new TableDumpSpec(
attr._tableName, attr._csvFields, attr.UniqueKeys,
attr._tableName, attr._csvFields, attr.UniqueKeys, attr.VersionCompatibility,
(c, k, v) => m.Invoke(null, [c, k, v]));
})
.Where(s => s != null)
Expand Down
2 changes: 1 addition & 1 deletion src/Unity/AssetDb/DirectBufferExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static T Read<T>(this ref DirectBuffer @this) where T : unmanaged
public static T ReadExpectEnd<T>(this in DirectBuffer @this) where T : unmanaged
{
if (@this.Length != Unsafe.SizeOf<T>())
throw new InvalidOperationException("Did not consume entire value");
throw new InvalidOperationException($"Did not consume entire value. Expected {@this.Length}, actual: {Unsafe.SizeOf<T>()}");

return @this.Read<T>(0);
}
Expand Down
26 changes: 24 additions & 2 deletions src/Unity/AssetDb/SourceAssetLmdb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OkTools.Unity.AssetDb;

public static class SourceAssetLmdb
{
static readonly uint[] k_expectedDbVersions = [9, 10, 0x218FD4A3];
static readonly uint[] k_expectedDbVersions = [9, 10, 0x218FD4A3, 0xB7728EEA];
public static AssetLmdb OpenLmdb(NPath projectRoot) =>
new(projectRoot.Combine(UnityProjectConstants.SourceAssetDbNPath), k_expectedDbVersions);

Expand Down Expand Up @@ -99,7 +99,7 @@ public static void DumpGuidToPath(DumpContext dump, DirectBuffer key, DirectBuff
dump.Json!.WriteString(unityGuid.ToString(), path);
}

[AssetLmdbTable("hash", "Path,Hash,Time,FileSize,IsUntrusted", UniqueKeys = true)]
[AssetLmdbTable("hash", "Path,Hash,Time,FileSize,IsUntrusted", UniqueKeys = true, VersionCompatibility = [9, 10, 0x218FD4A3])]
public static void DumpPathToHash(DumpContext dump, DirectBuffer key, DirectBuffer value)
{
// HashDB.cpp: HashDB::m_pPathToHash
Expand All @@ -122,6 +122,28 @@ public static void DumpPathToHash(DumpContext dump, DirectBuffer key, DirectBuff
}
}

[AssetLmdbTable("hash", "Path,Hash,Time,FileSize,IsUntrusted", UniqueKeys = true, VersionCompatibility = [0xB7728EEA])]
public static void DumpPathToHash2(DumpContext dump, DirectBuffer key, DirectBuffer value)
{
// HashDB.cpp: HashDB::m_pPathToHash

var path = key.ToAsciiString();
var hash = value.ReadExpectEnd<HashDBValueNoFileSize>();

if (dump.Csv != null)
dump.Csv.Write($"{path},{hash.hash},{hash.TimeAsDateTime},{hash.isUntrusted},");
else
{
dump.Json!.WriteStartObject(path);

dump.Json.WriteString("Hash", hash.hash.ToString());
dump.Json.WriteString("Time", hash.TimeAsDateTime);
dump.Json.WriteBoolean("IsUntrusted", hash.isUntrusted);

dump.Json.WriteEndObject();
}
}

[AssetLmdbTable("Misc", "Name,Value0,Value1,...", UniqueKeys = true)]
public static void DumpMisc(DumpContext dump, DirectBuffer key, DirectBuffer value)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Unity/AssetDb/SourceAssetLmdbSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ struct HashDBValue // Modules/AssetDatabase/Editor/V2/HashDB.h

public DateTime TimeAsDateTime => new(time); // C++ DateTime not binary compatible because extra field in C# version, but easy to convert (they both use the same ticks epoch+resolution)
}

struct HashDBValueNoFileSize // Modules/AssetDatabase/Editor/V2/HashDB.h
{
public Hash128 hash;
public long time;
public bool isUntrusted;

public DateTime TimeAsDateTime => new(time); // C++ DateTime not binary compatible because extra field in C# version, but easy to convert (they both use the same ticks epoch+resolution)
}
4 changes: 2 additions & 2 deletions src/Unity/Unity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal static IReadOnlyList<Process> FindUnityProcessesForProject(NPath projec

foreach (var unityProcess in Process.GetProcessesByName(UnityConstants.UnityProcessName))
{
var workingDir = NativeWindows.SafeGetProcessCurrentDirectory(unityProcess.Id)?.ToNPath();
var workingDir = "";//NativeWindows.SafeGetProcessCurrentDirectory(unityProcess.Id)?.ToNPath();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look temporarily commented out, is that right?

if (workingDir == projectPath)
matches.Add(unityProcess);
else
Expand All @@ -63,7 +63,7 @@ internal static IReadOnlyList<Process> FindUnityProcessesForProject(NPath projec
{
foreach (var unityProcess in unityProcesses.Where(p => p.MainWindowHandle != default))
{
var unityCommandLine = NativeWindows.SafeGetProcessCommandLine(unityProcess.Id);
var unityCommandLine = "";//NativeWindows.SafeGetProcessCommandLine(unityProcess.Id);
if (unityCommandLine == null)
continue;

Expand Down