mirror of https://github.com/stella-emu/stella.git
Fix ZIP handling wrt what is a valid filename (take new extensions into account).
This commit is contained in:
parent
a84f76fd5f
commit
fe0d29a795
|
@ -18,6 +18,7 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
|
#include "Bankswitch.hxx"
|
||||||
#include "OSystem.hxx"
|
#include "OSystem.hxx"
|
||||||
#include "FSNodeFactory.hxx"
|
#include "FSNodeFactory.hxx"
|
||||||
#include "FSNodeZIP.hxx"
|
#include "FSNodeZIP.hxx"
|
||||||
|
@ -38,14 +39,6 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
||||||
_isDirectory(false),
|
_isDirectory(false),
|
||||||
_isFile(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)
|
// Extract ZIP file and virtual file (if specified)
|
||||||
size_t pos = BSPF::findIgnoreCase(p, ".zip");
|
size_t pos = BSPF::findIgnoreCase(p, ".zip");
|
||||||
if(pos == string::npos)
|
if(pos == string::npos)
|
||||||
|
@ -67,7 +60,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
||||||
if(pos+5 < p.length())
|
if(pos+5 < p.length())
|
||||||
{
|
{
|
||||||
_virtualPath = p.substr(pos+5);
|
_virtualPath = p.substr(pos+5);
|
||||||
_isFile = isFile(_virtualPath);
|
_isFile = Bankswitch::isValidRomName(_virtualPath);
|
||||||
_isDirectory = !_isFile;
|
_isDirectory = !_isFile;
|
||||||
}
|
}
|
||||||
else if(_numFiles == 1)
|
else if(_numFiles == 1)
|
||||||
|
@ -76,7 +69,7 @@ FilesystemNodeZIP::FilesystemNodeZIP(const string& p)
|
||||||
while(zip.hasNext() && !found)
|
while(zip.hasNext() && !found)
|
||||||
{
|
{
|
||||||
const string& file = zip.next();
|
const string& file = zip.next();
|
||||||
if(isFile(file))
|
if(Bankswitch::isValidRomName(file))
|
||||||
{
|
{
|
||||||
_virtualPath = file;
|
_virtualPath = file;
|
||||||
_isFile = true;
|
_isFile = true;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include "Bankswitch.hxx"
|
||||||
#include "ZipHandler.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)
|
// Count ROM files (we do it at this level so it will be cached)
|
||||||
while(hasNext())
|
while(hasNext())
|
||||||
{
|
if(Bankswitch::isValidRomName(next()))
|
||||||
const std::string& file = next();
|
|
||||||
if(BSPF::endsWithIgnoreCase(file, ".a26") ||
|
|
||||||
BSPF::endsWithIgnoreCase(file, ".bin") ||
|
|
||||||
BSPF::endsWithIgnoreCase(file, ".rom"))
|
|
||||||
(*zip)->romfiles++;
|
(*zip)->romfiles++;
|
||||||
}
|
|
||||||
|
|
||||||
return ZIPERR_NONE;
|
return ZIPERR_NONE;
|
||||||
|
|
||||||
|
|
|
@ -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('.');
|
string::size_type idx = name.find_last_of('.');
|
||||||
if(idx != string::npos)
|
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(name.getPath(), ext);
|
||||||
return isValidRomName(file, extension);
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -74,15 +74,17 @@ class Bankswitch
|
||||||
/**
|
/**
|
||||||
Is this a valid ROM filename (does it have a valid extension?).
|
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
|
@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 FilesystemNode& name);
|
||||||
|
static bool isValidRomName(const string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TypeComparator {
|
struct TypeComparator {
|
||||||
|
|
Loading…
Reference in New Issue