diff --git a/src/common/FSNodeZIP.cxx b/src/common/FSNodeZIP.cxx index 0af148608..73c48aee0 100644 --- a/src/common/FSNodeZIP.cxx +++ b/src/common/FSNodeZIP.cxx @@ -18,6 +18,7 @@ #include #include "bspf.hxx" +#include "Bankswitch.hxx" #include "OSystem.hxx" #include "FSNodeFactory.hxx" #include "FSNodeZIP.hxx" @@ -38,14 +39,6 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) _isDirectory(false), _isFile(false) { - // Is this a valid file? - auto isFile = [](const string& file) - { - return BSPF::endsWithIgnoreCase(file, ".a26") || - BSPF::endsWithIgnoreCase(file, ".bin") || - BSPF::endsWithIgnoreCase(file, ".rom"); - }; - // Extract ZIP file and virtual file (if specified) size_t pos = BSPF::findIgnoreCase(p, ".zip"); if(pos == string::npos) @@ -67,7 +60,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) if(pos+5 < p.length()) { _virtualPath = p.substr(pos+5); - _isFile = isFile(_virtualPath); + _isFile = Bankswitch::isValidRomName(_virtualPath); _isDirectory = !_isFile; } else if(_numFiles == 1) @@ -76,7 +69,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p) while(zip.hasNext() && !found) { const string& file = zip.next(); - if(isFile(file)) + if(Bankswitch::isValidRomName(file)) { _virtualPath = file; _isFile = true; diff --git a/src/common/ZipHandler.cxx b/src/common/ZipHandler.cxx index 673e5784e..903404a3e 100644 --- a/src/common/ZipHandler.cxx +++ b/src/common/ZipHandler.cxx @@ -19,6 +19,7 @@ #include #include +#include "Bankswitch.hxx" #include "ZipHandler.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -261,13 +262,8 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char* filename, zip_file** // Count ROM files (we do it at this level so it will be cached) while(hasNext()) - { - const std::string& file = next(); - if(BSPF::endsWithIgnoreCase(file, ".a26") || - BSPF::endsWithIgnoreCase(file, ".bin") || - BSPF::endsWithIgnoreCase(file, ".rom")) + if(Bankswitch::isValidRomName(next())) (*zip)->romfiles++; - } return ZIPERR_NONE; diff --git a/src/emucore/Bankswitch.cxx b/src/emucore/Bankswitch.cxx index 4f8efca28..36efe39c8 100644 --- a/src/emucore/Bankswitch.cxx +++ b/src/emucore/Bankswitch.cxx @@ -49,9 +49,8 @@ Bankswitch::Type Bankswitch::typeFromExtension(const FilesystemNode& file) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Bankswitch::isValidRomName(const FilesystemNode& file, string& ext) +bool Bankswitch::isValidRomName(const string& name, string& ext) { - const string& name = file.getPath(); string::size_type idx = name.find_last_of('.'); if(idx != string::npos) { @@ -67,10 +66,23 @@ bool Bankswitch::isValidRomName(const FilesystemNode& file, string& ext) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Bankswitch::isValidRomName(const FilesystemNode& file) +bool Bankswitch::isValidRomName(const FilesystemNode& name, string& ext) { - string extension; // not actually used - return isValidRomName(file, extension); + return isValidRomName(name.getPath(), ext); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Bankswitch::isValidRomName(const FilesystemNode& name) +{ + string ext; // extension not used + return isValidRomName(name.getPath(), ext); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Bankswitch::isValidRomName(const string& name) +{ + string ext; // extension not used + return isValidRomName(name, ext); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Bankswitch.hxx b/src/emucore/Bankswitch.hxx index 7ec11596d..2f8b386c8 100644 --- a/src/emucore/Bankswitch.hxx +++ b/src/emucore/Bankswitch.hxx @@ -74,15 +74,17 @@ class Bankswitch /** Is this a valid ROM filename (does it have a valid extension?). - @param name File node of potential ROM file + @param name Filename of potential ROM file @param ext The extension extracted from the given file */ - static bool isValidRomName(const FilesystemNode& name, string& ext); + static bool isValidRomName(const string& name, string& ext); /** - Convenience function when extension isn't needed. + Convenience functions for different parameter types. */ + static bool isValidRomName(const FilesystemNode& name, string& ext); static bool isValidRomName(const FilesystemNode& name); + static bool isValidRomName(const string& name); private: struct TypeComparator {