mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-09-14 15:15:38 -04:00
fix: report installed status for non-mod resources
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
20 files changed
+80
-67
No files matched your search
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
DataPackResourceModel::DataPackResourceModel(const BaseInstance& base_inst,
|
||||
DataPackResourceModel::DataPackResourceModel(ResourceFolderModel* resourceList,
|
||||
const ResourceAPI* api,
|
||||
QString debugName,
|
||||
QString metaEntryBase)
|
||||
: ResourceModel(api), m_base_instance(base_inst), m_debugName(debugName + " (Model)"), m_metaEntryBase(metaEntryBase)
|
||||
: ResourceModel(resourceList, api), m_debugName(debugName + " (Model)"), m_metaEntryBase(metaEntryBase)
|
||||
{}
|
||||
|
||||
/******** Make data requests ********/
|
||||
@@ -21,13 +21,17 @@ DataPackResourceModel::DataPackResourceModel(const BaseInstance& base_inst,
|
||||
ResourceAPI::SearchArgs DataPackResourceModel::createSearchArguments()
|
||||
{
|
||||
auto sort = getCurrentSortingMethodByIndex();
|
||||
return { ModPlatform::ResourceType::DataPack, m_nextSearchOffset, m_searchTerm, sort, ModPlatform::ModLoaderType::DataPack };
|
||||
return { .type = ModPlatform::ResourceType::DataPack,
|
||||
.offset = m_nextSearchOffset,
|
||||
.search = m_searchTerm,
|
||||
.sorting = sort,
|
||||
.loaders = ModPlatform::ModLoaderType::DataPack };
|
||||
}
|
||||
|
||||
ResourceAPI::VersionSearchArgs DataPackResourceModel::createVersionsArguments(const QModelIndex& entry)
|
||||
{
|
||||
auto pack = m_packs[entry.row()];
|
||||
return { pack, {}, ModPlatform::ModLoaderType::DataPack };
|
||||
return { .pack = pack, .mcVersions = {}, .loaders = ModPlatform::ModLoaderType::DataPack };
|
||||
}
|
||||
|
||||
ResourceAPI::ProjectInfoArgs DataPackResourceModel::createInfoArguments(const QModelIndex& entry)
|
||||
|
||||
@@ -21,7 +21,7 @@ class DataPackResourceModel : public ResourceModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DataPackResourceModel(BaseInstance const&, const ResourceAPI*, QString, QString);
|
||||
DataPackResourceModel(ResourceFolderModel*, const ResourceAPI*, QString, QString);
|
||||
|
||||
/* Ask the API for more information */
|
||||
void searchWithTerm(const QString& term, unsigned int sort);
|
||||
@@ -34,9 +34,6 @@ class DataPackResourceModel : public ResourceModel {
|
||||
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override;
|
||||
|
||||
protected:
|
||||
const BaseInstance& m_base_instance;
|
||||
|
||||
private:
|
||||
QString m_debugName;
|
||||
QString m_metaEntryBase;
|
||||
|
||||
@@ -43,7 +43,7 @@ DataPackResourcePage::DataPackResourcePage(ResourceDownloadDialog* dialog,
|
||||
const ResourceAPI* api)
|
||||
: ResourcePage(dialog, instance, prepareDataPackDescriptor(), std::move(provider))
|
||||
{
|
||||
m_model = new DataPackResourceModel(instance, api, debugName(), metaEntryBase());
|
||||
m_model = new DataPackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase());
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
addSortings();
|
||||
|
||||
@@ -21,8 +21,15 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
ModModel::ModModel(BaseInstance& baseInst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase)
|
||||
: ResourceModel(api), m_baseInstance(baseInst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase))
|
||||
ModModel::ModModel(BaseInstance& baseInst,
|
||||
ResourceFolderModel* resourceList,
|
||||
const ResourceAPI* api,
|
||||
const QString& debugName,
|
||||
QString metaEntryBase)
|
||||
: ResourceModel(resourceList, api)
|
||||
, m_baseInstance(baseInst)
|
||||
, m_debugName(debugName + " (Model)")
|
||||
, m_metaEntryBase(std::move(metaEntryBase))
|
||||
{}
|
||||
|
||||
/******** Make data requests ********/
|
||||
@@ -104,28 +111,6 @@ void ModModel::searchWithTerm(const QString& term, unsigned int sort, bool filte
|
||||
refresh();
|
||||
}
|
||||
|
||||
bool ModModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const
|
||||
{
|
||||
auto allMods = static_cast<MinecraftInstance&>(m_baseInstance).loaderModList()->allMods();
|
||||
return std::ranges::any_of(allMods, [pack](Mod* mod) {
|
||||
if (auto meta = mod->metadata(); meta) {
|
||||
return meta->provider == pack->provider && meta->project_id == pack->addonId;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
QVariant ModModel::getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const
|
||||
{
|
||||
auto allMods = static_cast<MinecraftInstance&>(m_baseInstance).loaderModList()->allMods();
|
||||
for (auto* mod : allMods) {
|
||||
if (auto meta = mod->metadata(); meta && meta->provider == pack->provider && meta->project_id == pack->addonId) {
|
||||
return meta->version();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool checkSide(ModPlatform::SideType filter, ModPlatform::SideType value)
|
||||
|
||||
@@ -28,14 +28,12 @@ class ModModel : public ResourceModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ModModel(BaseInstance&, const ResourceAPI* api, const QString& debugName, QString metaEntryBase);
|
||||
ModModel(BaseInstance&, ResourceFolderModel*, const ResourceAPI* api, const QString& debugName, QString metaEntryBase);
|
||||
|
||||
/* Ask the API for more information */
|
||||
void searchWithTerm(const QString& term, unsigned int sort, bool filterChanged);
|
||||
|
||||
void setFilter(std::shared_ptr<ModFilterWidget::Filter> filter) { m_filter = std::move(filter); }
|
||||
QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const override;
|
||||
|
||||
[[nodiscard]] QString debugName() const override { return m_debugName; }
|
||||
[[nodiscard]] QString metaEntryBase() const override { return m_metaEntryBase; }
|
||||
|
||||
@@ -45,8 +43,6 @@ class ModModel : public ResourceModel {
|
||||
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex& index) override;
|
||||
|
||||
protected:
|
||||
bool isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const override;
|
||||
|
||||
bool checkFilters(ModPlatform::IndexedPack::Ptr pack) override;
|
||||
bool checkVersionFilters(const ModPlatform::IndexedVersion& version) override;
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ ModPage::ModPage(ResourceDownloadDialog* dialog,
|
||||
ModFilterWidget* filterWidget)
|
||||
: ResourcePage(dialog, instance, prepareModDescriptor(), std::move(p)), m_api(api)
|
||||
{
|
||||
auto* model = new ModModel(instance, api, debugName(), metaEntryBase());
|
||||
auto* model = new ModModel(instance, getDialog()->getBaseModel(), api, debugName(), metaEntryBase());
|
||||
m_model = model;
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
|
||||
@@ -18,19 +18,19 @@
|
||||
#include "BuildConfig.h"
|
||||
#include "settings/SettingsObject.h"
|
||||
|
||||
#include "minecraft/mod/ResourceFolderModel.h"
|
||||
#include "modplatform/ModIndex.h"
|
||||
#include "modplatform/ResourceAPI.h"
|
||||
#include "net/ApiRequest.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
#include "modplatform/ModIndex.h"
|
||||
|
||||
#include "ui/widgets/ProjectItem.h"
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
QHash<ResourceModel*, bool> ResourceModel::s_runningModels;
|
||||
|
||||
ResourceModel::ResourceModel(const ResourceAPI* api) : m_api(api)
|
||||
ResourceModel::ResourceModel(ResourceFolderModel* resourceList, const ResourceAPI* api) : m_resourceList(resourceList), m_api(api)
|
||||
{
|
||||
s_runningModels.insert(this, true);
|
||||
if (APPLICATION_DYN) {
|
||||
@@ -43,6 +43,38 @@ ResourceModel::~ResourceModel()
|
||||
s_runningModels.find(this).value() = false;
|
||||
}
|
||||
|
||||
bool ResourceModel::isPackInstalled(ModPlatform::IndexedPack::Ptr pack) const
|
||||
{
|
||||
if (!m_resourceList) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (qsizetype i = 0; i < m_resourceList->size(); ++i) {
|
||||
auto& resource = m_resourceList->at(i);
|
||||
if (auto meta = resource.metadata(); meta && meta->provider == pack->provider && meta->project_id == pack->addonId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant ResourceModel::getInstalledPackVersion(ModPlatform::IndexedPack::Ptr pack) const
|
||||
{
|
||||
if (!m_resourceList) {
|
||||
return {};
|
||||
}
|
||||
|
||||
for (qsizetype i = 0; i < m_resourceList->size(); ++i) {
|
||||
auto& resource = m_resourceList->at(i);
|
||||
if (auto meta = resource.metadata(); meta) {
|
||||
if (meta->provider == pack->provider && meta->project_id == pack->addonId) {
|
||||
return meta->version();
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
auto ResourceModel::data(const QModelIndex& index, int role) const -> QVariant
|
||||
{
|
||||
int pos = index.row();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
class NetJob;
|
||||
class ResourceAPI;
|
||||
class ResourceFolderModel;
|
||||
|
||||
namespace ModPlatform {
|
||||
struct IndexedPack;
|
||||
@@ -34,7 +35,7 @@ class ResourceModel : public QAbstractListModel {
|
||||
public:
|
||||
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
|
||||
|
||||
explicit ResourceModel(const ResourceAPI* api);
|
||||
ResourceModel(ResourceFolderModel*, const ResourceAPI* api);
|
||||
~ResourceModel() override;
|
||||
|
||||
auto data(const QModelIndex& /*index*/, int role) const -> QVariant override;
|
||||
@@ -54,7 +55,7 @@ class ResourceModel : public QAbstractListModel {
|
||||
|
||||
auto getSortingMethods() const { return m_api->getSortingMethods(); }
|
||||
|
||||
virtual QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr /*unused*/) const { return {}; }
|
||||
virtual QVariant getInstalledPackVersion(ModPlatform::IndexedPack::Ptr /*unused*/) const;
|
||||
/** Whether the version is opted out or not. Currently only makes sense in CF. */
|
||||
virtual bool optedOut(const ModPlatform::IndexedVersion& ver) const
|
||||
{
|
||||
@@ -110,7 +111,7 @@ class ResourceModel : public QAbstractListModel {
|
||||
|
||||
auto getCurrentSortingMethodByIndex() const -> std::optional<ResourceAPI::SortingMethod>;
|
||||
|
||||
virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr /*unused*/) const { return false; }
|
||||
virtual bool isPackInstalled(ModPlatform::IndexedPack::Ptr /*unused*/) const;
|
||||
|
||||
protected:
|
||||
/* Basic search parameters */
|
||||
@@ -119,6 +120,8 @@ class ResourceModel : public QAbstractListModel {
|
||||
QString m_searchTerm;
|
||||
unsigned int m_currentSortIndex = 0;
|
||||
|
||||
ResourceFolderModel* m_resourceList = nullptr;
|
||||
|
||||
const ResourceAPI* m_api;
|
||||
|
||||
// Job for searching for new entries
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
ResourcePackResourceModel::ResourcePackResourceModel(const BaseInstance& base_inst,
|
||||
ResourcePackResourceModel::ResourcePackResourceModel(ResourceFolderModel* resourceList,
|
||||
const ResourceAPI* api,
|
||||
const QString& debugName,
|
||||
QString metaEntryBase)
|
||||
: ResourceModel(api), m_base_instance(base_inst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase))
|
||||
: ResourceModel(resourceList, api), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase))
|
||||
{}
|
||||
|
||||
/******** Make data requests ********/
|
||||
|
||||
@@ -18,7 +18,7 @@ class ResourcePackResourceModel : public ResourceModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ResourcePackResourceModel(const BaseInstance&, const ResourceAPI*, const QString& debugName, QString metaEntryBase);
|
||||
ResourcePackResourceModel(ResourceFolderModel*, const ResourceAPI*, const QString& debugName, QString metaEntryBase);
|
||||
|
||||
/* Ask the API for more information */
|
||||
void searchWithTerm(const QString& term, unsigned int sort);
|
||||
@@ -31,9 +31,6 @@ class ResourcePackResourceModel : public ResourceModel {
|
||||
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override;
|
||||
|
||||
protected:
|
||||
const BaseInstance& m_base_instance;
|
||||
|
||||
private:
|
||||
QString m_debugName;
|
||||
QString m_metaEntryBase;
|
||||
|
||||
@@ -42,7 +42,7 @@ ResourcePackResourcePage::ResourcePackResourcePage(ResourceDownloadDialog* dialo
|
||||
const ResourceAPI* api)
|
||||
: ResourcePage(dialog, instance, prepareResourcePackDescriptor(), std::move(provider))
|
||||
{
|
||||
m_model = new ResourcePackResourceModel(instance, api, debugName(), metaEntryBase());
|
||||
m_model = new ResourcePackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase());
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
addSortings();
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace ResourceDownload {
|
||||
|
||||
ShaderPackResourceModel::ShaderPackResourceModel(const BaseInstance& baseInst,
|
||||
ShaderPackResourceModel::ShaderPackResourceModel(ResourceFolderModel* resourceList,
|
||||
const ResourceAPI* api,
|
||||
const QString& debugName,
|
||||
QString metaEntryBase)
|
||||
: ResourceModel(api), m_baseInstance(baseInst), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase))
|
||||
: ResourceModel(resourceList, api), m_debugName(debugName + " (Model)"), m_metaEntryBase(std::move(metaEntryBase))
|
||||
{}
|
||||
|
||||
/******** Make data requests ********/
|
||||
|
||||
@@ -18,7 +18,7 @@ class ShaderPackResourceModel : public ResourceModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ShaderPackResourceModel(const BaseInstance&, const ResourceAPI*, const QString& debugName, QString metaEntryBase);
|
||||
ShaderPackResourceModel(ResourceFolderModel*, const ResourceAPI*, const QString& debugName, QString metaEntryBase);
|
||||
|
||||
/* Ask the API for more information */
|
||||
void searchWithTerm(const QString& term, unsigned int sort);
|
||||
@@ -31,9 +31,6 @@ class ShaderPackResourceModel : public ResourceModel {
|
||||
ResourceAPI::VersionSearchArgs createVersionsArguments(const QModelIndex&) override;
|
||||
ResourceAPI::ProjectInfoArgs createInfoArguments(const QModelIndex&) override;
|
||||
|
||||
protected:
|
||||
const BaseInstance& m_baseInstance;
|
||||
|
||||
private:
|
||||
QString m_debugName;
|
||||
QString m_metaEntryBase;
|
||||
|
||||
@@ -40,7 +40,7 @@ ShaderPackResourcePage::ShaderPackResourcePage(ResourceDownloadDialog* dialog,
|
||||
const ResourceAPI* api)
|
||||
: ResourcePage(dialog, instance, prepareShaderPackDescriptor(), std::move(provider))
|
||||
{
|
||||
m_model = new ShaderPackResourceModel(instance, api, debugName(), metaEntryBase());
|
||||
m_model = new ShaderPackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase());
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
addSortings();
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
static std::vector<Version> s_availableVersions = {};
|
||||
|
||||
namespace ResourceDownload {
|
||||
TexturePackResourceModel::TexturePackResourceModel(const BaseInstance& inst,
|
||||
TexturePackResourceModel::TexturePackResourceModel(ResourceFolderModel* inst,
|
||||
const ResourceAPI* api,
|
||||
const QString& debugName,
|
||||
QString metaEntryBase)
|
||||
|
||||
@@ -13,7 +13,7 @@ class TexturePackResourceModel : public ResourcePackResourceModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TexturePackResourceModel(const BaseInstance& inst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase);
|
||||
TexturePackResourceModel(ResourceFolderModel* inst, const ResourceAPI* api, const QString& debugName, QString metaEntryBase);
|
||||
|
||||
inline ::Version maximumTexturePackVersion() const { return { "1.6" }; }
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ TexturePackResourcePage::TexturePackResourcePage(ResourceDownloadDialog* dialog,
|
||||
{
|
||||
m_model = model;
|
||||
if (!m_model) {
|
||||
m_model = new TexturePackResourceModel(instance, api, debugName(), metaEntryBase());
|
||||
m_model = new TexturePackResourceModel(getDialog()->getBaseModel(), api, debugName(), metaEntryBase());
|
||||
}
|
||||
m_ui->packView->setModel(m_model);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "Json.h"
|
||||
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "modplatform/flame/FlameAPI.h"
|
||||
#include "ui/pages/modplatform/flame/FlameResourcePages.h"
|
||||
@@ -17,15 +18,15 @@ static bool isOptedOut(const ModPlatform::IndexedVersion& ver)
|
||||
return ver.downloadUrl.isEmpty();
|
||||
}
|
||||
|
||||
FlameTexturePackModel::FlameTexturePackModel(const BaseInstance& base)
|
||||
: TexturePackResourceModel(base, &FlameAPI::get(), Flame::debugName(), Flame::metaEntryBase())
|
||||
FlameTexturePackModel::FlameTexturePackModel(ResourceFolderModel* resourceList)
|
||||
: TexturePackResourceModel(resourceList, &FlameAPI::get(), Flame::debugName(), Flame::metaEntryBase())
|
||||
{}
|
||||
|
||||
ResourceAPI::SearchArgs FlameTexturePackModel::createSearchArguments()
|
||||
{
|
||||
auto args = TexturePackResourceModel::createSearchArguments();
|
||||
|
||||
auto profile = static_cast<const MinecraftInstance&>(m_base_instance).getPackProfile();
|
||||
auto profile = static_cast<const MinecraftInstance&>(*m_resourceList->instance()).getPackProfile();
|
||||
QString instance_minecraft_version = profile->getComponentVersion("net.minecraft");
|
||||
|
||||
// Bypass the texture pack logic, because we can't do multiple versions in the API query
|
||||
|
||||
@@ -12,7 +12,7 @@ class FlameTexturePackModel : public TexturePackResourceModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FlameTexturePackModel(const BaseInstance&);
|
||||
FlameTexturePackModel(ResourceFolderModel*);
|
||||
~FlameTexturePackModel() override = default;
|
||||
|
||||
bool optedOut(const ModPlatform::IndexedVersion& ver) const override;
|
||||
|
||||
@@ -74,7 +74,8 @@ ResourcePackResourcePage* Flame::createResourcePackResourcePage(ResourceDownload
|
||||
|
||||
TexturePackResourcePage* Flame::createTexturePackResourcePage(ResourceDownloadDialog* dialog, BaseInstance& instance)
|
||||
{
|
||||
return new TexturePackResourcePage(dialog, instance, prepareFlame(), &FlameAPI::get(), new FlameTexturePackModel(instance));
|
||||
return new TexturePackResourcePage(dialog, instance, prepareFlame(), &FlameAPI::get(),
|
||||
new FlameTexturePackModel(dialog->getBaseModel()));
|
||||
}
|
||||
|
||||
ModPage* Flame::createModPage(ResourceDownloadDialog* dialog, BaseInstance& instance)
|
||||
|
||||
Reference in new issue
Block a user