From 2a3bb4329e23539c49c86dea7f25fc9fa4e5b192 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 12 Feb 2018 16:47:03 +0100 Subject: [PATCH] load and update existing game specific properties file --- Changes.txt | 2 ++ src/emucore/OSystem.cxx | 66 +++++++++++++++++++++++++++++++++++--- src/emucore/OSystem.hxx | 15 ++++++++- src/emucore/PropsSet.hxx | 5 +++ src/gui/GameInfoDialog.cxx | 11 ++++--- src/gui/LauncherDialog.cxx | 2 +- 6 files changed, 90 insertions(+), 11 deletions(-) diff --git a/Changes.txt b/Changes.txt index 167e6a03a..95620c946 100644 --- a/Changes.txt +++ b/Changes.txt @@ -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 diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 2a5704382..cad1847fe 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -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(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 -OSystem::openConsole(const FilesystemNode& romfile, string& md5) +unique_ptr OSystem::openConsole(const FilesystemNode& romfile, string& md5) { unique_ptr 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); } } diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 24d690e59..00432b8be 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -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 myPropSet; + // Pointer to the game's PropertiesSet object + unique_ptr myGamePropSet; + + // MD5 of the currently loaded game PropertiesSet object + string myGamePropSetMD5; + // Pointer to the (currently defined) Console object unique_ptr myConsole; @@ -516,6 +528,7 @@ class OSystem string myConfigFile; string myPaletteFile; string myPropertiesFile; + string myGamePropertiesFile; FilesystemNode myRomFile; string myRomMD5; diff --git a/src/emucore/PropsSet.hxx b/src/emucore/PropsSet.hxx index 10f7e99ad..187110f63 100644 --- a/src/emucore/PropsSet.hxx +++ b/src/emucore/PropsSet.hxx @@ -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; diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index d5b291f75..3c736f571 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -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(); diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 69d20b00c..c163e2a6f 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -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); }