aboutsummaryrefslogtreecommitdiff
path: root/backends/vkeybd/virtual-keyboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/vkeybd/virtual-keyboard.cpp')
-rw-r--r--backends/vkeybd/virtual-keyboard.cpp85
1 files changed, 55 insertions, 30 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;
}