Skip to content

Commit

Permalink
Merge branch 'PrismLauncher:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhelvetican authored Nov 8, 2024
2 parents ffbda07 + 1d9508c commit 12f8147
Show file tree
Hide file tree
Showing 40 changed files with 245 additions and 222 deletions.
56 changes: 48 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,56 @@

## Code formatting

Try to follow the existing formatting.
If there is no existing formatting, you may use `clang-format` with our included `.clang-format` configuration.
All files are formatted with `clang-format` using the configuration in `.clang-format`. Ensure it is run on changed files before committing!

In general, in order of importance:
We have no tool for enforcing names but please follow the following conventions for C++:
- Class and type names should be formatted as `PascalCase`: `MyClass`.
- Private or protected class data members should be formatted as `camelCase` prefixed with `m_`: `m_myCounter`.
- Private or protected `static` class data members should be formatted as `camelCase` prefixed with `s_`: `s_instance`.
- Public class data members should be formatted as `camelCase` without the prefix: `dateOfBirth`.
- Public, private or protected `static const` class data members should be formatted as `SCREAMING_SNAKE_CASE`: `MAX_VALUE`.
- Class function members should be formatted as `camelCase` without a prefix: `incrementCounter`.
- Global functions and non-`const` global variables should be formatted as `camelCase` without a prefix: `globalData`.
- `const` global variables, macros, and enum constants should be formatted as `SCREAMING_SNAKE_CASE`: `LIGHT_GRAY`.
- Avoid inventing acronyms or abbreviations especially for a name of multiple words - like `tp` for `texturePack`.

- Make sure your IDE is not messing up line endings or whitespace and avoid using linters.
- Prefer readability over dogma.
- Keep to the existing formatting.
- Indent with 4 space unless it's in a submodule.
- Keep lists (of arguments, parameters, initializers...) as lists, not paragraphs. It should either read from top to bottom, or left to right. Not both.
Here is what these conventions with the formatting configuration look like:

```c++
#define AWESOMENESS 10

constexpr double PI = 3.14159;

enum class PizzaToppings { HAM_AND_PINEAPPLE, OREO_AND_KETCHUP };

struct Person {
QString name;
QDateTime dateOfBirth;

long daysOld() const { return dateOfBirth.daysTo(QDateTime::currentDateTime()); }
};

class ImportantClass {
public:
void incrementCounter()
{
if (m_counter + 1 > MAX_COUNTER_VALUE)
throw std::runtime_error("Counter has reached limit!");

++m_counter;
}

int counter() const { return m_counter; }

private:
static constexpr int MAX_COUNTER_VALUE = 100;
int m_counter;
};

ImportantClass importantClassInstance;
```

If you see any names which do not follow these conventions, it is preferred that you leave them be - renames increase the number of changes therefore make reviewing harder and make your PR more prone to conflicts. However, if you're refactoring a whole class anyway, it's fine.

## Signing your work

Expand Down
14 changes: 7 additions & 7 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
":/icons/multimc/128x128/instances/", ":/icons/multimc/scalable/instances/" };
m_icons.reset(new IconList(instFolders, setting->get().toString()));
connect(setting.get(), &Setting::SettingChanged,
[&](const Setting&, QVariant value) { m_icons->directoryChanged(value.toString()); });
[this](const Setting&, QVariant value) { m_icons->directoryChanged(value.toString()); });
qDebug() << "<> Instance icons initialized.";
}

Expand Down Expand Up @@ -1081,11 +1081,11 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)

