Navigation Menu

Skip to content

Commit

Permalink
- Add new meta and accessors for it
Browse files Browse the repository at this point in the history
  • Loading branch information
emukidid committed Oct 23, 2014
1 parent 7fd9ec0 commit d733526
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
34 changes: 29 additions & 5 deletions TextureArchive/ArchiveReader.cpp
@@ -1,6 +1,8 @@
extern "C" {
#include <string.h>
};
#include "ArchiveReader.h"
#include "Endian.h"

#ifdef SHOW_DEBUG
#include "../gui/DEBUG.h"
#endif
Expand All @@ -11,6 +13,13 @@ static void readBinary(FILE* file, T& data) {
swap(data);
}

template <typename T>
static void readBinaryWithSize(FILE* file, T& data, int size) {
memset(data, 0, sizeof(data));
fread(&data, size, 1, file);
swap(data);
}

ArchiveReader::ArchiveReader(const char* filename) :
file(fopen(filename, "rb")), table(readMetadata()) {
stream.zalloc = NULL; stream.zfree = NULL; stream.opaque = NULL;
Expand All @@ -21,12 +30,27 @@ ArchiveReader::~ArchiveReader() {
delete table;
}

char* ArchiveReader::getDescription() { return &description[0]; }
char* ArchiveReader::getAuthor() { return &author[0]; }
char* ArchiveReader::getPacker() { return &packer[0]; }
char* ArchiveReader::getDatepacked() { return &datepacked[0]; }
unsigned char* ArchiveReader::getIcon() { return &icon[0]; }

ArchiveTable* ArchiveReader::readMetadata() {
unsigned int magic, tableOffset, tableSize = 0;

readBinary(file, magic);
if('GXA1' != magic) return new ArchiveTable(0);

readBinary(file, magic);//GXA1
if(0x47584131 != magic) return new ArchiveTable(0);

readBinaryWithSize(file, description, 64);
readBinaryWithSize(file, author, 16);
readBinaryWithSize(file, packer, 16);
readBinaryWithSize(file, datepacked, 12);
readBinaryWithSize(file, icon, 96 * 72 * 2);

//sprintf(txtbuffer,"PAK info:\r\nDescription: [%s]\r\nAuthor: [%s] Packer: [%s] Date Packed: [%s]\r\n",
// description, author, packer, datepacked);
//DEBUG_print(txtbuffer,DBG_USBGECKO);

readBinary(file, tableOffset);
readBinary(file, tableSize);

Expand Down
12 changes: 11 additions & 1 deletion TextureArchive/ArchiveReader.h
Expand Up @@ -59,11 +59,21 @@ class ArchiveReader {
bool readTexture(void* textureData, const ArchiveEntry&);
bool readTexture(void* textureData, const ArchiveEntry&,
const ArchiveEntryInfo&, unsigned int stride);
char *getDescription();
char *getAuthor();
char *getPacker();
char *getDatepacked();
unsigned char *getIcon();

private:
FILE* file;
ArchiveTable* table;


char description[68];
char author[20];
char packer[20];
char datepacked[16]; // Date packed yyyy/mm/dd
unsigned char icon[96*72*2]; // RGB5A3 icon<br>
static const int COMPRESSION = 9, CHUNK_SIZE = 2 * 1024;
z_stream stream;

Expand Down

0 comments on commit d733526

Please sign in to comment.