diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 8d60f6fb1..9c84b4165 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -648,35 +648,8 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size if(md5 == "") md5 = MD5::hash(image, size); - // Handle ROM properties, do some error checking - // Only add to the database when necessary - bool toInsert = false; - - // First, does this ROM have a per-ROM properties entry? - // If so, load it into the database - FilesystemNode propsNode(rom.getPathWithExt(".pro")); - if(propsNode.exists() && propsNode.isFile()) - { - Logger::info("Loading per-ROM properties: " + propsNode.getShortPath()); - myPropSet->load(propsNode.getPath(), false); - } - - // Next, make sure we have a valid md5 and name - Properties props; - if(!myPropSet->getMD5(md5, props)) - { - props.set(PropType::Cart_MD5, md5); - toInsert = true; - } - if(toInsert || props.get(PropType::Cart_Name) == EmptyString) - { - props.set(PropType::Cart_Name, rom.getNameWithExt("")); - toInsert = true; - } - - // Finally, insert properties if any info was missing - if(toInsert) - myPropSet->insert(props, false); + // Make sure to load a per-ROM properties entry, if one exists + myPropSet->loadPerROM(rom, md5); return image; } diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index a13a9c759..a74a999e7 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -156,6 +156,37 @@ void PropertiesSet::insert(const Properties& properties, bool save) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void PropertiesSet::loadPerROM(const FilesystemNode& rom, const string& md5) +{ + // Handle ROM properties, do some error checking + // Only add to the database when necessary + bool toInsert = false; + + // First, does this ROM have a per-ROM properties entry? + // If so, load it into the database + FilesystemNode propsNode(rom.getPathWithExt(".pro")); + if(propsNode.exists() && propsNode.isFile()) + load(propsNode.getPath(), false); + + // Next, make sure we have a valid md5 and name + Properties props; + if(!getMD5(md5, props)) + { + props.set(PropType::Cart_MD5, md5); + toInsert = true; + } + if(toInsert || props.get(PropType::Cart_Name) == EmptyString) + { + props.set(PropType::Cart_Name, rom.getNameWithExt("")); + toInsert = true; + } + + // Finally, insert properties if any info was missing + if(toInsert) + insert(props, false); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PropertiesSet::print() const { diff --git a/src/emucore/PropsSet.hxx b/src/emucore/PropsSet.hxx index 71924749a..f5a763ef8 100644 --- a/src/emucore/PropsSet.hxx +++ b/src/emucore/PropsSet.hxx @@ -42,7 +42,7 @@ class PropertiesSet /** Trivial constructor. */ - PropertiesSet() = default; + PropertiesSet() = default; /** Load properties from the specified file, and create an internal @@ -90,6 +90,21 @@ class PropertiesSet */ void insert(const Properties& properties, bool save = true); + /** + Load properties for a specific ROM from a per-ROM properties file, + if it exists. In any event, also do some error checking, like making + sure that the properties have a valid name, etc. + + NOTE: This method is meant to be called only when starting Stella + and loading a ROM for the first time. Currently, that means + only from the ROM launcher or when actually opening the ROM. + *** FOR ALL OTHER CASES, USE getMD5() *** + + @param rom The node representing the rom file + @param md5 The md5 of the property to get + */ + void loadPerROM(const FilesystemNode& rom, const string& md5); + /** Prints the contents of the PropertiesSet as a flat file. */ diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 8b1852528..3cfa43185 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -48,6 +48,11 @@ RomInfoWidget::RomInfoWidget(GuiObject* boss, const GUI::Font& font, void RomInfoWidget::setProperties(const FilesystemNode& node, const string& md5) { myHaveProperties = true; + + // Make sure to load a per-ROM properties entry, if one exists + instance().propSet().loadPerROM(node, md5); + + // And now get the properties for this ROM instance().propSet().getMD5(md5, myProperties); // Decide whether the information should be shown immediately