Duplicate default config to new config files

This commit is contained in:
Charles J. Cliffe 2015-07-20 22:09:36 -04:00
parent 13139c7dbf
commit ddedc984b0
2 changed files with 20 additions and 4 deletions

View File

@ -199,11 +199,11 @@ void AppConfig::setConfigName(std::string configName) {
this->configName = configName;
}
std::string AppConfig::getConfigFileName() {
std::string AppConfig::getConfigFileName(bool ignoreName) {
std::string cfgFileDir = getConfigDir();
wxFileName cfgFile;
if (configName.length()) {
if (configName.length() && !ignoreName) {
std::string tempFn("config-");
tempFn.append(configName);
tempFn.append(".xml");
@ -261,7 +261,23 @@ bool AppConfig::load() {
wxFileName cfgFile = wxFileName(cfgFileName);
if (!cfgFile.Exists()) {
return true;
if (configName.length()) {
wxFileName baseConfig = wxFileName(getConfigFileName(true));
if (baseConfig.Exists()) {
std::string baseConfigFileName = baseConfig.GetFullPath(wxPATH_NATIVE).ToStdString();
std::cout << "Creating new configuration file '" << cfgFileName << "' by copying '" << baseConfigFileName << "'..";
wxCopyFile(baseConfigFileName, cfgFileName);
if (!cfgFile.Exists()) {
std::cout << "failed." << std::endl;
return true;
}
std::cout << "ok." << std::endl;
} else {
return true;
}
} else {
return true;
}
}
if (cfgFile.IsFileReadable()) {

View File

@ -60,7 +60,7 @@ public:
long long getSnap();
void setConfigName(std::string configName);
std::string getConfigFileName();
std::string getConfigFileName(bool ignoreName=false);
bool save();
bool load();
bool reset();