mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-08-03 11:27:33 -04:00
fix:resource update with loaders
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
a75713897d
commit
bd570aa5d1
@ -218,9 +218,19 @@ QList<ModPlatform::Category> FlameAPI::loadModCategories(std::shared_ptr<QByteAr
|
||||
|
||||
std::optional<ModPlatform::IndexedVersion> FlameAPI::getLatestVersion(QList<ModPlatform::IndexedVersion> versions,
|
||||
QList<ModPlatform::ModLoaderType> instanceLoaders,
|
||||
ModPlatform::ModLoaderTypes modLoaders)
|
||||
ModPlatform::ModLoaderTypes modLoaders,
|
||||
bool checkLoaders)
|
||||
{
|
||||
static const auto noLoader = ModPlatform::ModLoaderType(0);
|
||||
if (!checkLoaders) {
|
||||
std::optional<ModPlatform::IndexedVersion> ver;
|
||||
for (auto file_tmp : versions) {
|
||||
if (!ver.has_value() || file_tmp.date > ver->date) {
|
||||
ver = file_tmp;
|
||||
}
|
||||
}
|
||||
return ver;
|
||||
}
|
||||
QHash<ModPlatform::ModLoaderType, ModPlatform::IndexedVersion> bestMatch;
|
||||
auto checkVersion = [&bestMatch](const ModPlatform::IndexedVersion& version, const ModPlatform::ModLoaderType& loader) {
|
||||
if (bestMatch.contains(loader)) {
|
||||
|
@ -18,7 +18,8 @@ class FlameAPI : public NetworkResourceAPI {
|
||||
|
||||
std::optional<ModPlatform::IndexedVersion> getLatestVersion(QList<ModPlatform::IndexedVersion> versions,
|
||||
QList<ModPlatform::ModLoaderType> instanceLoaders,
|
||||
ModPlatform::ModLoaderTypes fallback);
|
||||
ModPlatform::ModLoaderTypes fallback,
|
||||
bool checkLoaders);
|
||||
|
||||
Task::Ptr getProjects(QStringList addonIds, std::shared_ptr<QByteArray> response) const override;
|
||||
Task::Ptr matchFingerprints(const QList<uint>& fingerprints, std::shared_ptr<QByteArray> response);
|
||||
|
@ -87,7 +87,7 @@ void FlameCheckUpdate::getLatestVersionCallback(Resource* resource, std::shared_
|
||||
qCritical() << e.what();
|
||||
qDebug() << doc;
|
||||
}
|
||||
auto latest_ver = api.getLatestVersion(pack->versions, m_loadersList, resource->metadata()->loaders);
|
||||
auto latest_ver = api.getLatestVersion(pack->versions, m_loadersList, resource->metadata()->loaders, !m_loadersList.isEmpty());
|
||||
|
||||
setStatus(tr("Parsing the API response from CurseForge for '%1'...").arg(resource->name()));
|
||||
|
||||
|
@ -15,6 +15,26 @@
|
||||
|
||||
static ModrinthAPI api;
|
||||
|
||||
ModrinthCheckUpdate::ModrinthCheckUpdate(QList<Resource*>& resources,
|
||||
std::list<Version>& mcVersions,
|
||||
QList<ModPlatform::ModLoaderType> loadersList,
|
||||
std::shared_ptr<ResourceFolderModel> resourceModel)
|
||||
: CheckUpdateTask(resources, mcVersions, std::move(loadersList), std::move(resourceModel))
|
||||
, m_hashType(ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first())
|
||||
{
|
||||
if (!m_loadersList.isEmpty()) { // this is for mods so append all the other posible loaders to the initial list
|
||||
m_initialSize = m_loadersList.length();
|
||||
ModPlatform::ModLoaderTypes modLoaders;
|
||||
for (auto m : resources) {
|
||||
modLoaders |= m->metadata()->loaders;
|
||||
}
|
||||
for (auto l : m_loadersList) {
|
||||
modLoaders &= ~l;
|
||||
}
|
||||
m_loadersList.append(ModPlatform::modLoaderTypesToList(modLoaders));
|
||||
}
|
||||
}
|
||||
|
||||
bool ModrinthCheckUpdate::abort()
|
||||
{
|
||||
if (m_job)
|
||||
@ -34,6 +54,7 @@ void ModrinthCheckUpdate::executeTask()
|
||||
|
||||
auto hashing_task =
|
||||
makeShared<ConcurrentTask>("MakeModrinthHashesTask", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt());
|
||||
bool startHasing = false;
|
||||
for (auto* resource : m_resources) {
|
||||
auto hash = resource->metadata()->hash;
|
||||
|
||||
@ -45,23 +66,37 @@ void ModrinthCheckUpdate::executeTask()
|
||||
connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, resource](QString hash) { m_mappings.insert(hash, resource); });
|
||||
connect(hash_task.get(), &Task::failed, [this] { failed("Failed to generate hash"); });
|
||||
hashing_task->addTask(hash_task);
|
||||
startHasing = true;
|
||||
} else {
|
||||
m_mappings.insert(hash, resource);
|
||||
}
|
||||
}
|
||||
|
||||
connect(hashing_task.get(), &Task::finished, this, &ModrinthCheckUpdate::checkNextLoader);
|
||||
m_job = hashing_task;
|
||||
hashing_task->start();
|
||||
if (startHasing) {
|
||||
connect(hashing_task.get(), &Task::finished, this, &ModrinthCheckUpdate::checkNextLoader);
|
||||
m_job = hashing_task;
|
||||
hashing_task->start();
|
||||
} else {
|
||||
checkNextLoader();
|
||||
}
|
||||
}
|
||||
|
||||
void ModrinthCheckUpdate::getUpdateModsForLoader(std::optional<ModPlatform::ModLoaderTypes> loader)
|
||||
void ModrinthCheckUpdate::getUpdateModsForLoader(std::optional<ModPlatform::ModLoaderTypes> loader, bool forceModLoaderCheck)
|
||||
{
|
||||
setStatus(tr("Waiting for the API response from Modrinth..."));
|
||||
setProgress(m_progress + 1, m_progressTotal);
|
||||
|
||||
auto response = std::make_shared<QByteArray>();
|
||||
QStringList hashes = m_mappings.keys();
|
||||
QStringList hashes;
|
||||
if (forceModLoaderCheck && loader.has_value()) {
|
||||
for (auto hash : m_mappings.keys()) {
|
||||
if (m_mappings[hash]->metadata()->loaders & loader.value()) {
|
||||
hashes.append(hash);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hashes = m_mappings.keys();
|
||||
}
|
||||
auto job = api.latestVersions(hashes, m_hashType, m_gameVersions, loader, response);
|
||||
|
||||
connect(job.get(), &Task::succeeded, this, [this, response, loader] { checkVersionsResponse(response, loader); });
|
||||
@ -69,6 +104,7 @@ void ModrinthCheckUpdate::getUpdateModsForLoader(std::optional<ModPlatform::ModL
|
||||
connect(job.get(), &Task::failed, this, &ModrinthCheckUpdate::checkNextLoader);
|
||||
|
||||
m_job = job;
|
||||
m_loaderIdx++;
|
||||
job->start();
|
||||
}
|
||||
|
||||
@ -165,16 +201,11 @@ void ModrinthCheckUpdate::checkNextLoader()
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_loadersList.isEmpty() && m_loaderIdx == 0) {
|
||||
getUpdateModsForLoader({});
|
||||
m_loaderIdx++;
|
||||
if (m_loaderIdx < m_loadersList.size()) { // this are mods so check with loades
|
||||
getUpdateModsForLoader(m_loadersList.at(m_loaderIdx), m_loaderIdx > m_initialSize);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_loaderIdx < m_loadersList.size()) {
|
||||
getUpdateModsForLoader(m_loadersList.at(m_loaderIdx));
|
||||
m_loaderIdx++;
|
||||
} else if (m_loadersList.isEmpty() && m_loaderIdx == 0) { // this are other resources no need to check more than once with empty loader
|
||||
getUpdateModsForLoader();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -192,4 +223,4 @@ void ModrinthCheckUpdate::checkNextLoader()
|
||||
}
|
||||
|
||||
emitSucceeded();
|
||||
}
|
||||
}
|
@ -9,17 +9,14 @@ class ModrinthCheckUpdate : public CheckUpdateTask {
|
||||
ModrinthCheckUpdate(QList<Resource*>& resources,
|
||||
std::list<Version>& mcVersions,
|
||||
QList<ModPlatform::ModLoaderType> loadersList,
|
||||
std::shared_ptr<ResourceFolderModel> resourceModel)
|
||||
: CheckUpdateTask(resources, mcVersions, std::move(loadersList), std::move(resourceModel))
|
||||
, m_hashType(ModPlatform::ProviderCapabilities::hashType(ModPlatform::ResourceProvider::MODRINTH).first())
|
||||
{}
|
||||
std::shared_ptr<ResourceFolderModel> resourceModel);
|
||||
|
||||
public slots:
|
||||
bool abort() override;
|
||||
|
||||
protected slots:
|
||||
void executeTask() override;
|
||||
void getUpdateModsForLoader(std::optional<ModPlatform::ModLoaderTypes> loader);
|
||||
void getUpdateModsForLoader(std::optional<ModPlatform::ModLoaderTypes> loader = {}, bool forceModLoaderCheck = false);
|
||||
void checkVersionsResponse(std::shared_ptr<QByteArray> response, std::optional<ModPlatform::ModLoaderTypes> loader);
|
||||
void checkNextLoader();
|
||||
|
||||
@ -28,4 +25,5 @@ class ModrinthCheckUpdate : public CheckUpdateTask {
|
||||
QHash<QString, Resource*> m_mappings;
|
||||
QString m_hashType;
|
||||
int m_loaderIdx = 0;
|
||||
int m_initialSize = 0;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user