Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvements to the Instance system #2107

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 53 additions & 13 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "ui/pages/global/AccountListPage.h"
#include "ui/pages/global/CustomCommandsPage.h"
#include "ui/pages/global/EnvironmentVariablesPage.h"
#include "ui/pages/global/ExternalInstancePage.h"
#include "ui/pages/global/ExternalToolsPage.h"
#include "ui/pages/global/JavaPage.h"
#include "ui/pages/global/LanguagePage.h"
Expand Down Expand Up @@ -237,7 +238,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
{ { "a", "profile" }, "Use the account specified by its profile name (only valid in combination with --launch)", "profile" },
{ "alive", "Write a small '" + liveCheckFile + "' file after the launcher starts" },
{ { "I", "import" }, "Import instance or resource from specified local path or URL", "url" },
{ "show", "Opens the window for the specified instance (by instance ID)", "show" } });
{ "show", "Opens the window for the specified instance (by instance ID)", "show" },
{ "settings", "Override the configuration entry in the configuration file. Usage:--settings key1=value1&key2=value2...",
"settings" } });
// Has to be positional for some OS to handle that properly
parser.addPositionalArgument("URL", "Import the resource(s) at the given URL(s) (same as -I / --import)", "[URL...]");

Expand All @@ -253,6 +256,19 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)

m_instanceIdToShowWindowOf = parser.value("show");

for (const auto& setting1 : parser.values("settings")) {
for (const auto& setting2 : setting1.split("&")) {
auto index = setting2.indexOf('=');
if (index != -1) {
QString key = setting2.left(index);
QString value = setting2.right(setting2.length() - index - 1);
m_settingsOverride.append(QPair<QString, QString>(key, value));
} else {
std::cerr << "Error format, please provide as key=value." << std::endl;
}
}
}

for (auto url : parser.values("import")) {
m_urlsToImport.append(normalizeImportUrl(url));
}
Expand Down Expand Up @@ -297,23 +313,30 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
adjustedBy = "Command line";
dataPath = dirParam;
} else {
QDir foo;
if (DesktopServices::isSnap()) {
foo = QDir(getenv("SNAP_USER_COMMON"));
auto varName = (BuildConfig.LAUNCHER_NAME.toUpper() + "_COMMON_DIR");
auto env = QString(qEnvironmentVariable(varName.toUtf8().constData()));
if (!env.isEmpty() && FS::ensureFolderPathExists(env)) {
dataPath = QDir(env).absolutePath();
adjustedBy = "Environment variable" + varName;
} else {
foo = QDir(FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), ".."));
}
QDir foo;
if (DesktopServices::isSnap()) {
foo = QDir(getenv("SNAP_USER_COMMON"));
} else {
foo = QDir(FS::PathCombine(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), ".."));
}

dataPath = foo.absolutePath();
adjustedBy = "Persistent data path";
dataPath = foo.absolutePath();
adjustedBy = "Persistent data path";

#ifndef Q_OS_MACOS
if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) {
dataPath = m_rootPath;
adjustedBy = "Portable data path";
m_portable = true;
}
if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) {
dataPath = m_rootPath;
adjustedBy = "Portable data path";
m_portable = true;
}
#endif
}
}

if (!FS::ensureFolderPathExists(dataPath)) {
Expand Down Expand Up @@ -754,10 +777,27 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
// FTBApp instances
m_settings->registerSetting("FTBAppInstancesPath", "");

// The command line sets the override
{
for (auto& setting1 : m_settingsOverride) {
if (m_settings->contains(setting1.first)) {
auto setting2 = m_settings->get(setting1.first);
if (setting2.isValid()) {
qDebug() << "The <> of setting option has an override option from the command line, <> -> <>" << setting1.first
<< setting2 << setting1.second;
m_settings->registerConstant(setting1.first, setting1.second);
} else {
qDebug() << "The <> of setting option does not exist. skip." << setting1.first;
}
}
}
}

// Init page provider
{
m_globalSettingsProvider = std::make_shared<GenericPageProvider>(tr("Settings"));
m_globalSettingsProvider->addPage<LauncherPage>();
m_globalSettingsProvider->addPage<ExternalInstancePage>();
m_globalSettingsProvider->addPage<MinecraftPage>();
m_globalSettingsProvider->addPage<JavaPage>();
m_globalSettingsProvider->addPage<LanguagePage>();
Expand Down
1 change: 1 addition & 0 deletions launcher/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class Application : public QApplication {
QString m_profileToUse;
bool m_liveCheck = false;
QList<QUrl> m_urlsToImport;
QList<QPair<QString, QString>> m_settingsOverride;
QString m_instanceIdToShowWindowOf;
std::unique_ptr<QFile> logFile;
};
5 changes: 5 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ set(SETTINGS_SOURCES
settings/OverrideSetting.h
settings/PassthroughSetting.cpp
settings/PassthroughSetting.h
settings/ConstantSetting.cpp
settings/ConstantSetting.h
settings/Setting.cpp
settings/Setting.h
settings/SettingsObject.cpp
Expand Down Expand Up @@ -887,6 +889,8 @@ SET(LAUNCHER_SOURCES
# GUI - global settings pages
ui/pages/global/AccountListPage.cpp
ui/pages/global/AccountListPage.h
ui/pages/global/ExternalInstancePage.cpp
ui/pages/global/ExternalInstancePage.h
ui/pages/global/CustomCommandsPage.cpp
ui/pages/global/CustomCommandsPage.h
ui/pages/global/EnvironmentVariablesPage.cpp
Expand Down Expand Up @@ -1124,6 +1128,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/setupwizard/PasteWizardPage.ui
ui/setupwizard/ThemeWizardPage.ui
ui/pages/global/AccountListPage.ui
ui/pages/global/ExternalInstancePage.ui
ui/pages/global/JavaPage.ui
ui/pages/global/LauncherPage.ui
ui/pages/global/APIPage.ui
Expand Down