mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-04 20:36:58 +03:00
Detect resources incompatible with the MC version
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
157ae6fb72
commit
e2d503456f
5 changed files with 48 additions and 4 deletions
|
|
@ -258,9 +258,11 @@ void ModFolderModel::onParseSucceeded(int ticket, QString mod_id)
|
|||
auto resource = find(mod_id);
|
||||
|
||||
auto result = cast_task->result();
|
||||
if (result && resource)
|
||||
static_cast<Mod*>(resource.get())->finishResolvingWithDetails(std::move(result->details));
|
||||
if (result && resource) {
|
||||
auto* mod = static_cast<Mod*>(resource.get());
|
||||
mod->finishResolvingWithDetails(std::move(result->details));
|
||||
|
||||
}
|
||||
emit dataChanged(index(row, RequiresColumn), index(row, RequiredByColumn));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "FileSystem.h"
|
||||
#include "StringUtils.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
|
||||
Resource::Resource(QObject* parent) : QObject(parent) {}
|
||||
|
||||
|
|
@ -111,6 +113,24 @@ void Resource::setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
|
|||
m_metadata = metadata;
|
||||
}
|
||||
|
||||
void Resource::determineCompat(const BaseInstance* inst) {
|
||||
if (m_metadata == nullptr) {
|
||||
m_isCompatible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
auto mcInst = dynamic_cast<const MinecraftInstance*>(inst);
|
||||
if (mcInst == nullptr) {
|
||||
m_isCompatible = true;
|
||||
return;
|
||||
}
|
||||
|
||||
auto profile = mcInst->getPackProfile();
|
||||
QString mcVersion = profile->getComponentVersion("net.minecraft");
|
||||
|
||||
m_isCompatible = m_metadata->mcVersions.contains(mcVersion);
|
||||
}
|
||||
|
||||
int Resource::compare(const Resource& other, SortType type) const
|
||||
{
|
||||
switch (type) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@
|
|||
#include "MetadataHandler.h"
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
class BaseInstance;
|
||||
|
||||
enum class ResourceType {
|
||||
UNKNOWN, //!< Indicates an unspecified resource type.
|
||||
ZIPFILE, //!< The resource is a zip file containing the resource's class files.
|
||||
|
|
@ -119,6 +121,13 @@ class Resource : public QObject {
|
|||
void setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata);
|
||||
void setMetadata(const Metadata::ModStruct& metadata) { setMetadata(std::make_shared<Metadata::ModStruct>(metadata)); }
|
||||
|
||||
/**
|
||||
* Returns whether the resource is compatible with the instance.
|
||||
* This is initially true, and may be updated when calling determineCompat with an instance.
|
||||
*/
|
||||
bool isCompatible() const { return m_isCompatible; }
|
||||
void determineCompat(const BaseInstance* inst);
|
||||
|
||||
/** Compares two Resources, for sorting purposes, considering a ascending order, returning:
|
||||
* > 0: 'this' comes after 'other'
|
||||
* = 0: 'this' is equal to 'other'
|
||||
|
|
@ -188,6 +197,8 @@ class Resource : public QObject {
|
|||
/* Whether the resource is enabled (e.g. shows up in the game) or not. */
|
||||
bool m_enabled = true;
|
||||
|
||||
bool m_isCompatible = true;
|
||||
|
||||
/* Used to keep trach of pending / concluded actions on the resource. */
|
||||
bool m_is_resolving = false;
|
||||
bool m_is_resolved = false;
|
||||
|
|
|
|||
|
|
@ -810,7 +810,13 @@ void ResourceFolderModel::applyUpdates(QSet<QString>& current_set, QSet<QString>
|
|||
auto const& current_resource = m_resources.at(row);
|
||||
|
||||
if (new_resource->dateTimeChanged() == current_resource->dateTimeChanged()) {
|
||||
// no significant change, ignore...
|
||||
// no significant change
|
||||
bool oldCompat = current_resource->isCompatible();
|
||||
current_resource->determineCompat(m_instance);
|
||||
|
||||
if (current_resource->isCompatible() != oldCompat) {
|
||||
emit dataChanged(index(row, 0), index(row, columnCount({}) - 1));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -825,6 +831,8 @@ void ResourceFolderModel::applyUpdates(QSet<QString>& current_set, QSet<QString>
|
|||
}
|
||||
|
||||
m_resources[row].reset(new_resource);
|
||||
new_resource->determineCompat(m_instance);
|
||||
|
||||
resolveResource(m_resources.at(row));
|
||||
emit dataChanged(index(row, 0), index(row, columnCount(QModelIndex()) - 1));
|
||||
}
|
||||
|
|
@ -872,6 +880,7 @@ void ResourceFolderModel::applyUpdates(QSet<QString>& current_set, QSet<QString>
|
|||
|
||||
for (auto& added : added_set) {
|
||||
auto res = new_resources[added];
|
||||
res->determineCompat(m_instance);
|
||||
m_resources.append(res);
|
||||
resolveResource(m_resources.last());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,11 @@
|
|||
#include <QObject>
|
||||
#include <QRunnable>
|
||||
#include <memory>
|
||||
#include "minecraft/mod/Mod.h"
|
||||
#include "minecraft/mod/Resource.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class BaseInstance;
|
||||
|
||||
class ResourceFolderLoadTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue