-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathUnityFile.cs
More file actions
46 lines (36 loc) · 1.06 KB
/
UnityFile.cs
File metadata and controls
46 lines (36 loc) · 1.06 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
using System;
namespace UnityDataTools.FileSystem;
// Use this class to read data from a Unity file.
public class UnityFile : IDisposable
{
internal UnityFile()
{
}
internal UnityFileHandle m_Handle;
public long Read(long size, byte[] buffer)
{
var r = DllWrapper.ReadFile(m_Handle, size, buffer, out var actualSize);
UnityFileSystem.HandleErrors(r);
return actualSize;
}
public long Seek(long offset, SeekOrigin origin = SeekOrigin.Begin)
{
var r = DllWrapper.SeekFile(m_Handle, offset, origin, out var newPosition);
UnityFileSystem.HandleErrors(r);
return newPosition;
}
public long GetSize()
{
// This could be a property but as it may throw an exception, it's probably better as a method.
var r = DllWrapper.GetFileSize(m_Handle, out var size);
UnityFileSystem.HandleErrors(r);
return size;
}
public void Dispose()
{
if (m_Handle != null && !m_Handle.IsInvalid)
{
m_Handle.Dispose();
}
}
}