aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-01-03 22:29:17 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-01-03 22:29:17 +0100
commit1e57c2b3f6bd2a4f1756150e669eedffc29cf13d (patch)
tree01f22e47b85e556cd4fae4431f578f9c38bb12ca /src/main.cpp
parentUpdated PKGBUILD (diff)
downloadsmolbote-1e57c2b3f6bd2a4f1756150e669eedffc29cf13d.tar.xz
Fixed crash with Settings dialog
- User Configuration gets completely written, instead of being just overrides
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp61
1 files changed, 33 insertions, 28 deletions
diff --git a/src/main.cpp b/src/main.cpp
index ffb7a4d..fb9eeba 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,7 +22,7 @@
#endif
// read config into std::string, supports qrc
-inline std::string readConfig(QString path)
+inline std::string readConfig(const QString &path)
{
QFile conf(path);
std::string ret;
@@ -33,7 +33,7 @@ inline std::string readConfig(QString path)
return ret;
}
-bool writeUserConfig(const std::string &path, Configuration &config)
+void bootstrapUserConfig(const std::string &path, Configuration &config)
{
// set firstRun to false so we don't re-init on every run
config.setValue<bool>("browser.firstRun", false);
@@ -56,8 +56,6 @@ bool writeUserConfig(const std::string &path, Configuration &config)
// downloads.path
std::string downloadsPath = config.value<std::string>("downloads.path").value();
config.setValue<std::string>("downloads.path", patchHome(downloadsPath, home.toStdString()));
-
- return config.writeUserConfiguration(path);
}
int main(int argc, char *argv[])
@@ -116,6 +114,8 @@ int main(int argc, char *argv[])
#ifdef QT_DEBUG
qDebug("config=%s", qUtf8Printable(parser.value(configOption)));
qDebug("default-config=%s", qUtf8Printable(parser.value(defaultConfigOption)));
+ qDebug("socket=%s", qUtf8Printable(parser.value(socketOption)));
+ qDebug("profile=%s", qUtf8Printable(parser.value(profileOption)));
#endif
if(parser.isSet(printDefaultConfigOption)) {
@@ -124,50 +124,55 @@ int main(int argc, char *argv[])
return 0;
}
- // TODO: check for other instances
- // if we socket hasn't been disabled (socket is not none)
- if(parser.value(socketOption) != "none") {
- bool bindOk = instance.bindLocalSocket(parser.value(socketOption));
- if(bindOk) {
- qDebug("Connected to local socket: %s", qUtf8Printable(instance.serverName()));
- } else {
- // pass arguments to new instance
- return instance.sendMessage(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());
- }
- }
-
std::shared_ptr<Configuration> config = std::make_shared<Configuration>();
- config->readDefaultConfiguration(readConfig(parser.value(defaultConfigOption)));
config->readUserConfiguration(parser.value(configOption).toStdString());
+ config->parseDefaultConfiguration(readConfig(parser.value(defaultConfigOption)));
// check if first run
- if(config->value<bool>("browser.firstRun").value() || parser.isSet(generateUserConfigOption)) {
+ if(config->value<bool>("browser.firstRun").value_or(true) || parser.isSet(generateUserConfigOption)) {
// create a user config file
+
QString path = parser.value(configOption);
- // there may be no smolbote.cfg
+ // make sure we have a path
if(path.isEmpty()) {
path = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/smolbote.cfg";
}
-
+ // make sure the directory exists
QDir configDir = QFileInfo(path).absoluteDir();
if(!configDir.exists()) {
- bool mkpathSuccess = configDir.mkpath(".");
-#ifdef QT_DEBUG
- qDebug("mkpath %s: %s", qUtf8Printable(configDir.absolutePath()), mkpathSuccess ? "ok" : "failed");
-#endif
+ configDir.mkpath(".");
}
-#ifdef QT_DEBUG
- qDebug("Generating user config on first run to %s", qUtf8Printable(path));
-#endif
+ // remove any existing config
+ if(QFile::exists(path)) {
+ QFile::remove(path);
+ }
+
+ config->parse(readConfig(parser.value(defaultConfigOption)));
- qDebug("Saving config to: %s - %s", qUtf8Printable(path), writeUserConfig(path.toStdString(), *config) ? "ok" : "failed");
+ // patch paths
+ bootstrapUserConfig(path.toStdString(), *config);
+ std::cout << "Generating config to: " << qUtf8Printable(path) << (config->writeUserConfiguration(path.toStdString()) ? " ok" : " failed") << std::endl;
+
+ // exit if this is the only thing we needed to do
if(parser.isSet(generateUserConfigOption)) {
return 0;
}
}
+ // check for other instances
+ // if we socket hasn't been disabled (socket is not none)
+ if(parser.value(socketOption) != "none") {
+ bool bindOk = instance.bindLocalSocket(parser.value(socketOption));
+ if(bindOk) {
+ qDebug("Connected to local socket: %s", qUtf8Printable(instance.serverName()));
+ } else {
+ // pass arguments to new instance
+ return instance.sendMessage(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());
+ }
+ }
+
instance.setConfiguration(config);
instance.createSession(parser.value(profileOption), parser.isSet(newWindowOption), parser.positionalArguments());