forked from BAndysc/WoWDatabaseEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.cs
35 lines (31 loc) · 1.02 KB
/
Extensions.cs
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
using WDE.Common.MPQ;
using WDE.MpqReader.Structures;
namespace WDE.MpqReader
{
public static class Extensions
{
public static byte[]? ReadFile(this IMpqArchive archive, FileId path)
{
var size = archive.GetFileSize(path.ToString());
if (!size.HasValue)
return null;
var buf = new byte[size.Value];
archive.ReadFile(buf, (int)size.Value, path.ToString());
return buf;
}
public static PooledArray<byte>? ReadFilePool(this IMpqArchive archive, FileId path)
{
var size = archive.GetFileSize(path.ToString());
if (!size.HasValue)
return null;
var buf = new PooledArray<byte>(size.Value);
int? read = archive.ReadFile(buf.AsArray(), size.Value, path.ToString());
if (read != size)
{
buf.Dispose();
throw new Exception("Couldn't load file " + path);
}
return buf;
}
}
}