diff options
| -rw-r--r-- | common/xmlparser.cpp | 5 | ||||
| -rw-r--r-- | common/xmlparser.h | 10 | ||||
| -rw-r--r-- | gui/ThemeEngine.cpp | 40 | 
3 files changed, 39 insertions, 16 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index b93a5205be..6c1aa7d0e4 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -43,7 +43,7 @@ bool XMLParser::parserError(const char *errorString, ...) {  	int lineStart = 0;  	if (_fileName == "Memory Stream") { -		lineStart = MAX(0, _pos - 35); +		lineStart = MAX(0, original_pos - 35);  		lineCount = 0;  	} else {  		do { @@ -51,7 +51,7 @@ bool XMLParser::parserError(const char *errorString, ...) {  				lineCount++;  				if (lineStart == 0) -					lineStart = MAX(pos + 1, _pos - 60); +					lineStart = MAX(pos + 1, original_pos - 60);  			}  			_stream->seek(-1, SEEK_CUR); @@ -210,7 +210,6 @@ bool XMLParser::parse() {  	bool selfClosure = false;  	_state = kParserNeedKey; -	_pos = 0;  	_activeKey.clear();  	_char = _stream->readByte(); diff --git a/common/xmlparser.h b/common/xmlparser.h index 7edabf62f3..967b73535b 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -222,6 +222,13 @@ public:  		_fileName = "Compressed File Stream";  		return true;  	} +	 +	void close() { +		if (_stream) { +			delete _stream; +			_stream = 0; +		} +	}  	/**  	 * The actual parsing function. @@ -361,7 +368,7 @@ protected:  					break;  				if (_char == 0) -					parserError("Comment has no closure."); +					return parserError("Comment has no closure.");  			}  			_char = _stream->readByte();  			return true; @@ -449,7 +456,6 @@ protected:  	Common::List<XMLKeyLayout*> _layoutList;  private: -	int _pos; /** Current position on the XML buffer. */  	char _char;  	SeekableReadStream *_stream;  	Common::String _fileName; diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index c04ca52834..c33251b546 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -501,6 +501,7 @@ bool ThemeEngine::loadDefaultXML() {  	// file inside the themes directory.  	// Use the Python script "makedeftheme.py" to convert a normal XML theme  	// into the "default.inc" file, which is ready to be included in the code. +	bool result;  #ifdef GUI_ENABLE_BUILTIN_THEME  	const char *defaultXML = @@ -513,7 +514,10 @@ bool ThemeEngine::loadDefaultXML() {  	_themeName = "ScummVM Classic Theme (Builtin Version)";  	_themeFileName = "builtin"; -	return parser()->parse(); +	result = parser()->parse(); +	parser()->close(); +	 +	return result;  #else  	warning("The built-in theme is not enabled in the current build. Please load an external theme");  	return false; @@ -527,6 +531,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {  	char fileNameBuffer[32];  	Common::String stxHeader;  	int parseCount = 0; +	bool failed = false;  #ifdef USE_ZLIB  	unzFile zipFile = unzOpen((themeName).c_str()); @@ -550,19 +555,25 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {  					if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) {  						warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str()); -						return false; +						failed = true;  					}  					delete stream; -				} else { +				} else if (!failed) {  					parseCount++; -					if (parser()->loadStream(stream) == false || parser()->parse() == false) { +					if (parser()->loadStream(stream) == false) {  						warning("Failed to load stream for zipped file '%s'", fileNameBuffer); -						unzClose(zipFile); -						return false; +						failed = true; +					} +					 +					if (parser()->parse() == false) { +						warning("Theme parsing failed on zipped file '%s'.", fileNameBuffer); +						failed = true;  					} +					 +					parser()->close();  				}  			}  @@ -581,13 +592,20 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {  				return false;  			for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) { -				if (i->getName().hasSuffix(".stx")) { +				if (!failed && i->getName().hasSuffix(".stx")) {  					parseCount++; -					if (parser()->loadFile(*i) == false || parser()->parse() == false) { +					if (parser()->loadFile(*i) == false) { +						warning("Failed to load STX file '%s'", i->getName().c_str()); +						failed = true; +					} +					 +					if (parser()->parse() == false) {  						warning("Failed to parse STX file '%s'", i->getName().c_str()); -						return false; +						failed = true;  					} +					 +					parser()->close();  				} else if (i->getName() == "THEMERC") {  					Common::File f;  					f.open(*i); @@ -595,7 +613,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {  					if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) {  						warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str()); -						return false; +						failed = true;  					}  				}  			} @@ -608,7 +626,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {  #endif -	return (parseCount > 0 && _themeName.empty() == false); +	return (parseCount > 0 && _themeName.empty() == false && failed == false);  }  | 
