diff options
-rw-r--r-- | backends/networking/sdl_net/indexpagehandler.cpp | 55 | ||||
-rw-r--r-- | backends/networking/sdl_net/indexpagehandler.h | 1 |
2 files changed, 33 insertions, 23 deletions
diff --git a/backends/networking/sdl_net/indexpagehandler.cpp b/backends/networking/sdl_net/indexpagehandler.cpp index 37fcac6419..a1a426d048 100644 --- a/backends/networking/sdl_net/indexpagehandler.cpp +++ b/backends/networking/sdl_net/indexpagehandler.cpp @@ -23,6 +23,7 @@ #include "backends/networking/sdl_net/indexpagehandler.h" #include "backends/networking/sdl_net/localwebserver.h" #include "common/archive.h" +#include "common/config-manager.h" #include "common/file.h" #include "common/translation.h" #include "common/unzip.h" @@ -101,44 +102,52 @@ void IndexPageHandler::replace(Common::String &source, const Common::String &wha } } -Common::ArchiveMemberList IndexPageHandler::listArchive() { - Common::ArchiveMemberList resultList; +Common::Archive *IndexPageHandler::getZipArchive() { + // first search in themepath + if (ConfMan.hasKey("themepath")) { + const Common::FSNode &node = Common::FSNode(ConfMan.get("themepath")); + if (!node.exists() || !node.isReadable() || !node.isDirectory()) + return false; + + Common::FSNode fileNode = node.getChild(ARCHIVE_NAME); + if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) { + Common::SeekableReadStream *const stream = fileNode.createReadStream(); + Common::Archive *zipArchive = Common::makeZipArchive(stream); + if (zipArchive) return zipArchive; + } + } - // Find "wwwroot.zip" with SearchMan and call its listMembers() + // then use SearchMan to find it Common::ArchiveMemberList fileList; SearchMan.listMatchingMembers(fileList, ARCHIVE_NAME); for (Common::ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { Common::ArchiveMember const &m = **it; Common::SeekableReadStream *const stream = m.createReadStream(); Common::Archive *zipArchive = Common::makeZipArchive(stream); - if (zipArchive) { - zipArchive->listMembers(resultList); - delete zipArchive; - break; - } + if (zipArchive) return zipArchive; } + return nullptr; +} + +Common::ArchiveMemberList IndexPageHandler::listArchive() { + Common::ArchiveMemberList resultList; + Common::Archive *zipArchive = getZipArchive(); + if (zipArchive) { + zipArchive->listMembers(resultList); + delete zipArchive; + } return resultList; } Common::SeekableReadStream *const IndexPageHandler::getArchiveFile(Common::String name) { Common::SeekableReadStream *result = nullptr; - - // Find "wwwroot.zip" with SearchMan and call its getMember(name) - Common::ArchiveMemberList fileList; - SearchMan.listMatchingMembers(fileList, ARCHIVE_NAME); - for (Common::ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { - Common::ArchiveMember const &m = **it; - Common::SeekableReadStream *const stream = m.createReadStream(); - Common::Archive *zipArchive = Common::makeZipArchive(stream); - if (zipArchive) { - const Common::ArchiveMemberPtr ptr = zipArchive->getMember(name); - result = ptr->createReadStream(); - delete zipArchive; - break; - } + Common::Archive *zipArchive = getZipArchive(); + if (zipArchive) { + const Common::ArchiveMemberPtr ptr = zipArchive->getMember(name); + result = ptr->createReadStream(); + delete zipArchive; } - return result; } diff --git a/backends/networking/sdl_net/indexpagehandler.h b/backends/networking/sdl_net/indexpagehandler.h index 143c300336..df509a42b5 100644 --- a/backends/networking/sdl_net/indexpagehandler.h +++ b/backends/networking/sdl_net/indexpagehandler.h @@ -37,6 +37,7 @@ class IndexPageHandler: public GUI::CommandSender { void handleResource(Client &client); void replace(Common::String &source, const Common::String &what, const Common::String &with); + Common::Archive *getZipArchive(); Common::ArchiveMemberList listArchive(); Common::SeekableReadStream *const getArchiveFile(Common::String name); Common::String readEverythingFromStream(Common::SeekableReadStream *const stream); |