diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index f56b255da..315c38dec 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -47,6 +47,8 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) #endif } +// cerr << " => p: " << p << endl; + // Open file at least once to initialize the virtual file count try { @@ -66,26 +68,23 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) // We always need a virtual file/path // Either one is given, or we use the first one - if(pos+5 < p.length()) + if(pos+5 < p.length()) // if something comes after '.zip' { _virtualPath = p.substr(pos+5); _isFile = Bankswitch::isValidRomName(_virtualPath); _isDirectory = !_isFile; - -// cerr << _virtualPath << ", isfile: " << _isFile << endl; - } else if(_numFiles == 1) { bool found = false; while(myZipHandler->hasNext() && !found) { - const auto [name, size, isFile] = myZipHandler->next(); + const auto& [name, size] = myZipHandler->next(); if(Bankswitch::isValidRomName(name)) { _virtualPath = name; _size = size; - _isFile = isFile; + _isFile = true; found = true; } @@ -105,6 +104,8 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) FilesystemNodeFactory::Type::SYSTEM); setFlags(_zipFile, _virtualPath, _realNode); +// cerr << "==============================================================\n"; +// cerr << _name << ", file: " << _isFile << ", dir: " << _isDirectory << endl << endl; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -115,6 +116,7 @@ FilesystemNodeZIP::FilesystemNodeZIP( _isDirectory{isdir}, _isFile{!isdir} { +// cerr << "=> c'tor 2: " << zipfile << ", " << virtualpath << ", " << isdir << endl; setFlags(zipfile, virtualpath, realnode); } @@ -155,7 +157,7 @@ bool FilesystemNodeZIP::exists() const myZipHandler->open(_zipFile); while(myZipHandler->hasNext()) { - const auto [name, size, isFile] = myZipHandler->next(); + const auto& [name, size] = myZipHandler->next(); if(BSPF::startsWithIgnoreCase(name, _virtualPath)) return true; } @@ -178,17 +180,20 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode) const std::set dirs; myZipHandler->open(_zipFile); +// cerr << "CHILDREN: --------------------------------\n"; while(myZipHandler->hasNext()) { // Only consider entries that start with '_virtualPath' // Ignore empty filenames and '__MACOSX' virtual directories - const auto [name, size, isFile] = myZipHandler->next(); + const auto& [name, size] = myZipHandler->next(); if(BSPF::startsWithIgnoreCase(name, "__MACOSX") || name == EmptyString) continue; if(BSPF::startsWithIgnoreCase(name, _virtualPath)) { // First strip off the leading directory - const string& curr = name.substr(_virtualPath == "" ? 0 : _virtualPath.size()+1); + const string& curr = name.substr( + _virtualPath == "" ? 0 : _virtualPath.size()+1); +// cerr << " curr: " << curr << endl; // Only add sub-directory entries once const auto pos = curr.find_first_of("/\\"); if(pos != string::npos) @@ -204,6 +209,10 @@ bool FilesystemNodeZIP::getChildren(AbstractFSList& myList, ListMode mode) const myList.emplace_back(new FilesystemNodeZIP(_zipFile, vpath, _realNode, 0, true)); } +// cerr << "list: \n"; +// for(auto& s: myList) +// cerr << s->getPath() << " : isdir: " << s->isDirectory() << endl; +// cerr << "------------------------------------------\n"; return true; } @@ -223,7 +232,7 @@ size_t FilesystemNodeZIP::read(ByteBuffer& image, size_t) const bool found = false; while(myZipHandler->hasNext() && !found) { - const auto [name, size, isFile] = myZipHandler->next(); + const auto& [name, size] = myZipHandler->next(); found = name == _virtualPath; } @@ -266,7 +275,7 @@ AbstractFSNodePtr FilesystemNodeZIP::getParent() const const char* start = _path.c_str(); const char* end = lastPathComponent(_path); - return make_shared(string(start, end - start - 1)); + return make_unique(string(start, end - start - 1)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/ZipHandler.cxx b/src/common/ZipHandler.cxx index 28683a80d..e4e568691 100644 --- a/src/common/ZipHandler.cxx +++ b/src/common/ZipHandler.cxx @@ -67,7 +67,7 @@ void ZipHandler::open(const string& filename) { while(hasNext()) { - const auto [name, size, isFile] = next(); + const auto& [name, size] = next(); if(Bankswitch::isValidRomName(name)) myZip->myRomfiles++; } @@ -96,7 +96,7 @@ bool ZipHandler::hasNext() const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::tuple ZipHandler::next() +std::tuple ZipHandler::next() { if(hasNext()) { @@ -106,9 +106,9 @@ std::tuple ZipHandler::next() else if(header->uncompressedLength == 0) return next(); else - return {header->filename, header->uncompressedLength, true}; + return {header->filename, header->uncompressedLength}; } - return {EmptyString, 0, false}; + return {EmptyString, 0}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/ZipHandler.hxx b/src/common/ZipHandler.hxx index b50645143..8f539145b 100644 --- a/src/common/ZipHandler.hxx +++ b/src/common/ZipHandler.hxx @@ -43,7 +43,7 @@ class ZipHandler // The following form an iterator for processing the filenames in the ZIP file void reset(); // Reset iterator to first file bool hasNext() const; // Answer whether there are more files present - std::tuple next(); // Get information on next file + std::tuple next(); // Get information on next file // Decompress the currently selected file and return its length // An exception will be thrown on any errors diff --git a/src/emucore/FSNode.cxx b/src/emucore/FSNode.cxx index 65a7fc110..e2adfc626 100644 --- a/src/emucore/FSNode.cxx +++ b/src/emucore/FSNode.cxx @@ -41,10 +41,12 @@ void FilesystemNode::setPath(const string& path) // Is this potentially a ZIP archive? #if defined(ZIP_SUPPORT) if (BSPF::containsIgnoreCase(path, ".zip")) - _realNode = FilesystemNodeFactory::create(path, FilesystemNodeFactory::Type::ZIP); + _realNode = FilesystemNodeFactory::create(path, + FilesystemNodeFactory::Type::ZIP); else #endif - _realNode = FilesystemNodeFactory::create(path, FilesystemNodeFactory::Type::SYSTEM); + _realNode = FilesystemNodeFactory::create(path, + FilesystemNodeFactory::Type::SYSTEM); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -78,14 +80,13 @@ bool FilesystemNode::getAllChildren(FSList& fslist, ListMode mode, { // Sort only once at the end #if defined(ZIP_SUPPORT) - // before sorting, replace single file ZIP archive names with contained file names - // because they are displayed using their contained file names + // before sorting, replace single file ZIP archive names with contained + // file names because they are displayed using their contained file names for(auto& i : fslist) { if(BSPF::endsWithIgnoreCase(i.getPath(), ".zip")) { FilesystemNodeZIP zipNode(i.getPath()); - i.setName(zipNode.getName()); } } @@ -108,8 +109,8 @@ bool FilesystemNode::getAllChildren(FSList& fslist, ListMode mode, if(BSPF::endsWithIgnoreCase(i.getPath(), ".zip")) { // Force ZIP c'tor to be called - AbstractFSNodePtr ptr = FilesystemNodeFactory::create(i.getPath(), - FilesystemNodeFactory::Type::ZIP); + AbstractFSNodePtr ptr = FilesystemNodeFactory::create( + i.getPath(), FilesystemNodeFactory::Type::ZIP); FilesystemNode zipNode(ptr); i = zipNode; } @@ -143,14 +144,13 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode, return false; #if defined(ZIP_SUPPORT) - // before sorting, replace single file ZIP archive names with contained file names - // because they are displayed using their contained file names + // before sorting, replace single file ZIP archive names with contained + // file names because they are displayed using their contained file names for(auto& i : tmp) { if(BSPF::endsWithIgnoreCase(i->getPath(), ".zip")) { FilesystemNodeZIP node(i->getPath()); - i->setName(node.getName()); } } @@ -185,8 +185,8 @@ bool FilesystemNode::getChildren(FSList& fslist, ListMode mode, if (BSPF::endsWithIgnoreCase(i->getPath(), ".zip")) { // Force ZIP c'tor to be called - AbstractFSNodePtr ptr = FilesystemNodeFactory::create(i->getPath(), - FilesystemNodeFactory::Type::ZIP); + AbstractFSNodePtr ptr = FilesystemNodeFactory::create( + i->getPath(), FilesystemNodeFactory::Type::ZIP); FilesystemNode zipNode(ptr); if(filter(zipNode)) diff --git a/src/gui/LauncherFileListWidget.hxx b/src/gui/LauncherFileListWidget.hxx index ca1c4d5b0..b5c6abb8f 100644 --- a/src/gui/LauncherFileListWidget.hxx +++ b/src/gui/LauncherFileListWidget.hxx @@ -26,7 +26,7 @@ class Settings; #include "FileListWidget.hxx" /** - Specialization of the general FileListWidget which procides support for + Specialization of the general FileListWidget which provides support for user defined favorites, recently played ROMs and most popular ROMs. @author Thomas Jentzsch