aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2022-12-24 20:38:29 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2022-12-24 20:43:17 -0700
commit8422e3ac01c861125fd6aea441714a2fb38e5ff9 (patch)
treef684e91976927f8139092a2d7fbf0d2b732ed004
parentcfce54fe46f7d3db39e50c4113cb9fc74d6719e2 (diff)
downloadPrismLauncher-8422e3ac01c861125fd6aea441714a2fb38e5ff9.tar.gz
PrismLauncher-8422e3ac01c861125fd6aea441714a2fb38e5ff9.tar.bz2
PrismLauncher-8422e3ac01c861125fd6aea441714a2fb38e5ff9.zip
feat: zip resource validation check for flame
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
-rw-r--r--launcher/minecraft/mod/DataPack.cpp2
-rw-r--r--launcher/minecraft/mod/ResourcePack.cpp2
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.cpp147
-rw-r--r--launcher/modplatform/flame/FlameInstanceCreationTask.h3
4 files changed, 120 insertions, 34 deletions
diff --git a/launcher/minecraft/mod/DataPack.cpp b/launcher/minecraft/mod/DataPack.cpp
index 6c333285..ea1d097b 100644
--- a/launcher/minecraft/mod/DataPack.cpp
+++ b/launcher/minecraft/mod/DataPack.cpp
@@ -41,7 +41,7 @@ void DataPack::setPackFormat(int new_format_id)
QMutexLocker locker(&m_data_lock);
if (!s_pack_format_versions.contains(new_format_id)) {
- qWarning() << "Pack format '%1' is not a recognized resource pack id!";
+ qWarning() << "Pack format '" << new_format_id << "' is not a recognized data pack id!";
}
m_pack_format = new_format_id;
diff --git a/launcher/minecraft/mod/ResourcePack.cpp b/launcher/minecraft/mod/ResourcePack.cpp
index 47da4fea..87995215 100644
--- a/launcher/minecraft/mod/ResourcePack.cpp
+++ b/launcher/minecraft/mod/ResourcePack.cpp
@@ -27,7 +27,7 @@ void ResourcePack::setPackFormat(int new_format_id)
QMutexLocker locker(&m_data_lock);
if (!s_pack_format_versions.contains(new_format_id)) {
- qWarning() << "Pack format '%1' is not a recognized resource pack id!";
+ qWarning() << "Pack format '" << new_format_id << "' is not a recognized resource pack id!";
}
m_pack_format = new_format_id;
diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
index 1d441f09..2b1bc8d0 100644
--- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
+++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp
@@ -53,6 +53,13 @@
#include "ui/dialogs/BlockedModsDialog.h"
#include "ui/dialogs/CustomMessageBox.h"
+#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
+#include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
+#include <minecraft/mod/tasks/LocalDataPackParseTask.h>
+#include <minecraft/mod/tasks/LocalModParseTask.h>
+#include <qdebug.h>
+#include <qfileinfo.h>
+
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
{ "1.4.2", "6.0.1.355" },
{ "1.4.7", "6.6.2.534" },
@@ -401,6 +408,11 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
QList<BlockedMod> blocked_mods;
auto anyBlocked = false;
for (const auto& result : results.files.values()) {
+
+ if(result.fileName.endsWith(".zip")) {
+ m_ZIP_resources.append(std::make_pair(result.fileName, result.targetFolder));
+ }
+
if (!result.resolved || result.url.isEmpty()) {
BlockedMod blocked_mod;
blocked_mod.name = result.fileName;
@@ -439,37 +451,6 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
}
}
-/// @brief copy the matched blocked mods to the instance staging area
-/// @param blocked_mods list of the blocked mods and their matched paths
-void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
-{
- setStatus(tr("Copying Blocked Mods..."));
- setAbortable(false);
- int i = 0;
- int total = blocked_mods.length();
- setProgress(i, total);
- for (auto const& mod : blocked_mods) {
- if (!mod.matched) {
- qDebug() << mod.name << "was not matched to a local file, skipping copy";
- continue;
- }
-
- auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", mod.targetFolder, mod.name);
-
- setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total)));
-
- qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path;
-
- if (!FS::copy(mod.localPath, dest_path)()) {
- qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed";
- }
-
- i++;
- setProgress(i, total);
- }
-
- setAbortable(true);
-}
void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
{
@@ -509,7 +490,10 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
}
m_mod_id_resolver.reset();
- connect(m_files_job.get(), &NetJob::succeeded, this, [&]() { m_files_job.reset(); });
+ connect(m_files_job.get(), &NetJob::succeeded, this, [&]() {
+ m_files_job.reset();
+ validateZIPResouces();
+ });
connect(m_files_job.get(), &NetJob::failed, [&](QString reason) {
m_files_job.reset();
setError(reason);
@@ -520,3 +504,102 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
setStatus(tr("Downloading mods..."));
m_files_job->start();
}
+
+/// @brief copy the matched blocked mods to the instance staging area
+/// @param blocked_mods list of the blocked mods and their matched paths
+void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
+{
+ setStatus(tr("Copying Blocked Mods..."));
+ setAbortable(false);
+ int i = 0;
+ int total = blocked_mods.length();
+ setProgress(i, total);
+ for (auto const& mod : blocked_mods) {
+ if (!mod.matched) {
+ qDebug() << mod.name << "was not matched to a local file, skipping copy";
+ continue;
+ }
+
+ auto destPath = FS::PathCombine(m_stagingPath, "minecraft", mod.targetFolder, mod.name);
+
+ setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total)));
+
+ qDebug() << "Will try to copy" << mod.localPath << "to" << destPath;
+
+ if (!FS::copy(mod.localPath, destPath)()) {
+ qDebug() << "Copy of" << mod.localPath << "to" << destPath << "Failed";
+ }
+
+ i++;
+ setProgress(i, total);
+ }
+
+ setAbortable(true);
+}
+
+static bool moveFile(QString src, QString dst)
+{
+ if (!FS::copy(src, dst)()) { // copy
+ qDebug() << "Copy of" << src << "to" << dst << "Failed!";
+ return false;
+ } else {
+ if (!FS::deletePath(src)) { // remove origonal
+ qDebug() << "Deleation of" << src << "Failed!";
+ return false;
+ };
+ }
+ return true;
+}
+
+void FlameCreationTask::validateZIPResouces()
+{
+ qDebug() << "Validating resoucres stored as .zip are in the right place";
+ for (auto [fileName, targetFolder] : m_ZIP_resources) {
+ qDebug() << "Checking" << fileName << "...";
+ auto localPath = FS::PathCombine(m_stagingPath, "minecraft", targetFolder, fileName);
+ QFileInfo localFileInfo(localPath);
+ if (localFileInfo.exists() && localFileInfo.isFile()) {
+ if (ResourcePackUtils::validate(localFileInfo)) {
+ if (targetFolder != "resourcepacks") {
+ qDebug() << "Target folder of" << fileName << "is incorrect, it's a resource pack.";
+ auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "resourcepacks", fileName);
+ qDebug() << "Moveing" << localPath << "to" << destPath;
+ moveFile(localPath, destPath);
+ } else {
+ qDebug() << fileName << "is in the right place :" << targetFolder;
+ }
+ } else if (TexturePackUtils::validate(localFileInfo)) {
+ if (targetFolder != "texturepacks") {
+ qDebug() << "Target folder of" << fileName << "is incorrect, it's a pre 1.6 texture pack.";
+ auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "texturepacks", fileName);
+ qDebug() << "Moveing" << localPath << "to" << destPath;
+ moveFile(localPath, destPath);
+ } else {
+ qDebug() << fileName << "is in the right place :" << targetFolder;
+ }
+ } else if (DataPackUtils::validate(localFileInfo)) {
+ if (targetFolder != "datapacks") {
+ qDebug() << "Target folder of" << fileName << "is incorrect, it's a data pack.";
+ auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "datapacks", fileName);
+ qDebug() << "Moveing" << localPath << "to" << destPath;
+ moveFile(localPath, destPath);
+ } else {
+ qDebug() << fileName << "is in the right place :" << targetFolder;
+ }
+ } else if (ModUtils::validate(localFileInfo)) {
+ if (targetFolder != "mods") {
+ qDebug() << "Target folder of" << fileName << "is incorrect, it's a mod.";
+ auto destPath = FS::PathCombine(m_stagingPath, "minecraft", "mods", fileName);
+ qDebug() << "Moveing" << localPath << "to" << destPath;
+ moveFile(localPath, destPath);
+ } else {
+ qDebug() << fileName << "is in the right place :" << targetFolder;
+ }
+ } else {
+ qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
+ }
+ } else {
+ qDebug() << "Can't find" << localPath << "to validate it, ignoreing";
+ }
+ }
+}
diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.h b/launcher/modplatform/flame/FlameInstanceCreationTask.h
index 3a1c729f..498e1d6e 100644
--- a/launcher/modplatform/flame/FlameInstanceCreationTask.h
+++ b/launcher/modplatform/flame/FlameInstanceCreationTask.h
@@ -77,6 +77,7 @@ class FlameCreationTask final : public InstanceCreationTask {
void idResolverSucceeded(QEventLoop&);
void setupDownloadJob(QEventLoop&);
void copyBlockedMods(QList<BlockedMod> const& blocked_mods);
+ void validateZIPResouces();
private:
QWidget* m_parent = nullptr;
@@ -90,5 +91,7 @@ class FlameCreationTask final : public InstanceCreationTask {
QString m_managed_id, m_managed_version_id;
+ QList<std::pair<QString, QString>> m_ZIP_resources;
+
std::optional<InstancePtr> m_instance;
};