Commit 022ab5ed authored by nanahira's avatar nanahira

support Chinese everywhere

parent 39c86e4b
......@@ -81,6 +81,75 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
spmemvfs_env_fini();
return true;
}
bool DataManager::LoadDB(const char* file) {
IReadFile* reader = FileSystem->createAndOpenFile(file);
if(reader == NULL)
return false;
spmemvfs_db_t db;
spmembuffer_t * mem = (spmembuffer_t*)calloc(sizeof(spmembuffer_t), 1);
spmemvfs_env_init();
mem->total = mem->used = reader->getSize();
mem->data = (char*)malloc(mem->total + 1);
reader->read(mem->data, mem->total);
reader->drop();
(mem->data)[mem->total] = '\0';
if(spmemvfs_open_db(&db, file, mem) != SQLITE_OK)
return Error(&db);
sqlite3* pDB = db.handle;
sqlite3_stmt* pStmt;
const char* sql = "select * from datas,texts where datas.id=texts.id";
if(sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
return Error(&db);
CardDataC cd;
CardString cs;
int step = 0;
do {
step = sqlite3_step(pStmt);
if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
return Error(&db, pStmt);
else if(step == SQLITE_ROW) {
cd.code = sqlite3_column_int(pStmt, 0);
cd.ot = sqlite3_column_int(pStmt, 1);
cd.alias = sqlite3_column_int(pStmt, 2);
cd.setcode = sqlite3_column_int64(pStmt, 3);
cd.type = sqlite3_column_int(pStmt, 4);
cd.attack = sqlite3_column_int(pStmt, 5);
cd.defense = sqlite3_column_int(pStmt, 6);
if(cd.type & TYPE_LINK) {
cd.link_marker = cd.defense;
cd.defense = 0;
} else
cd.link_marker = 0;
unsigned int level = sqlite3_column_int(pStmt, 7);
cd.level = level & 0xff;
cd.lscale = (level >> 24) & 0xff;
cd.rscale = (level >> 16) & 0xff;
cd.race = sqlite3_column_int(pStmt, 8);
cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10);
_datas.insert(std::make_pair(cd.code, cd));
if(const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.name = strBuffer;
}
if(const char* text = (const char*)sqlite3_column_text(pStmt, 13)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.text = strBuffer;
}
for(int i = 0; i < 16; ++i) {
if(const char* text = (const char*)sqlite3_column_text(pStmt, i + 14)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.desc[i] = strBuffer;
}
}
_strings.emplace(cd.code, cs);
}
} while(step != SQLITE_DONE);
sqlite3_finalize(pStmt);
spmemvfs_close_db(&db);
spmemvfs_env_fini();
return true;
}
bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
if(!fp)
......
......@@ -13,6 +13,7 @@ class DataManager {
public:
DataManager(): _datas(8192), _strings(8192) {}
bool LoadDB(const wchar_t* wfile);
bool LoadDB(const char* file);
bool LoadStrings(const char* file);
bool LoadStrings(IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
......
......@@ -868,7 +868,13 @@ void Game::LoadExpansions() {
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4)) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
#ifdef _WIN32
dataManager.LoadDB(fpath);
#else
char fpath_utf8[1024];
BufferIO::EncodeUTF8(fpath, fpath_utf8);
dataManager.LoadDB(fpath_utf8);
#endif
}
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4)) {
wchar_t fpath[1024];
......@@ -887,17 +893,21 @@ void Game::LoadExpansions() {
for(u32 j = 0; j < archive->getFileCount(); ++j) {
#ifdef _WIN32
const wchar_t* fname = archive->getFullFileName(j).c_str();
#else
wchar_t fname[1024];
const char* uname = archive->getFullFileName(j).c_str();
BufferIO::DecodeUTF8(uname, fname);
#endif
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".cdb", 4))
dataManager.LoadDB(fname);
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".conf", 5)) {
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(fname);
dataManager.LoadStrings(reader);
}
#else
const char* fname = archive->getFullFileName(j).c_str();
if(strrchr(fname, '.') && !mystrncasecmp(strrchr(fname, '.'), ".cdb", 4))
dataManager.LoadDB(fname);
if(strrchr(fname, '.') && !mystrncasecmp(strrchr(fname, '.'), ".conf", 5)) {
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(fname);
dataManager.LoadStrings(reader);
}
#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