aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-11-20 11:04:10 -0300
committerflow <flowlnlnln@gmail.com>2022-11-20 11:10:26 -0300
commitdf0f9259c0bf79e10b27ad5b429b53559ffd15f0 (patch)
tree0f0d061fb8cc8017de86403e61e2abdcaf732c42 /launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
parentd92ae530d7c585eb859d852ba1877230a82d867e (diff)
downloadPrismLauncher-df0f9259c0bf79e10b27ad5b429b53559ffd15f0.tar.gz
PrismLauncher-df0f9259c0bf79e10b27ad5b429b53559ffd15f0.tar.bz2
PrismLauncher-df0f9259c0bf79e10b27ad5b429b53559ffd15f0.zip
refactor: move RP/TP validation to their respective utils
This makes it easier to validate individual resources, and allows the logic to be used in other places in the future, if we need to. Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp')
-rw-r--r--launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
index d744c535..f58a0620 100644
--- a/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
+++ b/launcher/minecraft/mod/tasks/LocalResourcePackParseTask.cpp
@@ -28,14 +28,14 @@
namespace ResourcePackUtils {
-bool process(ResourcePack& pack)
+bool process(ResourcePack& pack, ProcessingLevel level)
{
switch (pack.type()) {
case ResourceType::FOLDER:
- ResourcePackUtils::processFolder(pack);
+ ResourcePackUtils::processFolder(pack, level);
return true;
case ResourceType::ZIPFILE:
- ResourcePackUtils::processZIP(pack);
+ ResourcePackUtils::processZIP(pack, level);
return true;
default:
qWarning() << "Invalid type for resource pack parse task!";
@@ -43,7 +43,7 @@ bool process(ResourcePack& pack)
}
}
-void processFolder(ResourcePack& pack)
+void processFolder(ResourcePack& pack, ProcessingLevel level)
{
Q_ASSERT(pack.type() == ResourceType::FOLDER);
@@ -60,6 +60,9 @@ void processFolder(ResourcePack& pack)
mcmeta_file.close();
}
+ if (level == ProcessingLevel::BasicInfoOnly)
+ return;
+
QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png"));
if (image_file_info.isFile()) {
QFile mcmeta_file(image_file_info.filePath());
@@ -74,7 +77,7 @@ void processFolder(ResourcePack& pack)
}
}
-void processZIP(ResourcePack& pack)
+void processZIP(ResourcePack& pack, ProcessingLevel level)
{
Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
@@ -98,6 +101,11 @@ void processZIP(ResourcePack& pack)
file.close();
}
+ if (level == ProcessingLevel::BasicInfoOnly) {
+ zip.close();
+ return;
+ }
+
if (zip.setCurrentFile("pack.png")) {
if (!file.open(QIODevice::ReadOnly)) {
qCritical() << "Failed to open file in zip.";
@@ -138,6 +146,13 @@ void processPackPNG(ResourcePack& pack, QByteArray&& raw_data)
qWarning() << "Failed to parse pack.png.";
}
}
+
+bool validate(QFileInfo file)
+{
+ ResourcePack rp{ file };
+ return ResourcePackUtils::process(rp, ProcessingLevel::BasicInfoOnly) && rp.valid();
+}
+
} // namespace ResourcePackUtils
LocalResourcePackParseTask::LocalResourcePackParseTask(int token, ResourcePack& rp)