From e8ed2fa1dd0dd90f7351bef6006975101b6ee0d0 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 23 Jun 2019 14:43:09 -0230 Subject: [PATCH] Fix file selector with certain ZIP files not containing any ROMs. --- src/emucore/FSNode.cxx | 26 ++++++++++++++++++-------- src/gui/LauncherDialog.cxx | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index d22db333a..73671476c 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -84,12 +84,15 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode) const for (const auto& i: tmp) { #if defined(ZIP_SUPPORT) - // Force ZIP c'tor to be called if (BSPF::endsWithIgnoreCase(i->getPath(), ".zip")) { + // Force ZIP c'tor to be called AbstractFSNodePtr ptr = FilesystemNodeFactory::create(i->getPath(), FilesystemNodeFactory::Type::ZIP); - fslist.emplace_back(FilesystemNode(ptr)); + if (ptr->getName() != EmptyString) + fslist.emplace_back(FilesystemNode(ptr)); + else + fslist.emplace_back(FilesystemNode(i)); } else #endif @@ -108,31 +111,35 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& FilesystemNode::getName() const { - return _realNode->getName(); + return _realNode ? _realNode->getName() : EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void FilesystemNode::setName(const string& name) { - _realNode->setName(name); + if (_realNode) + _realNode->setName(name); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string& FilesystemNode::getPath() const { - return _realNode->getPath(); + return _realNode ? _realNode->getPath() : EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string FilesystemNode::getShortPath() const { - return _realNode->getShortPath(); + return _realNode ? _realNode->getShortPath() : EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string FilesystemNode::getNameWithExt(const string& ext) const { + if (!_realNode) + return EmptyString; + size_t pos = _realNode->getName().find_last_of("/\\"); string s = pos == string::npos ? _realNode->getName() : _realNode->getName().substr(pos+1); @@ -144,6 +151,9 @@ string FilesystemNode::getNameWithExt(const string& ext) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string FilesystemNode::getPathWithExt(const string& ext) const { + if (!_realNode) + return EmptyString; + string s = _realNode->getPath(); size_t pos = s.find_last_of("."); @@ -159,7 +169,7 @@ bool FilesystemNode::hasParent() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FilesystemNode FilesystemNode::getParent() const { - if (_realNode == nullptr) + if (!_realNode) return *this; AbstractFSNodePtr node = _realNode->getParent(); @@ -212,7 +222,7 @@ uInt32 FilesystemNode::read(ByteBuffer& image) const throw runtime_error("File not found/readable"); // First let the private subclass attempt to open the file - if ((size = _realNode->read(image)) > 0) + if (_realNode && (size = _realNode->read(image)) > 0) return size; // Otherwise, the default behaviour is to read from a normal C++ ifstream diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 046b4c706..b90d8c99a 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -271,6 +271,7 @@ const FilesystemNode& LauncherDialog::currentNode() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void LauncherDialog::reload() { + myMD5List.clear(); myList->reload(); }