2017-02-21 11:01:06 +00:00
|
|
|
#include "LaunchConfig.hxx"
|
|
|
|
|
2018-06-25 22:06:20 +00:00
|
|
|
#include <set>
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
#include <Main/options.hxx>
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2017-07-19 18:24:33 +00:00
|
|
|
static bool static_enableDownloadDirUI = true;
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
LaunchConfig::LaunchConfig(QObject* parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchConfig::reset()
|
|
|
|
{
|
|
|
|
m_values.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchConfig::applyToOptions() const
|
|
|
|
{
|
2018-06-26 10:08:01 +00:00
|
|
|
const auto extraArgs = extraArgNames();
|
2017-02-21 11:01:06 +00:00
|
|
|
flightgear::Options* options = flightgear::Options::sharedInstance();
|
2018-06-25 22:06:20 +00:00
|
|
|
std::for_each(m_values.begin(), m_values.end(),
|
2018-06-26 10:08:01 +00:00
|
|
|
[options, &extraArgs](const Arg& arg)
|
2018-06-25 22:06:20 +00:00
|
|
|
{
|
|
|
|
const auto name = arg.arg.toStdString();
|
|
|
|
if (arg.origin == Launcher) {
|
2018-06-26 10:08:01 +00:00
|
|
|
auto it = extraArgs.find(name);
|
|
|
|
if (it != extraArgs.end()) {
|
2018-06-25 22:06:20 +00:00
|
|
|
qInfo() << "skipping arg:" << arg.arg << "=" << arg.value << "because the user has over-ridden it";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
options->addOption(name, arg.value.toStdString());
|
|
|
|
});
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 10:08:01 +00:00
|
|
|
std::set<std::string> LaunchConfig::extraArgNames() const
|
|
|
|
{
|
|
|
|
// build a set of all the extra args we have defined
|
|
|
|
std::set<std::string> r;
|
|
|
|
for (auto arg : m_values) {
|
|
|
|
// don't override prop: arguments
|
|
|
|
if (arg.arg == "prop") continue;
|
|
|
|
|
|
|
|
if (arg.origin == ExtraArgs)
|
|
|
|
r.insert(arg.arg.toStdString());
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-06-25 22:06:20 +00:00
|
|
|
void LaunchConfig::setArg(QString name, QString value, Origin origin)
|
2017-02-21 11:01:06 +00:00
|
|
|
{
|
2018-06-25 22:06:20 +00:00
|
|
|
m_values.push_back(Arg(name, value, origin));
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchConfig::setArg(const std::string &name, const std::string &value)
|
|
|
|
{
|
2018-06-25 22:06:20 +00:00
|
|
|
setArg(QString::fromStdString(name), QString::fromStdString(value), Launcher);
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 22:06:20 +00:00
|
|
|
void LaunchConfig::setProperty(QString path, QVariant value, Origin origin)
|
2017-02-21 11:01:06 +00:00
|
|
|
{
|
2018-06-25 22:06:20 +00:00
|
|
|
m_values.push_back(Arg("prop", path + "=" + value.toString(), origin));
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchConfig::setEnableDisableOption(QString name, bool value)
|
|
|
|
{
|
2018-06-25 22:06:20 +00:00
|
|
|
m_values.push_back(Arg((value ? "enable-" : "disable-") + name, "", Launcher));
|
2017-02-21 11:01:06 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
QString LaunchConfig::htmlForCommandLine()
|
|
|
|
{
|
|
|
|
QString html;
|
|
|
|
string_list commandLineOpts = flightgear::Options::sharedInstance()->extractOptions();
|
|
|
|
if (!commandLineOpts.empty()) {
|
|
|
|
html += tr("<p>Options passed on the command line:</p>\n");
|
|
|
|
html += "<ul>\n";
|
|
|
|
for (auto opt : commandLineOpts) {
|
|
|
|
html += QString("<li>--") + QString::fromStdString(opt) + "</li>\n";
|
|
|
|
}
|
|
|
|
html += "</ul>\n";
|
|
|
|
}
|
2018-06-25 22:06:20 +00:00
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
reset();
|
|
|
|
collect();
|
|
|
|
|
2018-06-26 10:08:01 +00:00
|
|
|
const auto extraArgs = extraArgNames();
|
|
|
|
|
2018-06-22 11:09:35 +00:00
|
|
|
html += tr("<p>Options set in the launcher:</p>\n");
|
|
|
|
html += "<ul>\n";
|
2018-06-25 22:06:20 +00:00
|
|
|
for (auto arg : valuesFromLauncher()) {
|
2018-06-26 10:08:01 +00:00
|
|
|
auto it = extraArgs.find(arg.arg.toStdString());
|
|
|
|
html += "<li>";
|
|
|
|
bool strikeThrough = (it != extraArgs.end());
|
|
|
|
if (strikeThrough) {
|
|
|
|
html += "<i>";
|
|
|
|
}
|
2018-06-25 22:06:20 +00:00
|
|
|
if (arg.value.isEmpty()) {
|
2018-06-26 10:08:01 +00:00
|
|
|
html += QString("--") + arg.arg;
|
2018-06-25 22:06:20 +00:00
|
|
|
} else if (arg.arg == "prop") {
|
2018-06-26 10:08:01 +00:00
|
|
|
html += QString("--") + arg.arg + ":" + arg.value;
|
2018-06-25 22:06:20 +00:00
|
|
|
} else {
|
2018-06-26 10:08:01 +00:00
|
|
|
html += QString("--") + arg.arg + "=" + arg.value;
|
2018-06-25 22:06:20 +00:00
|
|
|
}
|
2018-06-26 10:08:01 +00:00
|
|
|
if (strikeThrough) {
|
|
|
|
html += tr(" (will be skipped due to being specified as an additional argument)") + "</i> ";
|
|
|
|
}
|
|
|
|
html += "</li>\n";
|
2018-06-25 22:06:20 +00:00
|
|
|
}
|
|
|
|
html += "</ul>\n";
|
|
|
|
|
|
|
|
html += tr("<p>Options set as additional arguments:</p>\n");
|
|
|
|
html += "<ul>\n";
|
|
|
|
for (auto arg : valuesFromExtraArgs()) {
|
2018-06-22 11:09:35 +00:00
|
|
|
if (arg.value.isEmpty()) {
|
|
|
|
html += QString("<li>--") + arg.arg + "</li>\n";
|
|
|
|
} else if (arg.arg == "prop") {
|
|
|
|
html += QString("<li>--") + arg.arg + ":" + arg.value + "</li>\n";
|
|
|
|
} else {
|
|
|
|
html += QString("<li>--") + arg.arg + "=" + arg.value + "</li>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
html += "</ul>\n";
|
|
|
|
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
QVariant LaunchConfig::getValueForKey(QString group, QString key, QVariant defaultValue) const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup(group);
|
|
|
|
auto v = settings.value(key, defaultValue);
|
|
|
|
bool convertedOk = v.convert(defaultValue.type());
|
|
|
|
if (!convertedOk) {
|
|
|
|
qWarning() << "type forcing on loaded value failed:" << key << v << v.typeName() << defaultValue;
|
|
|
|
}
|
|
|
|
// qInfo() << Q_FUNC_INFO << key << "value" << v << v.typeName() << convertedOk;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchConfig::setValueForKey(QString group, QString key, QVariant var)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup(group);
|
|
|
|
// qInfo() << "saving" << key << "with value" << var << var.typeName();
|
|
|
|
settings.setValue(key, var);
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
QString LaunchConfig::defaultDownloadDir() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(flightgear::defaultDownloadDir().utf8Str());
|
|
|
|
}
|
|
|
|
|
2017-07-19 18:24:33 +00:00
|
|
|
bool LaunchConfig::enableDownloadDirUI() const
|
|
|
|
{
|
|
|
|
return static_enableDownloadDirUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LaunchConfig::setEnableDownloadDirUI(bool enableDownloadDirUI)
|
|
|
|
{
|
|
|
|
static_enableDownloadDirUI = enableDownloadDirUI;
|
|
|
|
}
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
auto LaunchConfig::values() const -> std::vector<Arg>
|
|
|
|
{
|
|
|
|
return m_values;
|
|
|
|
}
|
2018-06-25 22:06:20 +00:00
|
|
|
|
|
|
|
auto LaunchConfig::valuesFromLauncher() const -> std::vector<Arg>
|
|
|
|
{
|
|
|
|
std::vector<Arg> result;
|
|
|
|
std::copy_if(m_values.begin(), m_values.end(), std::back_inserter(result), [](const Arg& a)
|
|
|
|
{ return a.origin == Launcher; });
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto LaunchConfig::valuesFromExtraArgs() const -> std::vector<Arg>
|
|
|
|
{
|
|
|
|
std::vector<Arg> result;
|
|
|
|
std::copy_if(m_values.begin(), m_values.end(), std::back_inserter(result), [](const Arg& a)
|
|
|
|
{ return a.origin == ExtraArgs; });
|
|
|
|
return result;
|
|
|
|
}
|