mirror of https://github.com/stella-emu/stella.git
Automaticall load a properties file with the same name as the ROM from the ROM directory.
Still TODO is support loading if the properties file is in a ZIP file.
This commit is contained in:
parent
21b4bc36fa
commit
c326d55836
|
@ -646,11 +646,35 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size
|
||||||
if(md5 == "")
|
if(md5 == "")
|
||||||
md5 = MD5::hash(image, size);
|
md5 = MD5::hash(image, size);
|
||||||
|
|
||||||
// Some games may not have a name, since there may not
|
// Handle ROM properties, do some error checking
|
||||||
// be an entry in stella.pro. In that case, we use the rom name
|
// Only add to the database when necessary
|
||||||
// and reinsert the properties object
|
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;
|
Properties props;
|
||||||
myPropSet->getMD5WithInsert(rom, md5, 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);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,13 @@
|
||||||
#include "PropsSet.hxx"
|
#include "PropsSet.hxx"
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PropertiesSet::load(const string& filename)
|
void PropertiesSet::load(const string& filename, bool save)
|
||||||
{
|
{
|
||||||
ifstream in(filename);
|
ifstream in(filename);
|
||||||
|
|
||||||
Properties prop;
|
Properties prop;
|
||||||
while(in >> prop)
|
while(in >> prop)
|
||||||
insert(prop);
|
insert(prop, save);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -117,26 +117,6 @@ bool PropertiesSet::getMD5(const string& md5, Properties& properties,
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
void PropertiesSet::getMD5WithInsert(const FilesystemNode& rom,
|
|
||||||
const string& md5, Properties& properties)
|
|
||||||
{
|
|
||||||
bool toInsert = false;
|
|
||||||
|
|
||||||
if(!getMD5(md5, properties))
|
|
||||||
{
|
|
||||||
properties.set(PropType::Cart_MD5, md5);
|
|
||||||
toInsert = true;
|
|
||||||
}
|
|
||||||
if(toInsert || properties.get(PropType::Cart_Name) == EmptyString)
|
|
||||||
{
|
|
||||||
properties.set(PropType::Cart_Name, rom.getNameWithExt(""));
|
|
||||||
toInsert = true;
|
|
||||||
}
|
|
||||||
if(toInsert)
|
|
||||||
insert(properties, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void PropertiesSet::insert(const Properties& properties, bool save)
|
void PropertiesSet::insert(const Properties& properties, bool save)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,8 +49,10 @@ class PropertiesSet
|
||||||
searchable list.
|
searchable list.
|
||||||
|
|
||||||
@param filename Full pathname of input file to use
|
@param filename Full pathname of input file to use
|
||||||
|
@param save Indicates whether the properties should be saved
|
||||||
|
when the program exits
|
||||||
*/
|
*/
|
||||||
void load(const string& filename);
|
void load(const string& filename, bool save = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save properties to the specified file.
|
Save properties to the specified file.
|
||||||
|
@ -78,19 +80,6 @@ class PropertiesSet
|
||||||
bool getMD5(const string& md5, Properties& properties,
|
bool getMD5(const string& md5, Properties& properties,
|
||||||
bool useDefaults = false) const;
|
bool useDefaults = false) const;
|
||||||
|
|
||||||
/**
|
|
||||||
Get the property from the set with the given MD5, at the same time
|
|
||||||
checking if it exists. If it doesn't, insert a temporary copy into
|
|
||||||
the set.
|
|
||||||
|
|
||||||
@param rom The ROM file used to calculate the MD5
|
|
||||||
@param md5 The md5 of the property to get
|
|
||||||
@param properties The properties with the given MD5, or the default
|
|
||||||
properties if not found
|
|
||||||
*/
|
|
||||||
void getMD5WithInsert(const FilesystemNode& rom, const string& md5,
|
|
||||||
Properties& properties);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Insert the properties into the set. If a duplicate is inserted
|
Insert the properties into the set. If a duplicate is inserted
|
||||||
the old properties are overwritten with the new ones.
|
the old properties are overwritten with the new ones.
|
||||||
|
|
Loading…
Reference in New Issue