2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-10 13:47:46 +00:00

integrated zlib and libpng; initial driver work

This commit is contained in:
Jack Andersen
2015-05-18 21:01:18 -10:00
parent 30ac6e7d8c
commit d10c3a831d
47 changed files with 45522 additions and 137 deletions

View File

@@ -3,6 +3,8 @@
#endif
#include <stdio.h>
#include <blowfish/blowfish.h>
#include <zlib/zlib.h>
#include "HECLDatabase.hpp"
#include "CSQLite.hpp"
@@ -13,10 +15,12 @@ namespace HECLDatabase
class CLooseDatabase final : public IDatabase
{
CSQLite m_sql;
Access m_access;
Access m_access;
public:
CLooseDatabase(const std::string& path, Access access)
: m_sql(path.c_str(), (m_access == READONLY) ? true : false), m_access(access)
: m_mainSql((path+"/main.db").c_str(), (m_access == READONLY) ? true : false),
m_cookedSql((path+"/cooked.db").c_str(), (m_access == READONLY) ? true : false),
m_access(access)
{
}
@@ -46,11 +50,18 @@ public:
const IDataObject* addDataBlob(const std::string& name, const void* data, size_t length)
{
/* Hash data */
ObjectHash hash(data, length);
/* Compress data into file */
FILE* fp = fopen("", "wb");
m_mainSql.insertObject(name, "DUMB", hash, length, length);
}
const IDataObject* addDataBlob(const void* data, size_t length)
{
return addDataBlob(std::string(), data, length);
}
bool writeDatabase(IDatabase::Type type, const std::string& path) const

View File

@@ -16,7 +16,7 @@ namespace HECLDatabase
static const char* skDBINIT =
"PRAGMA foreign_keys = ON;\n"
"CREATE TABLE IF NOT EXISTS objects(rowid INTEGER PRIMARY KEY,"
"name UNIQUE,"
"name,"
"type4cc UNSIGNED INTEGER,"
"hash64 UNSIGNED INTEGER,"
"compLen UNSIGNED INTEGER,"
@@ -106,7 +106,7 @@ public:
uint32_t&&, // type4cc
uint64_t&&, // hash64
size_t&&, // compLen
size_t&&)>& // decompLen
size_t&&)> // decompLen
objectAdder)
{
while (sqlite3_step(m_selObjects) == SQLITE_ROW)
@@ -132,7 +132,8 @@ public:
return retval;
}
bool insertObject(const std::string& name, const FourCC& type, const ObjectHash& hash, size_t compLen, size_t decompLen)
bool insertObject(const std::string& name, const FourCC& type, const ObjectHash& hash,
size_t compLen, size_t decompLen)
{
}

View File

