Commit 6667cdc5 authored by mercury233's avatar mercury233

add load cdb from zip

parent 24e5ca92
......@@ -8,9 +8,7 @@ wchar_t DataManager::strBuffer[4096];
byte DataManager::scriptBuffer[0x20000];
DataManager dataManager;
bool DataManager::LoadDB(const char* file) {
wchar_t wfile[256];
BufferIO::DecodeUTF8(file, wfile);
bool DataManager::LoadDB(const wchar_t* wfile) {
IReadFile* reader = FileSystem->createAndOpenFile(wfile);
if(reader == NULL)
return false;
......@@ -22,6 +20,8 @@ bool DataManager::LoadDB(const char* file) {
reader->read(mem->data, mem->total);
reader->drop();
(mem->data)[mem->total] = '\0';
char file[256];
BufferIO::EncodeUTF8(wfile, file);
if(spmemvfs_open_db(&db, file, mem) != SQLITE_OK)
return Error(&db);
sqlite3* pDB = db.handle;
......
......@@ -12,7 +12,7 @@ namespace ygo {
class DataManager {
public:
DataManager(): _datas(8192), _strings(8192) {}
bool LoadDB(const char* file);
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(int code, CardData* pData);
......
......@@ -57,8 +57,8 @@ bool Game::Initialize() {
return false;
}
dataManager.FileSystem = device->getFileSystem();
LoadExpansionDB();
if(!dataManager.LoadDB("cards.cdb")) {
LoadExpansions();
if(!dataManager.LoadDB(L"cards.cdb")) {
ErrorLog("Failed to load card database (cards.cdb)!");
return false;
}
......@@ -866,13 +866,25 @@ void Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gu
dataManager.strBuffer[pbuffer] = 0;
pControl->setText(dataManager.strBuffer);
}
void Game::LoadExpansionDB() {
FileSystem::TraversalDir("./expansions", [](const char* name, bool isdir) {
if(!isdir && strrchr(name, '.') && !mystrncasecmp(strrchr(name, '.'), ".cdb", 4)) {
char fpath[1024];
sprintf(fpath, "./expansions/%s", name);
void Game::LoadExpansions() {
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4)) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%s", name);
dataManager.LoadDB(fpath);
}
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4)) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%s", name);
dataManager.FileSystem->addFileArchive(fpath);
size_t len = wcslen(name);
wchar_t expansname[256];
wcsncpy(expansname, name, len - 4);
expansname[len - 4] = 0;
wcscat(expansname, L".cdb");
dataManager.LoadDB(expansname);
}
});
}
void Game::RefreshDeck(irr::gui::IGUIComboBox* cbDeck) {
......
......@@ -107,7 +107,7 @@ public:
void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar);
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0);
void LoadExpansionDB();
void LoadExpansions();
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
......
......@@ -77,17 +77,13 @@ int main(int argc, char* argv[]) {
bool keep_on_return = false;
for(int i = 1; i < wargc; ++i) {
if(wargv[i][0] == L'-' && wargv[i][1] == L'e' && wargv[i][2] != L'\0') {
char param[128];
BufferIO::EncodeUTF8(&wargv[i][2], param);
ygo::dataManager.LoadDB(param);
ygo::dataManager.LoadDB(&wargv[i][2]);
continue;
}
if(!wcscmp(wargv[i], L"-e")) { // extra database
++i;
if(i < wargc) {
char param[128];
BufferIO::EncodeUTF8(wargv[i], param);
ygo::dataManager.LoadDB(param);
ygo::dataManager.LoadDB(wargv[i]);
}
continue;
} else if(!wcscmp(wargv[i], L"-n")) { // nickName
......
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