bool Application::createSetupWizard()
{
bool javaRequired = [&]() {
if (BuildConfig.JAVA_DOWNLOADER_ENABLED && m_settings->get("AutomaticJavaDownload").toBool()) {
bool javaRequired = [this]() {
if (BuildConfig.JAVA_DOWNLOADER_ENABLED && settings()->get("AutomaticJavaDownload").toBool()) {
return false;
}
bool ignoreJavaWizard = m_settings->get("IgnoreJavaWizard").toBool();
bool ignoreJavaWizard = settings()->get("IgnoreJavaWizard").toBool();
if (ignoreJavaWizard) {
return false;
}
Expand All @@ -1099,8 +1099,8 @@ bool Application::createSetupWizard()
QString actualPath = FS::ResolveExecutable(currentJavaPath);
return actualPath.isNull();
}();
bool askjava = BuildConfig.JAVA_DOWNLOADER_ENABLED && !javaRequired && !m_settings->get("AutomaticJavaDownload").toBool() &&
!m_settings->get("AutomaticJavaSwitch").toBool() && !m_settings->get("UserAskedAboutAutomaticJavaDownload").toBool();
bool askjava = BuildConfig.JAVA_DOWNLOADER_ENABLED && !javaRequired && !settings()->get("AutomaticJavaDownload").toBool() &&
!settings()->get("AutomaticJavaSwitch").toBool() && !settings()->get("UserAskedAboutAutomaticJavaDownload").toBool();
bool languageRequired = settings()->get("Language").toString().isEmpty();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
bool validWidgets = m_themeManager->isValidApplicationTheme(settings()->get("ApplicationTheme").toString());
Expand Down Expand Up @@ -1507,7 +1507,7 @@ void Application::controllerSucceeded()
// on success, do...
if (controller->instance()->settings()->get("AutoCloseConsole").toBool()) {
if (extras.window) {
extras.window->close();
QMetaObject::invokeMethod(extras.window, &QWidget::close, Qt::QueuedConnection);
}
}
extras.controller.reset();
Expand Down
4 changes: 2 additions & 2 deletions launcher/DataMigrationTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void DataMigrationTask::executeTask()

// 1. Scan
// Check how many files we gotta copy
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&] {
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this] {
return m_copy(true); // dry run to collect amount of files
});
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &DataMigrationTask::dryRunFinished);
Expand Down Expand Up @@ -60,7 +60,7 @@ void DataMigrationTask::dryRunFinished()
setProgress(m_copy.totalCopied(), m_toCopy);
setStatus(tr("Copying %1…").arg(shortenedName));
});
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [&] {
m_copyFuture = QtConcurrent::run(QThreadPool::globalInstance(), [this] {
return m_copy(false); // actually copy now
});
connect(&m_copyFutureWatcher, &QFutureWatcher<bool>::finished, this, &DataMigrationTask::copyFinished);
Expand Down
10 changes: 5 additions & 5 deletions launcher/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ bool copy::operator()(const QString& offset, bool dryRun)
opt |= copy_opts::overwrite_existing;

// Function that'll do the actual copying
auto copy_file = [&](QString src_path, QString relative_dst_path) {
auto copy_file = [this, dryRun, src, dst, opt, &err](QString src_path, QString relative_dst_path) {
if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist))
return;

Expand Down Expand Up @@ -428,7 +428,7 @@ void create_link::make_link_list(const QString& offset)
m_recursive = true;

// Function that'll do the actual linking
auto link_file = [&](QString src_path, QString relative_dst_path) {
auto link_file = [this, dst](QString src_path, QString relative_dst_path) {
if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist)) {
qDebug() << "path" << relative_dst_path << "in black list or not in whitelist";
return;
Expand Down Expand Up @@ -523,7 +523,7 @@ void create_link::runPrivileged(const QString& offset)

QString serverName = BuildConfig.LAUNCHER_APP_BINARY_NAME + "_filelink_server" + StringUtils::getRandomAlphaNumeric();

connect(&m_linkServer, &QLocalServer::newConnection, this, [&]() {
connect(&m_linkServer, &QLocalServer::newConnection, this, [this, &gotResults]() {
qDebug() << "Client connected, sending out pairs";
// construct block of data to send
QByteArray block;
Expand Down Expand Up @@ -605,7 +605,7 @@ void create_link::runPrivileged(const QString& offset)
}

ExternalLinkFileProcess* linkFileProcess = new ExternalLinkFileProcess(serverName, m_useHardLinks, this);
connect(linkFileProcess, &ExternalLinkFileProcess::processExited, this, [&]() { emit finishedPrivileged(gotResults); });
connect(linkFileProcess, &ExternalLinkFileProcess::processExited, this, [this, gotResults]() { emit finishedPrivileged(gotResults); });
connect(linkFileProcess, &ExternalLinkFileProcess::finished, linkFileProcess, &QObject::deleteLater);

linkFileProcess->start();
Expand Down Expand Up @@ -1295,7 +1295,7 @@ bool clone::operator()(const QString& offset, bool dryRun)
std::error_code err;

// Function that'll do the actual cloneing
auto cloneFile = [&](QString src_path, QString relative_dst_path) {
auto cloneFile = [this, dryRun, dst, &err](QString src_path, QString relative_dst_path) {
if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist))
return;

Expand Down
2 changes: 1 addition & 1 deletion launcher/InstanceCopyTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void InstanceCopyTask::executeTask()
QEventLoop loop;
bool got_priv_results = false;

connect(&folderLink, &FS::create_link::finishedPrivileged, this, [&](bool gotResults) {
connect(&folderLink, &FS::create_link::finishedPrivileged, this, [&got_priv_results, &loop](bool gotResults) {
if (!gotResults) {
qDebug() << "Privileged run exited without results!";
}
Expand Down
2 changes: 1 addition & 1 deletion launcher/InstanceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ InstanceList::InstListError InstanceList::loadList()
int front_bookmark = -1;
int back_bookmark = -1;
int currentItem = -1;
auto removeNow = [&]() {
auto removeNow = [this, &front_bookmark, &back_bookmark, &currentItem]() {
beginRemoveRows(QModelIndex(), front_bookmark, back_bookmark);
m_instances.erase(m_instances.begin() + front_bookmark, m_instances.begin() + back_bookmark + 1);
endRemoveRows();
Expand Down
2 changes: 1 addition & 1 deletion launcher/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void Version::parse()
if (m_string.isEmpty())
return;

auto classChange = [&](QChar lastChar, QChar currentChar) {
auto classChange = [&currentSection](QChar lastChar, QChar currentChar) {
if (lastChar.isNull())
return false;
if (lastChar.isDigit() != currentChar.isDigit())
Expand Down
6 changes: 3 additions & 3 deletions launcher/filelink/FileLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ void FileLinkApp::joinServer(QString server)

in.setDevice(&socket);

connect(&socket, &QLocalSocket::connected, this, [&]() { qDebug() << "connected to server"; });
connect(&socket, &QLocalSocket::connected, this, []() { qDebug() << "connected to server"; });

connect(&socket, &QLocalSocket::readyRead, this, &FileLinkApp::readPathPairs);

connect(&socket, &QLocalSocket::errorOccurred, this, [&](QLocalSocket::LocalSocketError socketError) {
connect(&socket, &QLocalSocket::errorOccurred, this, [this](QLocalSocket::LocalSocketError socketError) {
m_status = Failed;
switch (socketError) {
case QLocalSocket::ServerNotFoundError:
Expand All @@ -132,7 +132,7 @@ void FileLinkApp::joinServer(QString server)
}
});

connect(&socket, &QLocalSocket::disconnected, this, [&]() {
connect(&socket, &QLocalSocket::disconnected, this, [this]() {
qDebug() << "disconnected from server, should exit";
m_status = Succeeded;
exit();
Expand Down
8 changes: 4 additions & 4 deletions launcher/java/JavaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ QList<QString> JavaUtils::FindJavaPaths()
{
QList<QString> javas;
javas.append(this->GetDefaultJava()->path);
auto scanJavaDir = [&](
auto scanJavaDir = [&javas](
const QString& dirPath,
const std::function<bool(const QFileInfo&)>& filter = [](const QFileInfo&) { return true; }) {
QDir dir(dirPath);
Expand All @@ -424,7 +424,7 @@ QList<QString> JavaUtils::FindJavaPaths()
};
// java installed in a snap is installed in the standard directory, but underneath $SNAP
auto snap = qEnvironmentVariable("SNAP");
auto scanJavaDirs = [&](const QString& dirPath) {
auto scanJavaDirs = [scanJavaDir, snap](const QString& dirPath) {
scanJavaDir(dirPath);
if (!snap.isNull()) {
scanJavaDir(snap + dirPath);
Expand Down Expand Up @@ -546,12 +546,12 @@ QStringList getPrismJavaBundle()
{
QList<QString> javas;

auto scanDir = [&](QString prefix) {
auto scanDir = [&javas](QString prefix) {
javas.append(FS::PathCombine(prefix, "jre", "bin", JavaUtils::javaExecutable));
javas.append(FS::PathCombine(prefix, "bin", JavaUtils::javaExecutable));
javas.append(FS::PathCombine(prefix, JavaUtils::javaExecutable));
};
auto scanJavaDir = [&](const QString& dirPath) {
auto scanJavaDir = [scanDir](const QString& dirPath) {
QDir dir(dirPath);
if (!dir.exists())
return;
Expand Down
2 changes: 1 addition & 1 deletion launcher/launch/steps/PostLaunchCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void PostLaunchCommand::executeTask()

void PostLaunchCommand::on_state(LoggedProcess::State state)
{
auto getError = [&]() { return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); };
auto getError = [this]() { return tr("Post-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); };
switch (state) {
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
Expand Down
2 changes: 1 addition & 1 deletion launcher/launch/steps/PreLaunchCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void PreLaunchCommand::executeTask()

void PreLaunchCommand::on_state(LoggedProcess::State state)
{
auto getError = [&]() { return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); };
auto getError = [this]() { return tr("Pre-Launch command failed with code %1.\n\n").arg(m_process.exitCode()); };
switch (state) {
case LoggedProcess::Aborted:
case LoggedProcess::Crashed:
Expand Down
4 changes: 2 additions & 2 deletions launcher/meta/VersionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Version::Ptr VersionList::getVersion(const QString& version)

bool VersionList::hasVersion(QString version) const
{
auto ver =
std::find_if(m_versions.constBegin(), m_versions.constEnd(), [&](Meta::Version::Ptr const& a) { return a->version() == version; });
auto ver = std::find_if(m_versions.constBegin(), m_versions.constEnd(),
[version](Meta::Version::Ptr const& a) { return a->version() == version; });
return (ver != m_versions.constEnd());
}

Expand Down
8 changes: 4 additions & 4 deletions launcher/minecraft/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
{
bool local = isLocal();
// Lambda function to get the absolute file path
auto actualPath = [&](QString relPath) {
auto actualPath = [this, local, overridePath](QString relPath) {
relPath = FS::RemoveInvalidPathChars(relPath);
QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
if (local && !overridePath.isEmpty()) {
Expand Down Expand Up @@ -115,7 +115,7 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
bool local = isLocal();

// Lambda function to check if a local file exists
auto check_local_file = [&](QString storage) {
auto check_local_file = [overridePath, &failedLocalFiles](QString storage) {
QFileInfo fileinfo(storage);
QString fileName = fileinfo.fileName();
auto fullPath = FS::PathCombine(overridePath, fileName);
Expand All @@ -128,7 +128,7 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
};

// Lambda function to add a download request
auto add_download = [&](QString storage, QString url, QString sha1) {
auto add_download = [this, local, check_local_file, cache, stale, &out](QString storage, QString url, QString sha1) {
if (local) {
return check_local_file(storage);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
}
}
} else {
auto raw_dl = [&]() {
auto raw_dl = [this, raw_storage]() {
if (!m_absoluteURL.isEmpty()) {
return m_absoluteURL;
}
Expand Down
4 changes: 2 additions & 2 deletions launcher/minecraft/MinecraftInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr
out << "Libraries:";
QStringList jars, nativeJars;
profile->getLibraryFiles(runtimeContext(), jars, nativeJars, getLocalLibraryPath(), binRoot());
auto printLibFile = [&](const QString& path) {
auto printLibFile = [&out](const QString& path) {
QFileInfo info(path);
if (info.exists()) {
out << " " + path;
Expand All @@ -874,7 +874,7 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr
}

// mods and core mods
auto printModList = [&](const QString& label, ModFolderModel& model) {
auto printModList = [&out](const QString& label, ModFolderModel& model) {
if (model.size()) {
out << QString("%1:").arg(label);
auto modList = model.allMods();
Expand Down
2 changes: 1 addition & 1 deletion launcher/minecraft/OneSixVersionFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument& doc
}
}

auto readLibs = [&](const char* which, QList<LibraryPtr>& outList) {
auto readLibs = [&root, &out, &filename](const char* which, QList<LibraryPtr>& outList) {
for (auto libVal : requireArray(root.value(which))) {
QJsonObject libObj = requireObject(libVal);
// parse the library
Expand Down
2 changes: 1 addition & 1 deletion launcher/minecraft/PackProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ bool PackProfile::removeComponent_internal(ComponentPtr patch)
}

// FIXME: we need a generic way of removing local resources, not just jar mods...
auto preRemoveJarMod = [&](LibraryPtr jarMod) -> bool {
auto preRemoveJarMod = [this](LibraryPtr jarMod) -> bool {
if (!jarMod->isLocal()) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions launcher/minecraft/launch/LauncherPartLaunch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ LauncherPartLaunch::LauncherPartLaunch(LaunchTask* parent)
{
if (parent->instance()->settings()->get("CloseAfterLaunch").toBool()) {
std::shared_ptr<QMetaObject::Connection> connection{ new QMetaObject::Connection };
*connection =
connect(&m_process, &LoggedProcess::log, this, [=](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
*connection = connect(
&m_process, &LoggedProcess::log, this, [connection](const QStringList& lines, [[maybe_unused]] MessageLevel::Enum level) {
qDebug() << lines;
if (lines.filter(QRegularExpression(".*Setting user.+", QRegularExpression::CaseInsensitiveOption)).length() != 0) {
APPLICATION->closeAllWindows();
Expand Down
10 changes: 6 additions & 4 deletions launcher/minecraft/mod/ResourceFolderModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ bool ResourceFolderModel::update()
connect(m_current_update_task.get(), &Task::failed, this, &ResourceFolderModel::onUpdateFailed, Qt::ConnectionType::QueuedConnection);
connect(
m_current_update_task.get(), &Task::finished, this,
[=] {
[this] {
m_current_update_task.reset();
if (m_scheduled_update) {
m_scheduled_update = false;
Expand Down Expand Up @@ -343,12 +343,14 @@ void ResourceFolderModel::resolveResource(Resource* res)
m_active_parse_tasks.insert(ticket, task);

connect(
task.get(), &Task::succeeded, this, [=] { onParseSucceeded(ticket, res->internal_id()); }, Qt::ConnectionType::QueuedConnection);
task.get(), &Task::succeeded, this, [this, ticket, res] { onParseSucceeded(ticket, res->internal_id()); },
Qt::ConnectionType::QueuedConnection);
connect(
task.get(), &Task::failed, this, [=] { onParseFailed(ticket, res->internal_id()); }, Qt::ConnectionType::QueuedConnection);
task.get(), &Task::failed, this, [this, ticket, res] { onParseFailed(ticket, res->internal_id()); },
Qt::ConnectionType::QueuedConnection);
connect(
task.get(), &Task::finished, this,
[=] {
[this, ticket] {
m_active_parse_tasks.remove(ticket);
emit parseFinished();
},
Expand Down
Loading

0 comments on commit 12f8147

Please sign in to comment.