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