1
0
Fork 0

View-command-line page marks overriden args

We mark up launcher arguments which are over-ridden
This commit is contained in:
James Turner 2018-06-26 11:08:01 +01:00
parent 5ada6d46d9
commit 31f80e2431
2 changed files with 36 additions and 16 deletions

View file

@ -22,24 +22,15 @@ void LaunchConfig::reset()
void LaunchConfig::applyToOptions() const
{
// build a set of all the extra args we have defined
std::set<std::string> extraArgNames;
for (auto arg : m_values) {
// don't override prop: arguments
if (arg.arg == "prop") continue;
if (arg.origin == ExtraArgs)
extraArgNames.insert(arg.arg.toStdString());
}
const auto extraArgs = extraArgNames();
flightgear::Options* options = flightgear::Options::sharedInstance();
std::for_each(m_values.begin(), m_values.end(),
[options, &extraArgNames](const Arg& arg)
[options, &extraArgs](const Arg& arg)
{
const auto name = arg.arg.toStdString();
if (arg.origin == Launcher) {
auto it = extraArgNames.find(name);
if (it != extraArgNames.end()) {
auto it = extraArgs.find(name);
if (it != extraArgs.end()) {
qInfo() << "skipping arg:" << arg.arg << "=" << arg.value << "because the user has over-ridden it";
return;
}
@ -48,6 +39,20 @@ void LaunchConfig::applyToOptions() const
});
}
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;
}
void LaunchConfig::setArg(QString name, QString value, Origin origin)
{
m_values.push_back(Arg(name, value, origin));
@ -84,16 +89,28 @@ QString LaunchConfig::htmlForCommandLine()
reset();
collect();
const auto extraArgs = extraArgNames();
html += tr("<p>Options set in the launcher:</p>\n");
html += "<ul>\n";
for (auto arg : valuesFromLauncher()) {
auto it = extraArgs.find(arg.arg.toStdString());
html += "<li>";
bool strikeThrough = (it != extraArgs.end());
if (strikeThrough) {
html += "<i>";
}
if (arg.value.isEmpty()) {
html += QString("<li>--") + arg.arg + "</li>\n";
html += QString("--") + arg.arg;
} else if (arg.arg == "prop") {
html += QString("<li>--") + arg.arg + ":" + arg.value + "</li>\n";
html += QString("--") + arg.arg + ":" + arg.value;
} else {
html += QString("<li>--") + arg.arg + "=" + arg.value + "</li>\n";
html += QString("--") + arg.arg + "=" + arg.value;
}
if (strikeThrough) {
html += tr(" (will be skipped due to being specified as an additional argument)") + "</i> ";
}
html += "</li>\n";
}
html += "</ul>\n";

View file

@ -1,6 +1,7 @@
#ifndef FG_GUI_LAUNCHCONFIG_HXX
#define FG_GUI_LAUNCHCONFIG_HXX
#include <set>
#include <QObject>
#include <QVariant>
@ -72,6 +73,8 @@ signals:
void collect();
private:
std::set<std::string> extraArgNames() const;
std::vector<Arg> m_values;
QString m_defaultDownloadDir;
};