mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-19 00:15:30 +00:00
Reduced memory usage by closing theme files after parsing. Could make things a tad slower.
svn-id: r34677
This commit is contained in:
parent
f267d42080
commit
c8f42a3973
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
warning("Failed to parse STX file '%s'", i->getName().c_str());
|
||||
return 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());
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user