mirror of https://github.com/stella-emu/stella.git
Improve processing files that aren't valid ROMs.
Now, the extension is actually checked before opening the ROM. Streaming ROMs (MVC) are already taken care of, but still TODO is limit read to Cart::maxSize().
This commit is contained in:
parent
06f42252fa
commit
f50b8f068d
|
@ -43,7 +43,7 @@ class FixedStack
|
||||||
bool full() const { return _size >= CAPACITY; }
|
bool full() const { return _size >= CAPACITY; }
|
||||||
|
|
||||||
T top() const { return _stack[_size - 1]; }
|
T top() const { return _stack[_size - 1]; }
|
||||||
T get(uInt32 pos) { return _stack[pos]; }
|
T get(uInt32 pos) const { return _stack[pos]; }
|
||||||
void push(const T& x) { _stack[_size++] = x; }
|
void push(const T& x) { _stack[_size++] = x; }
|
||||||
T pop() { return std::move(_stack[--_size]); }
|
T pop() { return std::move(_stack[--_size]); }
|
||||||
uInt32 size() const { return _size; }
|
uInt32 size() const { return _size; }
|
||||||
|
|
|
@ -782,14 +782,17 @@ string OSystem::getROMMD5(const FilesystemNode& rom) const
|
||||||
ByteBuffer OSystem::openROM(const FilesystemNode& rom, size_t& size,
|
ByteBuffer OSystem::openROM(const FilesystemNode& rom, size_t& size,
|
||||||
bool showErrorMessage) const
|
bool showErrorMessage) const
|
||||||
{
|
{
|
||||||
// First check if this is a 'streaming' ROM (one where we only read
|
// First check if this is a valid ROM filename
|
||||||
// a portion of the file)
|
const bool isValidROM = rom.isFile() && Bankswitch::isValidRomName(rom);
|
||||||
|
if(!isValidROM && showErrorMessage)
|
||||||
|
throw runtime_error("Unrecognized ROM file type");
|
||||||
|
|
||||||
|
// Next check for a proper file size:
|
||||||
|
// Streaming ROMs read only a portion of the file
|
||||||
|
// TODO: Otherwise, cap the size to the maximum Cart size
|
||||||
const size_t sizeToRead = CartDetector::isProbablyMVC(rom);
|
const size_t sizeToRead = CartDetector::isProbablyMVC(rom);
|
||||||
|
|
||||||
// Next check if rom is a valid size
|
// Now we can try to open the file
|
||||||
// TODO: We should check if ROM is < Cart::maxSize(), but only
|
|
||||||
// if it's not a ZIP file (that size should be higher; still TBD)
|
|
||||||
|
|
||||||
ByteBuffer image;
|
ByteBuffer image;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,7 +166,7 @@ FileListWidget::IconType FileListWidget::getIconType(const string& path) const
|
||||||
? IconType::zip : IconType::directory;
|
? IconType::zip : IconType::directory;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return node.isFile() && Bankswitch::isValidRomName(node.getName())
|
return node.isFile() && Bankswitch::isValidRomName(node)
|
||||||
? IconType::rom : IconType::unknown;
|
? IconType::rom : IconType::unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue