From 91ba4cf75ee30c64779edb5b7644e5a830de5026 Mon Sep 17 00:00:00 2001
From: Sefa Eyeoglu <contact@scrumplex.net>
Date: Mon, 14 Aug 2023 18:16:53 +0200
Subject: chore: reformat

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
---
 launcher/minecraft/Library.cpp | 187 ++++++++++++++---------------------------
 1 file changed, 65 insertions(+), 122 deletions(-)

(limited to 'launcher/minecraft/Library.cpp')

diff --git a/launcher/minecraft/Library.cpp b/launcher/minecraft/Library.cpp
index e0318ef2..0bb618b4 100644
--- a/launcher/minecraft/Library.cpp
+++ b/launcher/minecraft/Library.cpp
@@ -36,106 +36,90 @@
 #include "Library.h"
 #include "MinecraftInstance.h"
 
+#include <BuildConfig.h>
+#include <FileSystem.h>
 #include <net/ApiDownload.h>
 #include <net/ChecksumValidator.h>
-#include <FileSystem.h>
-#include <BuildConfig.h>
-
 
-void Library::getApplicableFiles(const RuntimeContext & runtimeContext, QStringList& jar, QStringList& native, QStringList& native32,
-                                 QStringList& native64, const QString &overridePath) const
+void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
+                                 QStringList& jar,
+                                 QStringList& native,
+                                 QStringList& native32,
+                                 QStringList& native64,
+                                 const QString& overridePath) const
 {
     bool local = isLocal();
-    auto actualPath = [&](QString relPath)
-    {
+    auto actualPath = [&](QString relPath) {
         QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
-        if(local && !overridePath.isEmpty())
-        {
+        if (local && !overridePath.isEmpty()) {
             QString fileName = out.fileName();
             return QFileInfo(FS::PathCombine(overridePath, fileName)).absoluteFilePath();
         }
         return out.absoluteFilePath();
     };
     QString raw_storage = storageSuffix(runtimeContext);
-    if(isNative())
-    {
-        if (raw_storage.contains("${arch}"))
-        {
+    if (isNative()) {
+        if (raw_storage.contains("${arch}")) {
             auto nat32Storage = raw_storage;
             nat32Storage.replace("${arch}", "32");
             auto nat64Storage = raw_storage;
             nat64Storage.replace("${arch}", "64");
             native32 += actualPath(nat32Storage);
             native64 += actualPath(nat64Storage);
-        }
-        else
-        {
+        } else {
             native += actualPath(raw_storage);
         }
-    }
-    else
-    {
+    } else {
         jar += actualPath(raw_storage);
     }
 }
 
-QList<NetAction::Ptr> Library::getDownloads(
-    const RuntimeContext & runtimeContext,
-    class HttpMetaCache* cache,
-    QStringList& failedLocalFiles,
-    const QString & overridePath
-) const
+QList<NetAction::Ptr> Library::getDownloads(const RuntimeContext& runtimeContext,
+                                            class HttpMetaCache* cache,
+                                            QStringList& failedLocalFiles,
+                                            const QString& overridePath) const
 {
     QList<NetAction::Ptr> out;
     bool stale = isAlwaysStale();
     bool local = isLocal();
 
-    auto check_local_file = [&](QString storage)
-    {
+    auto check_local_file = [&](QString storage) {
         QFileInfo fileinfo(storage);
         QString fileName = fileinfo.fileName();
         auto fullPath = FS::PathCombine(overridePath, fileName);
         QFileInfo localFileInfo(fullPath);
-        if(!localFileInfo.exists())
-        {
+        if (!localFileInfo.exists()) {
             failedLocalFiles.append(localFileInfo.filePath());
             return false;
         }
         return true;
     };
 
-    auto add_download = [&](QString storage, QString url, QString sha1)
-    {
-        if(local)
-        {
+    auto add_download = [&](QString storage, QString url, QString sha1) {
+        if (local) {
             return check_local_file(storage);
         }
         auto entry = cache->resolveEntry("libraries", storage);
-        if(stale)
-        {
+        if (stale) {
             entry->setStale(true);
         }
         if (!entry->isStale())
             return true;
         Net::Download::Options options;
-        if(stale)
-        {
+        if (stale) {
             options |= Net::Download::Option::AcceptLocalFiles;
         }
 
         // Don't add a time limit for the libraries cache entry validity
         options |= Net::Download::Option::MakeEternal;
 
-        if(sha1.size())
-        {
+        if (sha1.size()) {
             auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
             auto dl = Net::ApiDownload::makeCached(url, entry, options);
             dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
             qDebug() << "Checksummed Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
             out.append(dl);
-        }
-        else
-        {
+        } else {
             out.append(Net::ApiDownload::makeCached(url, entry, options));
             qDebug() << "Download for:" << rawName().serialize() << "storage:" << storage << "url:" << url;
         }
@@ -143,121 +127,89 @@ QList<NetAction::Ptr> Library::getDownloads(
     };
 
     QString raw_storage = storageSuffix(runtimeContext);
-    if(m_mojangDownloads)
-    {
-        if(isNative())
-        {
+    if (m_mojangDownloads) {
+        if (isNative()) {
             auto nativeClassifier = getCompatibleNative(runtimeContext);
-            if(!nativeClassifier.isNull())
-            {
-                if(nativeClassifier.contains("${arch}"))
-                {
+            if (!nativeClassifier.isNull()) {
+                if (nativeClassifier.contains("${arch}")) {
                     auto nat32Classifier = nativeClassifier;
                     nat32Classifier.replace("${arch}", "32");
                     auto nat64Classifier = nativeClassifier;
                     nat64Classifier.replace("${arch}", "64");
                     auto nat32info = m_mojangDownloads->getDownloadInfo(nat32Classifier);
-                    if(nat32info)
-                    {
+                    if (nat32info) {
                         auto cooked_storage = raw_storage;
                         cooked_storage.replace("${arch}", "32");
                         add_download(cooked_storage, nat32info->url, nat32info->sha1);
                     }
                     auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
-                    if(nat64info)
-                    {
+                    if (nat64info) {
                         auto cooked_storage = raw_storage;
                         cooked_storage.replace("${arch}", "64");
                         add_download(cooked_storage, nat64info->url, nat64info->sha1);
                     }
-                }
-                else
-                {
+                } else {
                     auto info = m_mojangDownloads->getDownloadInfo(nativeClassifier);
-                    if(info)
-                    {
+                    if (info) {
                         add_download(raw_storage, info->url, info->sha1);
                     }
                 }
-            }
-            else
-            {
+            } else {
                 qDebug() << "Ignoring native library" << m_name.serialize() << "because it has no classifier for current OS";
             }
-        }
-        else
-        {
-            if(m_mojangDownloads->artifact)
-            {
+        } else {
+            if (m_mojangDownloads->artifact) {
                 auto artifact = m_mojangDownloads->artifact;
                 add_download(raw_storage, artifact->url, artifact->sha1);
-            }
-            else
-            {
+            } else {
                 qDebug() << "Ignoring java library" << m_name.serialize() << "because it has no artifact";
             }
         }
-    }
-    else
-    {
-        auto raw_dl = [&]()
-        {
-            if (!m_absoluteURL.isEmpty())
-            {
+    } else {
+        auto raw_dl = [&]() {
+            if (!m_absoluteURL.isEmpty()) {
                 return m_absoluteURL;
             }
 
-            if (m_repositoryURL.isEmpty())
-            {
+            if (m_repositoryURL.isEmpty()) {
                 return BuildConfig.LIBRARY_BASE + raw_storage;
             }
 
-            if(m_repositoryURL.endsWith('/'))
-            {
+            if (m_repositoryURL.endsWith('/')) {
                 return m_repositoryURL + raw_storage;
-            }
-            else
-            {
+            } else {
                 return m_repositoryURL + QChar('/') + raw_storage;
             }
         }();
-        if (raw_storage.contains("${arch}"))
-        {
+        if (raw_storage.contains("${arch}")) {
             QString cooked_storage = raw_storage;
             QString cooked_dl = raw_dl;
             add_download(cooked_storage.replace("${arch}", "32"), cooked_dl.replace("${arch}", "32"), QString());
             cooked_storage = raw_storage;
             cooked_dl = raw_dl;
             add_download(cooked_storage.replace("${arch}", "64"), cooked_dl.replace("${arch}", "64"), QString());
-        }
-        else
-        {
+        } else {
             add_download(raw_storage, raw_dl, QString());
         }
     }
     return out;
 }
 
-bool Library::isActive(const RuntimeContext & runtimeContext) const
+bool Library::isActive(const RuntimeContext& runtimeContext) const
 {
     bool result = true;
-    if (m_rules.empty())
-    {
+    if (m_rules.empty()) {
         result = true;
-    }
-    else
-    {
+    } else {
         RuleAction ruleResult = Disallow;
-        for (auto rule : m_rules)
-        {
+        for (auto rule : m_rules) {
             RuleAction temp = rule->apply(this, runtimeContext);
             if (temp != Defer)
                 ruleResult = temp;
         }
         result = result && (ruleResult == Allow);
     }
-    if (isNative())
-    {
+    if (isNative()) {
         result = result && !getCompatibleNative(runtimeContext).isNull();
     }
     return result;
@@ -273,7 +225,8 @@ bool Library::isAlwaysStale() const
     return m_hint == "always-stale";
 }
 
-QString Library::getCompatibleNative(const RuntimeContext & runtimeContext) const {
+QString Library::getCompatibleNative(const RuntimeContext& runtimeContext) const
+{
     // try to match precise classifier "[os]-[arch]"
     auto entry = m_nativeClassifiers.constFind(runtimeContext.getClassifier());
     // try to match imprecise classifier on legacy architectures "[os]"
@@ -298,63 +251,53 @@ QString Library::defaultStoragePrefix()
 
 QString Library::storagePrefix() const
 {
-    if(m_storagePrefix.isEmpty())
-    {
+    if (m_storagePrefix.isEmpty()) {
         return defaultStoragePrefix();
     }
     return m_storagePrefix;
 }
 
-QString Library::filename(const RuntimeContext & runtimeContext) const
+QString Library::filename(const RuntimeContext& runtimeContext) const
 {
-    if(!m_filename.isEmpty())
-    {
+    if (!m_filename.isEmpty()) {
         return m_filename;
     }
     // non-native? use only the gradle specifier
-    if (!isNative())
-    {
+    if (!isNative()) {
         return m_name.getFileName();
     }
 
     // otherwise native, override classifiers. Mojang HACK!
     GradleSpecifier nativeSpec = m_name;
     QString nativeClassifier = getCompatibleNative(runtimeContext);
-    if (!nativeClassifier.isNull())
-    {
+    if (!nativeClassifier.isNull()) {
         nativeSpec.setClassifier(nativeClassifier);
-    }
-    else
-    {
+    } else {
         nativeSpec.setClassifier("INVALID");
     }
     return nativeSpec.getFileName();
 }
 
-QString Library::displayName(const RuntimeContext & runtimeContext) const
+QString Library::displayName(const RuntimeContext& runtimeContext) const
 {
-    if(!m_displayname.isEmpty())
+    if (!m_displayname.isEmpty())
         return m_displayname;
     return filename(runtimeContext);
 }
 
-QString Library::storageSuffix(const RuntimeContext & runtimeContext) const
+QString Library::storageSuffix(const RuntimeContext& runtimeContext) const
 {
     // non-native? use only the gradle specifier
-    if (!isNative())
-    {
+    if (!isNative()) {
         return m_name.toPath(m_filename);
     }
 
     // otherwise native, override classifiers. Mojang HACK!
     GradleSpecifier nativeSpec = m_name;
     QString nativeClassifier = getCompatibleNative(runtimeContext);
-    if (!nativeClassifier.isNull())
-    {
+    if (!nativeClassifier.isNull()) {
         nativeSpec.setClassifier(nativeClassifier);
-    }
-    else
-    {
+    } else {
         nativeSpec.setClassifier("INVALID");
     }
     return nativeSpec.toPath(m_filename);
-- 
cgit