Commit c936d24a authored by fallenstardust's avatar fallenstardust

DataManage: fix LoadStrings(IReadFile* reader)

parent db4198ec
......@@ -107,23 +107,23 @@ bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
if(!fp)
return false;
char linebuf[256];
while(fgets(linebuf, 256, fp)) {
char linebuf[TEXT_LINE_SIZE]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
ReadStringConfLine(linebuf);
}
fclose(fp);
return true;
}
bool DataManager::LoadStrings(IReadFile* reader) {
char ch[2] = " ";
char linebuf[256] = "";
while(reader->read(&ch[0], 1)) {
if(ch[0] == '\0')
char ch{};
std::string linebuf;
while (reader->read(&ch, 1)) {
if (ch == '\0')
break;
std::strcat(linebuf, ch);
if(ch[0] == '\n') {
ReadStringConfLine(linebuf);
linebuf[0] = '\0';
linebuf.push_back(ch);
if (ch == '\n' || linebuf.size() >= TEXT_LINE_SIZE - 1) {
ReadStringConfLine(linebuf.data());
linebuf.clear();
}
}
reader->drop();
......@@ -132,7 +132,7 @@ bool DataManager::LoadStrings(IReadFile* reader) {
void DataManager::ReadStringConfLine(const char* linebuf) {
if(linebuf[0] != '!')
return;
char strbuf[256]{};
char strbuf[TEXT_LINE_SIZE]{};
int value{};
wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1)
......
......@@ -1683,6 +1683,7 @@ void Game::RefreshDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBo
void Game::RefreshDeck(const wchar_t* deckpath, const std::function<void(const wchar_t*)>& additem) {
if(!wcsncasecmp(deckpath, L"./pack", 6)) {
for(auto& pack : deckBuilder.expansionPacks) {
// add pack/xxx.ydk
additem(pack.substr(5, pack.size() - 9).c_str());
}
}
......
......@@ -23,6 +23,7 @@
constexpr int DEFAULT_DUEL_RULE = 5;
constexpr int CONFIG_LINE_SIZE = 1024;
constexpr int TEXT_LINE_SIZE = 256;
namespace ygo {
......
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