Commit ae09b4aa authored by mercury233's avatar mercury233

add load script from zip

parent 6667cdc5
......@@ -6,6 +6,7 @@ namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
wchar_t DataManager::strBuffer[4096];
byte DataManager::scriptBuffer[0x20000];
IFileSystem* DataManager::FileSystem;
DataManager dataManager;
bool DataManager::LoadDB(const wchar_t* wfile) {
......@@ -75,7 +76,7 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
}
} while(step != SQLITE_DONE);
sqlite3_finalize(pStmt);
spmemvfs_close_db(&db);
spmemvfs_close_db(&db);
spmemvfs_env_fini();
return true;
}
......@@ -117,7 +118,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) {
BufferIO::DecodeUTF8(sqlite3_errmsg(pDB->handle), strBuffer);
if(pStmt)
sqlite3_finalize(pStmt);
spmemvfs_close_db(pDB);
spmemvfs_close_db(pDB);
spmemvfs_env_fini();
return false;
}
......@@ -334,21 +335,16 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
return ScriptReader(script_name, slen);
}
byte* DataManager::ScriptReader(const char* script_name, int* slen) {
FILE *fp;
#ifdef _WIN32
wchar_t fname[256];
BufferIO::DecodeUTF8(script_name, fname);
fp = _wfopen(fname, L"rb");
#else
fp = fopen(script_name, "rb");
#endif
if(!fp)
IReadFile* reader = FileSystem->createAndOpenFile(fname);
if(reader == NULL)
return 0;
int len = fread(scriptBuffer, 1, sizeof(scriptBuffer), fp);
fclose(fp);
if(len >= sizeof(scriptBuffer))
size_t size = reader->getSize();
if(size > sizeof(scriptBuffer))
return 0;
*slen = len;
reader->read(scriptBuffer, size);
*slen = size;
return scriptBuffer;
}
......
......@@ -55,7 +55,7 @@ public:
static int CardReader(int, void*);
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReader(const char* script_name, int* slen);
IFileSystem* FileSystem;
static IFileSystem* FileSystem;
};
extern DataManager dataManager;
......
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