-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfpk.c
More file actions
66 lines (55 loc) · 1.25 KB
/
Copy pathfpk.c
File metadata and controls
66 lines (55 loc) · 1.25 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
59
60
61
62
63
64
65
66
#include <piece.h>
#include "fpk.h"
static FILEACC g_fpk;
static int g_sct = -1;
static uint8_t cache[4096]; // ƒZƒNƒ^ƒLƒƒƒbƒVƒ…
int fpkOpenArchive(char* filename, fpack_header_t* header)
{
if(pceFileOpen(&g_fpk, filename, FOMD_RD) != 0)
return -1;
fpkFileReadPos((unsigned char*)header, 0, sizeof(fpack_header_t));
if(memcmp(header->signature, "KAPF", 4) != 0)
{
pceFileClose(&g_fpk);
return -1;
}
return 0;
}
void fpkCloseArchive()
{
pceFileClose(&g_fpk);
}
int fpkFileReadPos(unsigned char* buf, int pos, int size)
{
int rem = size;
int sct;
int len;
sct = pos / 4096;
pos %= 4096;
while(rem > 0) {
if(g_sct != sct) {
pceFileReadSct(&g_fpk, cache, sct, 4096);
g_sct = sct;
}
len = 4096 - pos;
if(len > rem) {
len = rem;
}
memcpy(buf, cache + pos, len);
buf += len;
rem -= len;
sct++;
pos = 0;
}
return size;
}
int fpkGetFileInfoN(int index, fpack_file_entry_t* entry)
{
fpkFileReadPos((unsigned char*)entry, sizeof(fpack_header_t) + index * sizeof(fpack_file_entry_t), sizeof(fpack_file_entry_t));
return 0;
}
int fpkExtractToBuffer(fpack_file_entry_t* entry, void* buffer)
{
fpkFileReadPos(buffer, entry->offset, entry->size);
return 0;
}