From 91ba4cf75ee30c64779edb5b7644e5a830de5026 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 14 Aug 2023 18:16:53 +0200 Subject: chore: reformat Signed-off-by: Sefa Eyeoglu --- launcher/minecraft/Agent.h | 19 +- launcher/minecraft/AssetsUtils.cpp | 119 ++---- launcher/minecraft/AssetsUtils.h | 17 +- launcher/minecraft/Component.cpp | 192 ++++----- launcher/minecraft/Component.h | 47 ++- launcher/minecraft/ComponentUpdateTask.cpp | 406 +++++++------------ launcher/minecraft/ComponentUpdateTask.h | 27 +- launcher/minecraft/ComponentUpdateTask_p.h | 19 +- launcher/minecraft/GradleSpecifier.h | 108 ++---- launcher/minecraft/LaunchProfile.cpp | 126 +++--- launcher/minecraft/LaunchProfile.h | 62 ++- launcher/minecraft/Library.cpp | 187 ++++----- launcher/minecraft/Library.h | 130 ++----- launcher/minecraft/MinecraftInstance.cpp | 331 ++++++---------- launcher/minecraft/MinecraftInstance.h | 31 +- launcher/minecraft/MinecraftLoadAndCheck.cpp | 15 +- launcher/minecraft/MinecraftLoadAndCheck.h | 20 +- launcher/minecraft/MinecraftUpdate.cpp | 59 +-- launcher/minecraft/MinecraftUpdate.h | 24 +- launcher/minecraft/MojangDownloadInfo.h | 34 +- launcher/minecraft/MojangVersionFormat.cpp | 218 ++++------- launcher/minecraft/MojangVersionFormat.h | 23 +- launcher/minecraft/OneSixVersionFormat.cpp | 233 ++++------- launcher/minecraft/OneSixVersionFormat.h | 32 +- launcher/minecraft/PackProfile.cpp | 427 ++++++++------------ launcher/minecraft/PackProfile.h | 66 ++-- launcher/minecraft/PackProfile_p.h | 12 +- launcher/minecraft/ParseUtils.cpp | 6 +- launcher/minecraft/ParseUtils.h | 2 +- launcher/minecraft/ProfileUtils.cpp | 88 ++--- launcher/minecraft/ProfileUtils.h | 14 +- launcher/minecraft/Rule.cpp | 14 +- launcher/minecraft/Rule.h | 71 ++-- launcher/minecraft/VanillaInstanceCreationTask.cpp | 8 +- launcher/minecraft/VersionFile.cpp | 20 +- launcher/minecraft/VersionFile.h | 27 +- launcher/minecraft/VersionFilterData.cpp | 65 ++-- launcher/minecraft/VersionFilterData.h | 10 +- launcher/minecraft/World.cpp | 280 ++++++-------- launcher/minecraft/World.h | 97 ++--- launcher/minecraft/WorldList.cpp | 344 ++++++++--------- launcher/minecraft/WorldList.h | 97 ++--- launcher/minecraft/auth/AccountData.cpp | 207 +++++----- launcher/minecraft/auth/AccountData.h | 23 +- launcher/minecraft/auth/AccountList.cpp | 428 ++++++++++----------- launcher/minecraft/auth/AccountList.h | 54 ++- launcher/minecraft/auth/AccountTask.cpp | 52 ++- launcher/minecraft/auth/AccountTask.h | 43 +-- launcher/minecraft/auth/AuthRequest.cpp | 53 +-- launcher/minecraft/auth/AuthRequest.h | 39 +- launcher/minecraft/auth/AuthSession.cpp | 9 +- launcher/minecraft/auth/AuthSession.h | 10 +- launcher/minecraft/auth/AuthStep.cpp | 4 +- launcher/minecraft/auth/AuthStep.h | 20 +- launcher/minecraft/auth/MinecraftAccount.cpp | 144 ++++--- launcher/minecraft/auth/MinecraftAccount.h | 118 ++---- launcher/minecraft/auth/Parsers.cpp | 192 ++++----- launcher/minecraft/auth/Parsers.h | 27 +- launcher/minecraft/auth/Yggdrasil.cpp | 162 ++++---- launcher/minecraft/auth/Yggdrasil.h | 38 +- launcher/minecraft/auth/flows/AuthFlow.cpp | 44 +-- launcher/minecraft/auth/flows/AuthFlow.h | 29 +- launcher/minecraft/auth/flows/MSA.cpp | 19 +- launcher/minecraft/auth/flows/MSA.h | 20 +- launcher/minecraft/auth/flows/Mojang.cpp | 19 +- launcher/minecraft/auth/flows/Mojang.h | 23 +- launcher/minecraft/auth/flows/Offline.cpp | 12 +- launcher/minecraft/auth/flows/Offline.h | 20 +- launcher/minecraft/auth/steps/EntitlementsStep.cpp | 23 +- launcher/minecraft/auth/steps/EntitlementsStep.h | 9 +- launcher/minecraft/auth/steps/GetSkinStep.cpp | 24 +- launcher/minecraft/auth/steps/GetSkinStep.h | 7 +- .../minecraft/auth/steps/LauncherLoginStep.cpp | 44 +-- launcher/minecraft/auth/steps/LauncherLoginStep.h | 7 +- launcher/minecraft/auth/steps/MSAStep.cpp | 25 +- launcher/minecraft/auth/steps/MSAStep.h | 18 +- .../auth/steps/MigrationEligibilityStep.cpp | 26 +- .../auth/steps/MigrationEligibilityStep.h | 7 +- .../minecraft/auth/steps/MinecraftProfileStep.cpp | 61 ++- .../minecraft/auth/steps/MinecraftProfileStep.h | 7 +- .../auth/steps/MinecraftProfileStepMojang.cpp | 63 ++- .../auth/steps/MinecraftProfileStepMojang.h | 7 +- launcher/minecraft/auth/steps/OfflineStep.cpp | 9 +- launcher/minecraft/auth/steps/OfflineStep.h | 4 +- .../minecraft/auth/steps/XboxAuthorizationStep.cpp | 132 +++---- .../minecraft/auth/steps/XboxAuthorizationStep.h | 19 +- launcher/minecraft/auth/steps/XboxProfileStep.cpp | 54 ++- launcher/minecraft/auth/steps/XboxProfileStep.h | 7 +- launcher/minecraft/auth/steps/XboxUserStep.cpp | 41 +- launcher/minecraft/auth/steps/XboxUserStep.h | 7 +- launcher/minecraft/auth/steps/YggdrasilStep.cpp | 25 +- launcher/minecraft/auth/steps/YggdrasilStep.h | 10 +- launcher/minecraft/gameoptions/GameOptions.cpp | 65 ++-- launcher/minecraft/gameoptions/GameOptions.h | 20 +- launcher/minecraft/launch/ClaimAccount.cpp | 8 +- launcher/minecraft/launch/ClaimAccount.h | 17 +- launcher/minecraft/launch/CreateGameFolders.cpp | 14 +- launcher/minecraft/launch/CreateGameFolders.h | 18 +- launcher/minecraft/launch/ExtractNatives.cpp | 46 +-- launcher/minecraft/launch/ExtractNatives.h | 14 +- launcher/minecraft/launch/LauncherPartLaunch.cpp | 104 ++--- launcher/minecraft/launch/LauncherPartLaunch.h | 36 +- .../minecraft/launch/MinecraftServerTarget.cpp | 31 +- launcher/minecraft/launch/MinecraftServerTarget.h | 2 +- launcher/minecraft/launch/ModMinecraftJar.cpp | 25 +- launcher/minecraft/launch/ModMinecraftJar.h | 15 +- launcher/minecraft/launch/PrintInstanceInfo.cpp | 79 ++-- launcher/minecraft/launch/PrintInstanceInfo.h | 18 +- launcher/minecraft/launch/ReconstructAssets.cpp | 7 +- launcher/minecraft/launch/ReconstructAssets.h | 12 +- launcher/minecraft/launch/ScanModFolders.cpp | 12 +- launcher/minecraft/launch/ScanModFolders.h | 19 +- launcher/minecraft/launch/VerifyJavaInstall.cpp | 22 +- launcher/minecraft/launch/VerifyJavaInstall.h | 9 +- launcher/minecraft/mod/DataPack.cpp | 8 +- launcher/minecraft/mod/MetadataHandler.h | 55 +-- launcher/minecraft/mod/Mod.cpp | 81 ++-- launcher/minecraft/mod/Mod.h | 96 +++-- launcher/minecraft/mod/ModDetails.h | 106 +++-- launcher/minecraft/mod/ModFolderModel.cpp | 253 ++++++------ launcher/minecraft/mod/ModFolderModel.h | 107 +++--- launcher/minecraft/mod/Resource.cpp | 8 +- launcher/minecraft/mod/Resource.h | 21 +- launcher/minecraft/mod/ResourceFolderModel.cpp | 24 +- launcher/minecraft/mod/ResourceFolderModel.h | 21 +- launcher/minecraft/mod/ResourcePack.cpp | 2 +- launcher/minecraft/mod/ResourcePackFolderModel.cpp | 23 +- launcher/minecraft/mod/ResourcePackFolderModel.h | 23 +- launcher/minecraft/mod/ShaderPackFolderModel.h | 6 +- launcher/minecraft/mod/TexturePack.cpp | 2 +- launcher/minecraft/mod/TexturePackFolderModel.cpp | 26 +- launcher/minecraft/mod/TexturePackFolderModel.h | 23 +- launcher/minecraft/mod/tasks/BasicFolderLoadTask.h | 12 +- launcher/minecraft/mod/tasks/LocalModParseTask.cpp | 24 +- launcher/minecraft/mod/tasks/LocalModUpdateTask.h | 30 +- .../mod/tasks/LocalResourcePackParseTask.cpp | 8 +- .../minecraft/mod/tasks/LocalResourceParse.cpp | 29 +- .../mod/tasks/LocalTexturePackParseTask.cpp | 11 +- .../mod/tasks/LocalWorldSaveParseTask.cpp | 8 +- .../minecraft/mod/tasks/LocalWorldSaveParseTask.h | 2 +- launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp | 77 ++-- launcher/minecraft/mod/tasks/ModFolderLoadTask.h | 82 ++-- launcher/minecraft/services/CapeChange.cpp | 30 +- launcher/minecraft/services/CapeChange.h | 20 +- launcher/minecraft/services/SkinDelete.cpp | 15 +- launcher/minecraft/services/SkinDelete.h | 13 +- launcher/minecraft/services/SkinUpload.cpp | 19 +- launcher/minecraft/services/SkinUpload.h | 20 +- launcher/minecraft/update/AssetUpdateTask.cpp | 30 +- launcher/minecraft/update/AssetUpdateTask.h | 17 +- launcher/minecraft/update/FMLLibrariesTask.cpp | 53 +-- launcher/minecraft/update/FMLLibrariesTask.h | 22 +- launcher/minecraft/update/FoldersTask.cpp | 8 +- launcher/minecraft/update/FoldersTask.h | 15 +- launcher/minecraft/update/LibrariesTask.cpp | 35 +- launcher/minecraft/update/LibrariesTask.h | 19 +- 156 files changed, 3546 insertions(+), 5103 deletions(-) (limited to 'launcher/minecraft') diff --git a/launcher/minecraft/Agent.h b/launcher/minecraft/Agent.h index 374e6e94..8958521e 100644 --- a/launcher/minecraft/Agent.h +++ b/launcher/minecraft/Agent.h @@ -9,28 +9,21 @@ class Agent; typedef std::shared_ptr AgentPtr; class Agent { -public: - Agent(LibraryPtr library, const QString &argument) + public: + Agent(LibraryPtr library, const QString& argument) { m_library = library; m_argument = argument; } -public: /* methods */ - - LibraryPtr library() { - return m_library; - } - QString argument() { - return m_argument; - } - -protected: /* data */ + public: /* methods */ + LibraryPtr library() { return m_library; } + QString argument() { return m_argument; } + protected: /* data */ /// The library pointing to the jar this Java agent is contained within LibraryPtr m_library; /// The argument to the Java agent, passed after an = if present QString m_argument; - }; diff --git a/launcher/minecraft/AssetsUtils.cpp b/launcher/minecraft/AssetsUtils.cpp index 65ad6da6..21c3007e 100644 --- a/launcher/minecraft/AssetsUtils.cpp +++ b/launcher/minecraft/AssetsUtils.cpp @@ -33,21 +33,21 @@ * limitations under the License. */ -#include +#include +#include #include #include -#include -#include +#include #include #include +#include #include -#include #include "AssetsUtils.h" +#include "BuildConfig.h" #include "FileSystem.h" #include "net/ApiDownload.h" #include "net/ChecksumValidator.h" -#include "BuildConfig.h" #include "Application.h" @@ -56,37 +56,32 @@ QSet collectPathsFromDir(QString dirPath) { QFileInfo dirInfo(dirPath); - if (!dirInfo.exists()) - { + if (!dirInfo.exists()) { return {}; } QSet out; QDirIterator iter(dirPath, QDirIterator::Subdirectories); - while (iter.hasNext()) - { + while (iter.hasNext()) { QString value = iter.next(); QFileInfo info(value); - if(info.isFile()) - { + if (info.isFile()) { out.insert(value); qDebug() << value; } } return out; } -} +} // namespace - -namespace AssetsUtils -{ +namespace AssetsUtils { /* * Returns true on success, with index populated * index is undefined otherwise */ -bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsIndex& index) +bool loadAssetsIndexJson(const QString& assetsId, const QString& path, AssetsIndex& index) { /* { @@ -105,8 +100,7 @@ bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsInd // Try to open the file and fail if we can't. // TODO: We should probably report this error to the user. - if (!file.open(QIODevice::ReadOnly)) - { + if (!file.open(QIODevice::ReadOnly)) { qCritical() << "Failed to read assets index file" << path; return false; } @@ -120,16 +114,14 @@ bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsInd QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parseError); // Fail if the JSON is invalid. - if (parseError.error != QJsonParseError::NoError) - { - qCritical() << "Failed to parse assets index file:" << parseError.errorString() - << "at offset " << QString::number(parseError.offset); + if (parseError.error != QJsonParseError::NoError) { + qCritical() << "Failed to parse assets index file:" << parseError.errorString() << "at offset " + << QString::number(parseError.offset); return false; } // Make sure the root is an object. - if (!jsonDoc.isObject()) - { + if (!jsonDoc.isObject()) { qCritical() << "Invalid assets index JSON: Root should be an array."; return false; } @@ -137,22 +129,19 @@ bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsInd QJsonObject root = jsonDoc.object(); QJsonValue isVirtual = root.value("virtual"); - if (!isVirtual.isUndefined()) - { + if (!isVirtual.isUndefined()) { index.isVirtual = isVirtual.toBool(false); } QJsonValue mapToResources = root.value("map_to_resources"); - if (!mapToResources.isUndefined()) - { + if (!mapToResources.isUndefined()) { index.mapToResources = mapToResources.toBool(false); } QJsonValue objects = root.value("objects"); QVariantMap map = objects.toVariant().toMap(); - for (QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) - { + for (QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter) { // qDebug() << iter.key(); QVariant variant = iter.value(); @@ -160,19 +149,14 @@ bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsInd AssetObject object; - for (QVariantMap::const_iterator nested_iter = nested_objects.begin(); - nested_iter != nested_objects.end(); ++nested_iter) - { + for (QVariantMap::const_iterator nested_iter = nested_objects.begin(); nested_iter != nested_objects.end(); ++nested_iter) { // qDebug() << nested_iter.key() << nested_iter.value().toString(); QString key = nested_iter.key(); QVariant value = nested_iter.value(); - if (key == "hash") - { + if (key == "hash") { object.hash = value.toString(); - } - else if (key == "size") - { + } else if (key == "size") { object.size = value.toDouble(); } } @@ -184,7 +168,7 @@ bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsInd } // FIXME: ugly code duplication -QDir getAssetsDir(const QString &assetsId, const QString &resourcesFolder) +QDir getAssetsDir(const QString& assetsId, const QString& resourcesFolder) { QDir assetsDir = QDir("assets/"); QDir indexDir = QDir(FS::PathCombine(assetsDir.path(), "indexes")); @@ -195,26 +179,21 @@ QDir getAssetsDir(const QString &assetsId, const QString &resourcesFolder) QFile indexFile(indexPath); QDir virtualRoot(FS::PathCombine(virtualDir.path(), assetsId)); - if (!indexFile.exists()) - { + if (!indexFile.exists()) { qCritical() << "No assets index file" << indexPath << "; can't determine assets path!"; return virtualRoot; } AssetsIndex index; - if(!AssetsUtils::loadAssetsIndexJson(assetsId, indexPath, index)) - { + if (!AssetsUtils::loadAssetsIndexJson(assetsId, indexPath, index)) { qCritical() << "Failed to load asset index file" << indexPath << "; can't determine assets path!"; return virtualRoot; } QString targetPath; - if(index.isVirtual) - { + if (index.isVirtual) { return virtualRoot; - } - else if(index.mapToResources) - { + } else if (index.mapToResources) { return QDir(resourcesFolder); } return virtualRoot; @@ -232,8 +211,7 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder) QFile indexFile(indexPath); QDir virtualRoot(FS::PathCombine(virtualDir.path(), assetsId)); - if (!indexFile.exists()) - { + if (!indexFile.exists()) { qCritical() << "No assets index file" << indexPath << "; can't reconstruct assets!"; return false; } @@ -241,31 +219,25 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder) qDebug() << "reconstructAssets" << assetsDir.path() << indexDir.path() << objectDir.path() << virtualDir.path() << virtualRoot.path(); AssetsIndex index; - if(!AssetsUtils::loadAssetsIndexJson(assetsId, indexPath, index)) - { + if (!AssetsUtils::loadAssetsIndexJson(assetsId, indexPath, index)) { qCritical() << "Failed to load asset index file" << indexPath << "; can't reconstruct assets!"; return false; } QString targetPath; bool removeLeftovers = false; - if(index.isVirtual) - { + if (index.isVirtual) { targetPath = virtualRoot.path(); removeLeftovers = true; qDebug() << "Reconstructing virtual assets folder at" << targetPath; - } - else if(index.mapToResources) - { + } else if (index.mapToResources) { targetPath = resourcesFolder; qDebug() << "Reconstructing resources folder at" << targetPath; } - if (!targetPath.isNull()) - { + if (!targetPath.isNull()) { auto presentFiles = collectPathsFromDir(targetPath); - for (QString map : index.objects.keys()) - { + for (QString map : index.objects.keys()) { AssetObject asset_object = index.objects.value(map); QString target_path = FS::PathCombine(targetPath, map); QFile target(target_path); @@ -279,8 +251,7 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder) presentFiles.remove(target_path); - if (!target.exists()) - { + if (!target.exists()) { QFileInfo info(target_path); QDir target_dir = info.dir(); @@ -293,10 +264,8 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder) } // TODO: Write last used time to virtualRoot/.lastused - if(removeLeftovers) - { - for(auto & file: presentFiles) - { + if (removeLeftovers) { + for (auto& file : presentFiles) { qDebug() << "Would remove" << file; } } @@ -304,16 +273,14 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder) return true; } -} +} // namespace AssetsUtils NetAction::Ptr AssetObject::getDownloadAction() { QFileInfo objectFile(getLocalPath()); - if ((!objectFile.isFile()) || (objectFile.size() != size)) - { + if ((!objectFile.isFile()) || (objectFile.size() != size)) { auto objectDL = Net::ApiDownload::makeFile(getUrl(), objectFile.filePath()); - if(hash.size()) - { + if (hash.size()) { auto rawHash = QByteArray::fromHex(hash.toLatin1()); objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash)); } @@ -341,15 +308,13 @@ QString AssetObject::getRelPath() NetJob::Ptr AssetsIndex::getDownloadJob() { auto job = makeShared(QObject::tr("Assets for %1").arg(id), APPLICATION->network()); - for (auto &object : objects.values()) - { + for (auto& object : objects.values()) { auto dl = object.getDownloadAction(); - if(dl) - { + if (dl) { job->addNetAction(dl); } } - if(job->size()) + if (job->size()) return job; return nullptr; } diff --git a/launcher/minecraft/AssetsUtils.h b/launcher/minecraft/AssetsUtils.h index 3dbf19ed..87956e57 100644 --- a/launcher/minecraft/AssetsUtils.h +++ b/launcher/minecraft/AssetsUtils.h @@ -15,13 +15,12 @@ #pragma once -#include #include +#include #include "net/NetAction.h" #include "net/NetJob.h" -struct AssetObject -{ +struct AssetObject { QString getRelPath(); QUrl getUrl(); QString getLocalPath(); @@ -31,8 +30,7 @@ struct AssetObject qint64 size; }; -struct AssetsIndex -{ +struct AssetsIndex { NetJob::Ptr getDownloadJob(); QString id; @@ -42,12 +40,11 @@ struct AssetsIndex }; /// FIXME: this is absolutely horrendous. REDO!!!! -namespace AssetsUtils -{ -bool loadAssetsIndexJson(const QString &id, const QString &file, AssetsIndex& index); +namespace AssetsUtils { +bool loadAssetsIndexJson(const QString& id, const QString& file, AssetsIndex& index); -QDir getAssetsDir(const QString &assetsId, const QString &resourcesFolder); +QDir getAssetsDir(const QString& assetsId, const QString& resourcesFolder); /// Reconstruct a virtual assets folder for the given assets ID and return the folder bool reconstructAssets(QString assetsId, QString resourcesFolder); -} +} // namespace AssetsUtils diff --git a/launcher/minecraft/Component.cpp b/launcher/minecraft/Component.cpp index ff81fcbb..96d67a05 100644 --- a/launcher/minecraft/Component.cpp +++ b/launcher/minecraft/Component.cpp @@ -33,22 +33,22 @@ * limitations under the License. */ -#include -#include #include "Component.h" +#include +#include #include -#include "meta/Version.h" -#include "VersionFile.h" -#include "minecraft/PackProfile.h" +#include "Application.h" #include "FileSystem.h" #include "OneSixVersionFormat.h" -#include "Application.h" +#include "VersionFile.h" +#include "meta/Version.h" +#include "minecraft/PackProfile.h" #include -Component::Component(PackProfile * parent, const QString& uid) +Component::Component(PackProfile* parent, const QString& uid) { assert(parent); m_parent = parent; @@ -56,7 +56,7 @@ Component::Component(PackProfile * parent, const QString& uid) m_uid = uid; } -Component::Component(PackProfile * parent, std::shared_ptr version) +Component::Component(PackProfile* parent, std::shared_ptr version) { assert(parent); m_parent = parent; @@ -68,7 +68,7 @@ Component::Component(PackProfile * parent, std::shared_ptr versio m_loaded = version->isLoaded(); } -Component::Component(PackProfile * parent, const QString& uid, std::shared_ptr file) +Component::Component(PackProfile* parent, const QString& uid, std::shared_ptr file) { assert(parent); m_parent = parent; @@ -88,33 +88,25 @@ std::shared_ptr Component::getMeta() void Component::applyTo(LaunchProfile* profile) { // do not apply disabled components - if(!isEnabled()) - { + if (!isEnabled()) { return; } auto vfile = getVersionFile(); - if(vfile) - { + if (vfile) { vfile->applyTo(profile, m_parent->runtimeContext()); - } - else - { + } else { profile->applyProblemSeverity(getProblemSeverity()); } } std::shared_ptr Component::getVersionFile() const { - if(m_metaVersion) - { - if(!m_metaVersion->isLoaded()) - { + if (m_metaVersion) { + if (!m_metaVersion->isLoaded()) { m_metaVersion->load(Net::Mode::Online); } return m_metaVersion->data(); - } - else - { + } else { return m_file; } } @@ -122,8 +114,7 @@ std::shared_ptr Component::getVersionFile() const std::shared_ptr Component::getVersionList() const { // FIXME: what if the metadata index isn't loaded yet? - if(APPLICATION->metadataIndex()->hasUid(m_uid)) - { + if (APPLICATION->metadataIndex()->hasUid(m_uid)) { return APPLICATION->metadataIndex()->get(m_uid); } return nullptr; @@ -131,12 +122,11 @@ std::shared_ptr Component::getVersionList() const int Component::getOrder() { - if(m_orderOverride) + if (m_orderOverride) return m_order; auto vfile = getVersionFile(); - if(vfile) - { + if (vfile) { return vfile->order; } return 0; @@ -166,13 +156,11 @@ QString Component::getFilename() } QDateTime Component::getReleaseDateTime() { - if(m_metaVersion) - { + if (m_metaVersion) { return m_metaVersion->time(); } auto vfile = getVersionFile(); - if(vfile) - { + if (vfile) { return vfile->releaseTime; } // FIXME: fake @@ -192,12 +180,10 @@ bool Component::canBeDisabled() bool Component::setEnabled(bool state) { bool intendedDisabled = !state; - if (!canBeDisabled()) - { + if (!canBeDisabled()) { intendedDisabled = false; } - if(intendedDisabled != m_disabled) - { + if (intendedDisabled != m_disabled) { m_disabled = intendedDisabled; emit dataChanged(); return true; @@ -212,10 +198,8 @@ bool Component::isCustom() bool Component::isCustomizable() { - if(m_metaVersion) - { - if(getVersionFile()) - { + if (m_metaVersion) { + if (getVersionFile()) { return true; } } @@ -227,10 +211,8 @@ bool Component::isRemovable() } bool Component::isRevertible() { - if (isCustom()) - { - if(APPLICATION->metadataIndex()->hasUid(m_uid)) - { + if (isCustom()) { + if (APPLICATION->metadataIndex()->hasUid(m_uid)) { return true; } } @@ -244,10 +226,8 @@ bool Component::isMoveable() bool Component::isVersionChangeable() { auto list = getVersionList(); - if(list) - { - if(!list->isLoaded()) - { + if (list) { + if (!list->isLoaded()) { list->load(Net::Mode::Online); } return list->count() != 0; @@ -257,8 +237,7 @@ bool Component::isVersionChangeable() void Component::setImportant(bool state) { - if(m_important != state) - { + if (m_important != state) { m_important = state; emit dataChanged(); } @@ -267,8 +246,7 @@ void Component::setImportant(bool state) ProblemSeverity Component::getProblemSeverity() const { auto file = getVersionFile(); - if(file) - { + if (file) { return file->getProblemSeverity(); } return ProblemSeverity::Error; @@ -277,49 +255,38 @@ ProblemSeverity Component::getProblemSeverity() const const QList Component::getProblems() const { auto file = getVersionFile(); - if(file) - { + if (file) { return file->getProblems(); } - return {{ProblemSeverity::Error, QObject::tr("Patch is not loaded yet.")}}; + return { { ProblemSeverity::Error, QObject::tr("Patch is not loaded yet.") } }; } void Component::setVersion(const QString& version) { - if(version == m_version) - { + if (version == m_version) { return; } m_version = version; - if(m_loaded) - { + if (m_loaded) { // we are loaded and potentially have state to invalidate - if(m_file) - { + if (m_file) { // we have a file... explicit version has been changed and there is nothing else to do. - } - else - { + } else { // we don't have a file, therefore we are loaded with metadata m_cachedVersion = version; // see if the meta version is loaded auto metaVersion = APPLICATION->metadataIndex()->get(m_uid, version); - if(metaVersion->isLoaded()) - { + if (metaVersion->isLoaded()) { // if yes, we can continue with that. m_metaVersion = metaVersion; - } - else - { + } else { // if not, we need loading m_metaVersion.reset(); m_loaded = false; } updateCachedData(); } - } - else - { + } else { // not loaded... assume it will be sorted out later by the update task } emit dataChanged(); @@ -327,41 +294,33 @@ void Component::setVersion(const QString& version) bool Component::customize() { - if(isCustom()) - { + if (isCustom()) { return false; } auto filename = getFilename(); - if(!FS::ensureFilePathExists(filename)) - { + if (!FS::ensureFilePathExists(filename)) { return false; } // FIXME: get rid of this try-catch. - try - { + try { QSaveFile jsonFile(filename); - if(!jsonFile.open(QIODevice::WriteOnly)) - { + if (!jsonFile.open(QIODevice::WriteOnly)) { return false; } auto vfile = getVersionFile(); - if(!vfile) - { + if (!vfile) { return false; } auto document = OneSixVersionFormat::versionFileToJson(vfile); jsonFile.write(document.toJson()); - if(!jsonFile.commit()) - { + if (!jsonFile.commit()) { return false; } m_file = vfile; m_metaVersion.reset(); emit dataChanged(); - } - catch (const Exception &error) - { + } catch (const Exception& error) { qWarning() << "Version could not be loaded:" << error.cause(); } return true; @@ -369,31 +328,25 @@ bool Component::customize() bool Component::revert() { - if(!isCustom()) - { + if (!isCustom()) { // already not custom return true; } auto filename = getFilename(); bool result = true; // just kill the file and reload - if(QFile::exists(filename)) - { + if (QFile::exists(filename)) { result = QFile::remove(filename); } - if(result) - { + if (result) { // file gone... m_file.reset(); // check local cache for metadata... auto version = APPLICATION->metadataIndex()->get(m_uid, m_version); - if(version->isLoaded()) - { + if (version->isLoaded()) { m_metaVersion = version; - } - else - { + } else { m_metaVersion.reset(); m_loaded = false; } @@ -407,23 +360,19 @@ bool Component::revert() * By default, only uids are compared for set operations. * This compares all fields of the Require structs in the sets. */ -static bool deepCompare(const std::set & a, const std::set & b) +static bool deepCompare(const std::set& a, const std::set& b) { // NOTE: this needs to be rewritten if the type of Meta::RequireSet changes - if(a.size() != b.size()) - { + if (a.size() != b.size()) { return false; } - for(const auto & reqA :a) - { - const auto &iter2 = b.find(reqA); - if(iter2 == b.cend()) - { + for (const auto& reqA : a) { + const auto& iter2 = b.find(reqA); + if (iter2 == b.cend()) { return false; } - const auto & reqB = *iter2; - if(!reqA.deepEquals(reqB)) - { + const auto& reqB = *iter2; + if (!reqA.deepEquals(reqB)) { return false; } } @@ -433,41 +382,32 @@ static bool deepCompare(const std::set & a, const std::setname) - { + if (m_cachedName != file->name) { m_cachedName = file->name; changed = true; } - if(m_cachedVersion != file->version) - { + if (m_cachedVersion != file->version) { m_cachedVersion = file->version; changed = true; } - if(m_cachedVolatile != file->m_volatile) - { + if (m_cachedVolatile != file->m_volatile) { m_cachedVolatile = file->m_volatile; changed = true; } - if(!deepCompare(m_cachedRequires, file->m_requires)) - { + if (!deepCompare(m_cachedRequires, file->m_requires)) { m_cachedRequires = file->m_requires; changed = true; } - if(!deepCompare(m_cachedConflicts, file->conflicts)) - { + if (!deepCompare(m_cachedConflicts, file->conflicts)) { m_cachedConflicts = file->conflicts; changed = true; } - if(changed) - { + if (changed) { emit dataChanged(); } - } - else - { + } else { // in case we removed all the metadata m_cachedRequires.clear(); m_cachedConflicts.clear(); diff --git a/launcher/minecraft/Component.h b/launcher/minecraft/Component.h index e7419c41..3474a22e 100644 --- a/launcher/minecraft/Component.h +++ b/launcher/minecraft/Component.h @@ -1,38 +1,36 @@ #pragma once -#include -#include -#include #include -#include "meta/JsonFormat.h" +#include +#include +#include #include "ProblemProvider.h" #include "QObjectPtr.h" +#include "meta/JsonFormat.h" class PackProfile; class LaunchProfile; -namespace Meta -{ - class Version; - class VersionList; -} +namespace Meta { +class Version; +class VersionList; +} // namespace Meta class VersionFile; -class Component : public QObject, public ProblemProvider -{ -Q_OBJECT -public: - Component(PackProfile * parent, const QString &uid); +class Component : public QObject, public ProblemProvider { + Q_OBJECT + public: + Component(PackProfile* parent, const QString& uid); // DEPRECATED: remove these constructors? - Component(PackProfile * parent, std::shared_ptr version); - Component(PackProfile * parent, const QString & uid, std::shared_ptr file); + Component(PackProfile* parent, std::shared_ptr version); + Component(PackProfile* parent, const QString& uid, std::shared_ptr file); - virtual ~Component(){} + virtual ~Component() {} - void applyTo(LaunchProfile *profile); + void applyTo(LaunchProfile* profile); bool isEnabled(); - bool setEnabled (bool state); + bool setEnabled(bool state); bool canBeDisabled(); bool isMoveable(); @@ -57,23 +55,22 @@ public: std::shared_ptr getVersionFile() const; std::shared_ptr getVersionList() const; - void setImportant (bool state); - + void setImportant(bool state); const QList getProblems() const override; ProblemSeverity getProblemSeverity() const override; - void setVersion(const QString & version); + void setVersion(const QString& version); bool customize(); bool revert(); void updateCachedData(); -signals: + signals: void dataChanged(); -public: /* data */ - PackProfile * m_parent; + public: /* data */ + PackProfile* m_parent; // BEGIN: persistent component list properties /// ID of the component diff --git a/launcher/minecraft/ComponentUpdateTask.cpp b/launcher/minecraft/ComponentUpdateTask.cpp index d55bc17f..0b85b81a 100644 --- a/launcher/minecraft/ComponentUpdateTask.cpp +++ b/launcher/minecraft/ComponentUpdateTask.cpp @@ -1,16 +1,16 @@ #include "ComponentUpdateTask.h" -#include "PackProfile_p.h" -#include "PackProfile.h" #include "Component.h" -#include "meta/Index.h" -#include "meta/VersionList.h" -#include "meta/Version.h" #include "ComponentUpdateTask_p.h" -#include "cassert" +#include "OneSixVersionFormat.h" +#include "PackProfile.h" +#include "PackProfile_p.h" #include "Version.h" +#include "cassert" +#include "meta/Index.h" +#include "meta/Version.h" +#include "meta/VersionList.h" #include "net/Mode.h" -#include "OneSixVersionFormat.h" #include "Application.h" @@ -32,8 +32,7 @@ * If the component list changes, start over. */ -ComponentUpdateTask::ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfile* list, QObject* parent) - : Task(parent) +ComponentUpdateTask::ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfile* list, QObject* parent) : Task(parent) { d.reset(new ComponentUpdateTaskData); d->m_list = list; @@ -41,9 +40,7 @@ ComponentUpdateTask::ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfi d->netmode = netmode; } -ComponentUpdateTask::~ComponentUpdateTask() -{ -} +ComponentUpdateTask::~ComponentUpdateTask() {} void ComponentUpdateTask::executeTask() { @@ -51,19 +48,12 @@ void ComponentUpdateTask::executeTask() loadComponents(); } -namespace -{ -enum class LoadResult -{ - LoadedLocal, - RequiresRemote, - Failed -}; +namespace { +enum class LoadResult { LoadedLocal, RequiresRemote, Failed }; LoadResult composeLoadResult(LoadResult a, LoadResult b) { - if (a < b) - { + if (a < b) { return b; } return a; @@ -71,28 +61,24 @@ LoadResult composeLoadResult(LoadResult a, LoadResult b) static LoadResult loadComponent(ComponentPtr component, Task::Ptr& loadTask, Net::Mode netmode) { - if(component->m_loaded) - { + if (component->m_loaded) { qDebug() << component->getName() << "is already loaded"; return LoadResult::LoadedLocal; } LoadResult result = LoadResult::Failed; auto customPatchFilename = component->getFilename(); - if(QFile::exists(customPatchFilename)) - { + if (QFile::exists(customPatchFilename)) { // if local file exists... // check for uid problems inside... bool fileChanged = false; auto file = ProfileUtils::parseJsonFile(QFileInfo(customPatchFilename), false); - if(file->uid != component->m_uid) - { + if (file->uid != component->m_uid) { file->uid = component->m_uid; fileChanged = true; } - if(fileChanged) - { + if (fileChanged) { // FIXME: @QUALITY do not ignore return value ProfileUtils::saveJsonFile(OneSixVersionFormat::versionFileToJson(file), customPatchFilename); } @@ -100,21 +86,16 @@ static LoadResult loadComponent(ComponentPtr component, Task::Ptr& loadTask, Net component->m_file = file; component->m_loaded = true; result = LoadResult::LoadedLocal; - } - else - { + } else { auto metaVersion = APPLICATION->metadataIndex()->get(component->m_uid, component->m_version); component->m_metaVersion = metaVersion; - if(metaVersion->isLoaded()) - { + if (metaVersion->isLoaded()) { component->m_loaded = true; result = LoadResult::LoadedLocal; - } - else - { + } else { metaVersion->load(netmode); loadTask = metaVersion->getCurrentTask(); - if(loadTask) + if (loadTask) result = LoadResult::RequiresRemote; else if (metaVersion->isLoaded()) result = LoadResult::LoadedLocal; @@ -155,21 +136,19 @@ static LoadResult loadPackProfile(ComponentPtr component, Task::Ptr& loadTask, N static LoadResult loadIndex(Task::Ptr& loadTask, Net::Mode netmode) { // FIXME: DECIDE. do we want to run the update task anyway? - if(APPLICATION->metadataIndex()->isLoaded()) - { + if (APPLICATION->metadataIndex()->isLoaded()) { qDebug() << "Index is already loaded"; return LoadResult::LoadedLocal; } APPLICATION->metadataIndex()->load(netmode); loadTask = APPLICATION->metadataIndex()->getCurrentTask(); - if(loadTask) - { + if (loadTask) { return LoadResult::RequiresRemote; } // FIXME: this is assuming the load succeeded... did it really? return LoadResult::LoadedLocal; } -} +} // namespace void ComponentUpdateTask::loadComponents() { @@ -183,34 +162,24 @@ void ComponentUpdateTask::loadComponents() Task::Ptr indexLoadTask; auto singleResult = loadIndex(indexLoadTask, d->netmode); result = composeLoadResult(result, singleResult); - if(indexLoadTask) - { + if (indexLoadTask) { qDebug() << "Remote loading is being run for metadata index"; RemoteLoadStatus status; status.type = RemoteLoadStatus::Type::Index; d->remoteLoadStatusList.append(status); - connect(indexLoadTask.get(), &Task::succeeded, [=]() - { - remoteLoadSucceeded(taskIndex); - }); - connect(indexLoadTask.get(), &Task::failed, [=](const QString & error) - { - remoteLoadFailed(taskIndex, error); - }); - connect(indexLoadTask.get(), &Task::aborted, [=]() - { - remoteLoadFailed(taskIndex, tr("Aborted")); - }); + connect(indexLoadTask.get(), &Task::succeeded, [=]() { remoteLoadSucceeded(taskIndex); }); + connect(indexLoadTask.get(), &Task::failed, [=](const QString& error) { remoteLoadFailed(taskIndex, error); }); + connect(indexLoadTask.get(), &Task::aborted, [=]() { remoteLoadFailed(taskIndex, tr("Aborted")); }); taskIndex++; } } // load all the components OR their lists... - for (auto component: d->m_list->d->components) - { + for (auto component : d->m_list->d->components) { Task::Ptr loadTask; LoadResult singleResult; RemoteLoadStatus::Type loadType; - // FIXME: to do this right, we need to load the lists and decide on which versions to use during dependency resolution. For now, ignore all that... + // FIXME: to do this right, we need to load the lists and decide on which versions to use during dependency resolution. For now, + // ignore all that... #if 0 switch(d->mode) { @@ -231,26 +200,15 @@ void ComponentUpdateTask::loadComponents() singleResult = loadComponent(component, loadTask, d->netmode); loadType = RemoteLoadStatus::Type::Version; #endif - if(singleResult == LoadResult::LoadedLocal) - { + if (singleResult == LoadResult::LoadedLocal) { component->updateCachedData(); } result = composeLoadResult(result, singleResult); - if (loadTask) - { + if (loadTask) { qDebug() << "Remote loading is being run for" << component->getName(); - connect(loadTask.get(), &Task::succeeded, [=]() - { - remoteLoadSucceeded(taskIndex); - }); - connect(loadTask.get(), &Task::failed, [=](const QString & error) - { - remoteLoadFailed(taskIndex, error); - }); - connect(loadTask.get(), &Task::aborted, [=]() - { - remoteLoadFailed(taskIndex, tr("Aborted")); - }); + connect(loadTask.get(), &Task::succeeded, [=]() { remoteLoadSucceeded(taskIndex); }); + connect(loadTask.get(), &Task::failed, [=](const QString& error) { remoteLoadFailed(taskIndex, error); }); + connect(loadTask.get(), &Task::aborted, [=]() { remoteLoadFailed(taskIndex, tr("Aborted")); }); RemoteLoadStatus status; status.type = loadType; status.PackProfileIndex = componentIndex; @@ -260,95 +218,73 @@ void ComponentUpdateTask::loadComponents() componentIndex++; } d->remoteTasksInProgress = taskIndex; - switch(result) - { - case LoadResult::LoadedLocal: - { + switch (result) { + case LoadResult::LoadedLocal: { // Everything got loaded. Advance to dependency resolution. resolveDependencies(d->mode == Mode::Launch || d->netmode == Net::Mode::Offline); break; } - case LoadResult::RequiresRemote: - { + case LoadResult::RequiresRemote: { // we wait for signals. break; } - case LoadResult::Failed: - { + case LoadResult::Failed: { emitFailed(tr("Some component metadata load tasks failed.")); break; } } } -namespace -{ - struct RequireEx : public Meta::Require - { - size_t indexOfFirstDependee = 0; - }; - struct RequireCompositionResult - { - bool ok; - RequireEx outcome; - }; - using RequireExSet = std::set; -} +namespace { +struct RequireEx : public Meta::Require { + size_t indexOfFirstDependee = 0; +}; +struct RequireCompositionResult { + bool ok; + RequireEx outcome; +}; +using RequireExSet = std::set; +} // namespace -static RequireCompositionResult composeRequirement(const RequireEx & a, const RequireEx & b) +static RequireCompositionResult composeRequirement(const RequireEx& a, const RequireEx& b) { assert(a.uid == b.uid); RequireEx out; out.uid = a.uid; out.indexOfFirstDependee = std::min(a.indexOfFirstDependee, b.indexOfFirstDependee); - if(a.equalsVersion.isEmpty()) - { + if (a.equalsVersion.isEmpty()) { out.equalsVersion = b.equalsVersion; - } - else if (b.equalsVersion.isEmpty()) - { + } else if (b.equalsVersion.isEmpty()) { out.equalsVersion = a.equalsVersion; - } - else if (a.equalsVersion == b.equalsVersion) - { + } else if (a.equalsVersion == b.equalsVersion) { out.equalsVersion = a.equalsVersion; - } - else - { + } else { // FIXME: mark error as explicit version conflict - return {false, out}; + return { false, out }; } - if(a.suggests.isEmpty()) - { + if (a.suggests.isEmpty()) { out.suggests = b.suggests; - } - else if (b.suggests.isEmpty()) - { + } else if (b.suggests.isEmpty()) { out.suggests = a.suggests; - } - else - { + } else { Version aVer(a.suggests); Version bVer(b.suggests); out.suggests = (aVer < bVer ? b.suggests : a.suggests); } - return {true, out}; + return { true, out }; } // gather the requirements from all components, finding any obvious conflicts -static bool gatherRequirementsFromComponents(const ComponentContainer & input, RequireExSet & output) +static bool gatherRequirementsFromComponents(const ComponentContainer& input, RequireExSet& output) { bool succeeded = true; size_t componentNum = 0; - for(auto component: input) - { - auto &componentRequires = component->m_cachedRequires; - for(const auto & componentRequire: componentRequires) - { - auto found = std::find_if(output.cbegin(), output.cend(), [componentRequire](const Meta::Require & req){ - return req.uid == componentRequire.uid; - }); + for (auto component : input) { + auto& componentRequires = component->m_cachedRequires; + for (const auto& componentRequire : componentRequires) { + auto found = std::find_if(output.cbegin(), output.cend(), + [componentRequire](const Meta::Require& req) { return req.uid == componentRequire.uid; }); RequireEx componenRequireEx; componenRequireEx.uid = componentRequire.uid; @@ -356,29 +292,18 @@ static bool gatherRequirementsFromComponents(const ComponentContainer & input, R componenRequireEx.equalsVersion = componentRequire.equalsVersion; componenRequireEx.indexOfFirstDependee = componentNum; - if(found != output.cend()) - { + if (found != output.cend()) { // found... process it further auto result = composeRequirement(componenRequireEx, *found); - if(result.ok) - { + if (result.ok) { output.erase(componenRequireEx); output.insert(result.outcome); - } - else - { - qCritical() - << "Conflicting requirements:" - << componentRequire.uid - << "versions:" - << componentRequire.equalsVersion - << ";" - << (*found).equalsVersion; + } else { + qCritical() << "Conflicting requirements:" << componentRequire.uid << "versions:" << componentRequire.equalsVersion + << ";" << (*found).equalsVersion; } succeeded &= result.ok; - } - else - { + } else { // not found, accumulate output.insert(componenRequireEx); } @@ -389,19 +314,17 @@ static bool gatherRequirementsFromComponents(const ComponentContainer & input, R } /// Get list of uids that can be trivially removed because nothing is depending on them anymore (and they are installed as deps) -static void getTrivialRemovals(const ComponentContainer & components, const RequireExSet & reqs, QStringList &toRemove) +static void getTrivialRemovals(const ComponentContainer& components, const RequireExSet& reqs, QStringList& toRemove) { - for(const auto & component: components) - { - if(!component->m_dependencyOnly) + for (const auto& component : components) { + if (!component->m_dependencyOnly) continue; - if(!component->m_cachedVolatile) + if (!component->m_cachedVolatile) continue; RequireEx reqNeedle; reqNeedle.uid = component->m_uid; const auto iter = reqs.find(reqNeedle); - if(iter == reqs.cend()) - { + if (iter == reqs.cend()) { toRemove.append(component->m_uid); } } @@ -415,60 +338,40 @@ static void getTrivialRemovals(const ComponentContainer & components, const Requ * toAdd - set of requirements than mean adding a new component * toChange - set of requirements that mean changing version of an existing component */ -static bool getTrivialComponentChanges(const ComponentIndex & index, const RequireExSet & input, RequireExSet & toAdd, RequireExSet & toChange) +static bool getTrivialComponentChanges(const ComponentIndex& index, const RequireExSet& input, RequireExSet& toAdd, RequireExSet& toChange) { - enum class Decision - { - Undetermined, - Met, - Missing, - VersionNotSame, - LockedVersionNotSame - } decision = Decision::Undetermined; + enum class Decision { Undetermined, Met, Missing, VersionNotSame, LockedVersionNotSame } decision = Decision::Undetermined; QString reqStr; bool succeeded = true; // list the composed requirements and say if they are met or unmet - for(auto & req: input) - { - do - { - if(req.equalsVersion.isEmpty()) - { + for (auto& req : input) { + do { + if (req.equalsVersion.isEmpty()) { reqStr = QString("Req: %1").arg(req.uid); - if(index.contains(req.uid)) - { + if (index.contains(req.uid)) { decision = Decision::Met; - } - else - { + } else { toAdd.insert(req); decision = Decision::Missing; } break; - } - else - { + } else { reqStr = QString("Req: %1 == %2").arg(req.uid, req.equalsVersion); - const auto & compIter = index.find(req.uid); - if(compIter == index.cend()) - { + const auto& compIter = index.find(req.uid); + if (compIter == index.cend()) { toAdd.insert(req); decision = Decision::Missing; break; } - auto & comp = (*compIter); - if(comp->getVersion() != req.equalsVersion) - { - if(comp->isCustom()) { + auto& comp = (*compIter); + if (comp->getVersion() != req.equalsVersion) { + if (comp->isCustom()) { decision = Decision::LockedVersionNotSame; } else { - if(comp->m_dependencyOnly) - { + if (comp->m_dependencyOnly) { decision = Decision::VersionNotSame; - } - else - { + } else { decision = Decision::LockedVersionNotSame; } } @@ -476,9 +379,8 @@ static bool getTrivialComponentChanges(const ComponentIndex & index, const Requi } decision = Decision::Met; } - } while(false); - switch(decision) - { + } while (false); + switch (decision) { case Decision::Undetermined: qCritical() << "No decision for" << reqStr; succeeded = false; @@ -520,26 +422,22 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly) * * NOTE: this is a placeholder and should eventually be replaced with something 'serious' */ - auto & components = d->m_list->d->components; - auto & componentIndex = d->m_list->d->componentIndex; + auto& components = d->m_list->d->components; + auto& componentIndex = d->m_list->d->componentIndex; RequireExSet allRequires; QStringList toRemove; - do - { + do { allRequires.clear(); toRemove.clear(); - if(!gatherRequirementsFromComponents(components, allRequires)) - { + if (!gatherRequirementsFromComponents(components, allRequires)) { emitFailed(tr("Conflicting requirements detected during dependency checking!")); return; } getTrivialRemovals(components, allRequires, toRemove); - if(!toRemove.isEmpty()) - { + if (!toRemove.isEmpty()) { qDebug() << "Removing obsolete components..."; - for(auto & remove : toRemove) - { + for (auto& remove : toRemove) { qDebug() << "Removing" << remove; d->m_list->remove(remove); } @@ -548,69 +446,50 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly) RequireExSet toAdd; RequireExSet toChange; bool succeeded = getTrivialComponentChanges(componentIndex, allRequires, toAdd, toChange); - if(!succeeded) - { + if (!succeeded) { emitFailed(tr("Instance has conflicting dependencies.")); return; } - if(checkOnly) - { - if(toAdd.size() || toChange.size()) - { + if (checkOnly) { + if (toAdd.size() || toChange.size()) { emitFailed(tr("Instance has unresolved dependencies while loading/checking for launch.")); - } - else - { + } else { emitSucceeded(); } return; } bool recursionNeeded = false; - if(toAdd.size()) - { + if (toAdd.size()) { // add stuff... - for(auto &add: toAdd) - { + for (auto& add : toAdd) { auto component = makeShared(d->m_list, add.uid); - if(!add.equalsVersion.isEmpty()) - { + if (!add.equalsVersion.isEmpty()) { // exact version qDebug() << "Adding" << add.uid << "version" << add.equalsVersion << "at position" << add.indexOfFirstDependee; component->m_version = add.equalsVersion; - } - else - { + } else { // version needs to be decided qDebug() << "Adding" << add.uid << "at position" << add.indexOfFirstDependee; -// ############################################################################################################ -// HACK HACK HACK HACK FIXME: this is a placeholder for deciding what version to use. For now, it is hardcoded. - if(!add.suggests.isEmpty()) - { + // ############################################################################################################ + // HACK HACK HACK HACK FIXME: this is a placeholder for deciding what version to use. For now, it is hardcoded. + if (!add.suggests.isEmpty()) { component->m_version = add.suggests; - } - else - { - if(add.uid == "org.lwjgl") - { + } else { + if (add.uid == "org.lwjgl") { component->m_version = "2.9.1"; - } - else if (add.uid == "org.lwjgl3") - { + } else if (add.uid == "org.lwjgl3") { component->m_version = "3.1.2"; - } - else if (add.uid == "net.fabricmc.intermediary" || add.uid == "org.quiltmc.hashed") - { - auto minecraft = std::find_if(components.begin(), components.end(), [](ComponentPtr & cmp){ - return cmp->getID() == "net.minecraft"; - }); - if(minecraft != components.end()) { + } else if (add.uid == "net.fabricmc.intermediary" || add.uid == "org.quiltmc.hashed") { + auto minecraft = std::find_if(components.begin(), components.end(), + [](ComponentPtr& cmp) { return cmp->getID() == "net.minecraft"; }); + if (minecraft != components.end()) { component->m_version = (*minecraft)->getVersion(); } } } -// HACK HACK HACK HACK FIXME: this is a placeholder for deciding what version to use. For now, it is hardcoded. -// ############################################################################################################ + // HACK HACK HACK HACK FIXME: this is a placeholder for deciding what version to use. For now, it is hardcoded. + // ############################################################################################################ } component->m_dependencyOnly = true; // FIXME: this should not work directly with the component list @@ -619,11 +498,9 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly) } recursionNeeded = true; } - if(toChange.size()) - { + if (toChange.size()) { // change a version of something that exists - for(auto &change: toChange) - { + for (auto& change : toChange) { // FIXME: this should not work directly with the component list qDebug() << "Setting version of " << change.uid << "to" << change.equalsVersion; auto component = componentIndex[change.uid]; @@ -632,31 +509,26 @@ void ComponentUpdateTask::resolveDependencies(bool checkOnly) recursionNeeded = true; } - if(recursionNeeded) - { + if (recursionNeeded) { loadComponents(); - } - else - { + } else { emitSucceeded(); } } void ComponentUpdateTask::remoteLoadSucceeded(size_t taskIndex) { - auto &taskSlot = d->remoteLoadStatusList[taskIndex]; - if(taskSlot.finished) - { + auto& taskSlot = d->remoteLoadStatusList[taskIndex]; + if (taskSlot.finished) { qWarning() << "Got multiple results from remote load task" << taskIndex; return; } qDebug() << "Remote task" << taskIndex << "succeeded"; taskSlot.succeeded = false; taskSlot.finished = true; - d->remoteTasksInProgress --; + d->remoteTasksInProgress--; // update the cached data of the component from the downloaded version file. - if (taskSlot.type == RemoteLoadStatus::Type::Version) - { + if (taskSlot.type == RemoteLoadStatus::Type::Version) { auto component = d->m_list->getComponent(taskSlot.PackProfileIndex); component->m_loaded = true; component->updateCachedData(); @@ -664,12 +536,10 @@ void ComponentUpdateTask::remoteLoadSucceeded(size_t taskIndex) checkIfAllFinished(); } - void ComponentUpdateTask::remoteLoadFailed(size_t taskIndex, const QString& msg) { - auto &taskSlot = d->remoteLoadStatusList[taskIndex]; - if(taskSlot.finished) - { + auto& taskSlot = d->remoteLoadStatusList[taskIndex]; + if (taskSlot.finished) { qWarning() << "Got multiple results from remote load task" << taskIndex; return; } @@ -678,31 +548,25 @@ void ComponentUpdateTask::remoteLoadFailed(size_t taskIndex, const QString& msg) taskSlot.succeeded = false; taskSlot.finished = true; taskSlot.error = msg; - d->remoteTasksInProgress --; + d->remoteTasksInProgress--; checkIfAllFinished(); } void ComponentUpdateTask::checkIfAllFinished() { - if(d->remoteTasksInProgress) - { + if (d->remoteTasksInProgress) { // not yet... return; } - if(d->remoteLoadSuccessful) - { + if (d->remoteLoadSuccessful) { // nothing bad happened... clear the temp load status and proceed with looking at dependencies d->remoteLoadStatusList.clear(); resolveDependencies(d->mode == Mode::Launch); - } - else - { + } else { // remote load failed... report error and bail QStringList allErrorsList; - for(auto & item: d->remoteLoadStatusList) - { - if(!item.succeeded) - { + for (auto& item : d->remoteLoadStatusList) { + if (!item.succeeded) { allErrorsList.append(item.error); } } diff --git a/launcher/minecraft/ComponentUpdateTask.h b/launcher/minecraft/ComponentUpdateTask.h index 4274cabb..2f396a04 100644 --- a/launcher/minecraft/ComponentUpdateTask.h +++ b/launcher/minecraft/ComponentUpdateTask.h @@ -1,37 +1,32 @@ #pragma once -#include "tasks/Task.h" #include "net/Mode.h" +#include "tasks/Task.h" #include class PackProfile; struct ComponentUpdateTaskData; -class ComponentUpdateTask : public Task -{ +class ComponentUpdateTask : public Task { Q_OBJECT -public: - enum class Mode - { - Launch, - Resolution - }; - -public: - explicit ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfile * list, QObject *parent = 0); + public: + enum class Mode { Launch, Resolution }; + + public: + explicit ComponentUpdateTask(Mode mode, Net::Mode netmode, PackProfile* list, QObject* parent = 0); virtual ~ComponentUpdateTask(); -protected: + protected: void executeTask(); -private: + private: void loadComponents(); void resolveDependencie