Commit 498e3ede authored by mercury233's avatar mercury233

add loading strings conf from archive

parent 8b692f78
......@@ -85,35 +85,52 @@ bool DataManager::LoadStrings(const char* file) {
if(!fp)
return false;
char linebuf[256];
char strbuf[256];
int value;
while(fgets(linebuf, 256, fp)) {
if(linebuf[0] != '!')
continue;
sscanf(linebuf, "!%s", strbuf);
if(!strcmp(strbuf, "system")) {
sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf);
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "victory")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "counter")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "setname")) {
sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf);//using tab for comment
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
}
ReadStringConfLine(linebuf);
}
fclose(fp);
for(int i = 0; i < 255; ++i)
myswprintf(numStrings[i], L"%d", i);
return true;
}
bool DataManager::LoadStrings(IReadFile* reader) {
char ch[2] = " ";
char linebuf[256] = "";
while(reader->read(&ch[0], 1)) {
if(ch[0] == '\0')
break;
strcat(linebuf, ch);
if(ch[0] == '\n') {
ReadStringConfLine(linebuf);
linebuf[0] = '\0';
}
}
return true;
}
void DataManager::ReadStringConfLine(const char* linebuf) {
if(linebuf[0] != '!')
return;
char strbuf[256];
int value;
sscanf(linebuf, "!%s", strbuf);
if(!strcmp(strbuf, "system")) {
sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf);
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "victory")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "counter")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "setname")) {
sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf);//using tab for comment
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
}
}
bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) {
BufferIO::DecodeUTF8(sqlite3_errmsg(pDB->handle), strBuffer);
if(pStmt)
......
......@@ -14,6 +14,8 @@ public:
DataManager(): _datas(8192), _strings(8192) {}
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
bool LoadStrings(IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(int code, CardData* pData);
code_pointer GetCodePointer(int code);
......
......@@ -885,6 +885,10 @@ void Game::LoadExpansions() {
const wchar_t* fname = archive->getFullFileName(j).c_str();
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);
}
}
}
}
......
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