Skip to content

Commit b572fd9

Browse files
committed
headers: add docs
1 parent a2e101c commit b572fd9

6 files changed

+97
-0
lines changed

pak_defs.h

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ typedef struct PakAlias {
3939

4040
#pragma pack(pop)
4141

42+
/**
43+
* Get pak version from pak buffer.
44+
* @param void *buffer - pointer to pak.
45+
* @return uint32_t - pak version.
46+
*/
4247
#define pakGetVerison(buffer) (*(uint32_t *)buffer)
4348
#define PAK_HEADER_SIZE_V4 sizeof(PakHeaderV4)
4449
#define PAK_HEADER_SIZE_V5 sizeof(PakHeaderV5)

pak_file.h

+23
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,32 @@
88

99
#include "pak_defs.h"
1010
#include "pak_header.h"
11+
12+
/**
13+
* Package a pak file, returns NULL_File on failure.
14+
* Note: this would allocate memory.
15+
* @param MyPakHeader *myHeader - pointer to MyPakHeader struct.
16+
* @param PakFile *pakResFile - pointer to all resource files.
17+
* @param PakAlias *pakAlias - pointer to all alias.
18+
* @return PakFile - the packed file.
19+
*/
1120
PakFile pakPackFiles(MyPakHeader *myHeader, PakFile *pakResFile,
1221
PakAlias *pakAlias);
22+
23+
/**
24+
* Get a single file from pak, returns NULL_File on failure.
25+
* @param void *pakBuffer - pointer to pak.
26+
* @param uint16_t *id - target file id.
27+
* @return PakFile - the target file.
28+
*/
1329
PakFile pakGetFile(void *pakBuffer, uint16_t id);
30+
31+
/**
32+
* Get all files from pak, returns NULL on failure.
33+
* Note: this would allocate memory.
34+
* @param void* buffer - pointer to pak.
35+
* @return PakFile* - pointer to all files in pak.
36+
*/
1437
PakFile *pakGetFiles(void *buffer);
1538

1639
#endif // __PAK_FILE_H__

pak_file_io.h

+13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@
77
#include <stdio.h>
88
#include <stdlib.h>
99

10+
/**
11+
* Read a file into memory, returns NULL_File on failure.
12+
* Note: this would allocate memory.
13+
* @param const char *fileName - target file name.
14+
* @return PakFile - target file content.
15+
*/
1016
PakFile readFile(const char *fileName);
17+
18+
/**
19+
* Write a file to storage, this would overwrite existing file.
20+
* @param const char *fileName - target file name.
21+
* @param PakFile file - target file content.
22+
* @return bool - succeed or not.
23+
*/
1124
bool writeFile(const char *fileName, const PakFile file);
1225

1326
#endif // __PAK_FILE_IO_H__

pak_get_file_type.h

+12
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@ typedef struct FileType {
1313
uint8_t size;
1414
} FileType;
1515

16+
/**
17+
* Generate a FileType, for internal uses only.
18+
* @param char* type - file extension.
19+
* @param char* identifer - file header identifer in string.
20+
* @see pakGetFileType()
21+
* @return FileType
22+
*/
1623
#define PAK_GEN_FILE_TYPE(type, identifer) \
1724
{type, identifer, sizeof(identifer) - 1}
1825

26+
/**
27+
* Get file extension form a file, returns "" on failure.
28+
* @param PakFile file - the file to parse.
29+
* @return char* - pointer to file extension.
30+
*/
1931
char *pakGetFileType(PakFile file);
2032

2133
#endif // __PAK_GET_FILE_TYPE_H__

pak_header.h

+20
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@
55
#include <stdio.h>
66
#include <strings.h>
77

8+
/**
9+
* Generate MyPakHeader struct from pak buffer.
10+
* @param _in_ void *buffer - pointer to pak buffer.
11+
* @param _out_ MyPakHeader myHeader - target file content.
12+
* @return bool - succeed or not.
13+
*/
814
bool pakParseHeader(void *buffer, MyPakHeader *myHeader);
15+
16+
/**
17+
* Write pak header from MyPakHeader struct to buffer.
18+
* @param MyPakHeader myHeader - target MyPakHeader struct.
19+
* @param void *buffer - pointer to target pak buffer.
20+
* @return unsigned int - pak header size, 0 on failure.
21+
*/
922
unsigned int pakWriteHeader(MyPakHeader *myHeader, void *buffer);
23+
24+
/**
25+
* Check if pak format is legal.
26+
* @param void *buffer - pointer to pak buffer.
27+
* @param unsigned int size - pak buffer size in bytes.
28+
* @return bool - succeed or not.
29+
*/
1030
bool pakCheckFormat(void *buffer, unsigned int size);
1131

1232
#endif // __PAK_HEADERS_H__

pak_pack.h

+24
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,32 @@
1818
#include "pak_file_io.h"
1919
#include "pak_get_file_type.h"
2020
#include "pak_header.h"
21+
22+
/**
23+
* Unpack a pak file to target path.
24+
* @param void *buffer - pointer to target pak buffer.
25+
* @param char *outputPath - target path.
26+
* @return bool - succeed or not.
27+
*/
2128
bool pakUnpack(void *buffer, char *outputPath);
29+
30+
/**
31+
* Pack a pak file from target index (ini) file,
32+
* returns NULL_File on failure.
33+
* Note: this would allocate memory.
34+
* @param PakFile pakIndex - target pak index file.
35+
* @param char *path - target path.
36+
* @return PakFile - packed pak.
37+
*/
2238
PakFile pakPack(PakFile pakIndex, char *path);
39+
40+
/**
41+
* Count number of specified char in string.
42+
* @param char *string - target string.
43+
* @param uint32_t length - target string length.
44+
* @param char toCount - specified char to count.
45+
* @return uint32_t - number of specified char.
46+
*/
2347
uint32_t countChar(char *string, uint32_t length, char toCount);
2448

2549
#endif // __PAK_PACKER_UNPACKER_H__

0 commit comments

Comments
 (0)