forked from similing4/pvf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeaderTreeNode.cs
61 lines (59 loc) · 2.54 KB
/
HeaderTreeNode.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
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace pvfLoaderXinyu
{
struct PvfHeader//头文件内容,没什么好说的
{
public int sizeGUID; //Always 0x24
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x24)]
public byte[] GUID;
public int fileVersion;
public int dirTreeLength;//头文件占用字节大小
public int dirTreeChecksum;//CRC32码
public int numFilesInDirTree;//PVF文件总数
}
class HeaderTreeNode
{
public byte[] unpackedFileByteArr;
public int filePathLength;
public int relativeOffset;
public int fileLength;
public int computedFileLength;
public string filePathName;
public uint fileNumber;
public uint fileCrc32;
public int readNodeFromBitArrStream(PvfHeader header, FileStream fs,byte[] unpackedHeaderTree, int offsite)
{
try
{
fileNumber = BitConverter.ToUInt32(unpackedHeaderTree, offsite);
filePathLength = BitConverter.ToInt32(unpackedHeaderTree, offsite + 4);
byte[] filePath = new byte[filePathLength];
Array.Copy(unpackedHeaderTree, offsite + 8, filePath, 0, filePathLength);
fileLength = BitConverter.ToInt32(unpackedHeaderTree, (offsite + filePathLength) + 8);
fileCrc32 = BitConverter.ToUInt32(unpackedHeaderTree, (offsite + filePathLength) + 12);
relativeOffset = BitConverter.ToInt32(unpackedHeaderTree, (offsite + filePathLength) + 0x10);
if (fileLength > 0)
{
computedFileLength = (int)((fileLength + 3L) & 4294967292L);
unpackedFileByteArr = new byte[computedFileLength];
fs.Seek(Marshal.SizeOf(typeof(PvfHeader)) + header.dirTreeLength + relativeOffset, SeekOrigin.Begin);
fs.Read(unpackedFileByteArr,0, computedFileLength);
Util.unpackHeaderTree(ref unpackedFileByteArr, computedFileLength, fileCrc32);
for (int i = 0; i < (computedFileLength - fileLength); i++)
{
unpackedFileByteArr[fileLength + i] = 0;
}
}
filePathName = Encoding.GetEncoding(0x3b5).GetString(filePath).TrimEnd(new char[1]);//CP949(韩语)
return filePathLength + 20;
}
catch
{
return -1;
}
}
}
}