First pass at cleaning up the various config file location mess

- only 'romdir' is configurable; the rest are now always under the 'basedir'
- next step is to allow 'basedir' to be configurable, and optionally use the APP dir
- ConfigPathDialog dialog is now almost empty (only contains romdir), so perhaps this can move elsewhere
This commit is contained in:
Stephen Anthony 2019-02-16 15:26:24 -03:30
parent 90e6cfa26b
commit 8f800d97b9
5 changed files with 36 additions and 230 deletions

View File

@ -189,35 +189,42 @@ void OSystem::saveConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::setConfigPaths() void OSystem::setConfigPaths()
{ {
// Paths are saved with special characters preserved ('~' or '.') // Make sure all required directories actually exist
// We do some error checking here, so the rest of the codebase doesn't auto buildDirIfRequired = [](string& path, const string& pathToBuild)
// have to worry about it {
FilesystemNode node; FilesystemNode node(pathToBuild);
string s; if(!node.isDirectory())
node.makeDir();
validatePath(myStateDir, "statedir", myBaseDir + "state"); path = node.getPath();
validatePath(mySnapshotSaveDir, "snapsavedir", defaultSaveDir()); };
validatePath(mySnapshotLoadDir, "snaploaddir", defaultLoadDir());
validatePath(myNVRamDir, "nvramdir", myBaseDir + "nvram");
validatePath(myCfgDir, "cfgdir", myBaseDir + "cfg");
s = mySettings->getString("cheatfile"); buildDirIfRequired(myStateDir, myBaseDir + "state");
if(s == "") s = myBaseDir + "stella.cht"; buildDirIfRequired(myNVRamDir, myBaseDir + "nvram");
node = FilesystemNode(s); buildDirIfRequired(myCfgDir, myBaseDir + "cfg");
myCheatFile = node.getPath();
mySettings->setValue("cheatfile", node.getShortPath());
s = mySettings->getString("palettefile"); buildDirIfRequired(mySnapshotSaveDir, defaultSaveDir());
if(s == "") s = myBaseDir + "stella.pal"; buildDirIfRequired(mySnapshotLoadDir, defaultLoadDir());
node = FilesystemNode(s);
myPaletteFile = node.getPath();
mySettings->setValue("palettefile", node.getShortPath());
s = mySettings->getString("propsfile"); myCheatFile = FilesystemNode(myBaseDir + "stella.cht").getPath();
if(s == "") s = myBaseDir + "stella.pro"; myPaletteFile = FilesystemNode(myBaseDir + "stella.pal").getPath();
node = FilesystemNode(s); myPropertiesFile = FilesystemNode(myBaseDir + "stella.pro").getPath();
myPropertiesFile = node.getPath();
mySettings->setValue("propsfile", node.getShortPath()); // TODO - remove this
auto dbgPath = [](const string& desc, const string& location)
{
cerr << desc << ": " << location << endl;
};
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);
dbgPath("pal file ", myPaletteFile);
dbgPath("pro file ", myPropertiesFile);
dbgPath("INI file ", myConfigFile);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -565,20 +572,6 @@ string OSystem::getROMInfo(const Console& console)
return buf.str(); return buf.str();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void OSystem::validatePath(string& path, const string& setting,
const string& defaultpath)
{
const string& s = mySettings->getString(setting) == "" ? defaultpath :
mySettings->getString(setting);
FilesystemNode node(s);
if(!node.isDirectory())
node.makeDir();
path = node.getPath();
mySettings->setValue(setting, node.getShortPath());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt64 OSystem::getTicks() const uInt64 OSystem::getTicks() const
{ {

View File

@ -563,18 +563,6 @@ class OSystem
*/ */
string getROMInfo(const Console& console); string getROMInfo(const Console& console);
/**
Validate the directory name, and create it if necessary.
Also, update the settings with the new name. For now, validation
means that the path must always end with the appropriate separator.
@param path The actual path being accessed and created
@param setting The setting corresponding to the path being considered
@param defaultpath The default path to use if the settings don't exist
*/
void validatePath(string& path, const string& setting,
const string& defaultpath);
double dispatchEmulation(EmulationWorker& emulationWorker); double dispatchEmulation(EmulationWorker& emulationWorker);
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported

View File

@ -104,12 +104,7 @@ Settings::Settings(OSystem& osystem)
// Config files and paths // Config files and paths
setInternal("romdir", ""); setInternal("romdir", "");
setInternal("statedir", ""); // FIXME setInternal("basedir", "");
setInternal("cheatfile", "");
setInternal("palettefile", "");
setInternal("propsfile", "");
setInternal("nvramdir", "");
setInternal("cfgdir", "");
// ROM browser options // ROM browser options
setInternal("exitlauncher", "false"); setInternal("exitlauncher", "false");
@ -547,13 +542,6 @@ void Settings::usage() const
<< " -mwheel <lines> Number of lines the mouse wheel will scroll in\n" << " -mwheel <lines> Number of lines the mouse wheel will scroll in\n"
<< " UI\n" << " UI\n"
<< " -romdir <dir> Directory in which to load ROM files\n" << " -romdir <dir> Directory in which to load ROM files\n"
<< " -statedir <dir> Directory in which to save/load state files\n"
<< " -cheatfile <file> Full pathname of cheatfile database\n"
<< " -palettefile <file> Full pathname of user-defined palette file\n"
<< " -propsfile <file> Full pathname of ROM properties file\n"
<< " -nvramdir <dir> Directory in which to save/load flash/EEPROM\n"
<< " files\n"
<< " -cfgdir <dir> Directory in which to save Distella config files\n"
<< " -avoxport <name> The name of the serial port where an AtariVox is\n" << " -avoxport <name> The name of the serial port where an AtariVox is\n"
<< " connected\n" << " connected\n"
<< " -holdreset Start the emulator with the Game Reset switch\n" << " -holdreset Start the emulator with the Game Reset switch\n"

View File

@ -41,11 +41,10 @@ ConfigPathDialog::ConfigPathDialog(
const int H_GAP = 8; const int H_GAP = 8;
const int lineHeight = font.getLineHeight(), const int lineHeight = font.getLineHeight(),
fontWidth = font.getMaxCharWidth(), fontWidth = font.getMaxCharWidth(),
buttonWidth = font.getStringWidth("Properties file") + 20, buttonWidth = font.getStringWidth("ROM Path") + 20,
buttonHeight = font.getLineHeight() + 4; buttonHeight = font.getLineHeight() + 4;
int xpos, ypos; int xpos, ypos;
WidgetArray wid; WidgetArray wid;
ButtonWidget* b;
// Set real dimensions // Set real dimensions
setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + V_GAP) + VBORDER, max_w, max_h); setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + V_GAP) + VBORDER, max_w, max_h);
@ -62,56 +61,6 @@ ConfigPathDialog::ConfigPathDialog(
_w - xpos - HBORDER, lineHeight, ""); _w - xpos - HBORDER, lineHeight, "");
wid.push_back(myRomPath); wid.push_back(myRomPath);
// Cheat file
xpos = HBORDER; ypos += buttonHeight + V_GAP;
b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
"Cheat file" + ELLIPSIS, kChooseCheatFileCmd);
wid.push_back(b);
xpos += buttonWidth + H_GAP;
myCheatFile = new EditTextWidget(this, font, xpos, ypos + 1,
_w - xpos - HBORDER, lineHeight, "");
wid.push_back(myCheatFile);
// Palette file
xpos = HBORDER; ypos += buttonHeight + V_GAP;
b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
"Palette file" + ELLIPSIS, kChoosePaletteFileCmd);
wid.push_back(b);
xpos += buttonWidth + H_GAP;
myPaletteFile = new EditTextWidget(this, font, xpos, ypos + 1,
_w - xpos - HBORDER, lineHeight, "");
wid.push_back(myPaletteFile);
// Properties file
xpos = HBORDER; ypos += buttonHeight + V_GAP;
b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
"Properties file" + ELLIPSIS, kChoosePropsFileCmd);
wid.push_back(b);
xpos += buttonWidth + H_GAP;
myPropsFile = new EditTextWidget(this, font, xpos, ypos + 1,
_w - xpos - HBORDER, lineHeight, "");
wid.push_back(myPropsFile);
// State directory
xpos = HBORDER; ypos += buttonHeight + V_GAP;
b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
"State path" + ELLIPSIS, kChooseStateDirCmd);
wid.push_back(b);
xpos += buttonWidth + H_GAP;
myStatePath = new EditTextWidget(this, font, xpos, ypos + 1,
_w - xpos - HBORDER, lineHeight, "");
wid.push_back(myStatePath);
// NVRAM directory
xpos = HBORDER; ypos += buttonHeight + V_GAP;
b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight,
"NVRAM path" + ELLIPSIS, kChooseNVRamDirCmd);
wid.push_back(b);
xpos += buttonWidth + H_GAP;
myNVRamPath = new EditTextWidget(this, font, xpos, ypos + 1,
_w - xpos - HBORDER, lineHeight, "");
wid.push_back(myNVRamPath);
// Add Defaults, OK and Cancel buttons // Add Defaults, OK and Cancel buttons
addDefaultsOKCancelBGroup(wid, font); addDefaultsOKCancelBGroup(wid, font);
@ -135,22 +84,12 @@ void ConfigPathDialog::loadConfig()
{ {
const Settings& settings = instance().settings(); const Settings& settings = instance().settings();
myRomPath->setText(settings.getString("romdir")); myRomPath->setText(settings.getString("romdir"));
myCheatFile->setText(settings.getString("cheatfile"));
myPaletteFile->setText(settings.getString("palettefile"));
myPropsFile->setText(settings.getString("propsfile"));
myNVRamPath->setText(settings.getString("nvramdir"));
myStatePath->setText(settings.getString("statedir"));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ConfigPathDialog::saveConfig() void ConfigPathDialog::saveConfig()
{ {
instance().settings().setValue("romdir", myRomPath->getText()); instance().settings().setValue("romdir", myRomPath->getText());
instance().settings().setValue("cheatfile", myCheatFile->getText());
instance().settings().setValue("palettefile", myPaletteFile->getText());
instance().settings().setValue("propsfile", myPropsFile->getText());
instance().settings().setValue("statedir", myStatePath->getText());
instance().settings().setValue("nvramdir", myNVRamPath->getText());
// Flush changes to disk and inform the OSystem // Flush changes to disk and inform the OSystem
instance().saveConfig(); instance().saveConfig();
@ -160,31 +99,8 @@ void ConfigPathDialog::saveConfig()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ConfigPathDialog::setDefaults() void ConfigPathDialog::setDefaults()
{ {
FilesystemNode node; FilesystemNode node("~");
const string& basedir = instance().baseDir();
node = FilesystemNode("~");
myRomPath->setText(node.getShortPath()); myRomPath->setText(node.getShortPath());
const string& cheatfile = basedir + "stella.cht";
node = FilesystemNode(cheatfile);
myCheatFile->setText(node.getShortPath());
const string& palettefile = basedir + "stella.pal";
node = FilesystemNode(palettefile);
myPaletteFile->setText(node.getShortPath());
const string& propsfile = basedir + "stella.pro";
node = FilesystemNode(propsfile);
myPropsFile->setText(node.getShortPath());
const string& nvramdir = basedir + "nvram";
node = FilesystemNode(nvramdir);
myNVRamPath->setText(node.getShortPath());
const string& statedir = basedir + "state";
node = FilesystemNode(statedir);
myStatePath->setText(node.getShortPath());
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -212,74 +128,10 @@ void ConfigPathDialog::handleCommand(CommandSender* sender, int cmd,
BrowserDialog::Directories, LauncherDialog::kRomDirChosenCmd); BrowserDialog::Directories, LauncherDialog::kRomDirChosenCmd);
break; break;
case kChooseCheatFileCmd:
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
createBrowser("Select cheat file");
myBrowser->show(myCheatFile->getText(),
BrowserDialog::FileLoad, kCheatFileChosenCmd);
break;
case kChoosePaletteFileCmd:
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
createBrowser("Select palette file");
myBrowser->show(myPaletteFile->getText(),
BrowserDialog::FileLoad, kPaletteFileChosenCmd);
break;
case kChoosePropsFileCmd:
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
createBrowser("Select properties file");
myBrowser->show(myPropsFile->getText(),
BrowserDialog::FileLoad, kPropsFileChosenCmd);
break;
case kChooseNVRamDirCmd:
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
createBrowser("Select NVRAM directory");
myBrowser->show(myNVRamPath->getText(),
BrowserDialog::Directories, kNVRamDirChosenCmd);
break;
case kChooseStateDirCmd:
// This dialog is resizable under certain conditions, so we need
// to re-create it as necessary
createBrowser("Select state directory");
myBrowser->show(myStatePath->getText(),
BrowserDialog::Directories, kStateDirChosenCmd);
break;
case LauncherDialog::kRomDirChosenCmd: case LauncherDialog::kRomDirChosenCmd:
myRomPath->setText(myBrowser->getResult().getShortPath()); myRomPath->setText(myBrowser->getResult().getShortPath());
break; break;
case kCheatFileChosenCmd:
myCheatFile->setText(myBrowser->getResult().getShortPath());
break;
case kPaletteFileChosenCmd:
myPaletteFile->setText(myBrowser->getResult().getShortPath());
break;
case kPropsFileChosenCmd:
myPropsFile->setText(myBrowser->getResult().getShortPath());
break;
case kNVRamDirChosenCmd:
myNVRamPath->setText(myBrowser->getResult().getShortPath());
break;
case kStateDirChosenCmd:
myStatePath->setText(myBrowser->getResult().getShortPath());
break;
case LauncherDialog::kReloadRomDirCmd:
sendCommand(LauncherDialog::kReloadRomDirCmd, 0, 0);
break;
default: default:
Dialog::handleCommand(sender, cmd, data, 0); Dialog::handleCommand(sender, cmd, data, 0);
break; break;

View File

@ -48,28 +48,13 @@ class ConfigPathDialog : public Dialog, public CommandSender
private: private:
enum { enum {
kChooseRomDirCmd = 'LOrm', // rom select kChooseRomDirCmd = 'LOrm', // rom select
kChooseStateDirCmd = 'LOsd', // state dir
kChooseCheatFileCmd = 'LOcf', // cheatfile (stella.cht)
kChoosePaletteFileCmd = 'LOpf', // palette file (stella.pal)
kChoosePropsFileCmd = 'LOpr', // properties file (stella.pro)
kChooseNVRamDirCmd = 'LOnv', // nvram (flash/eeprom) dir
kStateDirChosenCmd = 'LOsc', // state dir changed
kCheatFileChosenCmd = 'LOcc', // cheatfile changed
kPaletteFileChosenCmd = 'LOpc', // palette file changed
kPropsFileChosenCmd = 'LOrc', // properties file changed
kNVRamDirChosenCmd = 'LOnc' // nvram (flash/eeprom) dir changed
}; };
const GUI::Font& myFont; const GUI::Font& myFont;
// Config paths // Config paths
EditTextWidget* myRomPath; EditTextWidget* myRomPath;
EditTextWidget* myStatePath;
EditTextWidget* myNVRamPath;
EditTextWidget* myCheatFile;
EditTextWidget* myPaletteFile;
EditTextWidget* myPropsFile;
unique_ptr<BrowserDialog> myBrowser; unique_ptr<BrowserDialog> myBrowser;