-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathUnityArchive.cs
More file actions
58 lines (46 loc) · 1.47 KB
/
UnityArchive.cs
File metadata and controls
58 lines (46 loc) · 1.47 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
using System;
using System.Collections.Generic;
using System.Text;
namespace UnityDataTools.FileSystem;
// An archive node is a file in an archive.
public struct ArchiveNode
{
public string Path;
public long Size;
public ArchiveNodeFlags Flags;
}
// Class used to open a Unity archive file (such as an AssetBundle).
public class UnityArchive : IDisposable
{
internal UnityArchiveHandle m_Handle;
Lazy<List<ArchiveNode>> m_Nodes;
public IReadOnlyList<ArchiveNode> Nodes => m_Nodes.Value.AsReadOnly();
internal UnityArchive()
{
m_Nodes = new Lazy<List<ArchiveNode>>(() => GetArchiveNodes());
}
List<ArchiveNode> GetArchiveNodes()
{
var r = DllWrapper.GetArchiveNodeCount(m_Handle, out var count);
UnityFileSystem.HandleErrors(r);
if (count == 0)
return null;
var nodes = new List<ArchiveNode>(count);
var path = new StringBuilder(512);
for (var i = 0; i < count; ++i)
{
DllWrapper.GetArchiveNode(m_Handle, i, path, path.Capacity, out var size, out var flags);
UnityFileSystem.HandleErrors(r);
nodes.Add(new ArchiveNode() { Path = path.ToString(), Size = size, Flags = flags });
}
return nodes;
}
public void Dispose()
{
if (m_Handle != null && !m_Handle.IsInvalid)
{
m_Handle.Dispose();
m_Nodes = new Lazy<List<ArchiveNode>>(() => GetArchiveNodes());
}
}
}