Commit f5955f85 authored by Chen Bill's avatar Chen Bill

replace fopen, fclose, fgets

parent e542fa5a
......@@ -65,7 +65,7 @@ inline FILE* myfopen(const wchar_t* filename, const char* mode) {
#else
char fname[1024]{};
BufferIO::EncodeUTF8(filename, fname);
fp = fopen(fname, mode);
fp = std::fopen(fname, mode);
#endif
return fp;
}
......
......@@ -109,14 +109,14 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
return ret;
}
bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
FILE* fp = std::fopen(file, "r");
if(!fp)
return false;
char linebuf[TEXT_LINE_SIZE]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadStringConfLine(linebuf);
}
fclose(fp);
std::fclose(fp);
return true;
}
bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
......
......@@ -10,11 +10,11 @@ DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
auto cur = _lfList.rend();
FILE* fp = fopen(path, "r");
FILE* fp = std::fopen(path, "r");
char linebuf[256]{};
wchar_t strBuffer[256]{};
if(fp) {
while(fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
......@@ -42,7 +42,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
cur->content[code] = count;
cur->hash = cur->hash ^ ((hcode << 18) | (hcode >> 14)) ^ ((hcode << (27 + count)) | (hcode >> (5 - count)));
}
fclose(fp);
std::fclose(fp);
}
}
void DeckManager::LoadLFList() {
......@@ -325,7 +325,7 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* file) {
fprintf(fp, "!side\n");
for(size_t i = 0; i < deck.side.size(); ++i)
fprintf(fp, "%d\n", deck.side[i]->first);
fclose(fp);
std::fclose(fp);
return true;
}
bool DeckManager::DeleteDeck(const wchar_t* file) {
......@@ -394,7 +394,7 @@ bool DeckManager::SaveDeckBuffer(const int deckbuf[], const wchar_t* name) {
fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
fclose(fp);
std::fclose(fp);
return true;
}
}
......@@ -1276,11 +1276,11 @@ void Game::RefreshBot() {
if(!gameConf.enable_bot_mode)
return;
botInfo.clear();
FILE* fp = fopen("bot.conf", "r");
FILE* fp = std::fopen("bot.conf", "r");
char linebuf[256]{};
char strbuf[256]{};
if(fp) {
while(fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
......@@ -1288,17 +1288,17 @@ void Game::RefreshBot() {
if (sscanf(linebuf, "!%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.name);
if (!fgets(linebuf, 256, fp))
if (!std::fgets(linebuf, 256, fp))
break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.command);
if (!fgets(linebuf, 256, fp))
if (!std::fgets(linebuf, 256, fp))
break;
if (sscanf(linebuf, "%240[^\n]", strbuf) != 1)
continue;
BufferIO::DecodeUTF8(strbuf, newinfo.desc);
if (!fgets(linebuf, 256, fp))
if (!std::fgets(linebuf, 256, fp))
break;
newinfo.support_master_rule_3 = !!std::strstr(linebuf, "SUPPORT_MASTER_RULE_3");
newinfo.support_new_master_rule = !!std::strstr(linebuf, "SUPPORT_NEW_MASTER_RULE");
......@@ -1312,7 +1312,7 @@ void Game::RefreshBot() {
continue;
}
}
fclose(fp);
std::fclose(fp);
}
lstBotList->clear();
stBotInfo->setText(L"");
......@@ -1329,13 +1329,13 @@ void Game::RefreshBot() {
}
}
void Game::LoadConfig() {
FILE* fp = fopen("system.conf", "r");
FILE* fp = std::fopen("system.conf", "r");
if(!fp)
return;
char linebuf[CONFIG_LINE_SIZE]{};
char strbuf[64]{};
char valbuf[960]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
if (sscanf(linebuf, "%63s = %959s", strbuf, valbuf) != 2)
continue;
if(!std::strcmp(strbuf, "antialias")) {
......@@ -1464,10 +1464,10 @@ void Game::LoadConfig() {
}
}
}
fclose(fp);
std::fclose(fp);
}
void Game::SaveConfig() {
FILE* fp = fopen("system.conf", "w");
FILE* fp = std::fopen("system.conf", "w");
fprintf(fp, "#config file\n#nickname & gamename should be less than 20 characters\n");
char linebuf[CONFIG_LINE_SIZE];
fprintf(fp, "use_d3d = %d\n", gameConf.use_d3d ? 1 : 0);
......@@ -1538,7 +1538,7 @@ void Game::SaveConfig() {
fprintf(fp, "music_volume = %d\n", vol);
fprintf(fp, "music_mode = %d\n", (chkMusicMode->isChecked() ? 1 : 0));
#endif
fclose(fp);
std::fclose(fp);
}
void Game::ShowCardInfo(int code, bool resize) {
if(showingcode == code && !resize)
......@@ -1720,14 +1720,14 @@ void Game::AddDebugMsg(const char* msg) {
}
}
void Game::ErrorLog(const char* msg) {
FILE* fp = fopen("error.log", "at");
FILE* fp = std::fopen("error.log", "at");
if(!fp)
return;
time_t nowtime = std::time(nullptr);
char timebuf[40];
std::strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S", std::localtime(&nowtime));
fprintf(fp, "[%s]%s\n", timebuf, msg);
fclose(fp);
std::fclose(fp);
}
void Game::ClearTextures() {
matManager.mCard.setTexture(0, 0);
......
......@@ -590,7 +590,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t wlinebuf[1024];
std::wstring message = L"";
bool in_message = false;
while(fgets(linebuf, 1024, fp)) {
while(std::fgets(linebuf, 1024, fp)) {
if(!std::strncmp(linebuf, "--[[message", 11)) {
size_t len = std::strlen(linebuf);
char* msgend = std::strrchr(linebuf, ']');
......@@ -613,7 +613,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
message.append(wlinebuf);
}
}
fclose(fp);
std::fclose(fp);
mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str());
break;
}
......
......@@ -23,8 +23,8 @@ void Replay::BeginRecord() {
return;
#else
if(is_recording)
fclose(fp);
fp = fopen("./replay/_LastReplay.yrp", "wb");
std::fclose(fp);
fp = std::fopen("./replay/_LastReplay.yrp", "wb");
if(!fp)
return;
#endif
......@@ -76,7 +76,7 @@ void Replay::EndRecord() {
#ifdef _WIN32
CloseHandle(recording_fp);
#else
fclose(fp);
std::fclose(fp);
#endif
pheader.datasize = replay_size;
pheader.flag |= REPLAY_COMPRESSED;
......@@ -99,7 +99,7 @@ void Replay::SaveReplay(const wchar_t* name) {
return;
std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp);
fclose(rfp);
std::fclose(rfp);
}
bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = myfopen(name, "rb");
......@@ -117,12 +117,12 @@ bool Replay::OpenReplay(const wchar_t* name) {
replay_size = 0;
comp_size = 0;
if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) {
fclose(rfp);
std::fclose(rfp);
return false;
}
if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp);
fclose(rfp);
std::fclose(rfp);
if (pheader.datasize > MAX_REPLAY_SIZE)
return false;
replay_size = pheader.datasize;
......@@ -134,7 +134,7 @@ bool Replay::OpenReplay(const wchar_t* name) {
}
} else {
replay_size = std::fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
fclose(rfp);
std::fclose(rfp);
comp_size = 0;
}
is_replaying = true;
......@@ -148,7 +148,7 @@ bool Replay::CheckReplay(const wchar_t* name) {
return false;
ReplayHeader rheader;
size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
fclose(rfp);
std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) {
......
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