mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 16:41:02 +02:00
Merge pull request #15594 from huffman/feat/appconfig
DEV-54: Add support for application config
This commit is contained in:
commit
8d36b90b8b
1 changed files with 45 additions and 0 deletions
|
@ -75,6 +75,7 @@ int main(int argc, const char* argv[]) {
|
||||||
QCommandLineOption helpOption = parser.addHelpOption();
|
QCommandLineOption helpOption = parser.addHelpOption();
|
||||||
|
|
||||||
QCommandLineOption urlOption("url", "", "value");
|
QCommandLineOption urlOption("url", "", "value");
|
||||||
|
QCommandLineOption noLauncherOption("no-launcher", "Do not execute the launcher");
|
||||||
QCommandLineOption noUpdaterOption("no-updater", "Do not show auto-updater");
|
QCommandLineOption noUpdaterOption("no-updater", "Do not show auto-updater");
|
||||||
QCommandLineOption checkMinSpecOption("checkMinSpec", "Check if machine meets minimum specifications");
|
QCommandLineOption checkMinSpecOption("checkMinSpec", "Check if machine meets minimum specifications");
|
||||||
QCommandLineOption runServerOption("runServer", "Whether to run the server");
|
QCommandLineOption runServerOption("runServer", "Whether to run the server");
|
||||||
|
@ -84,6 +85,7 @@ int main(int argc, const char* argv[]) {
|
||||||
QCommandLineOption overrideScriptsPathOption(SCRIPTS_SWITCH, "set scripts <path>", "path");
|
QCommandLineOption overrideScriptsPathOption(SCRIPTS_SWITCH, "set scripts <path>", "path");
|
||||||
|
|
||||||
parser.addOption(urlOption);
|
parser.addOption(urlOption);
|
||||||
|
parser.addOption(noLauncherOption);
|
||||||
parser.addOption(noUpdaterOption);
|
parser.addOption(noUpdaterOption);
|
||||||
parser.addOption(checkMinSpecOption);
|
parser.addOption(checkMinSpecOption);
|
||||||
parser.addOption(runServerOption);
|
parser.addOption(runServerOption);
|
||||||
|
@ -106,6 +108,49 @@ int main(int argc, const char* argv[]) {
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString applicationPath;
|
||||||
|
{
|
||||||
|
// A temporary application instance is needed to get the location of the running executable
|
||||||
|
// Tests using high_resolution_clock show that this takes about 30-50 microseconds (on my machine, YMMV)
|
||||||
|
// If we wanted to avoid the QCoreApplication, we would need to write our own
|
||||||
|
// cross-platform implementation.
|
||||||
|
QCoreApplication tempApp(argc, const_cast<char**>(argv));
|
||||||
|
applicationPath = QCoreApplication::applicationDirPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const QString APPLICATION_CONFIG_FILENAME = "config.json";
|
||||||
|
QDir applicationDir(applicationPath);
|
||||||
|
QFile configFile(applicationDir.filePath(APPLICATION_CONFIG_FILENAME));
|
||||||
|
|
||||||
|
if (configFile.exists()) {
|
||||||
|
if (!configFile.open(QIODevice::ReadOnly)) {
|
||||||
|
qWarning() << "Found application config, but could not open it";
|
||||||
|
} else {
|
||||||
|
auto contents = configFile.readAll();
|
||||||
|
QJsonParseError error;
|
||||||
|
|
||||||
|
auto doc = QJsonDocument::fromJson(contents, &error);
|
||||||
|
if (error.error) {
|
||||||
|
qWarning() << "Found application config, but could not parse it: " << error.errorString();
|
||||||
|
} else {
|
||||||
|
static const QString LAUNCHER_PATH_KEY = "launcherPath";
|
||||||
|
QString launcherPath = doc.object()[LAUNCHER_PATH_KEY].toString();
|
||||||
|
if (!launcherPath.isEmpty()) {
|
||||||
|
if (!parser.isSet(noLauncherOption)) {
|
||||||
|
qDebug() << "Found a launcherPath in application config. Starting launcher.";
|
||||||
|
QProcess launcher;
|
||||||
|
launcher.setProgram(launcherPath);
|
||||||
|
launcher.startDetached();
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Found a launcherPath in application config, but the launcher"
|
||||||
|
" has been suppressed. Continuing normal execution.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Early check for --traceFile argument
|
// Early check for --traceFile argument
|
||||||
auto tracer = DependencyManager::set<tracing::Tracer>();
|
auto tracer = DependencyManager::set<tracing::Tracer>();
|
||||||
const char * traceFile = nullptr;
|
const char * traceFile = nullptr;
|
||||||
|
|
Loading…
Reference in a new issue