From 4e9039be2d3bc0357e6bfe577c5f2add8313f8d6 Mon Sep 17 00:00:00 2001 From: timoreo Date: Fri, 14 Jan 2022 09:43:42 +0100 Subject: Start of mod downloading --- launcher/ModDownloadTask.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 launcher/ModDownloadTask.cpp (limited to 'launcher/ModDownloadTask.cpp') diff --git a/launcher/ModDownloadTask.cpp b/launcher/ModDownloadTask.cpp new file mode 100644 index 00000000..22955470 --- /dev/null +++ b/launcher/ModDownloadTask.cpp @@ -0,0 +1,25 @@ +/* Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ModDownloadTask.h" + +ModDownloadTask::ModDownloadTask(const QUrl sourceUrl) { + m_sourceUrl = sourceUrl; +} + +void ModDownloadTask::executeTask() { + //TODO actually install the mod + emitSucceeded(); +} -- cgit From 9e6fa8f29aa8bc0f609bfcdb6460c6845b73448a Mon Sep 17 00:00:00 2001 From: timoreo Date: Fri, 14 Jan 2022 12:47:18 +0100 Subject: Added the downloading of the mods --- launcher/ModDownloadTask.cpp | 35 ++++++++++++++++++++-- launcher/ModDownloadTask.h | 15 +++++++++- .../modplatform/modrinth/ModrinthPackIndex.cpp | 4 ++- launcher/modplatform/modrinth/ModrinthPackIndex.h | 1 + launcher/ui/dialogs/ModDownloadDialog.cpp | 2 +- launcher/ui/dialogs/ModDownloadDialog.h | 1 + .../ui/pages/modplatform/modrinth/ModrinthPage.cpp | 2 +- 7 files changed, 53 insertions(+), 7 deletions(-) (limited to 'launcher/ModDownloadTask.cpp') diff --git a/launcher/ModDownloadTask.cpp b/launcher/ModDownloadTask.cpp index 22955470..263aa5d0 100644 --- a/launcher/ModDownloadTask.cpp +++ b/launcher/ModDownloadTask.cpp @@ -14,12 +14,41 @@ */ #include "ModDownloadTask.h" +#include "Application.h" -ModDownloadTask::ModDownloadTask(const QUrl sourceUrl) { - m_sourceUrl = sourceUrl; +ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, const std::shared_ptr mods) +: m_sourceUrl(sourceUrl), mods(mods), filename(filename) { } void ModDownloadTask::executeTask() { - //TODO actually install the mod + setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString())); + + m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network())); + m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename))); + connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ModDownloadTask::downloadSucceeded); + connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged); + connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed); + m_filesNetJob->start(); +} + +void ModDownloadTask::downloadSucceeded() +{ emitSucceeded(); + m_filesNetJob.reset(); +} + +void ModDownloadTask::downloadFailed(QString reason) +{ + emitFailed(reason); + m_filesNetJob.reset(); } + +void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total) +{ + emit progress(current, total); +} + +bool ModDownloadTask::abort() { + return m_filesNetJob->abort(); +} + diff --git a/launcher/ModDownloadTask.h b/launcher/ModDownloadTask.h index 067bd91c..8b39917c 100644 --- a/launcher/ModDownloadTask.h +++ b/launcher/ModDownloadTask.h @@ -16,20 +16,33 @@ #pragma once #include "QObjectPtr.h" #include "tasks/Task.h" +#include "minecraft/mod/ModFolderModel.h" +#include "net/NetJob.h" #include class ModDownloadTask : public Task { Q_OBJECT public: - explicit ModDownloadTask(const QUrl sourceUrl); + explicit ModDownloadTask(const QUrl sourceUrl, const QString filename, const std::shared_ptr mods); +public slots: + bool abort() override; protected: //! Entry point for tasks. void executeTask() override; private: QUrl m_sourceUrl; + std::shared_ptr m_filesNetJob; + const std::shared_ptr mods; + const QString filename; + + void downloadProgressChanged(qint64 current, qint64 total); + + void downloadFailed(QString reason); + + void downloadSucceeded(); }; diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index fa421ab2..fbfaeac8 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -37,7 +37,9 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray file.mcVersion = versionArray[0].toString(); file.version = Json::requireString(obj, "name"); //TODO show all the files ? - file.downloadUrl = Json::requireString(Json::requireArray(obj, "files")[0].toObject(),"url"); + auto parent = Json::requireArray(obj, "files")[0].toObject(); + file.downloadUrl = Json::requireString(parent, "url"); + file.fileName = Json::requireString(parent, "filename"); unsortedVersions.append(file); } auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.h b/launcher/modplatform/modrinth/ModrinthPackIndex.h index afc31ff2..e39b69ab 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.h +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.h @@ -22,6 +22,7 @@ struct IndexedVersion { QString mcVersion; QString downloadUrl; QString date; + QString fileName; }; struct IndexedPack diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index a40980ef..3b4e11e5 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -32,7 +32,7 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr& mods, QWidget *parent) - : QDialog(parent) + : QDialog(parent), mods(mods) { setObjectName(QStringLiteral("ModDownloadDialog")); resize(400, 347); diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index 6ce6ff61..ac40257d 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -46,6 +46,7 @@ public: void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr); ModDownloadTask * getTask(); + const std::shared_ptr &mods; public slots: void accept() override; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index ea1800d2..b68597ac 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -165,7 +165,7 @@ void ModrinthPage::suggestCurrent() return; } - dialog->setSuggestedMod(current.name, new ModDownloadTask(selectedVersion)); + dialog->setSuggestedMod(current.name, new ModDownloadTask(selectedVersion, current.versions.at(0).fileName ,dialog->mods)); } void ModrinthPage::onVersionSelectionChanged(QString data) -- cgit From 2896f70cd83761a1248d55b28e2b5cc2cf465049 Mon Sep 17 00:00:00 2001 From: timoreo Date: Fri, 14 Jan 2022 22:07:54 +0100 Subject: Removing copyrights --- launcher/ModDownloadTask.cpp | 15 --------------- launcher/ModDownloadTask.h | 15 --------------- launcher/ui/dialogs/ModDownloadDialog.cpp | 15 --------------- launcher/ui/dialogs/ModDownloadDialog.h | 15 --------------- launcher/ui/pages/modplatform/modrinth/ModrinthPage.h | 15 --------------- 5 files changed, 75 deletions(-) (limited to 'launcher/ModDownloadTask.cpp') diff --git a/launcher/ModDownloadTask.cpp b/launcher/ModDownloadTask.cpp index 263aa5d0..6e5463fc 100644 --- a/launcher/ModDownloadTask.cpp +++ b/launcher/ModDownloadTask.cpp @@ -1,18 +1,3 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "ModDownloadTask.h" #include "Application.h" diff --git a/launcher/ModDownloadTask.h b/launcher/ModDownloadTask.h index 950a4048..7e4f1b7d 100644 --- a/launcher/ModDownloadTask.h +++ b/launcher/ModDownloadTask.h @@ -1,18 +1,3 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #pragma once #include "QObjectPtr.h" #include "tasks/Task.h" diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp index ac5639e0..86ca050b 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.cpp +++ b/launcher/ui/dialogs/ModDownloadDialog.cpp @@ -1,18 +1,3 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #include "ModDownloadDialog.h" #include diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h index 7b2d18a0..12be7295 100644 --- a/launcher/ui/dialogs/ModDownloadDialog.h +++ b/launcher/ui/dialogs/ModDownloadDialog.h @@ -1,18 +1,3 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #pragma once #include diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 59671d0e..8ff5cbe4 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -1,18 +1,3 @@ -/* Copyright 2013-2021 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #pragma once #include -- cgit From 621e0ba4a887ab4dfdde6a6bba2e1c7b209fb6bc Mon Sep 17 00:00:00 2001 From: timoreo Date: Sat, 15 Jan 2022 10:25:24 +0100 Subject: Added smart file selection This might fail in a few special cases --- launcher/ModDownloadTask.cpp | 2 +- .../modplatform/modrinth/ModrinthPackIndex.cpp | 41 +++++++++++++++++++--- launcher/modplatform/modrinth/ModrinthPackIndex.h | 4 +-- .../ui/pages/modplatform/modrinth/ModrinthPage.cpp | 6 ++-- 4 files changed, 43 insertions(+), 10 deletions(-) (limited to 'launcher/ModDownloadTask.cpp') diff --git a/launcher/ModDownloadTask.cpp b/launcher/ModDownloadTask.cpp index 6e5463fc..08a02d29 100644 --- a/launcher/ModDownloadTask.cpp +++ b/launcher/ModDownloadTask.cpp @@ -8,7 +8,7 @@ ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, co void ModDownloadTask::executeTask() { setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString())); - m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network())); + m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network())); m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename))); connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ModDownloadTask::downloadSucceeded); connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged); diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp index ce408ca0..8d47699b 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp @@ -3,6 +3,10 @@ #include "Json.h" #include "net/NetJob.h" +#include "BaseInstance.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" + void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj) { @@ -20,9 +24,12 @@ void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj) pack.authors.append(packAuthor); //TODO delete this ? only one author ever exists } -void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr& network) +void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr& network, BaseInstance * inst) { QVector unsortedVersions; + bool hasFabric = !((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty(); + QString mcVersion = ((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.minecraft"); + for(auto versionIter: arr) { auto obj = versionIter.toObject(); Modrinth::IndexedVersion file; @@ -33,7 +40,6 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray if (versionArray.empty()) { continue; } - // pick the latest version supported for(auto mcVer : versionArray){ file.mcVersion.append(mcVer.toString()); } @@ -42,8 +48,35 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray file.loaders.append(loader.toString()); } file.version = Json::requireString(obj, "name"); - //TODO show all the files ? - auto parent = Json::requireArray(obj, "files")[0].toObject(); + + auto files = Json::requireArray(obj, "files"); + int i = 0; + while (files.count() > 1 && i < files.count()){ + //try to resolve the correct file + auto parent = files[i].toObject(); + auto fileName = Json::requireString(parent, "filename"); + //avoid grabbing "dev" files + if(fileName.contains("javadocs",Qt::CaseInsensitive) || fileName.contains("sources",Qt::CaseInsensitive)){ + i++; + continue; + } + //grab the correct mod loader + if(fileName.contains("forge",Qt::CaseInsensitive) || fileName.contains("fabric",Qt::CaseInsensitive) ){ + if(hasFabric){ + if(fileName.contains("forge",Qt::CaseInsensitive)){ + i++; + continue; + } + }else{ + if(fileName.contains("fabric",Qt::CaseInsensitive)){ + i++; + continue; + } + } + } + break; + } + auto parent = files[i].toObject(); file.downloadUrl = Json::requireString(parent, "url"); file.fileName = Json::requireString(parent, "filename"); diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.h b/launcher/modplatform/modrinth/ModrinthPackIndex.h index b3cffc40..01ae4b44 100644 --- a/launcher/modplatform/modrinth/ModrinthPackIndex.h +++ b/launcher/modplatform/modrinth/ModrinthPackIndex.h @@ -7,6 +7,7 @@ #include #include #include "net/NetJob.h" +#include "BaseInstance.h" namespace Modrinth { @@ -41,8 +42,7 @@ struct IndexedPack }; void loadIndexedPack(IndexedPack & m, QJsonObject & obj); -void loadIndexedPackVersions(IndexedPack & m, QJsonArray & arr, const shared_qobject_ptr& network); -void versionJobFinished(); +void loadIndexedPackVersions(IndexedPack &pack, QJsonArray &arr, const shared_qobject_ptr &network, BaseInstance *inst); } Q_DECLARE_METATYPE(Modrinth::IndexedPack) diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index f58a884c..fe5766dc 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -128,7 +128,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) QJsonArray arr = doc.array(); try { - Modrinth::loadIndexedPackVersions(current, arr, APPLICATION->network()); + Modrinth::loadIndexedPackVersions(current, arr, APPLICATION->network(), m_instance); } catch(const JSONValidationError &e) { @@ -145,7 +145,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl)); } if(ui->versionSelectionBox->count() == 0){ - ui->versionSelectionBox->addItem("No Valid Version found !", QVariant("")); + ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant("")); } suggestCurrent(); @@ -158,7 +158,7 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second) ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl)); } if(ui->versionSelectionBox->count() == 0){ - ui->versionSelectionBox->addItem("No Valid Version found !", QVariant("")); + ui->versionSelectionBox->addItem(tr("No Valid Version found !"), QVariant("")); } suggestCurrent(); } -- cgit