mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-01 06:40:15 +02:00
Unhardcode PREFIXES
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
13e13ea8fc
commit
b66d6b2812
@ -28,6 +28,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
@ -39,24 +40,23 @@
|
|||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
const QString FlamePackExportTask::TEMPLATE = "<li><a href=\"{url}\">{name}{authors}</a></li>\n";
|
const QString FlamePackExportTask::TEMPLATE = "<li><a href=\"{url}\">{name}{authors}</a></li>\n";
|
||||||
const QStringList FlamePackExportTask::FILE_EXTENSIONS({ "jar", "zip" });
|
const QStringList FlamePackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
||||||
|
|
||||||
FlamePackExportTask::FlamePackExportTask(const QString& name,
|
FlamePackExportTask::FlamePackExportTask(QString name,
|
||||||
const QString& version,
|
QString version,
|
||||||
const QString& author,
|
QString author,
|
||||||
bool optionalFiles,
|
bool optionalFiles,
|
||||||
InstancePtr instance,
|
MinecraftInstancePtr instance,
|
||||||
const QString& output,
|
QString output,
|
||||||
MMCZip::FilterFunction filter)
|
MMCZip::FilterFunction filter)
|
||||||
: name(name)
|
: name(std::move(name))
|
||||||
, version(version)
|
, version(std::move(version))
|
||||||
, author(author)
|
, author(std::move(author))
|
||||||
, optionalFiles(optionalFiles)
|
, optionalFiles(optionalFiles)
|
||||||
, instance(instance)
|
, instance(std::move(instance))
|
||||||
, mcInstance(dynamic_cast<MinecraftInstance*>(instance.get()))
|
, gameRoot(this->instance->gameRoot())
|
||||||
, gameRoot(instance->gameRoot())
|
, output(std::move(output))
|
||||||
, output(output)
|
, filter(std::move(filter))
|
||||||
, filter(filter)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void FlamePackExportTask::executeTask()
|
void FlamePackExportTask::executeTask()
|
||||||
@ -90,11 +90,7 @@ void FlamePackExportTask::collectFiles()
|
|||||||
pendingHashes.clear();
|
pendingHashes.clear();
|
||||||
resolvedFiles.clear();
|
resolvedFiles.clear();
|
||||||
|
|
||||||
if (mcInstance != nullptr) {
|
collectHashes();
|
||||||
mcInstance->loaderModList()->update();
|
|
||||||
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, &FlamePackExportTask::collectHashes);
|
|
||||||
} else
|
|
||||||
collectHashes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlamePackExportTask::collectHashes()
|
void FlamePackExportTask::collectHashes()
|
||||||
@ -102,7 +98,7 @@ void FlamePackExportTask::collectHashes()
|
|||||||
setAbortable(true);
|
setAbortable(true);
|
||||||
setStatus(tr("Finding file hashes..."));
|
setStatus(tr("Finding file hashes..."));
|
||||||
setProgress(1, 5);
|
setProgress(1, 5);
|
||||||
auto allMods = mcInstance->loaderModList()->allMods();
|
auto allMods = instance->loaderModList()->allMods();
|
||||||
ConcurrentTask::Ptr hashingTask(
|
ConcurrentTask::Ptr hashingTask(
|
||||||
new ConcurrentTask(this, "MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
|
new ConcurrentTask(this, "MakeHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
|
||||||
task.reset(hashingTask);
|
task.reset(hashingTask);
|
||||||
@ -379,9 +375,9 @@ QByteArray FlamePackExportTask::generateIndex()
|
|||||||
obj["version"] = version;
|
obj["version"] = version;
|
||||||
obj["author"] = author;
|
obj["author"] = author;
|
||||||
obj["overrides"] = "overrides";
|
obj["overrides"] = "overrides";
|
||||||
if (mcInstance) {
|
if (instance) {
|
||||||
QJsonObject version;
|
QJsonObject version;
|
||||||
auto profile = mcInstance->getPackProfile();
|
auto profile = instance->getPackProfile();
|
||||||
// collect all supported components
|
// collect all supported components
|
||||||
const ComponentPtr minecraft = profile->getComponent("net.minecraft");
|
const ComponentPtr minecraft = profile->getComponent("net.minecraft");
|
||||||
const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader");
|
const ComponentPtr quilt = profile->getComponent("org.quiltmc.quilt-loader");
|
||||||
|
@ -28,12 +28,12 @@
|
|||||||
class FlamePackExportTask : public Task {
|
class FlamePackExportTask : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FlamePackExportTask(const QString& name,
|
FlamePackExportTask(QString name,
|
||||||
const QString& version,
|
QString version,
|
||||||
const QString& author,
|
QString author,
|
||||||
bool optionalFiles,
|
bool optionalFiles,
|
||||||
InstancePtr instance,
|
MinecraftInstancePtr instance,
|
||||||
const QString& output,
|
QString output,
|
||||||
MMCZip::FilterFunction filter);
|
MMCZip::FilterFunction filter);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -47,8 +47,7 @@ class FlamePackExportTask : public Task {
|
|||||||
// inputs
|
// inputs
|
||||||
const QString name, version, author;
|
const QString name, version, author;
|
||||||
const bool optionalFiles;
|
const bool optionalFiles;
|
||||||
const InstancePtr instance;
|
const MinecraftInstancePtr instance;
|
||||||
MinecraftInstance* mcInstance;
|
|
||||||
const QDir gameRoot;
|
const QDir gameRoot;
|
||||||
const QString output;
|
const QString output;
|
||||||
const MMCZip::FilterFunction filter;
|
const MMCZip::FilterFunction filter;
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include "modplatform/helpers/HashUtils.h"
|
#include "modplatform/helpers/HashUtils.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
const QStringList ModrinthPackExportTask::PREFIXES({ "mods/", "coremods/", "resourcepacks/", "texturepacks/", "shaderpacks/" });
|
|
||||||
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
const QStringList ModrinthPackExportTask::FILE_EXTENSIONS({ "jar", "litemod", "zip" });
|
||||||
|
|
||||||
ModrinthPackExportTask::ModrinthPackExportTask(QString name,
|
ModrinthPackExportTask::ModrinthPackExportTask(QString name,
|
||||||
@ -87,16 +86,22 @@ void ModrinthPackExportTask::collectFiles()
|
|||||||
|
|
||||||
void ModrinthPackExportTask::collectHashes()
|
void ModrinthPackExportTask::collectHashes()
|
||||||
{
|
{
|
||||||
|
// TODO make this just use EnsureMetadataTask
|
||||||
|
|
||||||
setStatus(tr("Finding file hashes..."));
|
setStatus(tr("Finding file hashes..."));
|
||||||
|
|
||||||
|
QStringList prefixes;
|
||||||
|
|
||||||
for (const auto& model : instance->resourceLists()) {
|
for (const auto& model : instance->resourceLists()) {
|
||||||
QCoreApplication::processEvents(); // TODO: maybe don't do this?
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(model.get(), &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
connect(model.get(), &ModFolderModel::updateFinished, &loop, &QEventLoop::quit);
|
||||||
model->update();
|
model->update();
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
prefixes.append(gameRoot.relativeFilePath(model->dir().absolutePath()) + '/');
|
||||||
|
|
||||||
for (const Resource* resource : model->allResources()) {
|
for (const Resource* resource : model->allResources()) {
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
@ -163,7 +168,7 @@ void ModrinthPackExportTask::collectHashes()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// require sensible file types
|
// require sensible file types
|
||||||
if (!std::any_of(PREFIXES.begin(), PREFIXES.end(), [&relative](const QString& prefix) { return relative.startsWith(prefix); }))
|
if (!std::any_of(prefixes.begin(), prefixes.end(), [&relative](const QString& prefix) { return relative.startsWith(prefix); }))
|
||||||
continue;
|
continue;
|
||||||
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
|
if (!std::any_of(FILE_EXTENSIONS.begin(), FILE_EXTENSIONS.end(), [&relative](const QString& extension) {
|
||||||
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
|
return relative.endsWith('.' + extension) || relative.endsWith('.' + extension + ".disabled");
|
||||||
|
@ -48,7 +48,6 @@ class ModrinthPackExportTask : public Task {
|
|||||||
Metadata::ModSide side;
|
Metadata::ModSide side;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const QStringList PREFIXES;
|
|
||||||
static const QStringList FILE_EXTENSIONS;
|
static const QStringList FILE_EXTENSIONS;
|
||||||
|
|
||||||
// inputs
|
// inputs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user