Compare commits
No commits in common. "ce5b94341663d0ee3e991721644d0a88cc4b093b" and "7e08071e45c39d4732b7b64559a619d6270419f3" have entirely different histories.
ce5b943416
...
7e08071e45
32
compile
32
compile
@ -22,7 +22,6 @@ FG_BR_WHITE="\033[97"
|
|||||||
|
|
||||||
CC=clang
|
CC=clang
|
||||||
CFLAGS="-Wall -Werror -pedantic -Iinclude "
|
CFLAGS="-Wall -Werror -pedantic -Iinclude "
|
||||||
|
|
||||||
PCKR_SRC="\
|
PCKR_SRC="\
|
||||||
src/path_utils.c \
|
src/path_utils.c \
|
||||||
src/argparse.c \
|
src/argparse.c \
|
||||||
@ -31,24 +30,14 @@ PCKR_SRC="\
|
|||||||
src/pak.c \
|
src/pak.c \
|
||||||
src/pckr.c \
|
src/pckr.c \
|
||||||
src/main.c"
|
src/main.c"
|
||||||
|
|
||||||
PCKR_TEST_SRC="\
|
PCKR_TEST_SRC="\
|
||||||
src/path_utils.c \
|
src/path_utils.c \
|
||||||
src/io.c \
|
src/io.c \
|
||||||
src/pckr_test.c"
|
src/pckr_test.c"
|
||||||
PCKR_TEST_OUT="pckr_test"
|
PCKR_TEST_OUT="pckr_test"
|
||||||
|
|
||||||
PAKRD_TEST_SRC="\
|
|
||||||
src/path_utils.c \
|
|
||||||
src/io.c \
|
|
||||||
src/darr.c \
|
|
||||||
src/pak.c \
|
|
||||||
src/pakrd_test.c"
|
|
||||||
PAKRD_TEST_OUT="pakrd_test"
|
|
||||||
|
|
||||||
BUILD_TYPE="debug"
|
BUILD_TYPE="debug"
|
||||||
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-r|--release)
|
-r|--release)
|
||||||
@ -62,7 +51,6 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
if [[ $BUILD_TYPE == "debug" ]]; then
|
if [[ $BUILD_TYPE == "debug" ]]; then
|
||||||
CFLAGS+="-g "
|
CFLAGS+="-g "
|
||||||
PCKR_OUT="pckr"
|
PCKR_OUT="pckr"
|
||||||
@ -71,32 +59,14 @@ else
|
|||||||
PCKR_OUT="../proj/pckr"
|
PCKR_OUT="../proj/pckr"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Build pckr executable
|
# Build pckr executable
|
||||||
(set -x ; $CC $CFLAGS $PCKR_SRC -o $PCKR_OUT)
|
(set -x ; $CC $CFLAGS $PCKR_SRC -o $PCKR_OUT)
|
||||||
|
|
||||||
|
|
||||||
# Build pckr_test executable
|
# Build pckr_test executable
|
||||||
(set -x ; $CC $CFLAGS $PCKR_TEST_SRC -o $PCKR_TEST_OUT)
|
(set -x ; $CC $CFLAGS $PCKR_TEST_SRC -o $PCKR_TEST_OUT)
|
||||||
|
|
||||||
|
# Run pckr test
|
||||||
# Build pakrd_test executable
|
|
||||||
(set -x ; $CC $CFLAGS $PAKRD_TEST_SRC -o $PAKRD_TEST_OUT)
|
|
||||||
|
|
||||||
|
|
||||||
# Create test pak
|
|
||||||
./pckr ./test_assets ./assets
|
./pckr ./test_assets ./assets
|
||||||
|
|
||||||
|
|
||||||
# Run pckr_test
|
|
||||||
(./$PCKR_TEST_OUT && echo -e "\npckr_test [${FG_BR_GREEN}m${BOLD}m SUCCESS $CLEAR]") || echo -e "\npckr_test [${FG_BR_RED}m${BOLD}m FAILURE $CLEAR]"
|
(./$PCKR_TEST_OUT && echo -e "\npckr_test [${FG_BR_GREEN}m${BOLD}m SUCCESS $CLEAR]") || echo -e "\npckr_test [${FG_BR_RED}m${BOLD}m FAILURE $CLEAR]"
|
||||||
|
|
||||||
|
|
||||||
# Run pakrd_test
|
|
||||||
(./$PAKRD_TEST_OUT && echo -e "pakrd_test [${FG_BR_GREEN}m${BOLD}m SUCCESS $CLEAR]") || echo -e "pakrd_test [${FG_BR_RED}m${BOLD}m FAILURE $CLEAR]"
|
|
||||||
|
|
||||||
|
|
||||||
# Clean test assets
|
|
||||||
rm ./assets.pak
|
rm ./assets.pak
|
||||||
rm pckr_test
|
rm pckr_test
|
||||||
rm pakrd_test
|
|
||||||
|
@ -4,11 +4,6 @@
|
|||||||
#include "aliases.h"
|
#include "aliases.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u64 size;
|
|
||||||
u8 *data;
|
|
||||||
} buf_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 offset;
|
u64 offset;
|
||||||
u64 length;
|
u64 length;
|
||||||
@ -37,11 +32,6 @@ typedef struct {
|
|||||||
toc_t toc;
|
toc_t toc;
|
||||||
} pak_t;
|
} pak_t;
|
||||||
|
|
||||||
typedef struct pak_read pak_read_t;
|
|
||||||
|
|
||||||
bool create_asset_pack(const char *dirpath, const char *output);
|
bool create_asset_pack(const char *dirpath, const char *output);
|
||||||
pak_read_t *load_asset_pack(const char *filepath);
|
|
||||||
// buf_t read_file_from_pack(pak_read_t *pack, const char *filename);
|
|
||||||
void close_asset_pack(pak_read_t **pack);
|
|
||||||
|
|
||||||
#endif // !PAK_H
|
#endif // !PAK_H
|
||||||
|
70
src/pak.c
70
src/pak.c
@ -13,14 +13,6 @@
|
|||||||
#define PAK_PATCH 0
|
#define PAK_PATCH 0
|
||||||
#define PAK_EXT ".pak"
|
#define PAK_EXT ".pak"
|
||||||
|
|
||||||
struct pak_read {
|
|
||||||
pak_t header;
|
|
||||||
u8 *buf;
|
|
||||||
u8 *toc;
|
|
||||||
u64 assets_length;
|
|
||||||
u8 *assets;
|
|
||||||
};
|
|
||||||
|
|
||||||
toc_entry_t *create_toc_entry(const char *name, u64 offset);
|
toc_entry_t *create_toc_entry(const char *name, u64 offset);
|
||||||
void write_toc_entry(toc_entry_t *entry, FILE *fp);
|
void write_toc_entry(toc_entry_t *entry, FILE *fp);
|
||||||
void write_toc_entries(const toc_t *toc, toc_entry_t **entries, FILE *fp);
|
void write_toc_entries(const toc_t *toc, toc_entry_t **entries, FILE *fp);
|
||||||
@ -85,6 +77,8 @@ bool create_asset_pack(const char *dirpath, const char *output) {
|
|||||||
if (result.fp) {
|
if (result.fp) {
|
||||||
++(pak.toc.count);
|
++(pak.toc.count);
|
||||||
|
|
||||||
|
offset += sizeof(pak_entry_t);
|
||||||
|
|
||||||
toc_entry_t *toc_entry = create_toc_entry(result.name, offset);
|
toc_entry_t *toc_entry = create_toc_entry(result.name, offset);
|
||||||
pak_entry_t *pak_entry = create_pak_entry_from_file(result.fp);
|
pak_entry_t *pak_entry = create_pak_entry_from_file(result.fp);
|
||||||
|
|
||||||
@ -93,7 +87,7 @@ bool create_asset_pack(const char *dirpath, const char *output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pak.toc.size += sizeof(toc_entry_t) + toc_entry->length;
|
pak.toc.size += sizeof(toc_entry_t) + toc_entry->length;
|
||||||
offset += sizeof(pak_entry_t) + pak_entry->size;
|
offset += pak_entry->size;
|
||||||
|
|
||||||
darr_add(&toc_entries_darr, (void *)toc_entry);
|
darr_add(&toc_entries_darr, (void *)toc_entry);
|
||||||
darr_add(&pak_entries_darr, (void *)pak_entry);
|
darr_add(&pak_entries_darr, (void *)pak_entry);
|
||||||
@ -119,64 +113,6 @@ RETURN_CREATE_ASSET_PAK:
|
|||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
pak_read_t *load_asset_pack(const char *filepath) {
|
|
||||||
char full_path[PATH_MAX] = {0};
|
|
||||||
|
|
||||||
realpath(filepath, full_path);
|
|
||||||
|
|
||||||
pak_read_t *pack = NULL;
|
|
||||||
|
|
||||||
FILE *fp = fopen(full_path, "rb");
|
|
||||||
if (!fp) {
|
|
||||||
goto RETURN_LOAD_ASSET_PACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
pack = (pak_read_t *)malloc(sizeof(pak_read_t));
|
|
||||||
if (!pack) {
|
|
||||||
goto CLOSE_FILE_LOAD_ASSET_PACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 file_size = get_file_length(fp);
|
|
||||||
|
|
||||||
fread((void *)(&(pack->header)), sizeof(pak_t), 1, fp);
|
|
||||||
|
|
||||||
u64 data_size = file_size - sizeof(pak_t);
|
|
||||||
|
|
||||||
pack->buf = (u8 *)malloc(data_size);
|
|
||||||
if (!(pack->buf)) {
|
|
||||||
free(pack);
|
|
||||||
|
|
||||||
pack = NULL;
|
|
||||||
|
|
||||||
goto CLOSE_FILE_LOAD_ASSET_PACK;
|
|
||||||
}
|
|
||||||
|
|
||||||
fread((void *)(pack->buf), data_size, 1, fp);
|
|
||||||
|
|
||||||
pack->toc = pack->buf;
|
|
||||||
|
|
||||||
pack->assets_length = data_size - pack->header.toc.size;
|
|
||||||
|
|
||||||
pack->assets = pack->buf + pack->header.toc.size;
|
|
||||||
|
|
||||||
CLOSE_FILE_LOAD_ASSET_PACK:
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
RETURN_LOAD_ASSET_PACK:
|
|
||||||
return pack;
|
|
||||||
}
|
|
||||||
|
|
||||||
// buf_t read_file_from_pack(pak_read_t *pack, const char *filename) {}
|
|
||||||
|
|
||||||
void close_asset_pack(pak_read_t **pack) {
|
|
||||||
if (!(*pack)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(*pack);
|
|
||||||
*pack = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
toc_entry_t *create_toc_entry(const char *name, u64 offset) {
|
toc_entry_t *create_toc_entry(const char *name, u64 offset) {
|
||||||
u64 length = strlen(name);
|
u64 length = strlen(name);
|
||||||
u64 size = sizeof(toc_entry_t) + length + 1;
|
u64 size = sizeof(toc_entry_t) + length + 1;
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
#include "pak.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
pak_read_t *pack = load_asset_pack("assets.pak");
|
|
||||||
if (!pack) {
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
@ -124,7 +124,8 @@ i32 main(i32 argc, char *argv[]) {
|
|||||||
|
|
||||||
pos = ftell(fp);
|
pos = ftell(fp);
|
||||||
|
|
||||||
u64 new_pos = toc_entries[i]->offset + sizeof(pak_t) + pack.toc.size;
|
u64 new_pos =
|
||||||
|
toc_entries[i]->offset + sizeof(pak_t) + pack.toc.size - sizeof(u64);
|
||||||
|
|
||||||
fseek(fp, new_pos, SEEK_SET);
|
fseek(fp, new_pos, SEEK_SET);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user