Merge pull request #481 from ryanccn/import-resource-pack-dialog-uwu
This commit is contained in:
@ -15,7 +15,7 @@ static const QMap<int, std::pair<Version, Version>> s_pack_format_versions = {
|
||||
{ 3, { Version("1.11"), Version("1.12.2") } }, { 4, { Version("1.13"), Version("1.14.4") } },
|
||||
{ 5, { Version("1.15"), Version("1.16.1") } }, { 6, { Version("1.16.2"), Version("1.16.5") } },
|
||||
{ 7, { Version("1.17"), Version("1.17.1") } }, { 8, { Version("1.18"), Version("1.18.2") } },
|
||||
{ 9, { Version("1.19"), Version("1.19.2") } },
|
||||
{ 9, { Version("1.19"), Version("1.19.2") } }, { 11, { Version("1.19.3"), Version("1.19.3") } },
|
||||
};
|
||||
|
||||
void ResourcePack::setPackFormat(int new_format_id)
|
||||
@ -114,3 +114,8 @@ bool ResourcePack::applyFilter(QRegularExpression filter) const
|
||||
|
||||
return Resource::applyFilter(filter);
|
||||
}
|
||||
|
||||
bool ResourcePack::valid() const
|
||||
{
|
||||
return m_pack_format != 0;
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ class ResourcePack : public Resource {
|
||||
/** Thread-safe. */
|
||||
void setImage(QImage new_image);
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
|
||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||
|
||||
|
@ -62,3 +62,8 @@ QPixmap TexturePack::image(QSize size)
|
||||
TexturePackUtils::process(*this);
|
||||
return image(size);
|
||||
}
|
||||
|
||||
bool TexturePack::valid() const
|
||||
{
|
||||
return m_description != nullptr;
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ class TexturePack : public Resource {
|
||||
/** Thread-safe. */
|
||||
void setImage(QImage new_image);
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
protected:
|
||||
mutable QMutex m_data_lock;
|
||||
|
||||
|
@ -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)
|
||||
@ -152,8 +167,6 @@ bool LocalResourcePackParseTask::abort()
|
||||
|
||||
void LocalResourcePackParseTask::executeTask()
|
||||
{
|
||||
Q_ASSERT(m_resource_pack.valid());
|
||||
|
||||
if (!ResourcePackUtils::process(m_resource_pack))
|
||||
return;
|
||||
|
||||
|
@ -26,13 +26,19 @@
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace ResourcePackUtils {
|
||||
bool process(ResourcePack& pack);
|
||||
|
||||
void processZIP(ResourcePack& pack);
|
||||
void processFolder(ResourcePack& pack);
|
||||
enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processZIP(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
void processFolder(ResourcePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processMCMeta(ResourcePack& pack, QByteArray&& raw_data);
|
||||
void processPackPNG(ResourcePack& pack, QByteArray&& raw_data);
|
||||
|
||||
/** Checks whether a file is valid as a resource pack or not. */
|
||||
bool validate(QFileInfo file);
|
||||
} // namespace ResourcePackUtils
|
||||
|
||||
class LocalResourcePackParseTask : public Task {
|
||||
|
@ -28,14 +28,14 @@
|
||||
|
||||
namespace TexturePackUtils {
|
||||
|
||||
bool process(TexturePack& pack)
|
||||
bool process(TexturePack& pack, ProcessingLevel level)
|
||||
{
|
||||
switch (pack.type()) {
|
||||
case ResourceType::FOLDER:
|
||||
TexturePackUtils::processFolder(pack);
|
||||
TexturePackUtils::processFolder(pack, level);
|
||||
return true;
|
||||
case ResourceType::ZIPFILE:
|
||||
TexturePackUtils::processZIP(pack);
|
||||
TexturePackUtils::processZIP(pack, level);
|
||||
return true;
|
||||
default:
|
||||
qWarning() << "Invalid type for resource pack parse task!";
|
||||
@ -43,7 +43,7 @@ bool process(TexturePack& pack)
|
||||
}
|
||||
}
|
||||
|
||||
void processFolder(TexturePack& pack)
|
||||
void processFolder(TexturePack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||
|
||||
@ -60,6 +60,9 @@ void processFolder(TexturePack& 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(TexturePack& pack)
|
||||
}
|
||||
}
|
||||
|
||||
void processZIP(TexturePack& pack)
|
||||
void processZIP(TexturePack& pack, ProcessingLevel level)
|
||||
{
|
||||
Q_ASSERT(pack.type() == ResourceType::ZIPFILE);
|
||||
|
||||
@ -98,6 +101,11 @@ void processZIP(TexturePack& 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.";
|
||||
@ -129,6 +137,13 @@ void processPackPNG(TexturePack& pack, QByteArray&& raw_data)
|
||||
qWarning() << "Failed to parse pack.png.";
|
||||
}
|
||||
}
|
||||
|
||||
bool validate(QFileInfo file)
|
||||
{
|
||||
TexturePack rp{ file };
|
||||
return TexturePackUtils::process(rp, ProcessingLevel::BasicInfoOnly) && rp.valid();
|
||||
}
|
||||
|
||||
} // namespace TexturePackUtils
|
||||
|
||||
LocalTexturePackParseTask::LocalTexturePackParseTask(int token, TexturePack& rp)
|
||||
@ -143,8 +158,6 @@ bool LocalTexturePackParseTask::abort()
|
||||
|
||||
void LocalTexturePackParseTask::executeTask()
|
||||
{
|
||||
Q_ASSERT(m_texture_pack.valid());
|
||||
|
||||
if (!TexturePackUtils::process(m_texture_pack))
|
||||
return;
|
||||
|
||||
|
@ -27,13 +27,19 @@
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace TexturePackUtils {
|
||||
bool process(TexturePack& pack);
|
||||
|
||||
void processZIP(TexturePack& pack);
|
||||
void processFolder(TexturePack& pack);
|
||||
enum class ProcessingLevel { Full, BasicInfoOnly };
|
||||
|
||||
bool process(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processZIP(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
void processFolder(TexturePack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||
|
||||
void processPackTXT(TexturePack& pack, QByteArray&& raw_data);
|
||||
void processPackPNG(TexturePack& pack, QByteArray&& raw_data);
|
||||
|
||||
/** Checks whether a file is valid as a texture pack or not. */
|
||||
bool validate(QFileInfo file);
|
||||
} // namespace TexturePackUtils
|
||||
|
||||
class LocalTexturePackParseTask : public Task {
|
||||
|
Reference in New Issue
Block a user