This commit is contained in:
thrust26 2020-04-29 09:24:11 +02:00
commit 43069e5722
4 changed files with 37 additions and 44 deletions

View File

@ -728,7 +728,7 @@ string CartDebug::loadListFile()
if(myListFile == "")
{
FilesystemNode lst(myOSystem.romFile().getPathWithExt("") + ".lst");
FilesystemNode lst(myOSystem.romFile().getPathWithExt(".lst"));
if(lst.isFile() && lst.isReadable())
myListFile = lst.getPath();
else
@ -788,7 +788,7 @@ string CartDebug::loadSymbolFile()
if(mySymbolFile == "")
{
FilesystemNode sym(myOSystem.romFile().getPathWithExt("") + ".sym");
FilesystemNode sym(myOSystem.romFile().getPathWithExt(".sym"));
if(sym.isFile() && sym.isReadable())
mySymbolFile = sym.getPath();
else
@ -848,7 +848,7 @@ string CartDebug::loadConfigFile()
if(myCfgFile == "")
{
FilesystemNode romNode(myOSystem.romFile().getPathWithExt("") + ".cfg");
FilesystemNode romNode(myOSystem.romFile().getPathWithExt(".cfg"));
FilesystemNode cfg(myOSystem.cfgDir() + romNode.getName());
if(cfg.isFile() && cfg.isReadable())
myCfgFile = cfg.getPath();
@ -970,7 +970,7 @@ string CartDebug::saveConfigFile()
if(myCfgFile == "")
{
FilesystemNode romNode(myOSystem.romFile().getPathWithExt("") + ".cfg");
FilesystemNode romNode(myOSystem.romFile().getPathWithExt(".cfg"));
FilesystemNode cfg(myOSystem.cfgDir() + romNode.getName());
if(cfg.getParent().isWritable())
myCfgFile = cfg.getPath();

View File

@ -646,11 +646,35 @@ ByteBuffer OSystem::openROM(const FilesystemNode& rom, string& md5, size_t& size
if(md5 == "")
md5 = MD5::hash(image, size);
// Some games may not have a name, since there may not
// be an entry in stella.pro. In that case, we use the rom name
// and reinsert the properties object
// 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;
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;
}

View File

@ -24,13 +24,13 @@
#include "PropsSet.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PropertiesSet::load(const string& filename)
void PropertiesSet::load(const string& filename, bool save)
{
ifstream in(filename);
Properties prop;
while(in >> prop)
insert(prop);
insert(prop, save);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -117,26 +117,6 @@ bool PropertiesSet::getMD5(const string& md5, Properties& properties,
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)
{

View File

@ -49,8 +49,10 @@ class PropertiesSet
searchable list.
@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.
@ -78,19 +80,6 @@ class PropertiesSet
bool getMD5(const string& md5, Properties& properties,
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
the old properties are overwritten with the new ones.