Fix 'saveconfig' not saving file correctly (fixes #602).

This commit is contained in:
Stephen Anthony 2020-04-08 11:59:02 -02:30
parent 108d9c26f9
commit 85f0ae18c6
5 changed files with 27 additions and 11 deletions

View File

@ -28,6 +28,8 @@
* Added detection of color and audio data in DiStella.
* Restored 'cfg' directory for Distella config files.
-Have fun!

View File

@ -843,12 +843,13 @@ string CartDebug::loadSymbolFile()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string CartDebug::loadConfigFile()
{
// The default naming/location for config files is the ROM dir based on the
// actual ROM filename
// The default naming/location for config files is the CFG dir and based
// on the actual ROM filename
if(myCfgFile == "")
{
FilesystemNode cfg(myOSystem.romFile().getPathWithExt("") + ".cfg");
FilesystemNode romNode(myOSystem.romFile().getPathWithExt("") + ".cfg");
FilesystemNode cfg(myOSystem.cfgDir() + romNode.getName());
if(cfg.isFile() && cfg.isReadable())
myCfgFile = cfg.getPath();
else
@ -964,14 +965,14 @@ string CartDebug::loadConfigFile()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string CartDebug::saveConfigFile()
{
// The default naming/location for config files is the ROM dir based on the
// actual ROM filename
// The default naming/location for config files is the CFG dir and based
// on the actual ROM filename
FilesystemNode cfg;
if(myCfgFile == "")
{
cfg = FilesystemNode(myOSystem.romFile().getPathWithExt("") + ".cfg");
if(cfg.isFile() && cfg.isWritable())
FilesystemNode romNode(myOSystem.romFile().getPathWithExt("") + ".cfg");
FilesystemNode cfg(myOSystem.cfgDir() + romNode.getName());
if(cfg.getParent().isWritable())
myCfgFile = cfg.getPath();
else
return DebuggerParser::red("config file \'" + cfg.getShortPath() + "\' not writable");
@ -980,13 +981,14 @@ string CartDebug::saveConfigFile()
const string& name = myConsole.properties().get(PropType::Cart_Name);
const string& md5 = myConsole.properties().get(PropType::Cart_MD5);
FilesystemNode cfg(myCfgFile);
ofstream out(cfg.getPath());
if(!out.is_open())
return "Unable to save directives to " + cfg.getShortPath();
// Store all bank information
out << "//Stella.pro: \"" << name << "\"" << endl
<< "//MD5: " << md5 << endl
out << "// Stella.pro: \"" << name << "\"" << endl
<< "// MD5: " << md5 << endl
<< endl;
for(uInt32 b = 0; b < myConsole.cartridge().bankCount(); ++b)
{

View File

@ -343,7 +343,7 @@ class CartDebug : public DebuggerSystem
uInt16 myLabelLength{8}; // longest pre-defined label
// Filenames to use for various I/O (currently these are hardcoded)
string myListFile, mySymbolFile, myCfgFile, myDisasmFile, myRomFile;
string myListFile, mySymbolFile, myCfgFile, myDisasmFile;
/// Table of instruction mnemonics
static std::array<const char*, 16> ourTIAMnemonicR; // read mode

View File

@ -268,6 +268,9 @@ void OSystem::setConfigPaths()
buildDirIfRequired(myStateDir, myBaseDir + "state");
buildDirIfRequired(myNVRamDir, myBaseDir + "nvram");
#ifdef DEBUGGER_SUPPORT
buildDirIfRequired(myCfgDir, myBaseDir + "cfg");
#endif
#ifdef PNG_SUPPORT
mySnapshotSaveDir = mySettings->getString("snapsavedir");
@ -292,6 +295,7 @@ void OSystem::setConfigPaths()
dbgPath("base dir ", myBaseDir);
dbgPath("state dir ", myStateDir);
dbgPath("nvram dir ", myNVRamDir);
dbgPath("cfg dir ", myCfgDir);
dbgPath("ssave dir ", mySnapshotSaveDir);
dbgPath("sload dir ", mySnapshotLoadDir);
dbgPath("cheat file", myCheatFile);

View File

@ -270,6 +270,13 @@ class OSystem
const string& cheatFile() const { return myCheatFile; }
#endif
#ifdef DEBUGGER_SUPPORT
/**
Return the full/complete directory name for storing Distella cfg files.
*/
const string& cfgDir() const { return myCfgDir; }
#endif
#ifdef PNG_SUPPORT
/**
Return the full/complete directory name for saving and loading
@ -529,6 +536,7 @@ class OSystem
string mySnapshotSaveDir;
string mySnapshotLoadDir;
string myNVRamDir;
string myCfgDir;
string myDefaultSaveDir;
string myDefaultLoadDir;