feat: updated flame mod resolution
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
593f452986
commit
60d0013bc4
@ -19,7 +19,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QObject>
|
||||
|
||||
#include "LocalResourceParse.h"
|
||||
|
||||
@ -30,25 +30,19 @@
|
||||
#include "LocalTexturePackParseTask.h"
|
||||
#include "LocalWorldSaveParseTask.h"
|
||||
|
||||
|
||||
static const QMap<PackedResourceType, QString> s_packed_type_names = {
|
||||
{PackedResourceType::ResourcePack, QObject::tr("resource pack")},
|
||||
{PackedResourceType::TexturePack, QObject::tr("texture pack")},
|
||||
{PackedResourceType::DataPack, QObject::tr("data pack")},
|
||||
{PackedResourceType::ShaderPack, QObject::tr("shader pack")},
|
||||
{PackedResourceType::WorldSave, QObject::tr("world save")},
|
||||
{PackedResourceType::Mod , QObject::tr("mod")},
|
||||
{PackedResourceType::UNKNOWN, QObject::tr("unknown")}
|
||||
};
|
||||
static const QMap<PackedResourceType, QString> s_packed_type_names = { { PackedResourceType::ResourcePack, QObject::tr("resource pack") },
|
||||
{ PackedResourceType::TexturePack, QObject::tr("texture pack") },
|
||||
{ PackedResourceType::DataPack, QObject::tr("data pack") },
|
||||
{ PackedResourceType::ShaderPack, QObject::tr("shader pack") },
|
||||
{ PackedResourceType::WorldSave, QObject::tr("world save") },
|
||||
{ PackedResourceType::Mod, QObject::tr("mod") },
|
||||
{ PackedResourceType::UNKNOWN, QObject::tr("unknown") } };
|
||||
|
||||
namespace ResourceUtils {
|
||||
PackedResourceType identify(QFileInfo file){
|
||||
PackedResourceType identify(QFileInfo file)
|
||||
{
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (ModUtils::validate(file)) {
|
||||
// mods can contain resource and data packs so they must be tested first
|
||||
qDebug() << file.fileName() << "is a mod";
|
||||
return PackedResourceType::Mod;
|
||||
} else if (ResourcePackUtils::validate(file)) {
|
||||
if (ResourcePackUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a resource pack";
|
||||
return PackedResourceType::ResourcePack;
|
||||
} else if (TexturePackUtils::validate(file)) {
|
||||
@ -63,8 +57,12 @@ PackedResourceType identify(QFileInfo file){
|
||||
} else if (ShaderPackUtils::validate(file)) {
|
||||
qDebug() << file.fileName() << "is a shader pack";
|
||||
return PackedResourceType::ShaderPack;
|
||||
} else if (ModUtils::validate(file)) {
|
||||
// mods should be already filtered out by the API response
|
||||
qDebug() << file.fileName() << "is a mod";
|
||||
return PackedResourceType::Mod;
|
||||
} else {
|
||||
qDebug() << "Can't Identify" << file.fileName() ;
|
||||
qDebug() << "Can't Identify" << file.fileName();
|
||||
}
|
||||
} else {
|
||||
qDebug() << "Can't find" << file.absolutePath();
|
||||
@ -72,8 +70,9 @@ PackedResourceType identify(QFileInfo file){
|
||||
return PackedResourceType::UNKNOWN;
|
||||
}
|
||||
|
||||
QString getPackedTypeName(PackedResourceType type) {
|
||||
QString getPackedTypeName(PackedResourceType type)
|
||||
{
|
||||
return s_packed_type_names.constFind(type).value();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace ResourceUtils
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "FileResolvingTask.h"
|
||||
|
||||
#include "Json.h"
|
||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
#include "modplatform/modrinth/ModrinthPackIndex.h"
|
||||
@ -29,6 +30,7 @@ void Flame::FileResolvingTask::executeTask()
|
||||
setProgress(0, 3);
|
||||
m_dljob.reset(new NetJob("Mod id resolver", m_network));
|
||||
result.reset(new QByteArray());
|
||||
mods_result.reset(new QByteArray());
|
||||
// build json data to send
|
||||
QJsonObject object;
|
||||
|
||||
@ -37,9 +39,20 @@ void Flame::FileResolvingTask::executeTask()
|
||||
l.push_back(s.fileId);
|
||||
return l;
|
||||
}));
|
||||
|
||||
QJsonObject mods_object;
|
||||
|
||||
mods_object["modIds"] = QJsonArray::fromVariantList(
|
||||
std::accumulate(m_toProcess.files.begin(), m_toProcess.files.end(), QVariantList(), [](QVariantList& l, const File& s) {
|
||||
l.push_back(s.projectId);
|
||||
return l;
|
||||
}));
|
||||
QByteArray data = Json::toText(object);
|
||||
QByteArray mods_data = Json::toText(mods_object);
|
||||
auto dl = Net::Upload::makeByteArray(QUrl("https://api.curseforge.com/v1/mods/files"), result, data);
|
||||
m_dljob->addNetAction(dl);
|
||||
auto dl2 = Net::Upload::makeByteArray(QUrl("https://api.curseforge.com/v1/mods"), mods_result, mods_data);
|
||||
m_dljob->addNetAction(dl2);
|
||||
|
||||
auto step_progress = std::make_shared<TaskStepProgress>();
|
||||
connect(m_dljob.get(), &NetJob::finished, this, [this, step_progress]() {
|
||||
@ -66,6 +79,30 @@ void Flame::FileResolvingTask::executeTask()
|
||||
m_dljob->start();
|
||||
}
|
||||
|
||||
PackedResourceType getResourceType(int classId)
|
||||
{
|
||||
switch (classId) {
|
||||
case 17: // Worlds
|
||||
return PackedResourceType::WorldSave;
|
||||
case 6: // Mods
|
||||
return PackedResourceType::Mod;
|
||||
case 12: // Resource Packs
|
||||
// return PackedResourceType::ResourcePack; // not really a resourcepack
|
||||
/* fallthrough */
|
||||
case 4546: // Customization
|
||||
// return PackedResourceType::ShaderPack; // not really a shaderPack
|
||||
/* fallthrough */
|
||||
case 4471: // Modpacks
|
||||
/* fallthrough */
|
||||
case 5: // Bukkit Plugins
|
||||
/* fallthrough */
|
||||
case 4559: // Addons
|
||||
/* fallthrough */
|
||||
default:
|
||||
return PackedResourceType::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void Flame::FileResolvingTask::netJobFinished()
|
||||
{
|
||||
setProgress(1, 3);
|
||||
@ -75,10 +112,21 @@ void Flame::FileResolvingTask::netJobFinished()
|
||||
|
||||
QJsonDocument doc;
|
||||
QJsonArray array;
|
||||
QHash<int, PackedResourceType> resourceTypes;
|
||||
|
||||
try {
|
||||
doc = Json::requireDocument(*result);
|
||||
array = Json::requireArray(doc.object()["data"]);
|
||||
doc = Json::requireDocument(*mods_result);
|
||||
auto obj = Json::requireObject(doc);
|
||||
auto mods_array = Json::requireArray(obj, "data", "data");
|
||||
for (auto element : mods_array) {
|
||||
auto mod = Json::requireObject(element);
|
||||
auto id = Json::requireInteger(mod, "id", "modId");
|
||||
auto classId = Json::requireInteger(mod, "classId", "modClassId");
|
||||
resourceTypes.insert(id, getResourceType(classId));
|
||||
}
|
||||
|
||||
} catch (Json::JsonException& e) {
|
||||
qCritical() << "Non-JSON data returned from the CF API";
|
||||
qCritical() << e.cause();
|
||||
@ -106,6 +154,10 @@ void Flame::FileResolvingTask::netJobFinished()
|
||||
blockedProjects.insert(&out, output);
|
||||
}
|
||||
}
|
||||
out.resourceType = resourceTypes.value(out.projectId, PackedResourceType::UNKNOWN);
|
||||
if (out.resourceType == PackedResourceType::WorldSave) {
|
||||
out.targetFolder = "saves";
|
||||
}
|
||||
}
|
||||
auto step_progress = std::make_shared<TaskStepProgress>();
|
||||
connect(m_checkJob.get(), &NetJob::finished, this, [this, step_progress]() {
|
||||
|
@ -26,6 +26,7 @@ class FileResolvingTask : public Task {
|
||||
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
||||
Flame::Manifest m_toProcess;
|
||||
std::shared_ptr<QByteArray> result;
|
||||
std::shared_ptr<QByteArray> mods_result;
|
||||
NetJob::Ptr m_dljob;
|
||||
NetJob::Ptr m_checkJob;
|
||||
NetJob::Ptr m_slugJob;
|
||||
|
@ -60,7 +60,6 @@
|
||||
#include "minecraft/World.h"
|
||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
||||
|
||||
|
||||
const static QMap<QString, QString> forgemap = { { "1.2.5", "3.4.9.171" },
|
||||
{ "1.4.2", "6.0.1.355" },
|
||||
{ "1.4.7", "6.6.2.534" },
|
||||
@ -413,7 +412,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
||||
QList<BlockedMod> blocked_mods;
|
||||
auto anyBlocked = false;
|
||||
for (const auto& result : results.files.values()) {
|
||||
if (result.fileName.endsWith(".zip")) {
|
||||
if (result.resourceType != PackedResourceType::Mod) {
|
||||
m_ZIP_resources.append(std::make_pair(result.fileName, result.targetFolder));
|
||||
}
|
||||
|
||||
@ -502,7 +501,7 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop)
|
||||
m_files_job.reset();
|
||||
setError(reason);
|
||||
});
|
||||
connect(m_files_job.get(), &NetJob::progress, this, [this](qint64 current, qint64 total){
|
||||
connect(m_files_job.get(), &NetJob::progress, this, [this](qint64 current, qint64 total) {
|
||||
setDetails(tr("%1 out of %2 complete").arg(current).arg(total));
|
||||
setProgress(current, total);
|
||||
});
|
||||
@ -545,7 +544,6 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
||||
setAbortable(true);
|
||||
}
|
||||
|
||||
|
||||
void FlameCreationTask::validateZIPResouces()
|
||||
{
|
||||
qDebug() << "Validating whether resources stored as .zip are in the right place";
|
||||
@ -569,7 +567,7 @@ void FlameCreationTask::validateZIPResouces()
|
||||
return localPath;
|
||||
};
|
||||
|
||||
auto installWorld = [this](QString worldPath){
|
||||
auto installWorld = [this](QString worldPath) {
|
||||
qDebug() << "Installing World from" << worldPath;
|
||||
QFileInfo worldFileInfo(worldPath);
|
||||
World w(worldFileInfo);
|
||||
@ -586,29 +584,30 @@ void FlameCreationTask::validateZIPResouces()
|
||||
QString worldPath;
|
||||
|
||||
switch (type) {
|
||||
case PackedResourceType::Mod :
|
||||
case PackedResourceType::Mod:
|
||||
validatePath(fileName, targetFolder, "mods");
|
||||
break;
|
||||
case PackedResourceType::ResourcePack :
|
||||
case PackedResourceType::ResourcePack:
|
||||
validatePath(fileName, targetFolder, "resourcepacks");
|
||||
break;
|
||||
case PackedResourceType::TexturePack :
|
||||
case PackedResourceType::TexturePack:
|
||||
validatePath(fileName, targetFolder, "texturepacks");
|
||||
break;
|
||||
case PackedResourceType::DataPack :
|
||||
case PackedResourceType::DataPack:
|
||||
validatePath(fileName, targetFolder, "datapacks");
|
||||
break;
|
||||
case PackedResourceType::ShaderPack :
|
||||
case PackedResourceType::ShaderPack:
|
||||
// in theroy flame API can't do this but who knows, that *may* change ?
|
||||
// better to handle it if it *does* occure in the future
|
||||
validatePath(fileName, targetFolder, "shaderpacks");
|
||||
break;
|
||||
case PackedResourceType::WorldSave :
|
||||
case PackedResourceType::WorldSave:
|
||||
worldPath = validatePath(fileName, targetFolder, "saves");
|
||||
installWorld(worldPath);
|
||||
break;
|
||||
case PackedResourceType::UNKNOWN :
|
||||
default :
|
||||
case PackedResourceType::UNKNOWN:
|
||||
/* fallthrough */
|
||||
default:
|
||||
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";
|
||||
break;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QVector>
|
||||
#include "minecraft/mod/tasks/LocalResourceParse.h"
|
||||
|
||||
namespace Flame
|
||||
{
|
||||
@ -71,6 +72,7 @@ struct File
|
||||
Modpack,
|
||||
Mod
|
||||
} type = Type::Mod;
|
||||
PackedResourceType resourceType;
|
||||
};
|
||||
|
||||
struct Modloader
|
||||
|
Loading…
Reference in New Issue
Block a user