From 4833e4be7e55776a47169cdea926444e1cdeabe6 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 30 Jun 2022 19:26:37 +0200 Subject: add launch options to Qt frontend --- src/qt/main.cpp | 3 ++ src/qt/settings.cpp | 2 + src/qt/settings.ui | 119 +++++++++++++++++++++++++++++++++------------------- src/qt/workers.cpp | 25 ++++++++++- src/qt/workers.hpp | 5 +++ src/vdf/vdf.c | 2 +- 6 files changed, 110 insertions(+), 46 deletions(-) diff --git a/src/qt/main.cpp b/src/qt/main.cpp index 9cf530b..65a2751 100644 --- a/src/qt/main.cpp +++ b/src/qt/main.cpp @@ -4,6 +4,9 @@ int main(int argc, char *argv[]) { + QCoreApplication::setOrganizationName("OFQT"); + QCoreApplication::setApplicationName("OFQT"); + QApplication a(argc, argv); MainWindow w; w.show(); diff --git a/src/qt/settings.cpp b/src/qt/settings.cpp index 507e8c8..06d2e6f 100644 --- a/src/qt/settings.cpp +++ b/src/qt/settings.cpp @@ -23,11 +23,13 @@ void Settings::refresh() ui->revisionLabel->setText(QString("%1").arg(this->worker->getRevision())); ui->installLabel->setText(this->worker->getOfDir()); + ui->argumentsEdit->setText(this->worker->getArguments()); } void Settings::applySettings() { worker->setRemote(ui->serverEdit->text()); + worker->setArguments(ui->argumentsEdit->text()); this->hide(); } diff --git a/src/qt/settings.ui b/src/qt/settings.ui index 4fde446..9f6e972 100644 --- a/src/qt/settings.ui +++ b/src/qt/settings.ui @@ -6,8 +6,8 @@ 0 0 - 375 - 259 + 560 + 300 @@ -19,35 +19,68 @@ 0 - + + false + + + true + + - Server + Settings - + - + + + + 0 + 0 + + - Server + Launch Arguments - - - Qt::Horizontal + + + + 0 + 0 + - - - 40 - 20 - + + + + + + + + + + + 0 + 0 + - + + Server + + - + + + + 0 + 0 + + + @@ -75,29 +108,31 @@ + + + 0 + 0 + + Current Revision - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + 0 + 0 + + CURRENT_REVISION + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -106,29 +141,25 @@ + + + 0 + 0 + + Install Path - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + INSTALL_PATH + + true + diff --git a/src/qt/workers.cpp b/src/qt/workers.cpp index dc761e9..9d5dc37 100644 --- a/src/qt/workers.cpp +++ b/src/qt/workers.cpp @@ -86,6 +86,16 @@ void Worker::setRemote(QString remotestr) setLocalRemote(of_dir, remote); } +QString Worker::getArguments() +{ + return settings.value("launchArguments", QString()).toString(); +} + +void Worker::setArguments(QString argumentstr) +{ + settings.setValue("launchArguments", argumentstr); +} + int Worker::getRevision() { return getLocalRevision(of_dir); @@ -309,7 +319,20 @@ void Worker::doWork(const enum Worker::Tasks_t ¶meter) { case TASK_RUN: result = getSteamPID() > -1 ? RESULT_EXIT : RESULT_NO_STEAM; - if (result == RESULT_EXIT) runOpenFortress(NULL, 0); + if (result == RESULT_EXIT) + { + auto arg_list = getArguments().split(' ', Qt::SkipEmptyParts); + + auto argv = (char**)malloc(sizeof(char*) * arg_list.size()); + for (int i = 0; i < arg_list.size(); ++i) + argv[i] = strdup(arg_list[i].toStdString().c_str()); + + runOpenFortress(argv, arg_list.size()); + + for (int i = 0; i < arg_list.size(); ++i) + free(argv[i]); + free(argv); + } break; } diff --git a/src/qt/workers.hpp b/src/qt/workers.hpp index 82325cb..506d7ce 100644 --- a/src/qt/workers.hpp +++ b/src/qt/workers.hpp @@ -2,6 +2,7 @@ #define WORKERS_HPP #include +#include #include QT_BEGIN_NAMESPACE @@ -22,6 +23,8 @@ private: bool do_work = true; bool update_in_progress = false; + QSettings settings; + public: int progress = -1; QString infoText; @@ -32,6 +35,8 @@ public: QString getOfDir(); QString getRemote(); void setRemote(QString); + QString getArguments(); + void setArguments(QString); int getRevision(); int getRemoteRevision(); diff --git a/src/vdf/vdf.c b/src/vdf/vdf.c index fc43e8c..c9130a6 100644 --- a/src/vdf/vdf.c +++ b/src/vdf/vdf.c @@ -195,7 +195,7 @@ struct vdf_object* vdf_parse_buffer(const char* buffer, size_t size) o->type = VDF_TYPE_ARRAY; o->data.data_array.len = 0; o->data.data_array.data_value = malloc((sizeof(void*)) * (o->data.data_array.len + 1)); - o->data.data_array.data_value[o->data.data_array.len] = malloc(sizeof(struct vdf_object)), + o->data.data_array.data_value[o->data.data_array.len] = malloc(sizeof(struct vdf_object)); o->data.data_array.data_value[o->data.data_array.len]->parent = o; o = o->data.data_array.data_value[o->data.data_array.len]; -- cgit v1.2.3