aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod/tasks
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2022-12-24 11:22:06 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2022-12-24 15:55:10 -0700
commitccfe605920fba14d9e798bb26642d22ee45fe860 (patch)
tree95267d40dd4d8c8bbe8fad696df6116937034c18 /launcher/minecraft/mod/tasks
parent878614ff68163bbc95cbfc35611765f21a83bfed (diff)
downloadPrismLauncher-ccfe605920fba14d9e798bb26642d22ee45fe860.tar.gz
PrismLauncher-ccfe605920fba14d9e798bb26642d22ee45fe860.tar.bz2
PrismLauncher-ccfe605920fba14d9e798bb26642d22ee45fe860.zip
feat: add shaderpack validation
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/minecraft/mod/tasks')
-rw-r--r--launcher/minecraft/mod/tasks/LocalDataPackParseTask.h2
-rw-r--r--launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp8
-rw-r--r--launcher/minecraft/mod/tasks/LocalShaderPackParseTask copy.h0
-rw-r--r--launcher/minecraft/mod/tasks/LocalShaderPackParseTask.cpp116
-rw-r--r--launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h63
5 files changed, 184 insertions, 5 deletions
diff --git a/launcher/minecraft/mod/tasks/LocalDataPackParseTask.h b/launcher/minecraft/mod/tasks/LocalDataPackParseTask.h
index 9f6ece5c..54e3d398 100644
--- a/launcher/minecraft/mod/tasks/LocalDataPackParseTask.h
+++ b/launcher/minecraft/mod/tasks/LocalDataPackParseTask.h
@@ -47,7 +47,7 @@ bool validate(QFileInfo file);
class LocalDataPackParseTask : public Task {
Q_OBJECT
public:
- LocalDataPackParseTask(int token, DataPack& rp);
+ LocalDataPackParseTask(int token, DataPack& dp);
[[nodiscard]] bool canAbort() const override { return true; }
bool abort() override;
diff --git a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
index 18d7383d..2c41c9ae 100644
--- a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
+++ b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
@@ -75,15 +75,15 @@ bool processFolder(ResourcePack& pack, ProcessingLevel level)
QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png"));
if (image_file_info.exists() && image_file_info.isFile()) {
- QFile mcmeta_file(image_file_info.filePath());
- if (!mcmeta_file.open(QIODevice::ReadOnly))
+ QFile pack_png_file(image_file_info.filePath());
+ if (!pack_png_file.open(QIODevice::ReadOnly))
return false; // can't open pack.png file
- auto data = mcmeta_file.readAll();
+ auto data = pack_png_file.readAll();
bool pack_png_result = ResourcePackUtils::processPackPNG(pack, std::move(data));
- mcmeta_file.close();
+ pack_png_file.close();
if (!pack_png_result) {
return false; // pack.png invalid
}
diff --git a/launcher/minecraft/mod/tasks/LocalShaderPackParseTask copy.h b/launcher/minecraft/mod/tasks/LocalShaderPackParseTask copy.h
deleted file mode 100644
index e69de29b..00000000
--- a/launcher/minecraft/mod/tasks/LocalShaderPackParseTask copy.h
+++ /dev/null
diff --git a/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.cpp
new file mode 100644
index 00000000..088853b9
--- /dev/null
+++ b/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.cpp
@@ -0,0 +1,116 @@
+// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
+//
+// SPDX-License-Identifier: GPL-3.0-only
+
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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/>.
+ */
+
+#include "LocalShaderPackParseTask.h"
+
+#include "FileSystem.h"
+
+#include <quazip/quazip.h>
+#include <quazip/quazipfile.h>
+#include <quazip/quazipdir.h>
+
+namespace ShaderPackUtils {
+
+bool process(ShaderPack& pack, ProcessingLevel level)
+{
+ switch (pack.type()) {
+ case ResourceType::FOLDER:
+ return ShaderPackUtils::processFolder(pack, level);
+ case ResourceType::ZIPFILE:
+ return ShaderPackUtils::processZIP(pack, level);
+ default:
+ qWarning() << "Invalid type for shader pack parse task!";
+ return false;
+ }
+}
+
+bool processFolder(ShaderPack& pack, ProcessingLevel level)
+{
+ Q_ASSERT(pack.type() == ResourceType::FOLDER);
+
+ QFileInfo shaders_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "shaders"));
+ if (!shaders_dir_info.exists() || !shaders_dir_info.isDir()) {
+ return false; // assets dir does not exists or isn't valid
+ }
+ pack.setPackFormat(ShaderPackFormat::VALID);
+
+ if (level == ProcessingLevel::BasicInfoOnly) {
+ return true; // only need basic info already checked
+ }
+
+ return true; // all tests passed
+}
+
+bool processZIP(ShaderPack& pack, ProcessingLevel level)
+{
+ Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
+
+ QuaZip zip(pack.fileinfo().filePath());
+ if (!zip.open(QuaZip::mdUnzip))
+ return false; // can't open zip file
+
+ QuaZipFile file(&zip);
+
+ QuaZipDir zipDir(&zip);
+ if (!zipDir.exists("/shaders")) {
+ return false; // assets dir does not exists at zip root
+ }
+ pack.setPackFormat(ShaderPackFormat::VALID);
+
+ if (level == ProcessingLevel::BasicInfoOnly) {
+ zip.close();
+ return true; // only need basic info already checked
+ }
+
+ zip.close();
+
+ return true;
+}
+
+
+bool validate(QFileInfo file)
+{
+ ShaderPack sp{ file };
+ return ShaderPackUtils::process(sp, ProcessingLevel::BasicInfoOnly) && sp.valid();
+}
+
+} // namespace ShaderPackUtils
+
+LocalShaderPackParseTask::LocalShaderPackParseTask(int token, ShaderPack& sp)
+ : Task(nullptr, false), m_token(token), m_shader_pack(sp)
+{}
+
+bool LocalShaderPackParseTask::abort()
+{
+ m_aborted = true;
+ return true;
+}
+
+void LocalShaderPackParseTask::executeTask()
+{
+ if (!ShaderPackUtils::process(m_shader_pack))
+ return;
+
+ if (m_aborted)
+ emitAborted();
+ else
+ emitSucceeded();
+}
diff --git a/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h b/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h
index e69de29b..5d113508 100644
--- a/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h
+++ b/launcher/minecraft/mod/tasks/LocalShaderPackParseTask.h
@@ -0,0 +1,63 @@
+// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
+//
+// SPDX-License-Identifier: GPL-3.0-only
+
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.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 <QDebug>
+#include <QObject>
+
+#include "minecraft/mod/ShaderPack.h"
+
+#include "tasks/Task.h"
+
+namespace ShaderPackUtils {
+
+enum class ProcessingLevel { Full, BasicInfoOnly };
+
+bool process(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
+
+bool processZIP(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
+bool processFolder(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
+
+/** Checks whether a file is valid as a resource pack or not. */
+bool validate(QFileInfo file);
+} // namespace ShaderPackUtils
+
+class LocalShaderPackParseTask : public Task {
+ Q_OBJECT
+ public:
+ LocalShaderPackParseTask(int token, ShaderPack& sp);
+
+ [[nodiscard]] bool canAbort() const override { return true; }
+ bool abort() override;
+
+ void executeTask() override;
+
+ [[nodiscard]] int token() const { return m_token; }
+
+ private:
+ int m_token;
+
+ ShaderPack& m_shader_pack;
+
+ bool m_aborted = false;
+};