Commit 84200fa1 authored by mercury233's avatar mercury233 Committed by DailyShana

add errorlog on startup fail (#2154)

parent 8f435ab4
......@@ -38,8 +38,10 @@ bool Game::Initialize() {
params.DriverType = irr::video::EDT_OPENGL;
params.WindowSize = irr::core::dimension2d<u32>(1024, 640);
device = irr::createDeviceEx(params);
if(!device)
if(!device) {
ErrorLog("Failed to create Irrlicht Engine device!");
return false;
}
linePatternD3D = 0;
linePatternGL = 0x0f0f;
waitFrame = 0;
......@@ -61,13 +63,19 @@ bool Game::Initialize() {
driver->setTextureCreationFlag(irr::video::ETCF_CREATE_MIP_MAPS, false);
driver->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_QUALITY, true);
imageManager.SetDevice(device);
if(!imageManager.Initial())
if(!imageManager.Initial()) {
ErrorLog("Failed to load textures!");
return false;
}
LoadExpansionDB();
if(!dataManager.LoadDB("cards.cdb"))
if(!dataManager.LoadDB("cards.cdb")) {
ErrorLog("Failed to load card database (cards.cdb)!");
return false;
if(!dataManager.LoadStrings("strings.conf"))
}
if(!dataManager.LoadStrings("strings.conf")) {
ErrorLog("Failed to load strings!");
return false;
}
dataManager.LoadStrings("./expansions/strings.conf");
env = device->getGUIEnvironment();
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
......@@ -75,8 +83,10 @@ bool Game::Initialize() {
lpcFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 48);
guiFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, gameConf.textfontsize);
textFont = guiFont;
if(!numFont || !textFont)
if(!numFont || !textFont) {
ErrorLog("Failed to load font(s)!");
return false;
}
smgr = device->getSceneManager();
device->setWindowCaption(L"YGOPro");
device->setResizable(false);
......@@ -1369,17 +1379,22 @@ void Game::AddDebugMsg(char* msg)
AddChatMsg(wbuf, 9);
}
if (enable_log & 0x2) {
FILE* fp = fopen("error.log", "at");
if (!fp)
return;
time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime);
char timebuf[40];
strftime(timebuf, 40, "%Y-%m-%d %H:%M:%S", localedtime);
fprintf(fp, "[%s][Script Error]: %s\n", timebuf, msg);
fclose(fp);
char msgbuf[1040];
sprintf(msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf);
}
}
void Game::ErrorLog(char* msg) {
FILE* fp = fopen("error.log", "at");
if(!fp)
return;
time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime);
char timebuf[40];
strftime(timebuf, 40, "%Y-%m-%d %H:%M:%S", localedtime);
fprintf(fp, "[%s]%s\n", timebuf, msg);
fclose(fp);
}
bool Game::MakeDirectory(const std::string folder) {
std::string folder_builder;
std::string sub;
......
......@@ -135,6 +135,7 @@ public:
void AddChatMsg(wchar_t* msg, int player);
void ClearChatMsg();
void AddDebugMsg(char* msgbuf);
void ErrorLog(char* msgbuf);
bool MakeDirectory(const std::string folder);
void initUtils();
void ClearTextures();
......
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