diff options
-rw-r--r-- | backends/platform/maemo/maemo.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/ps3/ps3.cpp | 1 | ||||
-rw-r--r-- | backends/platform/sdl/psp2/psp2.cpp | 1 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard.cpp | 42 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard.h | 4 | ||||
-rw-r--r-- | common/ptr.h | 16 |
6 files changed, 37 insertions, 29 deletions
diff --git a/backends/platform/maemo/maemo.cpp b/backends/platform/maemo/maemo.cpp index dc1054940e..326c35a28f 100644 --- a/backends/platform/maemo/maemo.cpp +++ b/backends/platform/maemo/maemo.cpp @@ -108,8 +108,6 @@ void OSystem_SDL_Maemo::initBackend() { _keymapperDefaultBindings = new Common::KeymapperDefaultBindings(); #endif - ConfMan.set("vkeybdpath", DATA_PATH); - _model = detectModel(); #ifdef ENABLE_KEYMAPPER diff --git a/backends/platform/sdl/ps3/ps3.cpp b/backends/platform/sdl/ps3/ps3.cpp index 0bb8300014..b13088afd3 100644 --- a/backends/platform/sdl/ps3/ps3.cpp +++ b/backends/platform/sdl/ps3/ps3.cpp @@ -59,7 +59,6 @@ void OSystem_PS3::init() { void OSystem_PS3::initBackend() { ConfMan.set("joystick_num", 0); - ConfMan.set("vkeybdpath", PREFIX "/data"); ConfMan.registerDefault("fullscreen", true); ConfMan.registerDefault("aspect_ratio", true); diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp index 12154ba7d0..f959bbaf49 100644 --- a/backends/platform/sdl/psp2/psp2.cpp +++ b/backends/platform/sdl/psp2/psp2.cpp @@ -73,7 +73,6 @@ void OSystem_PSP2::init() { void OSystem_PSP2::initBackend() { ConfMan.set("joystick_num", 0); - ConfMan.set("vkeybdpath", PREFIX "/data"); ConfMan.registerDefault("fullscreen", true); ConfMan.registerDefault("aspect_ratio", false); ConfMan.registerDefault("gfx_mode", "2x"); 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); diff --git a/common/ptr.h b/common/ptr.h index f592beb005..f3b2f3cbfa 100644 --- a/common/ptr.h +++ b/common/ptr.h @@ -302,6 +302,22 @@ public: bool operator_bool() const { return _pointer != nullptr; } /** + * Resets the pointer with the new value. Old object will be destroyed + */ + void reset(PointerType o, DisposeAfterUse::Flag dispose) { + if (_dispose) D()(_pointer); + _pointer = o; + _dispose = dispose; + } + + /** + * Clears the pointer. Old object will be destroyed + */ + void reset() { + reset(nullptr, DisposeAfterUse::NO); + } + + /** * Returns the plain pointer value. * * @return the pointer the DisposablePtr manages |