From 97487cdaefae8b998a4506450e45612c6836b0a6 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 16 Apr 2022 21:52:10 -0230 Subject: [PATCH] When opening ROMs, ignore error messages in certain cases. --- src/emucore/OSystem.cxx | 10 ++++++---- src/emucore/OSystem.hxx | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index f3b10fd09..4993edbcb 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -753,7 +753,7 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size // but also adds a properties entry if the one for the ROM doesn't // contain a valid name - ByteBuffer image = openROM(rom, size); + ByteBuffer image = openROM(rom, size, true); // handle error message here if(image) { // If we get to this point, we know we have a valid file to open @@ -773,13 +773,14 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size string OSystem::getROMMD5(const FilesystemNode& rom) const { size_t size = 0; - const ByteBuffer image = openROM(rom, size); + const ByteBuffer image = openROM(rom, size, false); // ignore error message return image ? MD5::hash(image, size) : EmptyString; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -ByteBuffer OSystem::openROM(const FilesystemNode& rom, size_t& size) const +ByteBuffer OSystem::openROM(const FilesystemNode& rom, size_t& size, + bool showErrorMessage) const { // First check if this is a 'streaming' ROM (one where we only read // a portion of the file) @@ -797,7 +798,8 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, size_t& size) const } catch(const runtime_error& e) { - cerr << "ERROR: Couldn't open ROM (" << e.what() << ")"; + if(showErrorMessage) // If caller wants error messages, pass it back + throw; } return image; diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 5a548bd91..840dea9b7 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -623,10 +623,13 @@ class OSystem @param romfile The file node of the ROM to open (contains path) @param size The amount of data read into the image array + @param showErrorMessage Whether to show (or ignore) any errors + when opening the ROM @return Unique pointer to the array, otherwise nullptr */ - ByteBuffer openROM(const FilesystemNode& romfile, size_t& size) const; + ByteBuffer openROM(const FilesystemNode& romfile, size_t& size, + bool showErrorMessage) const; /** Creates an actual Console object based on the given info.