aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/minecraft')
-rw-r--r--launcher/minecraft/mod/MetadataHandler.h57
-rw-r--r--launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp132
-rw-r--r--launcher/minecraft/mod/tasks/GetModDependenciesTask.h65
-rw-r--r--launcher/minecraft/mod/tasks/LocalModGetAllTask.cpp52
-rw-r--r--launcher/minecraft/mod/tasks/LocalModGetAllTask.h45
-rw-r--r--launcher/minecraft/mod/tasks/LocalModUpdateTask.cpp33
6 files changed, 332 insertions, 52 deletions
diff --git a/launcher/minecraft/mod/MetadataHandler.h b/launcher/minecraft/mod/MetadataHandler.h
index 39723b49..f7f08a79 100644
--- a/launcher/minecraft/mod/MetadataHandler.h
+++ b/launcher/minecraft/mod/MetadataHandler.h
@@ -1,20 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
-* PolyMC - Minecraft Launcher
-* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, version 3.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#pragma once
@@ -42,28 +42,15 @@ class Metadata {
return Packwiz::V1::createModFormat(index_dir, internal_mod, mod_slug);
}
- static void update(QDir& index_dir, ModStruct& mod)
- {
- Packwiz::V1::updateModIndex(index_dir, mod);
- }
+ static void update(QDir& index_dir, ModStruct& mod) { Packwiz::V1::updateModIndex(index_dir, mod); }
- static void remove(QDir& index_dir, QString mod_slug)
- {
- Packwiz::V1::deleteModIndex(index_dir, mod_slug);
- }
+ static void remove(QDir& index_dir, QString mod_slug) { Packwiz::V1::deleteModIndex(index_dir, mod_slug); }
- static void remove(QDir& index_dir, QVariant& mod_id)
- {
- Packwiz::V1::deleteModIndex(index_dir, mod_id);
- }
+ static void remove(QDir& index_dir, QVariant& mod_id) { Packwiz::V1::deleteModIndex(index_dir, mod_id); }
- static auto get(QDir& index_dir, QString mod_slug) -> ModStruct
- {
- return Packwiz::V1::getIndexForMod(index_dir, mod_slug);
- }
+ static auto get(QDir& index_dir, QString mod_slug) -> ModStruct { return Packwiz::V1::getIndexForMod(index_dir, mod_slug); }
- static auto get(QDir& index_dir, QVariant& mod_id) -> ModStruct
- {
- return Packwiz::V1::getIndexForMod(index_dir, mod_id);
- }
+ static auto get(QDir& index_dir, QVariant& mod_id) -> ModStruct { return Packwiz::V1::getIndexForMod(index_dir, mod_id); }
+
+ static auto getAll(QDir& index_dir) -> QList<ModStruct> { return Packwiz::V1::getAllMods(index_dir); }
};
diff --git a/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp b/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp
new file mode 100644
index 00000000..7f184765
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "GetModDependenciesTask.h"
+
+#include <QDebug>
+#include "QObjectPtr.h"
+#include "minecraft/mod/MetadataHandler.h"
+#include "minecraft/mod/tasks/LocalModGetAllTask.h"
+#include "modplatform/ModIndex.h"
+#include "tasks/ConcurrentTask.h"
+#include "tasks/SequentialTask.h"
+
+GetModDependenciesTask::GetModDependenciesTask(QDir index_dir, QList<ModPlatform::IndexedVersion> selected, NewDependecyVersionAPITask api)
+ : m_selected(selected), m_getDependenciesVersionAPI(api)
+{
+ m_getAllMods = makeShared<LocalModGetAllTask>(index_dir);
+ m_getNetworkDep = makeShared<SequentialTask>(this, "GetDepInfo");
+ connect(m_getNetworkDep.get(), &Task::finished, &loop, &QEventLoop::quit);
+ QObject::connect(m_getAllMods.get(), &LocalModGetAllTask::getAllMods, [this](QList<Metadata::ModStruct> mods) {
+ m_mods = mods;
+ prepareDependecies();
+ });
+}
+
+void GetModDependenciesTask::executeTask()
+{
+ setStatus(tr("Geting all mods"));
+ m_getAllMods->start();
+ loop.exec();
+ emitSucceeded();
+}
+
+auto GetModDependenciesTask::abort() -> bool
+{
+ emitAborted();
+ return true;
+}
+
+void GetModDependenciesTask::prepareDependecies()
+{
+ auto c_dependencies = getDependenciesForVersions(m_selected);
+ if (c_dependencies.length() == 0) {
+ m_getNetworkDep->start();
+ return;
+ }
+ for (auto dep : c_dependencies) {
+ auto task =
+ m_getDependenciesVersionAPI(dep, [this](const ModPlatform::IndexedVersion& new_version) { addDependecies(new_version, 20); });
+ m_getNetworkDep->addTask(task);
+ }
+ m_getNetworkDep->start();
+}
+
+void GetModDependenciesTask::addDependecies(const ModPlatform::IndexedVersion& new_version, int level)
+{
+ // some mutex?
+ m_dependencies.append(new_version);
+ auto c_dependencies = getDependenciesForVersion(new_version);
+ if (c_dependencies.length() == 0) {
+ return;
+ }
+ if (level == 0) {
+ qWarning() << "Dependency cycle exeeded";
+ return;
+ }
+ for (auto dep : c_dependencies) {
+ auto task = m_getDependenciesVersionAPI(
+ dep, [this, level](const ModPlatform::IndexedVersion& new_versions) { addDependecies(new_versions, level - 1); });
+ m_getNetworkDep->addTask(task);
+ }
+};
+
+QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersions(const QList<ModPlatform::IndexedVersion>& selected)
+{
+ auto c_dependencies = QList<ModPlatform::Dependency>();
+ for (auto version : selected) {
+ for (auto ver_dep : version.dependencies) {
+ if (ver_dep.type == ModPlatform::DependencyType::REQUIRED) {
+ if (auto dep = std::find_if(c_dependencies.begin(), c_dependencies.end(),
+ [&ver_dep](const auto& i) { return i.addonId == ver_dep.addonId; });
+ dep == c_dependencies.end()) { // check the current dependency list
+ if (auto dep = std::find_if(selected.begin(), selected.end(),
+ [&ver_dep](const auto& i) { return i.addonId == ver_dep.addonId; });
+ dep == selected.end()) { // check the selected versions
+ if (auto dep = std::find_if(m_mods.begin(), m_mods.end(),
+ [&ver_dep](const auto& i) { return i.project_id == ver_dep.addonId; });
+ dep == m_mods.end()) { // check the existing mods
+ c_dependencies.append(ver_dep);
+ }
+ }
+ }
+ }
+ }
+ }
+ return c_dependencies;
+};
+
+QList<ModPlatform::Dependency> GetModDependenciesTask::getDependenciesForVersion(const ModPlatform::IndexedVersion& version)
+{
+ auto c_dependencies = QList<ModPlatform::Dependency>();
+ for (auto ver_dep : version.dependencies) {
+ if (ver_dep.type == ModPlatform::DependencyType::REQUIRED) {
+ if (auto dep = std::find_if(c_dependencies.begin(), c_dependencies.end(),
+ [&ver_dep](const auto& i) { return i.addonId == ver_dep.addonId; });
+ dep == c_dependencies.end()) { // check the current dependency list
+ if (auto dep =
+ std::find_if(m_mods.begin(), m_mods.end(), [&ver_dep](const auto& i) { return i.project_id == ver_dep.addonId; });
+ dep == m_mods.end()) { // check the existing mods
+ c_dependencies.append(ver_dep);
+ }
+ }
+ }
+ }
+ return c_dependencies;
+}; \ No newline at end of file
diff --git a/launcher/minecraft/mod/tasks/GetModDependenciesTask.h b/launcher/minecraft/mod/tasks/GetModDependenciesTask.h
new file mode 100644
index 00000000..7f7e1fb1
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/GetModDependenciesTask.h
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QDir>
+#include <QEventLoop>
+#include <functional>
+
+#include "minecraft/mod/MetadataHandler.h"
+#include "minecraft/mod/tasks/LocalModGetAllTask.h"
+#include "modplatform/ModIndex.h"
+#include "tasks/SequentialTask.h"
+#include "tasks/Task.h"
+
+class GetModDependenciesTask : public Task {
+ Q_OBJECT
+ public:
+ using Ptr = shared_qobject_ptr<GetModDependenciesTask>;
+ using LocalModGetAllTaskPtr = shared_qobject_ptr<LocalModGetAllTask>;
+
+ using NewDependecyVersionAPITask =
+ std::function<Task::Ptr(const ModPlatform::Dependency&, std::function<void(const ModPlatform::IndexedVersion&)>)>;
+
+ explicit GetModDependenciesTask(QDir index_dir, QList<ModPlatform::IndexedVersion> selected, NewDependecyVersionAPITask api);
+
+ auto canAbort() const -> bool override { return true; }
+ auto abort() -> bool override;
+
+ auto getDependecies() const -> QList<ModPlatform::IndexedVersion> { return m_dependencies; }
+
+ protected slots:
+ //! Entry point for tasks.
+ void executeTask() override;
+
+ void prepareDependecies();
+ void addDependecies(const ModPlatform::IndexedVersion&, int);
+ QList<ModPlatform::Dependency> getDependenciesForVersions(const QList<ModPlatform::IndexedVersion>&);
+ QList<ModPlatform::Dependency> getDependenciesForVersion(const ModPlatform::IndexedVersion&);
+
+ private:
+ QList<ModPlatform::IndexedVersion> m_selected;
+ QList<ModPlatform::IndexedVersion> m_dependencies;
+ QList<Metadata::ModStruct> m_mods;
+
+ LocalModGetAllTaskPtr m_getAllMods = nullptr;
+ NewDependecyVersionAPITask m_getDependenciesVersionAPI;
+ SequentialTask::Ptr m_getNetworkDep;
+ QEventLoop loop;
+};
diff --git a/launcher/minecraft/mod/tasks/LocalModGetAllTask.cpp b/launcher/minecraft/mod/tasks/LocalModGetAllTask.cpp
new file mode 100644
index 00000000..67058807
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/LocalModGetAllTask.cpp
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include "LocalModGetAllTask.h"
+
+#include "FileSystem.h"
+#include "minecraft/mod/MetadataHandler.h"
+
+#ifdef Q_OS_WIN32
+#include <windows.h>
+#endif
+
+LocalModGetAllTask::LocalModGetAllTask(QDir index_dir) : m_index_dir(index_dir)
+{
+ // Ensure a '.index' folder exists in the mods folder, and create it if it does not
+ if (!FS::ensureFolderPathExists(index_dir.path())) {
+ emitFailed(QString("Unable to create index for all mods!"));
+ }
+
+#ifdef Q_OS_WIN32
+ SetFileAttributesW(index_dir.path().toStdWString().c_str(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
+#endif
+}
+
+void LocalModGetAllTask::executeTask()
+{
+ setStatus(tr("Geting all mods"));
+ emit getAllMods(Metadata::getAll(m_index_dir));
+ emitSucceeded();
+}
+
+auto LocalModGetAllTask::abort() -> bool
+{
+ emitAborted();
+ return true;
+}
diff --git a/launcher/minecraft/mod/tasks/LocalModGetAllTask.h b/launcher/minecraft/mod/tasks/LocalModGetAllTask.h
new file mode 100644
index 00000000..bf4b78b7
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/LocalModGetAllTask.h
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QDir>
+
+#include "minecraft/mod/MetadataHandler.h"
+#include "tasks/Task.h"
+
+class LocalModGetAllTask : public Task {
+ Q_OBJECT
+ public:
+ using Ptr = shared_qobject_ptr<LocalModGetAllTask>;
+
+ explicit LocalModGetAllTask(QDir index_dir);
+
+ auto canAbort() const -> bool override { return true; }
+ auto abort() -> bool override;
+
+ protected slots:
+ //! Entry point for tasks.
+ void executeTask() override;
+
+ signals:
+ void getAllMods(QList<Metadata::ModStruct>);
+
+ private:
+ QDir m_index_dir;
+};
diff --git a/launcher/minecraft/mod/tasks/LocalModUpdateTask.cpp b/launcher/minecraft/mod/tasks/LocalModUpdateTask.cpp
index cc4e252c..6b139ca1 100644
--- a/launcher/minecraft/mod/tasks/LocalModUpdateTask.cpp
+++ b/launcher/minecraft/mod/tasks/LocalModUpdateTask.cpp
@@ -1,25 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
-* PolyMC - Minecraft Launcher
-* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
-* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, version 3.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
+ * PolyMC - Minecraft Launcher
+ * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
+ * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
#include "LocalModUpdateTask.h"
-#include "Application.h"
#include "FileSystem.h"
#include "minecraft/mod/MetadataHandler.h"