load and update existing game specific properties file

This commit is contained in:
thrust26 2018-02-12 16:47:03 +01:00
parent d65ac4875f
commit 2a3bb4329e
6 changed files with 90 additions and 11 deletions

View File

@ -5,6 +5,8 @@
* Fixes for collision corner cases (during HBlank)
* UI modernization (new widget look, dialog titles added, dialogs refactored)
5.0.2 to 5.1: (February 4, 2018)
* Added "Time Machine" mode, which automatically creates save states

View File

@ -217,6 +217,56 @@ void OSystem::setConfigPaths()
mySettings->setValue("propsfile", node.getShortPath());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertiesSet& OSystem::propSet(const string& md5)
{
FilesystemNode node = FilesystemNode();
return propSet(md5, node);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertiesSet& OSystem::propSet(const string& md5, const FilesystemNode& node)
{
if(md5 == EmptyString)
return *myPropSet;
else if(md5 == myGamePropSetMD5)
return *myGamePropSet;
else if (!node.exists())
return *myPropSet;
// Get a valid set of game specific properties
Properties props;
string path = myBaseDir + node.getNameWithExt(".pro");
// Create a properties set based on ROM name
FilesystemNode propNode = FilesystemNode(path);
myGamePropertiesFile = propNode.getPath();
myGamePropSet = make_unique<PropertiesSet>(myGamePropertiesFile);
// Check if game specific property file exists and has matching md5
if(myGamePropSet->size() && myGamePropSet->getMD5(md5, props))
{
myGamePropSetMD5 = md5;
return *myGamePropSet;
}
else
{
myGamePropSetMD5 = "";
return *myPropSet;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::saveGamePropSet(const string& md5)
{
if(myGamePropSet->size() && md5 == myGamePropSetMD5)
{
myGamePropSet->save(myGamePropertiesFile);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::setBaseDir(const string& basedir)
{
@ -447,8 +497,7 @@ void OSystem::logMessage(const string& message, uInt8 level)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unique_ptr<Console>
OSystem::openConsole(const FilesystemNode& romfile, string& md5)
unique_ptr<Console> OSystem::openConsole(const FilesystemNode& romfile, string& md5)
{
unique_ptr<Console> console;
@ -460,8 +509,15 @@ OSystem::openConsole(const FilesystemNode& romfile, string& md5)
// Get a valid set of properties, including any entered on the commandline
// For initial creation of the Cart, we're only concerned with the BS type
Properties props;
myPropSet->getMD5(md5, props);
// Load and use game specific props if existing
FilesystemNode node = FilesystemNode(romfile);
string path = myBaseDir + node.getNameWithExt(".pro");
PropertiesSet& propset = propSet(md5, romfile);
propset.getMD5(md5, props);
// Local helper method
auto CMDLINE_PROPS_UPDATE = [&](const string& name, PropertyType prop)
{
const string& s = mySettings->getString(name);
@ -481,12 +537,12 @@ OSystem::openConsole(const FilesystemNode& romfile, string& md5)
// and that the md5 (and hence the cart) has changed
if(props.get(Cartridge_MD5) != cartmd5)
{
if(!myPropSet->getMD5(cartmd5, props))
if(!propset.getMD5(cartmd5, props))
{
// Cart md5 wasn't found, so we create a new props for it
props.set(Cartridge_MD5, cartmd5);
props.set(Cartridge_Name, props.get(Cartridge_Name)+cart->multiCartID());
myPropSet->insert(props, false);
propset.insert(props, false);
}
}

View File

@ -115,7 +115,13 @@ class OSystem
@return The properties set object
*/
PropertiesSet& propSet() const { return *myPropSet; }
PropertiesSet& propSet(const string& md5 = EmptyString);
PropertiesSet& propSet(const string& md5, const FilesystemNode& node);
/**
Save the game specific property file.
*/
void saveGamePropSet(const string& md5);
/**
Get the console of the system. The console won't always exist,
@ -454,6 +460,12 @@ class OSystem
// Pointer to the PropertiesSet object
unique_ptr<PropertiesSet> myPropSet;
// Pointer to the game's PropertiesSet object
unique_ptr<PropertiesSet> myGamePropSet;
// MD5 of the currently loaded game PropertiesSet object
string myGamePropSetMD5;
// Pointer to the (currently defined) Console object
unique_ptr<Console> myConsole;
@ -516,6 +528,7 @@ class OSystem
string myConfigFile;
string myPaletteFile;
string myPropertiesFile;
string myGamePropertiesFile;
FilesystemNode myRomFile;
string myRomMD5;

View File

@ -112,6 +112,11 @@ class PropertiesSet
*/
void print() const;
/**
Return the size of the myExternalProps list
*/
uInt32 size() { return myExternalProps.size(); }
private:
using PropsList = std::map<string, Properties>;

View File

@ -348,7 +348,7 @@ void GameInfoDialog::loadConfig()
const string& md5 = instance().launcher().selectedRomMD5();
if(md5 != "")
{
instance().propSet().getMD5(md5, myGameProperties);
instance().propSet(md5).getMD5(md5, myGameProperties);
myPropertiesLoaded = true;
loadView();
}
@ -486,10 +486,13 @@ void GameInfoDialog::saveConfig()
myPPBlend->getValueLabel());
// Determine whether to add or remove an entry from the properties set
const string& md5 = myGameProperties.get(Cartridge_MD5);
if(myDefaultsSelected)
instance().propSet().removeMD5(myGameProperties.get(Cartridge_MD5));
instance().propSet(md5).removeMD5(myGameProperties.get(Cartridge_MD5));
else
instance().propSet().insert(myGameProperties);
instance().propSet(md5).insert(myGameProperties);
instance().saveGamePropSet(myGameProperties.get(Cartridge_MD5));
// In any event, inform the Console
if(instance().hasConsole())
@ -501,7 +504,7 @@ void GameInfoDialog::setDefaults()
{
// Load the default properties
string md5 = myGameProperties.get(Cartridge_MD5);
instance().propSet().getMD5(md5, myGameProperties, true);
instance().propSet(md5).getMD5(md5, myGameProperties, true);
// Reload the current dialog
loadView();

View File

@ -349,7 +349,7 @@ void LauncherDialog::loadRomInfo()
// Get the properties for this entry
Properties props;
instance().propSet().getMD5WithInsert(node, myGameList->md5(item), props);
instance().propSet(myGameList->md5(item), node).getMD5WithInsert(node, myGameList->md5(item), props);
myRomInfoWidget->setProperties(props);
}