Commit ae09b4aa authored by mercury233's avatar mercury233

add load script from zip

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