@@ -25,11 +25,12 @@ static TCloseCallback CLOSE_CALLBACK = NULL;
static void* CLOSE_CTX = NULL;
typedef struct mem_file mem_file;
struct mem_file {
struct mem_file
{
sqlite3_file base;
int nSize;
int nAlloc;
char *zAlloc;
char* zAlloc;
};
/*
@@ -40,30 +41,31 @@ static int memRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
static int memWrite(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
static int memTruncate(sqlite3_file*, sqlite3_int64 size);
static int memSync(sqlite3_file*, int flags);
static int memFileSize(sqlite3_file*, sqlite3_int64 *pSize);
static int memFileSize(sqlite3_file*, sqlite3_int64* pSize);
static int memLock(sqlite3_file*, int);
static int memUnlock(sqlite3_file*, int);
static int memCheckReservedLock(sqlite3_file*, int *pResOut);
static int memFileControl(sqlite3_file*, int op, void *pArg);
static int memCheckReservedLock(sqlite3_file*, int* pResOut);
static int memFileControl(sqlite3_file*, int op, void* pArg);
static int memSectorSize(sqlite3_file*);
static int memDeviceCharacteristics(sqlite3_file*);
/*
** Method declarations for fs_vfs.
*/
static int memOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int memDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int memAccess(sqlite3_vfs*, const char *zName, int flags, int *);
static int memFullPathname(sqlite3_vfs*, const char *zName, int nOut,char *zOut);
static void *memDlOpen(sqlite3_vfs*, const char *zFilename);
static void memDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
static void (*memDlSym(sqlite3_vfs*,void*, const char *zSymbol))(void);
static int memOpen(sqlite3_vfs*, const char*, sqlite3_file*, int , int*);
static int memDelete(sqlite3_vfs*, const char* zName, int syncDir);
static int memAccess(sqlite3_vfs*, const char* zName, int flags, int*);
static int memFullPathname(sqlite3_vfs*, const char* zName, int nOut, char* zOut);
static void* memDlOpen(sqlite3_vfs*, const char* zFilename);
static void memDlError(sqlite3_vfs*, int nByte, char* zErrMsg);
static void (*memDlSym(sqlite3_vfs*, void*, const char* zSymbol))(void);
static void memDlClose(sqlite3_vfs*, void*);
static int memRandomness(sqlite3_vfs*, int nByte, char *zOut);
static int memRandomness(sqlite3_vfs*, int nByte, char* zOut);
static int memSleep(sqlite3_vfs*, int microseconds);
static int memCurrentTime(sqlite3_vfs*, double*);
static sqlite3_vfs mem_vfs = {
static sqlite3_vfs mem_vfs =
{
1, /* iVersion */
0, /* szOsFile */
0, /* mxPathname */
@@ -84,7 +86,8 @@ static sqlite3_vfs mem_vfs = {
0 /* xCurrentTimeInt64 */
};
static sqlite3_io_methods mem_io_methods = {
static sqlite3_io_methods mem_io_methods =
{
1, /* iVersion */
memClose, /* xClose */
memRead, /* xRead */
@@ -114,9 +117,10 @@ static sqlite3_io_methods mem_io_methods = {
/*
** Close a mem-file.
*/
static int memClose(sqlite3_file *pFile){
mem_file *pTmp = (mem_file *)pFile;
if (CLOSE_CALLBACK)
static int memClose(sqlite3_file* pFile)
{
mem_file* pTmp = (mem_file*)pFile;
if(CLOSE_CALLBACK)
CLOSE_CALLBACK(pTmp->zAlloc, pTmp->nSize, CLOSE_CTX);
else
sqlite3_free(pTmp->zAlloc);
@@ -127,15 +131,15 @@ static int memClose(sqlite3_file *pFile){
** Read data from a mem-file.
*/
static int memRead(
sqlite3_file *pFile,
void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
mem_file *pTmp = (mem_file *)pFile;
if( (iAmt+iOfst)>pTmp->nSize ){
sqlite3_file* pFile,
void* zBuf,
int iAmt,
sqlite_int64 iOfst
)
{
mem_file* pTmp = (mem_file*)pFile;
if((iAmt + iOfst) > pTmp->nSize)
return SQLITE_IOERR_SHORT_READ;
}
memcpy(zBuf, &pTmp->zAlloc[iOfst], iAmt);
return SQLITE_OK;
}
@@ -144,31 +148,33 @@ static int memRead(
** Write data to a mem-file.
*/
static int memWrite(
sqlite3_file *pFile,
const void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
mem_file *pTmp = (mem_file *)pFile;
if( (iAmt+iOfst)>pTmp->nAlloc ){
int nNew = (int)(2*(iAmt+iOfst+pTmp->nAlloc));
char *zNew = sqlite3_realloc(pTmp->zAlloc, nNew);
if( !zNew ){
sqlite3_file* pFile,
const void* zBuf,
int iAmt,
sqlite_int64 iOfst
)
{
mem_file* pTmp = (mem_file*)pFile;
if((iAmt + iOfst) > pTmp->nAlloc)
{
int nNew = (int)(2 * (iAmt + iOfst + pTmp->nAlloc));
char* zNew = sqlite3_realloc(pTmp->zAlloc, nNew);
if(!zNew)
return SQLITE_NOMEM;
}
pTmp->zAlloc = zNew;
pTmp->nAlloc = nNew;
}
memcpy(&pTmp->zAlloc[iOfst], zBuf, iAmt);
pTmp->nSize = (int)MAX(pTmp->nSize, iOfst+iAmt);
pTmp->nSize = (int)MAX(pTmp->nSize, iOfst + iAmt);
return SQLITE_OK;
}
/*
** Truncate a mem-file.
*/
static int memTruncate(sqlite3_file *pFile, sqlite_int64 size){
mem_file *pTmp = (mem_file *)pFile;
static int memTruncate(sqlite3_file* pFile, sqlite_int64 size)
{
mem_file* pTmp = (mem_file*)pFile;
pTmp->nSize = (int)MIN(pTmp->nSize, size);
return SQLITE_OK;
}
@@ -176,15 +182,17 @@ static int memTruncate(sqlite3_file *pFile, sqlite_int64 size){
/*
** Sync a mem-file.
*/
static int memSync(sqlite3_file *pFile, int flags){
static int memSync(sqlite3_file* pFile, int flags)
{
return SQLITE_OK;
}
/*
** Return the current file-size of a mem-file.
*/
static int memFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
mem_file *pTmp = (mem_file *)pFile;
static int memFileSize(sqlite3_file* pFile, sqlite_int64* pSize)
{
mem_file* pTmp = (mem_file*)pFile;
*pSize = pTmp->nSize;
return SQLITE_OK;
}
@@ -192,21 +200,24 @@ static int memFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
/*
** Lock a mem-file.
*/
static int memLock(sqlite3_file *pFile, int eLock){
static int memLock(sqlite3_file* pFile, int eLock)
{
return SQLITE_OK;
}
/*
** Unlock a mem-file.
*/
static int memUnlock(sqlite3_file *pFile, int eLock){
static int memUnlock(sqlite3_file* pFile, int eLock)
{
return SQLITE_OK;
}
/*
** Check if another file-handle holds a RESERVED lock on a mem-file.
*/
static int memCheckReservedLock(sqlite3_file *pFile, int *pResOut){
static int memCheckReservedLock(sqlite3_file* pFile, int* pResOut)
{
*pResOut = 0;
return SQLITE_OK;
}
@@ -214,21 +225,24 @@ static int memCheckReservedLock(sqlite3_file *pFile, int *pResOut){
/*
** File control method. For custom operations on a mem-file.
*/
static int memFileControl(sqlite3_file *pFile, int op, void *pArg){
static int memFileControl(sqlite3_file* pFile, int op, void* pArg)
{
return SQLITE_OK;
}
/*
** Return the sector-size in bytes for a mem-file.
*/
static int memSectorSize(sqlite3_file *pFile){
static int memSectorSize(sqlite3_file* pFile)
{
return 0;
}
/*
** Return the device characteristic flags supported by a mem-file.
*/
static int memDeviceCharacteristics(sqlite3_file *pFile){
static int memDeviceCharacteristics(sqlite3_file* pFile)
{
return 0;
}
@@ -236,18 +250,19 @@ static int memDeviceCharacteristics(sqlite3_file *pFile){
** Open an mem file handle.
*/
static int memOpen(
sqlite3_vfs *pVfs,
const char *zName,
sqlite3_file *pFile,
int flags,
int *pOutFlags
){
if (flags != SQLITE_OPEN_MAIN_DB)
sqlite3_vfs* pVfs,
const char* zName,
sqlite3_file* pFile,
int flags,
int* pOutFlags
)
{
if(flags != SQLITE_OPEN_MAIN_DB)
{
fprintf(stderr, "the sqlite hecl mem VFS only supports main-db writing\n");
abort();
}
mem_file *p2 = (mem_file *)pFile;
mem_file* p2 = (mem_file*)pFile;
memset(p2, 0, sizeof(*p2));
p2->base.pMethods = &mem_io_methods;
return SQLITE_OK;
@@ -258,7 +273,8 @@ static int memOpen(
** ensure the file-system modifications are synced to disk before
** returning.
*/
static int memDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
static int memDelete(sqlite3_vfs* pVfs, const char* zPath, int dirSync)
{
return SQLITE_OK;
}
@@ -267,12 +283,13 @@ static int memDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
** is available, or false otherwise.
*/
static int memAccess(
sqlite3_vfs *pVfs,
const char *zPath,
int flags,
int *pResOut
){
if (flags & SQLITE_ACCESS_READ | SQLITE_ACCESS_READWRITE)
sqlite3_vfs* pVfs,
const char* zPath,
int flags,
int* pResOut
)
{
if(flags & SQLITE_ACCESS_READ | SQLITE_ACCESS_READWRITE)
return 1;
return 0;
}
@@ -283,11 +300,11 @@ static int memAccess(
** of at least (FS_MAX_PATHNAME+1) bytes.
*/
static int memFullPathname(
sqlite3_vfs *pVfs, /* Pointer to vfs object */
const char *zPath, /* Possibly relative input path */
int nOut, /* Size of output buffer in bytes */
char *zOut /* Output buffer */
){
sqlite3_vfs* pVfs, /* Pointer to vfs object */
const char* zPath, /* Possibly relative input path */
int nOut, /* Size of output buffer in bytes */
char* zOut) /* Output buffer */
{
strncpy(zOut, zPath, nOut);
return SQLITE_OK;
}
@@ -295,7 +312,8 @@ static int memFullPathname(
/*
** Open the dynamic library located at zPath and return a handle.
*/
static void *memDlOpen(sqlite3_vfs *pVfs, const char *zPath){
static void* memDlOpen(sqlite3_vfs* pVfs, const char* zPath)
{
return NULL;
}
@@ -304,27 +322,31 @@ static void *memDlOpen(sqlite3_vfs *pVfs, const char *zPath){
** utf-8 string describing the most recent error encountered associated
** with dynamic libraries.
*/
static void memDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
static void memDlError(sqlite3_vfs* pVfs, int nByte, char* zErrMsg)
{
}
/*
** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
*/
static void (*memDlSym(sqlite3_vfs *pVfs, void *pH, const char *zSym))(void){
static void (*memDlSym(sqlite3_vfs* pVfs, void* pH, const char* zSym))(void)
{
}
/*
** Close the dynamic library handle pHandle.
*/
static void memDlClose(sqlite3_vfs *pVfs, void *pHandle){
static void memDlClose(sqlite3_vfs* pVfs, void* pHandle)
{
}
/*
** Populate the buffer pointed to by zBufOut with nByte bytes of
** random data.
*/
static int memRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
for (int i=0 ; i<nByte ; ++i)
static int memRandomness(sqlite3_vfs* pVfs, int nByte, char* zBufOut)
{
for(int i = 0 ; i < nByte ; ++i)
zBufOut[i] = rand();
return nByte;
}
@@ -333,16 +355,18 @@ static int memRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
** Sleep for nMicro microseconds. Return the number of microseconds
** actually slept.
*/
static int memSleep(sqlite3_vfs *pVfs, int nMicro){
int seconds = (nMicro+999999)/1000000;
static int memSleep(sqlite3_vfs* pVfs, int nMicro)
{
int seconds = (nMicro + 999999) / 1000000;
sleep(seconds);
return seconds*1000000;
return seconds * 1000000;
}
/*
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int memCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
static int memCurrentTime(sqlite3_vfs* pVfs, double* pTimeOut)
{
*pTimeOut = 0.0;
return 0;
}
@@ -352,10 +376,11 @@ static int memCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
** true, the mem vfs becomes the new default vfs. It is the only publicly
** available function in this file.
*/
int sqlite_hecl_mem_vfs_register(TCloseCallback closeCb, void* ctx){
int sqlite_hecl_mem_vfs_register(TCloseCallback closeCb, void* ctx)
{
CLOSE_CALLBACK = closeCb;
CLOSE_CTX = ctx;
if (mem_vfs.szOsFile) return SQLITE_OK;
if(mem_vfs.szOsFile) return SQLITE_OK;
mem_vfs.szOsFile = sizeof(mem_file);
return sqlite3_vfs_register(&mem_vfs, 0);
}