forked from Unity-Technologies/UnityDataTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpectedDataGenerator.cs
More file actions
72 lines (57 loc) · 2.76 KB
/
ExpectedDataGenerator.cs
File metadata and controls
72 lines (57 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.IO;
using System.Linq;
using UnityDataTools.TestCommon;
namespace UnityDataTools.FileSystem.Tests;
public static class ExpectedDataGenerator
{
public static void Generate(Context context)
{
var expectedData = context.ExpectedData;
UnityFileSystem.Init();
using (var archive = UnityFileSystem.MountArchive(Path.Combine(context.UnityDataFolder, "assetbundle"), "/"))
{
expectedData.Add("NodeCount", archive.Nodes.Count);
foreach (var n in archive.Nodes)
{
expectedData.Add(n.Path + "-Size", n.Size);
expectedData.Add(n.Path + "-Flags", n.Flags);
using (var f = UnityFileSystem.OpenFile("/" + n.Path))
{
var buffer = new Byte[100];
f.Read(100, buffer);
expectedData.Add(n.Path + "-Data", buffer);
}
if (n.Flags.HasFlag(ArchiveNodeFlags.SerializedFile))
{
using var f = UnityFileSystem.OpenSerializedFile("/" + n.Path);
expectedData.Add(n.Path + "-ObjCount", f.Objects.Count);
expectedData.Add(n.Path + "-ExtRefCount", f.ExternalReferences.Count);
int i = 0;
foreach (var extRef in f.ExternalReferences)
{
expectedData.Add($"{n.Path}-ExtRef{i}-Guid", extRef.Guid);
expectedData.Add($"{n.Path}-ExtRef{i}-Path", extRef.Path);
expectedData.Add($"{n.Path}-ExtRef{i}-Type", extRef.Type);
++i;
}
var obj = f.Objects.First();
expectedData.Add($"{n.Path}-FirstObj-Id", obj.Id);
expectedData.Add($"{n.Path}-FirstObj-Offset", obj.Offset);
expectedData.Add($"{n.Path}-FirstObj-Size", obj.Size);
expectedData.Add($"{n.Path}-FirstObj-TypeId", obj.TypeId);
obj = f.Objects.Last();
expectedData.Add($"{n.Path}-LastObj-Id", obj.Id);
expectedData.Add($"{n.Path}-LastObj-Offset", obj.Offset);
expectedData.Add($"{n.Path}-LastObj-Size", obj.Size);
expectedData.Add($"{n.Path}-LastObj-TypeId", obj.TypeId);
}
}
UnityFileSystem.Cleanup();
var csprojFolder = Directory.GetParent(context.TestDataFolder).Parent.Parent.Parent.FullName;
var outputFolder = Path.Combine(csprojFolder, "ExpectedData", context.UnityDataVersion);
Directory.CreateDirectory(outputFolder);
expectedData.Save(outputFolder);
}
}
}