diff options
author | Bastien Bouclet | 2017-12-28 19:51:24 +0100 |
---|---|---|
committer | Bastien Bouclet | 2017-12-28 21:24:57 +0100 |
commit | 8fe7d520beb49d09db41b07a4047aac7d7d6623e (patch) | |
tree | 5527e68c11c0dae82ab8a8adb2f618a16349e0b1 /backends/vkeybd | |
parent | 2c8afb2bd25ed9992663f0fba0aeb2e43136c64f (diff) | |
download | scummvm-rg350-8fe7d520beb49d09db41b07a4047aac7d7d6623e.tar.gz scummvm-rg350-8fe7d520beb49d09db41b07a4047aac7d7d6623e.tar.bz2 scummvm-rg350-8fe7d520beb49d09db41b07a4047aac7d7d6623e.zip |
VKEYBD: Fallback to SearchMan when loading keyboard packs
Diffstat (limited to 'backends/vkeybd')
-rw-r--r-- | backends/vkeybd/virtual-keyboard.cpp | 42 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard.h | 4 |
2 files changed, 21 insertions, 25 deletions
diff --git a/backends/vkeybd/virtual-keyboard.cpp b/backends/vkeybd/virtual-keyboard.cpp index 80d7313a8c..267448c859 100644 --- a/backends/vkeybd/virtual-keyboard.cpp +++ b/backends/vkeybd/virtual-keyboard.cpp @@ -38,21 +38,21 @@ namespace Common { -VirtualKeyboard::VirtualKeyboard() : _currentMode(0) { +VirtualKeyboard::VirtualKeyboard() : + _currentMode(nullptr), + _fileArchive(nullptr, DisposeAfterUse::NO) { assert(g_system); _system = g_system; _parser = new VirtualKeyboardParser(this); _kbdGUI = new VirtualKeyboardGUI(this); _submitKeys = _loaded = false; - _fileArchive = 0; } VirtualKeyboard::~VirtualKeyboard() { deleteEvents(); delete _kbdGUI; delete _parser; - delete _fileArchive; } void VirtualKeyboard::deleteEvents() { @@ -74,33 +74,31 @@ void VirtualKeyboard::reset() { _kbdGUI->reset(); } -bool VirtualKeyboard::openPack(const String &packName, const FSNode &node) { - if (node.getChild(packName + ".xml").exists()) { - _fileArchive = new FSDirectory(node, 1); +bool VirtualKeyboard::openPack(const String &packName, Archive *searchPath, DisposeAfterUse::Flag disposeSearchPath) { + if (searchPath->hasFile(packName + ".xml")) { + _fileArchive.reset(searchPath, disposeSearchPath); // uncompressed keyboard pack - if (!_parser->loadFile(node.getChild(packName + ".xml"))) { - delete _fileArchive; - _fileArchive = 0; + if (!_parser->loadStream(searchPath->createReadStreamForMember(packName + ".xml"))) { + _fileArchive.reset(); return false; } return true; } - if (node.getChild(packName + ".zip").exists()) { + if (searchPath->hasFile(packName + ".zip")) { // compressed keyboard pack - _fileArchive = makeZipArchive(node.getChild(packName + ".zip")); + Archive *zip = makeZipArchive(searchPath->createReadStreamForMember(packName + ".zip")); + _fileArchive.reset(zip, DisposeAfterUse::YES); if (_fileArchive && _fileArchive->hasFile(packName + ".xml")) { if (!_parser->loadStream(_fileArchive->createReadStreamForMember(packName + ".xml"))) { - delete _fileArchive; - _fileArchive = 0; + _fileArchive.reset(); return false; } } else { warning("Could not find %s.xml file in %s.zip virtual keyboard pack", packName.c_str(), packName.c_str()); - delete _fileArchive; - _fileArchive = 0; + _fileArchive.reset(); return false; } @@ -113,19 +111,18 @@ bool VirtualKeyboard::openPack(const String &packName, const FSNode &node) { bool VirtualKeyboard::loadKeyboardPack(const String &packName) { _kbdGUI->initSize(_system->getOverlayWidth(), _system->getOverlayHeight()); - delete _fileArchive; - _fileArchive = 0; + _fileArchive.reset(); _loaded = false; bool opened = false; if (ConfMan.hasKey("vkeybdpath")) - opened = openPack(packName, FSNode(ConfMan.get("vkeybdpath"))); + opened = openPack(packName, new FSDirectory(ConfMan.get("vkeybdpath")), DisposeAfterUse::YES); else if (ConfMan.hasKey("extrapath")) - opened = openPack(packName, FSNode(ConfMan.get("extrapath"))); + opened = openPack(packName, new FSDirectory(ConfMan.get("extrapath")), DisposeAfterUse::YES); - // fallback to the current dir + // fallback to SearchMan if (!opened) - opened = openPack(packName, FSNode(".")); + opened = openPack(packName, &SearchMan, DisposeAfterUse::NO); if (opened) { _parser->setParseMode(VirtualKeyboardParser::kParseFull); @@ -136,8 +133,7 @@ bool VirtualKeyboard::loadKeyboardPack(const String &packName) { } else { warning("Error parsing the virtual keyboard pack '%s'", packName.c_str()); - delete _fileArchive; - _fileArchive = 0; + _fileArchive.reset(); } } else { warning("Virtual keyboard disabled due to missing pack file"); diff --git a/backends/vkeybd/virtual-keyboard.h b/backends/vkeybd/virtual-keyboard.h index 3b2b2196bd..38139e2ad8 100644 --- a/backends/vkeybd/virtual-keyboard.h +++ b/backends/vkeybd/virtual-keyboard.h @@ -226,7 +226,7 @@ public: protected: OSystem *_system; - Archive *_fileArchive; + DisposablePtr<Archive> _fileArchive; friend class VirtualKeyboardGUI; VirtualKeyboardGUI *_kbdGUI; @@ -237,7 +237,7 @@ protected: VirtualKeyboardParser *_parser; void reset(); - bool openPack(const String &packName, const FSNode &node); + bool openPack(const String &packName, Archive *searchPath, DisposeAfterUse::Flag disposeSearchPath); void deleteEvents(); bool checkModeResolutions(); void switchMode(Mode *newMode); |