mirror of https://github.com/stella-emu/stella.git
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:
parent
90e6cfa26b
commit
8f800d97b9
|
@ -189,35 +189,42 @@ void OSystem::saveConfig()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void OSystem::setConfigPaths()
|
||||
{
|
||||
// Paths are saved with special characters preserved ('~' or '.')
|
||||
// We do some error checking here, so the rest of the codebase doesn't
|
||||
// have to worry about it
|
||||
FilesystemNode node;
|
||||
string s;
|
||||
// Make sure all required directories actually exist
|
||||
auto buildDirIfRequired = [](string& path, const string& pathToBuild)
|
||||
{
|
||||
FilesystemNode node(pathToBuild);
|
||||
if(!node.isDirectory())
|
||||
node.makeDir();
|
||||
|
||||
validatePath(myStateDir, "statedir", myBaseDir + "state");
|
||||
validatePath(mySnapshotSaveDir, "snapsavedir", defaultSaveDir());
|
||||
validatePath(mySnapshotLoadDir, "snaploaddir", defaultLoadDir());
|
||||
validatePath(myNVRamDir, "nvramdir", myBaseDir + "nvram");
|
||||
validatePath(myCfgDir, "cfgdir", myBaseDir + "cfg");
|
||||
path = node.getPath();
|
||||
};
|
||||
|
||||
s = mySettings->getString("cheatfile");
|
||||
if(s == "") s = myBaseDir + "stella.cht";
|
||||
node = FilesystemNode(s);
|
||||
myCheatFile = node.getPath();
|
||||
mySettings->setValue("cheatfile", node.getShortPath());
|
||||
buildDirIfRequired(myStateDir, myBaseDir + "state");
|
||||
buildDirIfRequired(myNVRamDir, myBaseDir + "nvram");
|
||||
buildDirIfRequired(myCfgDir, myBaseDir + "cfg");
|
||||
|
||||
s = mySettings->getString("palettefile");
|
||||
if(s == "") s = myBaseDir + "stella.pal";
|
||||
node = FilesystemNode(s);
|
||||
myPaletteFile = node.getPath();
|
||||
mySettings->setValue("palettefile", node.getShortPath());
|
||||
buildDirIfRequired(mySnapshotSaveDir, defaultSaveDir());
|
||||
buildDirIfRequired(mySnapshotLoadDir, defaultLoadDir());
|
||||
|
||||
s = mySettings->getString("propsfile");
|
||||
if(s == "") s = myBaseDir + "stella.pro";
|
||||
node = FilesystemNode(s);
|
||||
myPropertiesFile = node.getPath();
|
||||
mySettings->setValue("propsfile", node.getShortPath());
|
||||
myCheatFile = FilesystemNode(myBaseDir + "stella.cht").getPath();
|
||||
myPaletteFile = FilesystemNode(myBaseDir + "stella.pal").getPath();
|
||||
myPropertiesFile = FilesystemNode(myBaseDir + "stella.pro").getPath();
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
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
|
||||
{
|
||||
|
|
|
@ -563,18 +563,6 @@ class OSystem
|
|||
*/
|
||||
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);
|
||||
|
||||
// Following constructors and assignment operators not supported
|
||||
|
|
|
@ -104,12 +104,7 @@ Settings::Settings(OSystem& osystem)
|
|||
|
||||
// Config files and paths
|
||||
setInternal("romdir", "");
|
||||
setInternal("statedir", "");
|
||||
setInternal("cheatfile", "");
|
||||
setInternal("palettefile", "");
|
||||
setInternal("propsfile", "");
|
||||
setInternal("nvramdir", "");
|
||||
setInternal("cfgdir", "");
|
||||
// FIXME setInternal("basedir", "");
|
||||
|
||||
// ROM browser options
|
||||
setInternal("exitlauncher", "false");
|
||||
|
@ -547,13 +542,6 @@ void Settings::usage() const
|
|||
<< " -mwheel <lines> Number of lines the mouse wheel will scroll in\n"
|
||||
<< " UI\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"
|
||||
<< " connected\n"
|
||||
<< " -holdreset Start the emulator with the Game Reset switch\n"
|
||||
|
|
|
@ -41,11 +41,10 @@ ConfigPathDialog::ConfigPathDialog(
|
|||
const int H_GAP = 8;
|
||||
const int lineHeight = font.getLineHeight(),
|
||||
fontWidth = font.getMaxCharWidth(),
|
||||
buttonWidth = font.getStringWidth("Properties file") + 20,
|
||||
buttonWidth = font.getStringWidth("ROM Path") + 20,
|
||||
buttonHeight = font.getLineHeight() + 4;
|
||||
int xpos, ypos;
|
||||
WidgetArray wid;
|
||||
ButtonWidget* b;
|
||||
|
||||
// Set real dimensions
|
||||
setSize(64 * fontWidth + HBORDER * 2, 9 * (lineHeight + V_GAP) + VBORDER, max_w, max_h);
|
||||
|
@ -62,56 +61,6 @@ ConfigPathDialog::ConfigPathDialog(
|
|||
_w - xpos - HBORDER, lineHeight, "");
|
||||
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
|
||||
addDefaultsOKCancelBGroup(wid, font);
|
||||
|
||||
|
@ -135,22 +84,12 @@ void ConfigPathDialog::loadConfig()
|
|||
{
|
||||
const Settings& settings = instance().settings();
|
||||
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()
|
||||
{
|
||||
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
|
||||
instance().saveConfig();
|
||||
|
@ -160,31 +99,8 @@ void ConfigPathDialog::saveConfig()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void ConfigPathDialog::setDefaults()
|
||||
{
|
||||
FilesystemNode node;
|
||||
const string& basedir = instance().baseDir();
|
||||
|
||||
node = FilesystemNode("~");
|
||||
FilesystemNode node("~");
|
||||
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);
|
||||
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:
|
||||
myRomPath->setText(myBrowser->getResult().getShortPath());
|
||||
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:
|
||||
Dialog::handleCommand(sender, cmd, data, 0);
|
||||
break;
|
||||
|
|
|
@ -49,27 +49,12 @@ class ConfigPathDialog : public Dialog, public CommandSender
|
|||
private:
|
||||
enum {
|
||||
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;
|
||||
|
||||
// Config paths
|
||||
EditTextWidget* myRomPath;
|
||||
EditTextWidget* myStatePath;
|
||||
EditTextWidget* myNVRamPath;
|
||||
EditTextWidget* myCheatFile;
|
||||
EditTextWidget* myPaletteFile;
|
||||
EditTextWidget* myPropsFile;
|
||||
|
||||
unique_ptr<BrowserDialog> myBrowser;
|
||||
|
||||
|
|
Loading…
Reference in New Issue