Fix ZIP handling wrt what is a valid filename (take new extensions into account).

This commit is contained in:
Stephen Anthony 2018-08-31 23:29:19 -02:30
parent a84f76fd5f
commit fe0d29a795
4 changed files with 27 additions and 24 deletions

View File

@ -18,6 +18,7 @@
#include <set>
#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;

View File

@ -19,6 +19,7 @@
#include <cstdlib>
#include <zlib.h>
#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;

View File

@ -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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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 {