aboutsummaryrefslogtreecommitdiff
path: root/gui/theme.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/theme.cpp')
-rw-r--r--gui/theme.cpp82
1 files changed, 22 insertions, 60 deletions
diff --git a/gui/theme.cpp b/gui/theme.cpp
index 3a6280ab95..df9ae34017 100644
--- a/gui/theme.cpp
+++ b/gui/theme.cpp
@@ -23,7 +23,8 @@
*/
#include "gui/theme.h"
-#include "common/fs.h"
+#include "common/file.h"
+#include "common/archive.h"
#include "common/unzip.h"
namespace GUI {
@@ -44,24 +45,11 @@ const Graphics::Font *Theme::loadFont(const char *filename) {
return font;
#ifdef USE_ZLIB
- unzFile zipFile = unzOpen((getThemeFileName()).c_str());
- if (zipFile && unzLocateFile(zipFile, cacheFilename.c_str(), 2) == UNZ_OK) {
- unz_file_info fileInfo;
- unzOpenCurrentFile(zipFile);
- unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
- uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
- assert(buffer);
- memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
- unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
- unzCloseCurrentFile(zipFile);
- Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
-
- font = Graphics::NewFont::loadFromCache(stream);
-
- delete[] buffer;
- buffer = 0;
+ ZipArchive zipArchive(getThemeFileName().c_str());
+ if (zipArchive.hasFile(cacheFilename)) {
+ Common::FilePtr stream(zipArchive.openFile(cacheFilename));
+ font = Graphics::NewFont::loadFromCache(*stream.get());
}
- unzClose(zipFile);
#endif
if (font)
return font;
@@ -74,24 +62,11 @@ const Graphics::Font *Theme::loadFont(const char *filename) {
#ifdef USE_ZLIB
if (!font) {
- unzFile zipFile = unzOpen((getThemeFileName()).c_str());
- if (zipFile && unzLocateFile(zipFile, filename, 2) == UNZ_OK) {
- unz_file_info fileInfo;
- unzOpenCurrentFile(zipFile);
- unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
- uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
- assert(buffer);
- memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
- unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
- unzCloseCurrentFile(zipFile);
- Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
-
- font = Graphics::NewFont::loadFont(stream);
-
- delete[] buffer;
- buffer = 0;
+ ZipArchive zipArchive(getThemeFileName().c_str());
+ if (zipArchive.hasFile(filename)) {
+ Common::FilePtr stream(zipArchive.openFile(filename));
+ font = Graphics::NewFont::loadFont(*stream.get());
}
- unzClose(zipFile);
}
#endif
@@ -154,8 +129,8 @@ bool Theme::themeConfigParseHeader(Common::String header, Common::String &themeN
return tok.empty();
}
-bool Theme::themeConfigUseable(const FilesystemNode &node, Common::String &themeName) {
- char stxHeader[128];
+bool Theme::themeConfigUseable(const Common::FilesystemNode &node, Common::String &themeName) {
+ Common::String stxHeader;
bool foundHeader = false;
if (ConfMan.hasKey("themepath"))
@@ -170,40 +145,27 @@ bool Theme::themeConfigUseable(const FilesystemNode &node, Common::String &theme
if (node.getName().hasSuffix(".zip")) {
#ifdef USE_ZLIB
- unzFile zipFile = unzOpen(node.getPath().c_str());
-
- if (zipFile && unzLocateFile(zipFile, "THEMERC", 2) == UNZ_OK) {
- unz_file_info fileInfo;
- unzOpenCurrentFile(zipFile);
- unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
- uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
- assert(buffer);
- memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
- unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
- unzCloseCurrentFile(zipFile);
- Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
- stream.readLine(stxHeader, 128);
-
- if (themeConfigParseHeader(stxHeader, themeName))
+ ZipArchive zipArchive(node.getPath().c_str());
+ if (zipArchive.hasFile("THEMERC")) {
+ Common::FilePtr stream(zipArchive.openFile("THEMERC"));
+ stxHeader = stream->readLine();
+ // TODO: Read first line of file. How?
+ if (themeConfigParseHeader(stxHeader.c_str(), themeName))
foundHeader = true;
-
- delete[] buffer;
- buffer = 0;
}
- unzClose(zipFile);
#else
return false;
#endif
} else if (node.isDirectory()) {
- FilesystemNode headerfile = node.getChild("THEMERC");
+ Common::FilesystemNode headerfile = node.getChild("THEMERC");
if (!headerfile.exists() || !headerfile.isReadable() || headerfile.isDirectory())
return false;
+ // TODO: File or FilePtr?
Common::File f;
f.open(headerfile);
- f.readLine(stxHeader, 128);
-
- if (themeConfigParseHeader(stxHeader, themeName))
+ stxHeader = f.readLine();
+ if (themeConfigParseHeader(stxHeader.c_str(), themeName))
foundHeader = true;
}