Some cleanup (in particular: do not convert String -> char * -> String needlessly) & code unification (thanks to Common::Archive, regular files and those in .zip files can both be accessed via Common::File)
svn-id: r34772
This commit is contained in:
parent
0802da1f7f
commit
ce7ffc4d0e
3 changed files with 19 additions and 30 deletions
|
@ -411,7 +411,7 @@ bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &fi
|
|||
_texts[textId]->_fontPtr = FontMan.getFontByName(file);
|
||||
|
||||
if (!_texts[textId]->_fontPtr) {
|
||||
_texts[textId]->_fontPtr = loadFont(file.c_str());
|
||||
_texts[textId]->_fontPtr = loadFont(file);
|
||||
|
||||
if (!_texts[textId]->_fontPtr)
|
||||
error("Couldn't load %s font '%s'", fontId.c_str(), file.c_str());
|
||||
|
@ -473,8 +473,7 @@ bool ThemeEngine::loadTheme(Common::String fileName) {
|
|||
if (fileName == "builtin") {
|
||||
if (!loadDefaultXML())
|
||||
error("Could not load default embeded theme");
|
||||
}
|
||||
else if (!loadThemeXML(fileName)) {
|
||||
} else if (!loadThemeXML(fileName)) {
|
||||
warning("Could not parse custom theme '%s'. Falling back to default theme", fileName.c_str());
|
||||
|
||||
if (!loadDefaultXML()) // if we can't load the embeded theme, this is a complete failure
|
||||
|
@ -545,7 +544,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {
|
|||
|
||||
if (zipFile.isOpen() && zipFile.listMembers(zipContents)) {
|
||||
for (Common::ArchiveMemberList::iterator za = zipContents.begin(); za != zipContents.end(); ++za) {
|
||||
if (!failed && matchString((*za)->getName().c_str(), "*.stx")) {
|
||||
if (!failed && (*za)->getName().hasSuffix(".stx")) {
|
||||
if (parser()->loadStream((*za)->open()) == false) {
|
||||
warning("Failed to load stream for zipped file '%s'", fileNameBuffer);
|
||||
failed = true;
|
||||
|
@ -562,7 +561,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {
|
|||
Common::SeekableReadStream *stream = (*za)->open();
|
||||
stxHeader = stream->readLine();
|
||||
|
||||
if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) {
|
||||
if (!themeConfigParseHeader(stxHeader, _themeName)) {
|
||||
warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str());
|
||||
failed = true;
|
||||
}
|
||||
|
@ -601,7 +600,7 @@ bool ThemeEngine::loadThemeXML(Common::String themeName) {
|
|||
f.open(*i);
|
||||
stxHeader = f.readLine();
|
||||
|
||||
if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) {
|
||||
if (!themeConfigParseHeader(stxHeader, _themeName)) {
|
||||
warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str());
|
||||
failed = true;
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ Theme::Theme() : _loadedThemeX(0), _loadedThemeY(0) {}
|
|||
|
||||
Theme::~Theme() {}
|
||||
|
||||
const Graphics::Font *Theme::loadFont(const char *filename) {
|
||||
const Graphics::Font *Theme::loadFont(const Common::String &filename) {
|
||||
const Graphics::NewFont *font = 0;
|
||||
Common::String cacheFilename = genCacheFilename(filename);
|
||||
Common::String cacheFilename = genCacheFilename(filename.c_str());
|
||||
Common::File fontFile;
|
||||
|
||||
if (!cacheFilename.empty()) {
|
||||
|
@ -45,7 +45,7 @@ const Graphics::Font *Theme::loadFont(const char *filename) {
|
|||
return font;
|
||||
|
||||
#ifdef USE_ZLIB
|
||||
Common::ZipArchive zipArchive(getThemeFileName().c_str());
|
||||
Common::ZipArchive zipArchive(getThemeFileName());
|
||||
Common::SeekableReadStream *stream(zipArchive.openFile(cacheFilename));
|
||||
if (stream) {
|
||||
font = Graphics::NewFont::loadFromCache(*stream);
|
||||
|
@ -63,7 +63,7 @@ const Graphics::Font *Theme::loadFont(const char *filename) {
|
|||
|
||||
#ifdef USE_ZLIB
|
||||
if (!font) {
|
||||
Common::ZipArchive zipArchive(getThemeFileName().c_str());
|
||||
Common::ZipArchive zipArchive(getThemeFileName());
|
||||
|
||||
Common::SeekableReadStream *stream(zipArchive.openFile(filename));
|
||||
if (stream) {
|
||||
|
@ -76,7 +76,7 @@ const Graphics::Font *Theme::loadFont(const char *filename) {
|
|||
if (font) {
|
||||
if (!cacheFilename.empty()) {
|
||||
if (!Graphics::NewFont::cacheFontData(*font, cacheFilename)) {
|
||||
warning("Couldn't create cache file for font '%s'", filename);
|
||||
warning("Couldn't create cache file for font '%s'", filename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,35 +133,26 @@ bool Theme::themeConfigParseHeader(Common::String header, Common::String &themeN
|
|||
}
|
||||
|
||||
bool Theme::themeConfigUseable(const Common::FSNode &node, Common::String &themeName) {
|
||||
Common::String stxHeader;
|
||||
Common::File stream;
|
||||
bool foundHeader = false;
|
||||
|
||||
if (node.getName().hasSuffix(".zip")) {
|
||||
#ifdef USE_ZLIB
|
||||
Common::ZipArchive zipArchive(node);
|
||||
if (zipArchive.hasFile("THEMERC")) {
|
||||
Common::File stream;
|
||||
stream.open("THEMERC", zipArchive);
|
||||
stxHeader = stream.readLine();
|
||||
// TODO: Read first line of file. How?
|
||||
if (themeConfigParseHeader(stxHeader.c_str(), themeName))
|
||||
foundHeader = true;
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
||||
} else if (node.isDirectory()) {
|
||||
Common::FSNode headerfile = node.getChild("THEMERC");
|
||||
if (!headerfile.exists() || !headerfile.isReadable() || headerfile.isDirectory())
|
||||
return false;
|
||||
stream.open(headerfile);
|
||||
}
|
||||
|
||||
// TODO: File or FilePtr?
|
||||
Common::File f;
|
||||
f.open(headerfile);
|
||||
stxHeader = f.readLine();
|
||||
if (themeConfigParseHeader(stxHeader.c_str(), themeName))
|
||||
foundHeader = true;
|
||||
if (stream.isOpen()) {
|
||||
Common::String stxHeader = stream.readLine();
|
||||
foundHeader = themeConfigParseHeader(stxHeader, themeName);
|
||||
}
|
||||
|
||||
return foundHeader;
|
||||
|
|
|
@ -334,9 +334,9 @@ public:
|
|||
* @see kThemeImages
|
||||
*/
|
||||
virtual const Graphics::Surface *getImageSurface(const kThemeImages n) const { return 0; }
|
||||
protected:
|
||||
|
||||
const Graphics::Font *loadFont(const char *filename);
|
||||
protected:
|
||||
const Graphics::Font *loadFont(const Common::String &filename);
|
||||
Common::String genCacheFilename(const char *filename);
|
||||
|
||||
public:
|
||||
|
@ -344,7 +344,6 @@ public:
|
|||
(_loadedThemeY != g_system->getOverlayHeight())); }
|
||||
|
||||
private:
|
||||
static const char *_defaultConfigINI;
|
||||
int _loadedThemeX, _loadedThemeY;
|
||||
};
|
||||
} // end of namespace GUI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue