From 7d58a50c46ecb7001702a696a3c92eb5ab3d0a36 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 6 Nov 2015 15:14:42 +0100 Subject: GUI: Removed 64k limit on built-in theme XML size --- gui/ThemeEngine.cpp | 18 +++++++++++++++--- gui/themes/default.inc | 13 +++++++++---- gui/themes/scummtheme.py | 30 +++++++++++++++++++----------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index ed01204180..016cfc136d 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -739,12 +739,24 @@ bool ThemeEngine::loadDefaultXML() { // 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. #ifndef DISABLE_GUI_BUILTIN_THEME - const char *defaultXML = #include "themes/default.inc" - ; + int xmllen = 0; + + for (int i = 0; i < ARRAYSIZE(defaultXML); i++) + xmllen += strlen(defaultXML[i]); + + byte *tmpXML = (byte *)malloc(xmllen + 1); + + for (int i = 0; i < ARRAYSIZE(defaultXML); i++) + strncat((char *)tmpXML, defaultXML[i], xmllen); + + if (!_parser->loadBuffer(tmpXML, xmllen)) { + free(tmpXML); - if (!_parser->loadBuffer((const byte *)defaultXML, strlen(defaultXML))) return false; + } + + free(tmpXML); _themeName = "ScummVM Classic Theme (Builtin Version)"; _themeId = "builtin"; diff --git a/gui/themes/default.inc b/gui/themes/default.inc index 33aac29835..90d7967bc0 100644 --- a/gui/themes/default.inc +++ b/gui/themes/default.inc @@ -1,5 +1,6 @@ - "" -"" +const char *defaultXML1 = "" +; + const char *defaultXML2 = "" "" "" "" "" -"" +; + const char *defaultXML3 = "" "" "" "" @@ -1895,7 +1897,8 @@ "" "" "" -"" +; + const char *defaultXML4 = "" "" "" "" @@ -3149,3 +3152,5 @@ "" "" "" +; +const char *defaultXML[] = { defaultXML1, defaultXML2, defaultXML3, defaultXML4 }; diff --git a/gui/themes/scummtheme.py b/gui/themes/scummtheme.py index 94dc08f1ef..d5fa4dfca7 100755 --- a/gui/themes/scummtheme.py +++ b/gui/themes/scummtheme.py @@ -35,11 +35,15 @@ def buildAllThemes(): if os.path.isdir(os.path.join('.', f)) and not f[0] == '.': buildTheme(f) -def parseSTX(theme_file, def_file): +def parseSTX(theme_file, def_file, subcount): comm = re.compile("", re.DOTALL) head = re.compile("<\?(.*?)\?>") strlitcount = 0 + subcount += 1 + + def_file.write(";\n const char *defaultXML" + str(subcount) + " = ") + output = "" for line in theme_file: output += line.rstrip("\r\n\t ").lstrip() @@ -55,8 +59,12 @@ def parseSTX(theme_file, def_file): for line in output.splitlines(): if line and not line.isspace(): strlitcount += len(line) + if strlitcount > 65535: + subcount += 1 + def_file.write(";\n const char *defaultXML" + str(subcount) + " = ") + strlitcount = len(line) def_file.write("\"" + line + "\"\n") - return strlitcount + return subcount def buildDefTheme(themeName): def_file = open("default.inc", "w") @@ -64,8 +72,8 @@ def buildDefTheme(themeName): if not os.path.isdir(themeName): print ("Cannot open default theme dir.") - def_file.write(""" ""\n""") - strlitcount = 24 + def_file.write("""const char *defaultXML1 = ""\n""") + subcount = 1 filenames = os.listdir(themeName) filenames.sort() @@ -73,16 +81,16 @@ def buildDefTheme(themeName): filename = os.path.join(themeName, filename) if os.path.isfile(filename) and filename.endswith(".stx"): theme_file = open(filename, "r") - strlitcount += parseSTX(theme_file, def_file) + subcount = parseSTX(theme_file, def_file, subcount) theme_file.close() - def_file.close() + def_file.write(";\nconst char *defaultXML[] = { defaultXML1") + for sub in range(2, subcount + 1): + def_file.write(", defaultXML" + str(sub)) - if strlitcount > 65535: - print("WARNING: default.inc string literal is of length %d which exceeds the" % strlitcount) - print(" maximum length of 65536 that C++ compilers are required to support.") - print(" It is likely that bugs will occur dependent on compiler behaviour.") - print(" To avoid this, reduce the size of the theme.") + def_file.write(" };\n") + + def_file.close() def printUsage(): print ("===============================") -- cgit v1.2.3