fix: cleanup and suggested changes
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
b2082bfde7
commit
3691f3a296
@ -45,7 +45,7 @@ class DataPack : public Resource {
|
|||||||
/** Gets, respectively, the lower and upper versions supported by the set pack format. */
|
/** Gets, respectively, the lower and upper versions supported by the set pack format. */
|
||||||
[[nodiscard]] std::pair<Version, Version> compatibleVersions() const;
|
[[nodiscard]] std::pair<Version, Version> compatibleVersions() const;
|
||||||
|
|
||||||
/** Gets the description of the resource pack. */
|
/** Gets the description of the data pack. */
|
||||||
[[nodiscard]] QString description() const { return m_description; }
|
[[nodiscard]] QString description() const { return m_description; }
|
||||||
|
|
||||||
/** Thread-safe. */
|
/** Thread-safe. */
|
||||||
@ -62,12 +62,12 @@ class DataPack : public Resource {
|
|||||||
protected:
|
protected:
|
||||||
mutable QMutex m_data_lock;
|
mutable QMutex m_data_lock;
|
||||||
|
|
||||||
/* The 'version' of a resource pack, as defined in the pack.mcmeta file.
|
/* The 'version' of a data pack, as defined in the pack.mcmeta file.
|
||||||
* See https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
|
* See https://minecraft.fandom.com/wiki/Data_pack#pack.mcmeta
|
||||||
*/
|
*/
|
||||||
int m_pack_format = 0;
|
int m_pack_format = 0;
|
||||||
|
|
||||||
/** The resource pack's description, as defined in the pack.mcmeta file.
|
/** The data pack's description, as defined in the pack.mcmeta file.
|
||||||
*/
|
*/
|
||||||
QString m_description;
|
QString m_description;
|
||||||
};
|
};
|
||||||
|
@ -17,8 +17,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") } },
|
{ 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") } },
|
{ 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") } },
|
{ 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("22w42a"), Version("22w44a") } },
|
||||||
// { 11, { Version("22w42a"), Version("22w44a") } }
|
|
||||||
{ 12, { Version("1.19.3"), Version("1.19.3") } },
|
{ 12, { Version("1.19.3"), Version("1.19.3") } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,12 +24,10 @@
|
|||||||
|
|
||||||
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h"
|
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h"
|
||||||
|
|
||||||
|
|
||||||
void ShaderPack::setPackFormat(ShaderPackFormat new_format)
|
void ShaderPack::setPackFormat(ShaderPackFormat new_format)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_data_lock);
|
QMutexLocker locker(&m_data_lock);
|
||||||
|
|
||||||
|
|
||||||
m_pack_format = new_format;
|
m_pack_format = new_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,24 +25,20 @@
|
|||||||
|
|
||||||
/* Info:
|
/* Info:
|
||||||
* Currently For Optifine / Iris shader packs,
|
* Currently For Optifine / Iris shader packs,
|
||||||
* could be expanded to support others should they exsist?
|
* could be expanded to support others should they exist?
|
||||||
*
|
*
|
||||||
* This class and enum are mostly here as placeholders for validating
|
* This class and enum are mostly here as placeholders for validating
|
||||||
* that a shaderpack exsists and is in the right format,
|
* that a shaderpack exists and is in the right format,
|
||||||
* namely that they contain a folder named 'shaders'.
|
* namely that they contain a folder named 'shaders'.
|
||||||
*
|
*
|
||||||
* In the technical sense it would be possible to parse files like `shaders/shaders.properties`
|
* In the technical sense it would be possible to parse files like `shaders/shaders.properties`
|
||||||
* to get information like the availble profiles but this is not all that usefull without more knoledge of the
|
* to get information like the available profiles but this is not all that useful without more knowledge of the
|
||||||
* shader mod used to be able to change settings
|
* shader mod used to be able to change settings.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
enum class ShaderPackFormat {
|
enum class ShaderPackFormat { VALID, INVALID };
|
||||||
VALID,
|
|
||||||
INVALID
|
|
||||||
};
|
|
||||||
|
|
||||||
class ShaderPack : public Resource {
|
class ShaderPack : public Resource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -27,7 +27,6 @@ void WorldSave::setSaveFormat(WorldSaveFormat new_save_format)
|
|||||||
{
|
{
|
||||||
QMutexLocker locker(&m_data_lock);
|
QMutexLocker locker(&m_data_lock);
|
||||||
|
|
||||||
|
|
||||||
m_save_format = new_save_format;
|
m_save_format = new_save_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +34,6 @@ void WorldSave::setSaveDirName(QString dir_name)
|
|||||||
{
|
{
|
||||||
QMutexLocker locker(&m_data_lock);
|
QMutexLocker locker(&m_data_lock);
|
||||||
|
|
||||||
|
|
||||||
m_save_dir_name = dir_name;
|
m_save_dir_name = dir_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,11 +27,7 @@
|
|||||||
|
|
||||||
class Version;
|
class Version;
|
||||||
|
|
||||||
enum class WorldSaveFormat {
|
enum class WorldSaveFormat { SINGLE, MULTI, INVALID };
|
||||||
SINGLE,
|
|
||||||
MULTI,
|
|
||||||
INVALID
|
|
||||||
};
|
|
||||||
|
|
||||||
class WorldSave : public Resource {
|
class WorldSave : public Resource {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -53,15 +49,13 @@ class WorldSave : public Resource {
|
|||||||
|
|
||||||
bool valid() const override;
|
bool valid() const override;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable QMutex m_data_lock;
|
mutable QMutex m_data_lock;
|
||||||
|
|
||||||
/* The 'version' of a resource pack, as defined in the pack.mcmeta file.
|
/** The format in which the save file is in.
|
||||||
* See https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
|
* Since saves can be distributed in various slightly different ways, this allows us to treat them separately.
|
||||||
*/
|
*/
|
||||||
WorldSaveFormat m_save_format = WorldSaveFormat::INVALID;
|
WorldSaveFormat m_save_format = WorldSaveFormat::INVALID;
|
||||||
|
|
||||||
QString m_save_dir_name;
|
QString m_save_dir_name;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
#include <quazip/quazipfile.h>
|
|
||||||
#include <quazip/quazipdir.h>
|
#include <quazip/quazipdir.h>
|
||||||
|
#include <quazip/quazipfile.h>
|
||||||
|
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ bool process(DataPack& pack, ProcessingLevel level)
|
|||||||
case ResourceType::ZIPFILE:
|
case ResourceType::ZIPFILE:
|
||||||
return DataPackUtils::processZIP(pack, level);
|
return DataPackUtils::processZIP(pack, level);
|
||||||
default:
|
default:
|
||||||
qWarning() << "Invalid type for resource pack parse task!";
|
qWarning() << "Invalid type for data pack parse task!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,11 +49,16 @@ bool processFolder(DataPack& pack, ProcessingLevel level)
|
|||||||
{
|
{
|
||||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||||
|
|
||||||
|
auto mcmeta_invalid = [&pack]() {
|
||||||
|
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||||
|
return false; // the mcmeta is not optional
|
||||||
|
};
|
||||||
|
|
||||||
QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.mcmeta"));
|
QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.mcmeta"));
|
||||||
if (mcmeta_file_info.exists() && mcmeta_file_info.isFile()) {
|
if (mcmeta_file_info.exists() && mcmeta_file_info.isFile()) {
|
||||||
QFile mcmeta_file(mcmeta_file_info.filePath());
|
QFile mcmeta_file(mcmeta_file_info.filePath());
|
||||||
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
||||||
return false; // can't open mcmeta file
|
return mcmeta_invalid(); // can't open mcmeta file
|
||||||
|
|
||||||
auto data = mcmeta_file.readAll();
|
auto data = mcmeta_file.readAll();
|
||||||
|
|
||||||
@ -61,10 +66,10 @@ bool processFolder(DataPack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
mcmeta_file.close();
|
mcmeta_file.close();
|
||||||
if (!mcmeta_result) {
|
if (!mcmeta_result) {
|
||||||
return false; // mcmeta invalid
|
return mcmeta_invalid(); // mcmeta invalid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // mcmeta file isn't a valid file
|
return mcmeta_invalid(); // mcmeta file isn't a valid file
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo data_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "data"));
|
QFileInfo data_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "data"));
|
||||||
@ -89,11 +94,16 @@ bool processZIP(DataPack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
QuaZipFile file(&zip);
|
QuaZipFile file(&zip);
|
||||||
|
|
||||||
|
auto mcmeta_invalid = [&pack]() {
|
||||||
|
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||||
|
return false; // the mcmeta is not optional
|
||||||
|
};
|
||||||
|
|
||||||
if (zip.setCurrentFile("pack.mcmeta")) {
|
if (zip.setCurrentFile("pack.mcmeta")) {
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Failed to open file in zip.";
|
qCritical() << "Failed to open file in zip.";
|
||||||
zip.close();
|
zip.close();
|
||||||
return false;
|
return mcmeta_invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = file.readAll();
|
auto data = file.readAll();
|
||||||
@ -102,10 +112,10 @@ bool processZIP(DataPack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
if (!mcmeta_result) {
|
if (!mcmeta_result) {
|
||||||
return false; // mcmeta invalid
|
return mcmeta_invalid(); // mcmeta invalid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // could not set pack.mcmeta as current file.
|
return mcmeta_invalid(); // could not set pack.mcmeta as current file.
|
||||||
}
|
}
|
||||||
|
|
||||||
QuaZipDir zipDir(&zip);
|
QuaZipDir zipDir(&zip);
|
||||||
@ -123,7 +133,7 @@ bool processZIP(DataPack& pack, ProcessingLevel level)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://minecraft.fandom.com/wiki/Tutorials/Creating_a_resource_pack#Formatting_pack.mcmeta
|
// https://minecraft.fandom.com/wiki/Data_pack#pack.mcmeta
|
||||||
bool processMCMeta(DataPack& pack, QByteArray&& raw_data)
|
bool processMCMeta(DataPack& pack, QByteArray&& raw_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -147,9 +157,7 @@ bool validate(QFileInfo file)
|
|||||||
|
|
||||||
} // namespace DataPackUtils
|
} // namespace DataPackUtils
|
||||||
|
|
||||||
LocalDataPackParseTask::LocalDataPackParseTask(int token, DataPack& dp)
|
LocalDataPackParseTask::LocalDataPackParseTask(int token, DataPack& dp) : Task(nullptr, false), m_token(token), m_data_pack(dp) {}
|
||||||
: Task(nullptr, false), m_token(token), m_resource_pack(dp)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool LocalDataPackParseTask::abort()
|
bool LocalDataPackParseTask::abort()
|
||||||
{
|
{
|
||||||
@ -159,7 +167,7 @@ bool LocalDataPackParseTask::abort()
|
|||||||
|
|
||||||
void LocalDataPackParseTask::executeTask()
|
void LocalDataPackParseTask::executeTask()
|
||||||
{
|
{
|
||||||
if (!DataPackUtils::process(m_resource_pack))
|
if (!DataPackUtils::process(m_data_pack))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_aborted)
|
if (m_aborted)
|
||||||
|
@ -59,7 +59,7 @@ class LocalDataPackParseTask : public Task {
|
|||||||
private:
|
private:
|
||||||
int m_token;
|
int m_token;
|
||||||
|
|
||||||
DataPack& m_resource_pack;
|
DataPack& m_data_pack;
|
||||||
|
|
||||||
bool m_aborted = false;
|
bool m_aborted = false;
|
||||||
};
|
};
|
||||||
|
@ -284,7 +284,8 @@ ModDetails ReadLiteModInfo(QByteArray contents)
|
|||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process(Mod& mod, ProcessingLevel level) {
|
bool process(Mod& mod, ProcessingLevel level)
|
||||||
|
{
|
||||||
switch (mod.type()) {
|
switch (mod.type()) {
|
||||||
case ResourceType::FOLDER:
|
case ResourceType::FOLDER:
|
||||||
return processFolder(mod, level);
|
return processFolder(mod, level);
|
||||||
@ -293,13 +294,13 @@ bool process(Mod& mod, ProcessingLevel level) {
|
|||||||
case ResourceType::LITEMOD:
|
case ResourceType::LITEMOD:
|
||||||
return processLitemod(mod);
|
return processLitemod(mod);
|
||||||
default:
|
default:
|
||||||
qWarning() << "Invalid type for resource pack parse task!";
|
qWarning() << "Invalid type for mod parse task!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool processZIP(Mod& mod, ProcessingLevel level) {
|
bool processZIP(Mod& mod, ProcessingLevel level)
|
||||||
|
{
|
||||||
ModDetails details;
|
ModDetails details;
|
||||||
|
|
||||||
QuaZip zip(mod.fileinfo().filePath());
|
QuaZip zip(mod.fileinfo().filePath());
|
||||||
@ -347,7 +348,6 @@ bool processZIP(Mod& mod, ProcessingLevel level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
zip.close();
|
zip.close();
|
||||||
mod.setDetails(details);
|
mod.setDetails(details);
|
||||||
|
|
||||||
@ -406,8 +406,8 @@ bool processZIP(Mod& mod, ProcessingLevel level) {
|
|||||||
return false; // no valid mod found in archive
|
return false; // no valid mod found in archive
|
||||||
}
|
}
|
||||||
|
|
||||||
bool processFolder(Mod& mod, ProcessingLevel level) {
|
bool processFolder(Mod& mod, ProcessingLevel level)
|
||||||
|
{
|
||||||
ModDetails details;
|
ModDetails details;
|
||||||
|
|
||||||
QFileInfo mcmod_info(FS::PathCombine(mod.fileinfo().filePath(), "mcmod.info"));
|
QFileInfo mcmod_info(FS::PathCombine(mod.fileinfo().filePath(), "mcmod.info"));
|
||||||
@ -427,8 +427,8 @@ bool processFolder(Mod& mod, ProcessingLevel level) {
|
|||||||
return false; // no valid mcmod.info file found
|
return false; // no valid mcmod.info file found
|
||||||
}
|
}
|
||||||
|
|
||||||
bool processLitemod(Mod& mod, ProcessingLevel level) {
|
bool processLitemod(Mod& mod, ProcessingLevel level)
|
||||||
|
{
|
||||||
ModDetails details;
|
ModDetails details;
|
||||||
|
|
||||||
QuaZip zip(mod.fileinfo().filePath());
|
QuaZip zip(mod.fileinfo().filePath());
|
||||||
@ -455,20 +455,18 @@ bool processLitemod(Mod& mod, ProcessingLevel level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Checks whether a file is valid as a mod or not. */
|
/** Checks whether a file is valid as a mod or not. */
|
||||||
bool validate(QFileInfo file) {
|
bool validate(QFileInfo file)
|
||||||
|
{
|
||||||
Mod mod{ file };
|
Mod mod{ file };
|
||||||
return ModUtils::process(mod, ProcessingLevel::BasicInfoOnly) && mod.valid();
|
return ModUtils::process(mod, ProcessingLevel::BasicInfoOnly) && mod.valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ModUtils
|
} // namespace ModUtils
|
||||||
|
|
||||||
|
|
||||||
LocalModParseTask::LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile)
|
LocalModParseTask::LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile)
|
||||||
: Task(nullptr, false), m_token(token), m_type(type), m_modFile(modFile), m_result(new Result())
|
: Task(nullptr, false), m_token(token), m_type(type), m_modFile(modFile), m_result(new Result())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
bool LocalModParseTask::abort()
|
bool LocalModParseTask::abort()
|
||||||
{
|
{
|
||||||
m_aborted.store(true);
|
m_aborted.store(true);
|
||||||
|
@ -27,32 +27,29 @@ bool processLitemod(Mod& mod, ProcessingLevel level = ProcessingLevel::Full);
|
|||||||
bool validate(QFileInfo file);
|
bool validate(QFileInfo file);
|
||||||
} // namespace ModUtils
|
} // namespace ModUtils
|
||||||
|
|
||||||
class LocalModParseTask : public Task
|
class LocalModParseTask : public Task {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
struct Result {
|
struct Result {
|
||||||
ModDetails details;
|
ModDetails details;
|
||||||
};
|
};
|
||||||
using ResultPtr = std::shared_ptr<Result>;
|
using ResultPtr = std::shared_ptr<Result>;
|
||||||
ResultPtr result() const {
|
ResultPtr result() const { return m_result; }
|
||||||
return m_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] bool canAbort() const override { return true; }
|
[[nodiscard]] bool canAbort() const override { return true; }
|
||||||
bool abort() override;
|
bool abort() override;
|
||||||
|
|
||||||
LocalModParseTask(int token, ResourceType type, const QFileInfo & modFile);
|
LocalModParseTask(int token, ResourceType type, const QFileInfo& modFile);
|
||||||
void executeTask() override;
|
void executeTask() override;
|
||||||
|
|
||||||
[[nodiscard]] int token() const { return m_token; }
|
[[nodiscard]] int token() const { return m_token; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processAsZip();
|
void processAsZip();
|
||||||
void processAsFolder();
|
void processAsFolder();
|
||||||
void processAsLitemod();
|
void processAsLitemod();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_token;
|
int m_token;
|
||||||
ResourceType m_type;
|
ResourceType m_type;
|
||||||
QFileInfo m_modFile;
|
QFileInfo m_modFile;
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
#include <quazip/quazipfile.h>
|
|
||||||
#include <quazip/quazipdir.h>
|
#include <quazip/quazipdir.h>
|
||||||
|
#include <quazip/quazipfile.h>
|
||||||
|
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
|
||||||
@ -46,11 +46,16 @@ bool processFolder(ResourcePack& pack, ProcessingLevel level)
|
|||||||
{
|
{
|
||||||
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
Q_ASSERT(pack.type() == ResourceType::FOLDER);
|
||||||
|
|
||||||
|
auto mcmeta_invalid = [&pack]() {
|
||||||
|
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||||
|
return false; // the mcmeta is not optional
|
||||||
|
};
|
||||||
|
|
||||||
QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.mcmeta"));
|
QFileInfo mcmeta_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.mcmeta"));
|
||||||
if (mcmeta_file_info.exists() && mcmeta_file_info.isFile()) {
|
if (mcmeta_file_info.exists() && mcmeta_file_info.isFile()) {
|
||||||
QFile mcmeta_file(mcmeta_file_info.filePath());
|
QFile mcmeta_file(mcmeta_file_info.filePath());
|
||||||
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
if (!mcmeta_file.open(QIODevice::ReadOnly))
|
||||||
return false; // can't open mcmeta file
|
return mcmeta_invalid(); // can't open mcmeta file
|
||||||
|
|
||||||
auto data = mcmeta_file.readAll();
|
auto data = mcmeta_file.readAll();
|
||||||
|
|
||||||
@ -58,10 +63,10 @@ bool processFolder(ResourcePack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
mcmeta_file.close();
|
mcmeta_file.close();
|
||||||
if (!mcmeta_result) {
|
if (!mcmeta_result) {
|
||||||
return false; // mcmeta invalid
|
return mcmeta_invalid(); // mcmeta invalid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // mcmeta file isn't a valid file
|
return mcmeta_invalid(); // mcmeta file isn't a valid file
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo assets_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "assets"));
|
QFileInfo assets_dir_info(FS::PathCombine(pack.fileinfo().filePath(), "assets"));
|
||||||
@ -73,11 +78,16 @@ bool processFolder(ResourcePack& pack, ProcessingLevel level)
|
|||||||
return true; // only need basic info already checked
|
return true; // only need basic info already checked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto png_invalid = [&pack]() {
|
||||||
|
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.png";
|
||||||
|
return true; // the png is optional
|
||||||
|
};
|
||||||
|
|
||||||
QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png"));
|
QFileInfo image_file_info(FS::PathCombine(pack.fileinfo().filePath(), "pack.png"));
|
||||||
if (image_file_info.exists() && image_file_info.isFile()) {
|
if (image_file_info.exists() && image_file_info.isFile()) {
|
||||||
QFile pack_png_file(image_file_info.filePath());
|
QFile pack_png_file(image_file_info.filePath());
|
||||||
if (!pack_png_file.open(QIODevice::ReadOnly))
|
if (!pack_png_file.open(QIODevice::ReadOnly))
|
||||||
return false; // can't open pack.png file
|
return png_invalid(); // can't open pack.png file
|
||||||
|
|
||||||
auto data = pack_png_file.readAll();
|
auto data = pack_png_file.readAll();
|
||||||
|
|
||||||
@ -85,10 +95,10 @@ bool processFolder(ResourcePack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
pack_png_file.close();
|
pack_png_file.close();
|
||||||
if (!pack_png_result) {
|
if (!pack_png_result) {
|
||||||
return false; // pack.png invalid
|
return png_invalid(); // pack.png invalid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // pack.png does not exists or is not a valid file.
|
return png_invalid(); // pack.png does not exists or is not a valid file.
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; // all tests passed
|
return true; // all tests passed
|
||||||
@ -104,11 +114,16 @@ bool processZIP(ResourcePack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
QuaZipFile file(&zip);
|
QuaZipFile file(&zip);
|
||||||
|
|
||||||
|
auto mcmeta_invalid = [&pack]() {
|
||||||
|
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.mcmeta";
|
||||||
|
return false; // the mcmeta is not optional
|
||||||
|
};
|
||||||
|
|
||||||
if (zip.setCurrentFile("pack.mcmeta")) {
|
if (zip.setCurrentFile("pack.mcmeta")) {
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Failed to open file in zip.";
|
qCritical() << "Failed to open file in zip.";
|
||||||
zip.close();
|
zip.close();
|
||||||
return false;
|
return mcmeta_invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = file.readAll();
|
auto data = file.readAll();
|
||||||
@ -117,10 +132,10 @@ bool processZIP(ResourcePack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
if (!mcmeta_result) {
|
if (!mcmeta_result) {
|
||||||
return false; // mcmeta invalid
|
return mcmeta_invalid(); // mcmeta invalid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // could not set pack.mcmeta as current file.
|
return mcmeta_invalid(); // could not set pack.mcmeta as current file.
|
||||||
}
|
}
|
||||||
|
|
||||||
QuaZipDir zipDir(&zip);
|
QuaZipDir zipDir(&zip);
|
||||||
@ -133,11 +148,16 @@ bool processZIP(ResourcePack& pack, ProcessingLevel level)
|
|||||||
return true; // only need basic info already checked
|
return true; // only need basic info already checked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto png_invalid = [&pack]() {
|
||||||
|
qWarning() << "Resource pack at" << pack.fileinfo().filePath() << "does not have a valid pack.png";
|
||||||
|
return true; // the png is optional
|
||||||
|
};
|
||||||
|
|
||||||
if (zip.setCurrentFile("pack.png")) {
|
if (zip.setCurrentFile("pack.png")) {
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
qCritical() << "Failed to open file in zip.";
|
qCritical() << "Failed to open file in zip.";
|
||||||
zip.close();
|
zip.close();
|
||||||
return false;
|
return png_invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = file.readAll();
|
auto data = file.readAll();
|
||||||
@ -146,10 +166,10 @@ bool processZIP(ResourcePack& pack, ProcessingLevel level)
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
if (!pack_png_result) {
|
if (!pack_png_result) {
|
||||||
return false; // pack.png invalid
|
return png_invalid(); // pack.png invalid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false; // could not set pack.mcmeta as current file.
|
return png_invalid(); // could not set pack.mcmeta as current file.
|
||||||
}
|
}
|
||||||
|
|
||||||
zip.close();
|
zip.close();
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
#include <quazip/quazipfile.h>
|
|
||||||
#include <quazip/quazipdir.h>
|
#include <quazip/quazipdir.h>
|
||||||
|
#include <quazip/quazipfile.h>
|
||||||
|
|
||||||
namespace ShaderPackUtils {
|
namespace ShaderPackUtils {
|
||||||
|
|
||||||
@ -85,7 +85,6 @@ bool processZIP(ShaderPack& pack, ProcessingLevel level)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool validate(QFileInfo file)
|
bool validate(QFileInfo file)
|
||||||
{
|
{
|
||||||
ShaderPack sp{ file };
|
ShaderPack sp{ file };
|
||||||
@ -94,9 +93,7 @@ bool validate(QFileInfo file)
|
|||||||
|
|
||||||
} // namespace ShaderPackUtils
|
} // namespace ShaderPackUtils
|
||||||
|
|
||||||
LocalShaderPackParseTask::LocalShaderPackParseTask(int token, ShaderPack& sp)
|
LocalShaderPackParseTask::LocalShaderPackParseTask(int token, ShaderPack& sp) : Task(nullptr, false), m_token(token), m_shader_pack(sp) {}
|
||||||
: Task(nullptr, false), m_token(token), m_shader_pack(sp)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool LocalShaderPackParseTask::abort()
|
bool LocalShaderPackParseTask::abort()
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -38,7 +37,7 @@ bool process(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
|||||||
bool processZIP(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
bool processZIP(ShaderPack& pack, ProcessingLevel level = ProcessingLevel::Full);
|
||||||
bool processFolder(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. */
|
/** Checks whether a file is valid as a shader pack or not. */
|
||||||
bool validate(QFileInfo file);
|
bool validate(QFileInfo file);
|
||||||
} // namespace ShaderPackUtils
|
} // namespace ShaderPackUtils
|
||||||
|
|
||||||
|
@ -24,12 +24,12 @@
|
|||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include <qdir.h>
|
|
||||||
#include <qfileinfo.h>
|
|
||||||
#include <quazip/quazip.h>
|
#include <quazip/quazip.h>
|
||||||
#include <quazip/quazipfile.h>
|
|
||||||
#include <quazip/quazipdir.h>
|
#include <quazip/quazipdir.h>
|
||||||
#include <utility>
|
#include <quazip/quazipfile.h>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
namespace WorldSaveUtils {
|
namespace WorldSaveUtils {
|
||||||
|
|
||||||
@ -41,15 +41,22 @@ bool process(WorldSave& pack, ProcessingLevel level)
|
|||||||
case ResourceType::ZIPFILE:
|
case ResourceType::ZIPFILE:
|
||||||
return WorldSaveUtils::processZIP(pack, level);
|
return WorldSaveUtils::processZIP(pack, level);
|
||||||
default:
|
default:
|
||||||
qWarning() << "Invalid type for shader pack parse task!";
|
qWarning() << "Invalid type for world save parse task!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief checks a folder structure to see if it contains a level.dat
|
||||||
|
/// @param dir the path to check
|
||||||
|
/// @param saves used in recursive call if a "saves" dir was found
|
||||||
|
/// @return std::tuple of (
|
||||||
|
/// bool <found level.dat>,
|
||||||
|
/// QString <name of folder containing level.dat>,
|
||||||
|
/// bool <saves folder found>
|
||||||
|
/// )
|
||||||
static std::tuple<bool, QString, bool> contains_level_dat(QDir dir, bool saves = false)
|
static std::tuple<bool, QString, bool> contains_level_dat(QDir dir, bool saves = false)
|
||||||
{
|
{
|
||||||
for(auto const& entry : dir.entryInfoList()) {
|
for (auto const& entry : dir.entryInfoList()) {
|
||||||
if (!entry.isDir()) {
|
if (!entry.isDir()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -64,12 +71,11 @@ static std::tuple<bool, QString, bool> contains_level_dat(QDir dir, bool saves =
|
|||||||
return std::make_tuple(false, "", saves);
|
return std::make_tuple(false, "", saves);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool processFolder(WorldSave& save, ProcessingLevel level)
|
bool processFolder(WorldSave& save, ProcessingLevel level)
|
||||||
{
|
{
|
||||||
Q_ASSERT(save.type() == ResourceType::FOLDER);
|
Q_ASSERT(save.type() == ResourceType::FOLDER);
|
||||||
|
|
||||||
auto [ found, save_dir_name, found_saves_dir ] = contains_level_dat(QDir(save.fileinfo().filePath()));
|
auto [found, save_dir_name, found_saves_dir] = contains_level_dat(QDir(save.fileinfo().filePath()));
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
return false;
|
return false;
|
||||||
@ -87,11 +93,18 @@ bool processFolder(WorldSave& save, ProcessingLevel level)
|
|||||||
return true; // only need basic info already checked
|
return true; // only need basic info already checked
|
||||||
}
|
}
|
||||||
|
|
||||||
// resurved for more intensive processing
|
// reserved for more intensive processing
|
||||||
|
|
||||||
return true; // all tests passed
|
return true; // all tests passed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief checks a folder structure to see if it contains a level.dat
|
||||||
|
/// @param zip the zip file to check
|
||||||
|
/// @return std::tuple of (
|
||||||
|
/// bool <found level.dat>,
|
||||||
|
/// QString <name of folder containing level.dat>,
|
||||||
|
/// bool <saves folder found>
|
||||||
|
/// )
|
||||||
static std::tuple<bool, QString, bool> contains_level_dat(QuaZip& zip)
|
static std::tuple<bool, QString, bool> contains_level_dat(QuaZip& zip)
|
||||||
{
|
{
|
||||||
bool saves = false;
|
bool saves = false;
|
||||||
@ -119,7 +132,7 @@ bool processZIP(WorldSave& save, ProcessingLevel level)
|
|||||||
if (!zip.open(QuaZip::mdUnzip))
|
if (!zip.open(QuaZip::mdUnzip))
|
||||||
return false; // can't open zip file
|
return false; // can't open zip file
|
||||||
|
|
||||||
auto [ found, save_dir_name, found_saves_dir ] = contains_level_dat(zip);
|
auto [found, save_dir_name, found_saves_dir] = contains_level_dat(zip);
|
||||||
|
|
||||||
if (save_dir_name.endsWith("/")) {
|
if (save_dir_name.endsWith("/")) {
|
||||||
save_dir_name.chop(1);
|
save_dir_name.chop(1);
|
||||||
@ -142,14 +155,13 @@ bool processZIP(WorldSave& save, ProcessingLevel level)
|
|||||||
return true; // only need basic info already checked
|
return true; // only need basic info already checked
|
||||||
}
|
}
|
||||||
|
|
||||||
// resurved for more intensive processing
|
// reserved for more intensive processing
|
||||||
|
|
||||||
zip.close();
|
zip.close();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool validate(QFileInfo file)
|
bool validate(QFileInfo file)
|
||||||
{
|
{
|
||||||
WorldSave sp{ file };
|
WorldSave sp{ file };
|
||||||
@ -158,9 +170,7 @@ bool validate(QFileInfo file)
|
|||||||
|
|
||||||
} // namespace WorldSaveUtils
|
} // namespace WorldSaveUtils
|
||||||
|
|
||||||
LocalWorldSaveParseTask::LocalWorldSaveParseTask(int token, WorldSave& save)
|
LocalWorldSaveParseTask::LocalWorldSaveParseTask(int token, WorldSave& save) : Task(nullptr, false), m_token(token), m_save(save) {}
|
||||||
: Task(nullptr, false), m_token(token), m_save(save)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool LocalWorldSaveParseTask::abort()
|
bool LocalWorldSaveParseTask::abort()
|
||||||
{
|
{
|
||||||
|
@ -53,15 +53,16 @@
|
|||||||
#include "ui/dialogs/BlockedModsDialog.h"
|
#include "ui/dialogs/BlockedModsDialog.h"
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
|
|
||||||
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
|
#include <QDebug>
|
||||||
#include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
|
#include <QFileInfo>
|
||||||
#include <minecraft/mod/tasks/LocalDataPackParseTask.h>
|
|
||||||
#include <minecraft/mod/tasks/LocalModParseTask.h>
|
#include "minecraft/World.h"
|
||||||
#include <minecraft/mod/tasks/LocalWorldSaveParseTask.h>
|
#include "minecraft/mod/tasks/LocalDataPackParseTask.h"
|
||||||
#include <minecraft/mod/tasks/LocalShaderPackParseTask.h>
|
#include "minecraft/mod/tasks/LocalModParseTask.h"
|
||||||
#include <minecraft/World.h>
|
#include "minecraft/mod/tasks/LocalResourcePackParseTask.h"
|
||||||
#include <qdebug.h>
|
#include "minecraft/mod/tasks/LocalShaderPackParseTask.h"
|
||||||
#include <qfileinfo.h>
|
#include "minecraft/mod/tasks/LocalTexturePackParseTask.h"
|
||||||
|
#include "minecraft/mod/tasks/LocalWorldSaveParseTask.h"
|
||||||
|
|
||||||
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
||||||
{ "1.4.2", "6.0.1.355" },
|
{ "1.4.2", "6.0.1.355" },
|
||||||
@ -411,8 +412,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
|||||||
QList<BlockedMod> blocked_mods;
|
QList<BlockedMod> blocked_mods;
|
||||||
auto anyBlocked = false;
|
auto anyBlocked = false;
|
||||||
for (const auto& result : results.files.values()) {
|
for (const auto& result : results.files.values()) {
|
||||||
|
if (result.fileName.endsWith(".zip")) {
|
||||||
if(result.fileName.endsWith(".zip")) {
|
|
||||||
m_ZIP_resources.append(std::make_pair(result.fileName, result.targetFolder));
|
m_ZIP_resources.append(std::make_pair(result.fileName, result.targetFolder));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +454,6 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
|
void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
|
||||||
{
|
{
|
||||||
m_files_job = new NetJob(tr("Mod download"), APPLICATION->network());
|
m_files_job = new NetJob(tr("Mod download"), APPLICATION->network());
|
||||||
@ -543,26 +542,26 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
|||||||
bool moveFile(QString src, QString dst)
|
bool moveFile(QString src, QString dst)
|
||||||
{
|
{
|
||||||
if (!FS::copy(src, dst)()) { // copy
|
if (!FS::copy(src, dst)()) { // copy
|
||||||
qDebug() << "Copy of" << src << "to" << dst << "Failed!";
|
qDebug() << "Copy of" << src << "to" << dst << "failed!";
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (!FS::deletePath(src)) { // remove original
|
if (!FS::deletePath(src)) { // remove original
|
||||||
qDebug() << "Deleation of" << src << "Failed!";
|
qDebug() << "Deletion of" << src << "failed!";
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FlameCreationTask::validateZIPResouces()
|
void FlameCreationTask::validateZIPResouces()
|
||||||
{
|
{
|
||||||
qDebug() << "Validating resoucres stored as .zip are in the right place";
|
qDebug() << "Validating whether resources stored as .zip are in the right place";
|
||||||
for (auto [fileName, targetFolder] : m_ZIP_resources) {
|
for (auto [fileName, targetFolder] : m_ZIP_resources) {
|
||||||
|
|
||||||
qDebug() << "Checking" << fileName << "...";
|
qDebug() << "Checking" << fileName << "...";
|
||||||
auto localPath = FS::PathCombine(m_stagingPath, "minecraft", targetFolder, fileName);
|
auto localPath = FS::PathCombine(m_stagingPath, "minecraft", targetFolder, fileName);
|
||||||
|
|
||||||
|
/// @brief check the target and move the the file
|
||||||
|
/// @return path where file can now be found
|
||||||
auto validatePath = [&localPath, this](QString fileName, QString targetFolder, QString realTarget) {
|
auto validatePath = [&localPath, this](QString fileName, QString targetFolder, QString realTarget) {
|
||||||
if (targetFolder != realTarget) {
|
if (targetFolder != realTarget) {
|
||||||
qDebug() << "Target folder of" << fileName << "is incorrect, it belongs in" << realTarget;
|
qDebug() << "Target folder of" << fileName << "is incorrect, it belongs in" << realTarget;
|
||||||
@ -610,7 +609,7 @@ void FlameCreationTask::validateZIPResouces()
|
|||||||
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
|
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Can't find" << localPath << "to validate it, ignoreing";
|
qDebug() << "Can't find" << localPath << "to validate it, ignoring";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class ResourcePackParseTest : public QObject {
|
|||||||
|
|
||||||
QVERIFY(pack.packFormat() == 6);
|
QVERIFY(pack.packFormat() == 6);
|
||||||
QVERIFY(pack.description() == "o quartel pegou fogo, policia deu sinal, acode acode acode a bandeira nacional");
|
QVERIFY(pack.description() == "o quartel pegou fogo, policia deu sinal, acode acode acode a bandeira nacional");
|
||||||
QVERIFY(valid == false);
|
QVERIFY(valid == false); // no assets dir
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user