Commit 9109414e authored by nanahira's avatar nanahira

Merge remote-tracking branch 'salix/patch-db' into merge-20260320

# Conflicts:
#	gframe/data_manager.cpp
#	gframe/premake5.lua
parents 3b8d3235 dd500934
#include "data_manager.h" #include "data_manager.h"
#include "game.h" #include "game.h"
#include "client_card.h" #include "client_card.h"
#include "spmemvfs/spmemvfs.h"
namespace ygo { namespace ygo {
...@@ -113,22 +112,48 @@ bool DataManager::LoadDB(const char* file) { ...@@ -113,22 +112,48 @@ bool DataManager::LoadDB(const char* file) {
return LoadDB(reader); return LoadDB(reader);
} }
bool DataManager::LoadDB(irr::io::IReadFile* reader) { bool DataManager::LoadDB(irr::io::IReadFile* reader) {
if(reader == nullptr) if (reader == nullptr)
return false; return false;
spmemvfs_db_t db;
spmembuffer_t* mem = (spmembuffer_t*)std::calloc(sizeof(spmembuffer_t), 1); sqlite3* db_handle = nullptr;
spmemvfs_env_init(); if (sqlite3_open(":memory:", &db_handle) != SQLITE_OK) {
mem->total = mem->used = reader->getSize(); Error(db_handle, nullptr);
mem->data = (char*)std::malloc(mem->total); sqlite3_close(db_handle);
reader->read(mem->data, mem->total); reader->drop();
return false;
}
sqlite3_int64 sz = reader->getSize();
unsigned char* buffer = (unsigned char*)sqlite3_malloc64(sz);
if (!buffer) {
Error(db_handle, nullptr);
sqlite3_close(db_handle);
reader->drop();
return false;
}
reader->read(buffer, sz);
reader->drop(); reader->drop();
bool ret{}; // force rollback-journal mode by setting header bytes 18 and 19 to 0x01
if (spmemvfs_open_db(&db, "temp.db", mem) != SQLITE_OK) if (sz >= 20 && buffer[18] == 0x02) {
ret = Error(db.handle); buffer[18] = 0x01;
else buffer[19] = 0x01;
ret = ReadDB(db.handle); }
spmemvfs_close_db(&db); int rc = sqlite3_deserialize(
spmemvfs_env_fini(); db_handle,
nullptr,
buffer,
sz,
sz,
SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_READONLY
);
if (rc != SQLITE_OK) {
Error(db_handle, nullptr);
sqlite3_close(db_handle);
return false;
}
bool ret = ReadDB(db_handle);
sqlite3_close(db_handle);
return ret; return ret;
} }
bool DataManager::LoadStrings(const char* file) { bool DataManager::LoadStrings(const char* file) {
......
include "lzma/." include "lzma/."
include "spmemvfs/."
project "YGOPro" project "YGOPro"
kind "WindowedApp" kind "WindowedApp"
...@@ -8,7 +7,7 @@ project "YGOPro" ...@@ -8,7 +7,7 @@ project "YGOPro"
files { "*.cpp", "*.h", "CGUISkinSystem/*.cpp", "CGUISkinSystem/*.h", "CXMLRegistry/*.cpp", "CXMLRegistry/*.h" } files { "*.cpp", "*.h", "CGUISkinSystem/*.cpp", "CGUISkinSystem/*.h", "CXMLRegistry/*.cpp", "CXMLRegistry/*.h" }
includedirs { "../ocgcore" } includedirs { "../ocgcore" }
links { "ocgcore", "clzma", "cspmemvfs", "sqlite3", "irrlicht", "freetype", "event" } links { "ocgcore", "clzma", "sqlite3", "irrlicht", "freetype", "event" }
if not OCGCORE_DYNAMIC then if not OCGCORE_DYNAMIC then
links { LUA_LIB_NAME } links { LUA_LIB_NAME }
end end
......
project "cspmemvfs"
kind "StaticLib"
cdialect "C11"
files { "*.c", "*.h" }
if BUILD_SQLITE then
includedirs { "../../sqlite3" }
end
filter "not action:vs*"
defines { "_POSIX_C_SOURCE=200809L" }
This diff is collapsed.
/*
* BSD 2-Clause License
*
* Copyright 2009 Stephen Liu
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __spmemvfs_h__
#define __spmemvfs_h__
#ifdef __cplusplus
extern "C" {
#endif
#include "sqlite3.h"
#define SPMEMVFS_NAME "spmemvfs"
typedef struct spmembuffer_t {
char * data;
int used;
int total;
} spmembuffer_t;
typedef struct spmemvfs_db_t {
sqlite3 * handle;
spmembuffer_t * mem;
} spmemvfs_db_t;
int spmemvfs_env_init();
void spmemvfs_env_fini();
int spmemvfs_open_db( spmemvfs_db_t * db, const char * path, spmembuffer_t * mem );
int spmemvfs_close_db( spmemvfs_db_t * db );
#ifdef __cplusplus
}
#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment