Partially revert previous commit: fix ROM launcher not showing properties in certain cases.

This commit is contained in:
Stephen Anthony 2020-05-15 15:25:27 -02:30
parent 308cc97974
commit a618d27f01
4 changed files with 54 additions and 30 deletions

View File

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

View File

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

View File

@ -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.
*/

View File

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