-
Notifications
You must be signed in to change notification settings - Fork 2
/
Archive.cs
97 lines (81 loc) · 2.46 KB
/
Archive.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
namespace Focus.Storage.Archives
{
public class Archive : IDisposable
{
public static Archive FromFile(string fileName)
{
var archive = new Archive();
archive.LoadFromFile(fileName);
return archive;
}
public uint ArchiveFlags
{
get { return Functions.BsaArchiveFlagsGet(handle); }
set { Functions.BsaArchiveFlagsSet(handle, value); }
}
public uint FileCount => Functions.BsaFileCountGet(handle);
public uint FileFlags
{
get { return Functions.BsaFileFlagsGet(handle); }
set { Functions.BsaFileFlagsSet(handle, value); }
}
public bool IsCompressionEnabled
{
get { return Functions.BsaCompressGet(handle); }
set { Functions.BsaCompressSet(handle, value); }
}
public bool IsDataSharingEnabled
{
get { return Functions.BsaShareDataGet(handle); }
set { Functions.BsaShareDataSet(handle, value); }
}
public ArchiveType Type => Functions.BsaArchiveTypeGet(handle);
public uint Version => Functions.BsaVersionGet(handle);
private readonly IntPtr handle;
private bool disposed;
private Archive()
{
handle = Functions.BsaCreate();
}
internal Archive(IntPtr handle)
{
this.handle = handle;
}
~Archive()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public IReadOnlyList<string> GetFileNames()
{
var fileNames = new List<string>();
Functions.BsaIterateFiles(handle, (archive, filePath, fileRecord, folderRecord, context) =>
{
fileNames.Add(filePath);
return false;
}, IntPtr.Zero);
return fileNames.AsReadOnly();
}
internal void LoadFromFile(string fileName)
{
Functions.BsaLoadFromFile(handle, fileName);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
Functions.BsaClose(handle);
Functions.BsaFree(handle);
}
disposed = true;
}
}
}