diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-06-22 13:26:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 13:26:47 -0700 |
commit | f1ebec641aa1a8f8992d6230a42001ad18c24a74 (patch) | |
tree | f0f15391035280e5c36cf3ed6119fbb0dbc6bcf1 /launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp | |
parent | c5f16276d74283169eccf3f6a8845da910af0221 (diff) | |
parent | 470518eb3a3e0e43d67b7a15823c060755ad3284 (diff) | |
download | PrismLauncher-f1ebec641aa1a8f8992d6230a42001ad18c24a74.tar.gz PrismLauncher-f1ebec641aa1a8f8992d6230a42001ad18c24a74.tar.bz2 PrismLauncher-f1ebec641aa1a8f8992d6230a42001ad18c24a74.zip |
Merge pull request #1058 from Ryex/feature/images-for-resource-page
Feature: image coumn for Mod, Resource Pack, and Texturepack pages
Diffstat (limited to 'launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp')
-rw-r--r-- | launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp index 38f1d7c1..a72e8115 100644 --- a/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp +++ b/launcher/minecraft/mod/tasks/LocalTexturePackParseTask.cpp @@ -131,6 +131,7 @@ bool processZIP(TexturePack& pack, ProcessingLevel level) bool packPNG_result = TexturePackUtils::processPackPNG(pack, std::move(data)); file.close(); + zip.close(); if (!packPNG_result) { return false; } @@ -147,7 +148,7 @@ bool processPackTXT(TexturePack& pack, QByteArray&& raw_data) return true; } -bool processPackPNG(TexturePack& pack, QByteArray&& raw_data) +bool processPackPNG(const TexturePack& pack, QByteArray&& raw_data) { auto img = QImage::fromData(raw_data); if (!img.isNull()) { @@ -159,6 +160,70 @@ bool processPackPNG(TexturePack& pack, QByteArray&& raw_data) return true; } +bool processPackPNG(const TexturePack& pack) +{ + auto png_invalid = [&pack]() { + qWarning() << "Texture pack at" << pack.fileinfo().filePath() << "does not have a valid pack.png"; + return false; + }; + + switch (pack.type()) { + case ResourceType::FOLDER: + { + QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png")); + if (image_file_info.exists() && image_file_info.isFile()) { + QFile pack_png_file(image_file_info.filePath()); + if (!pack_png_file.open(QIODevice::ReadOnly)) + return png_invalid(); // can't open pack.png file + + auto data = pack_png_file.readAll(); + + bool pack_png_result = TexturePackUtils::processPackPNG(pack, std::move(data)); + + pack_png_file.close(); + if (!pack_png_result) { + return png_invalid(); // pack.png invalid + } + } else { + return png_invalid(); // pack.png does not exists or is not a valid file. + } + } + case ResourceType::ZIPFILE: + { + 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); + if (zip.setCurrentFile("pack.png")) { + if (!file.open(QIODevice::ReadOnly)) { + qCritical() << "Failed to open file in zip."; + zip.close(); + return png_invalid(); + } + + auto data = file.readAll(); + + bool pack_png_result = TexturePackUtils::processPackPNG(pack, std::move(data)); + + file.close(); + if (!pack_png_result) { + zip.close(); + return png_invalid(); // pack.png invalid + } + } else { + zip.close(); + return png_invalid(); // could not set pack.mcmeta as current file. + } + } + default: + qWarning() << "Invalid type for resource pack parse task!"; + return false; + } +} + bool validate(QFileInfo file) { TexturePack rp{ file }; |