more user friendly handling of loading corrupt saved game files

This commit is contained in:
Mark Vejvoda
2013-11-14 03:33:15 +00:00
parent 41f7cc3648
commit 85799eddc2
4 changed files with 78 additions and 49 deletions

View File

@@ -254,7 +254,11 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
Game::loadGame(filename,program,false); Game::loadGame(filename,program,false);
} }
catch(const megaglest_runtime_error &ex) { catch(const megaglest_runtime_error &ex) {
showMessageBox(ex.what(), lang.getString("Notice"), true); char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d]\nError [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
showMessageBox(ex.what(), lang.getString("Notice"), false);
} }
return; return;
} }
@@ -283,8 +287,12 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
} }
} }
catch(const megaglest_runtime_error &ex) { catch(const megaglest_runtime_error &ex) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d]\nError [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
cleanupTexture(&previewTexture); cleanupTexture(&previewTexture);
showMessageBox(ex.what(), lang.getString("Notice"), true); showMessageBox(ex.what(), lang.getString("Notice"), false);
} }
} }
else { else {
@@ -302,7 +310,9 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n"); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Before load of XML\n");
std::map<string,string> mapExtraTagReplacementValues; std::map<string,string> mapExtraTagReplacementValues;
xmlTree.load(filename, Properties::getTagReplacementValues(&mapExtraTagReplacementValues),true); try {
xmlTree.load(filename, Properties::getTagReplacementValues(&mapExtraTagReplacementValues),true,false,true);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n"); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("After load of XML\n");
const XmlNode *rootNode= xmlTree.getRootNode(); const XmlNode *rootNode= xmlTree.getRootNode();
@@ -342,6 +352,14 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
infoTextLabel.setText(szBuf); infoTextLabel.setText(szBuf);
} }
} }
catch(const megaglest_runtime_error &ex) {
char szBuf[8096]="";
snprintf(szBuf,8096,"In [%s::%s Line: %d]\nError [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
showMessageBox(ex.what(), lang.getString("Notice"), false);
}
}
else { else {
infoTextLabel.setText(""); infoTextLabel.setText("");
} }

View File

@@ -90,7 +90,7 @@ public:
static bool isInitialized(); static bool isInitialized();
void cleanup(); void cleanup();
XmlNode *load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation=false); XmlNode *load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation=false,bool skipStackTrace=false);
void save(const string &path, const XmlNode *node); void save(const string &path, const XmlNode *node);
}; };
@@ -109,7 +109,7 @@ public:
static bool isInitialized(); static bool isInitialized();
void cleanup(); void cleanup();
XmlNode *load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation=false,bool skipStackCheck=false); XmlNode *load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation=false,bool skipStackTrace=false);
void save(const string &path, const XmlNode *node); void save(const string &path, const XmlNode *node);
}; };
@@ -133,7 +133,7 @@ public:
~XmlTree(); ~XmlTree();
void init(const string &name); void init(const string &name);
void load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false); void load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation=false,bool skipStackCheck=false,bool skipStackTrace=false);
void save(const string &path); void save(const string &path);
XmlNode *getRootNode() const {return rootNode;} XmlNode *getRootNode() const {return rootNode;}

View File

@@ -208,7 +208,7 @@ DOMNode *XmlIo::loadDOMNode(const string &path, bool noValidation) {
return NULL; return NULL;
} }
XmlNode *XmlIo::load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation) { XmlNode *XmlIo::load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation,bool skipStackTrace) {
//printf("Load file using Xerces engine [%s]\n",path.c_str()); //printf("Load file using Xerces engine [%s]\n",path.c_str());
try { try {
@@ -222,10 +222,15 @@ XmlNode *XmlIo::load(const string &path, const std::map<string,string> &mapTagRe
} }
catch(const DOMException &ex) { catch(const DOMException &ex) {
char szBuf[8096]=""; char szBuf[8096]="";
if(skipStackTrace == false) {
snprintf(szBuf,8096,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(ex.msg)); snprintf(szBuf,8096,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(ex.msg));
}
else {
snprintf(szBuf,8096,"Error loading: [%s], msg:\n%s",path.c_str(),XMLString::transcode(ex.msg));
}
SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf); SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf);
throw megaglest_runtime_error(szBuf); throw megaglest_runtime_error(szBuf,skipStackTrace);
} }
return NULL; return NULL;
} }
@@ -320,7 +325,7 @@ XmlIoRapid::~XmlIoRapid() {
cleanup(); cleanup();
} }
XmlNode *XmlIoRapid::load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation,bool skipStackCheck) { XmlNode *XmlIoRapid::load(const string &path, const std::map<string,string> &mapTagReplacementValues,bool noValidation,bool skipStackTrace) {
bool showPerfStats = SystemFlags::VERBOSE_MODE_ENABLED; bool showPerfStats = SystemFlags::VERBOSE_MODE_ENABLED;
Chrono chrono; Chrono chrono;
chrono.start(); chrono.start();
@@ -398,10 +403,16 @@ XmlNode *XmlIoRapid::load(const string &path, const std::map<string,string> &map
} }
catch(const exception &ex) { catch(const exception &ex) {
char szBuf[8096]=""; char szBuf[8096]="";
if(skipStackTrace == false) {
snprintf(szBuf,8096,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),ex.what()); snprintf(szBuf,8096,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),ex.what());
}
else {
snprintf(szBuf,8096,"Error loading: [%s], msg:\n%s",path.c_str(),ex.what());
}
SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf); SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf);
throw megaglest_runtime_error(szBuf); throw megaglest_runtime_error(szBuf,skipStackTrace);
} }
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] took msecs: %ld for file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),path.c_str()); //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] took msecs: %ld for file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),path.c_str());
@@ -506,7 +517,7 @@ typedef std::vector<XmlTree*> LoadStack;
//static LoadStack loadStack; //static LoadStack loadStack;
static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName"); static string loadStackCacheName = string(__FILE__) + string("_loadStackCacheName");
void XmlTree::load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation,bool skipStackCheck) { void XmlTree::load(const string &path, const std::map<string,string> &mapTagReplacementValues, bool noValidation,bool skipStackCheck,bool skipStackTrace) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] skipStackCheck = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),skipStackCheck); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] skipStackCheck = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),skipStackCheck);
clearRootNode(); clearRootNode();
@@ -532,10 +543,10 @@ void XmlTree::load(const string &path, const std::map<string,string> &mapTagRepl
loadPath = path; loadPath = path;
if(this->engine_type == XML_XERCES_ENGINE) { if(this->engine_type == XML_XERCES_ENGINE) {
this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation); this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues, noValidation,skipStackTrace);
} }
else { else {
this->rootNode= XmlIoRapid::getInstance().load(path, mapTagReplacementValues, noValidation,this->skipStackCheck); this->rootNode= XmlIoRapid::getInstance().load(path, mapTagReplacementValues, noValidation,skipStackTrace);
} }
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str());

View File

@@ -44,7 +44,7 @@ public:
string expected = text; string expected = text;
#ifdef HAVE_FRIBIDI #ifdef HAVE_FRIBIDI
Font::bidi_cvt(text); Font::bidi_cvt(text);
printf("Expected: [%s] result[%s]\n",expected.c_str(),text.c_str()); //printf("Expected: [%s] result[%s]\n",expected.c_str(),text.c_str());
CPPUNIT_ASSERT_EQUAL( expected,text ); CPPUNIT_ASSERT_EQUAL( expected,text );
#endif #endif