aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/vkeybd/virtual-keyboard.cpp85
-rw-r--r--backends/vkeybd/virtual-keyboard.h4
2 files changed, 58 insertions, 31 deletions
diff --git a/backends/vkeybd/virtual-keyboard.cpp b/backends/vkeybd/virtual-keyboard.cpp
index a95b79d213..4ca4a5f586 100644
--- a/backends/vkeybd/virtual-keyboard.cpp
+++ b/backends/vkeybd/virtual-keyboard.cpp
@@ -31,7 +31,6 @@
#include "backends/vkeybd/virtual-keyboard-parser.h"
#include "backends/vkeybd/keycode-descriptions.h"
#include "common/config-manager.h"
-#include "common/fs.h"
#include "common/unzip.h"
#define KEY_START_CHAR ('[')
@@ -77,51 +76,77 @@ void VirtualKeyboard::reset() {
_kbdGUI->reset();
}
-bool VirtualKeyboard::loadKeyboardPack(String packName) {
- _kbdGUI->initSize(_system->getOverlayWidth(), _system->getOverlayHeight());
-
- delete _fileArchive;
- _fileArchive = 0;
-
- FSNode vkDir;
- if (ConfMan.hasKey("vkeybdpath"))
- vkDir = FSNode(ConfMan.get("vkeybdpath"));
- else if (ConfMan.hasKey("extrapath"))
- vkDir = FSNode(ConfMan.get("extrapath"));
- else // use current directory
- vkDir = FSNode(".");
-
- if (vkDir.getChild(packName + ".xml").exists()) {
- _fileArchive = new FSDirectory(vkDir, 1);
+bool VirtualKeyboard::openPack(const String &packName, const FSNode &node) {
+ if (node.getChild(packName + ".xml").exists()) {
+ _fileArchive = new FSDirectory(node, 1);
// uncompressed keyboard pack
- if (!_parser->loadFile(vkDir.getChild(packName + ".xml")))
+ if (!_parser->loadFile(node.getChild(packName + ".xml"))) {
+ delete _fileArchive;
+ _fileArchive = 0;
return false;
+ }
+
+ return true;
+ }
- } else if (vkDir.getChild(packName + ".zip").exists()) {
- // compressed keyboard pack
#ifdef USE_ZLIB
- _fileArchive = new ZipArchive(vkDir.getChild(packName + ".zip"));
+ if (node.getChild(packName + ".zip").exists()) {
+ // compressed keyboard pack
+ _fileArchive = new ZipArchive(node.getChild(packName + ".zip"));
if (_fileArchive->hasFile(packName + ".xml")) {
- if (!_parser->loadStream(_fileArchive->createReadStreamForMember(packName + ".xml")))
+ if (!_parser->loadStream(_fileArchive->createReadStreamForMember(packName + ".xml"))) {
+ delete _fileArchive;
+ _fileArchive = 0;
return false;
+ }
} else {
warning("Could not find %s.xml file in %s.zip keyboard pack", packName.c_str(), packName.c_str());
+ delete _fileArchive;
+ _fileArchive = 0;
return false;
}
-#else
- return false;
+
+ return true;
+ }
#endif
+
+ return false;
+}
+
+bool VirtualKeyboard::loadKeyboardPack(const String &packName) {
+ _kbdGUI->initSize(_system->getOverlayWidth(), _system->getOverlayHeight());
+
+ delete _fileArchive;
+ _fileArchive = 0;
+ _loaded = false;
+
+ bool opened = false;
+ if (ConfMan.hasKey("vkeybdpath"))
+ opened = openPack(packName, FSNode(ConfMan.get("vkeybdpath")));
+ else if (ConfMan.hasKey("extrapath"))
+ opened = openPack(packName, FSNode(ConfMan.get("extrapath")));
+
+ // fallback to the current dir
+ if (!opened)
+ opened = openPack(packName, FSNode("."));
+
+ if (opened) {
+ _parser->setParseMode(VirtualKeyboardParser::kParseFull);
+ _loaded = _parser->parse();
+
+ if (_loaded) {
+ printf("Keyboard pack '%s' loaded successfully!\n", packName.c_str());
+ } else {
+ warning("Error parsing the keyboard pack '%s'", packName.c_str());
+
+ delete _fileArchive;
+ _fileArchive = 0;
+ }
} else {
warning("Keyboard pack not found");
- return false;
}
- _parser->setParseMode(VirtualKeyboardParser::kParseFull);
- _loaded = _parser->parse();
- if (_loaded)
- printf("Keyboard pack '%s' loaded successfully!\n", packName.c_str());
-
return _loaded;
}
diff --git a/backends/vkeybd/virtual-keyboard.h b/backends/vkeybd/virtual-keyboard.h
index e3a9cd3600..2c31afcb35 100644
--- a/backends/vkeybd/virtual-keyboard.h
+++ b/backends/vkeybd/virtual-keyboard.h
@@ -37,6 +37,7 @@ class OSystem;
#include "common/keyboard.h"
#include "common/list.h"
#include "common/str.h"
+#include "common/fs.h"
#include "backends/vkeybd/image-map.h"
#include "graphics/surface.h"
@@ -190,7 +191,7 @@ public:
* searches for a compressed keyboard pack by looking for packName.zip.
* @param packName name of the keyboard pack
*/
- bool loadKeyboardPack(String packName);
+ bool loadKeyboardPack(const String &packName);
/**
* Shows the keyboard, starting an event loop that will intercept all
@@ -232,6 +233,7 @@ protected:
VirtualKeyboardParser *_parser;
void reset();
+ bool openPack(const String &packName, const FSNode &node);
void deleteEvents();
bool checkModeResolutions();
void switchMode(Mode *newMode);