Merge pull request #374 from flowln/fix_lto

This commit is contained in:
txtsd 2022-11-04 15:39:41 +05:30 committed by GitHub
commit 8f045af867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 120 additions and 118 deletions

View File

@ -17,13 +17,14 @@
#include <memory> #include <memory>
#include "BaseVersion.h"
class MinecraftInstance; class MinecraftInstance;
class QDir; class QDir;
class QString; class QString;
class QObject; class QObject;
class Task; class Task;
class BaseVersion; class BaseVersion;
typedef std::shared_ptr<BaseVersion> BaseVersionPtr;
class BaseInstaller class BaseInstaller
{ {
@ -35,7 +36,7 @@ public:
virtual bool add(MinecraftInstance *to); virtual bool add(MinecraftInstance *to);
virtual bool remove(MinecraftInstance *from); virtual bool remove(MinecraftInstance *from);
virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersionPtr version, QObject *parent) = 0; virtual Task *createInstallTask(MinecraftInstance *instance, BaseVersion::Ptr version, QObject *parent) = 0;
protected: protected:
virtual QString id() const = 0; virtual QString id() const = 0;

View File

@ -25,6 +25,7 @@
class BaseVersion class BaseVersion
{ {
public: public:
using Ptr = std::shared_ptr<BaseVersion>;
virtual ~BaseVersion() {} virtual ~BaseVersion() {}
/*! /*!
* A string used to identify this version in config files. * A string used to identify this version in config files.
@ -54,6 +55,4 @@ public:
}; };
}; };
typedef std::shared_ptr<BaseVersion> BaseVersionPtr; Q_DECLARE_METATYPE(BaseVersion::Ptr)
Q_DECLARE_METATYPE(BaseVersionPtr)

View File

@ -40,20 +40,20 @@ BaseVersionList::BaseVersionList(QObject *parent) : QAbstractListModel(parent)
{ {
} }
BaseVersionPtr BaseVersionList::findVersion(const QString &descriptor) BaseVersion::Ptr BaseVersionList::findVersion(const QString &descriptor)
{ {
for (int i = 0; i < count(); i++) for (int i = 0; i < count(); i++)
{ {
if (at(i)->descriptor() == descriptor) if (at(i)->descriptor() == descriptor)
return at(i); return at(i);
} }
return BaseVersionPtr(); return nullptr;
} }
BaseVersionPtr BaseVersionList::getRecommended() const BaseVersion::Ptr BaseVersionList::getRecommended() const
{ {
if (count() <= 0) if (count() <= 0)
return BaseVersionPtr(); return nullptr;
else else
return at(0); return at(0);
} }
@ -66,7 +66,7 @@ QVariant BaseVersionList::data(const QModelIndex &index, int role) const
if (index.row() > count()) if (index.row() > count())
return QVariant(); return QVariant();
BaseVersionPtr version = at(index.row()); BaseVersion::Ptr version = at(index.row());
switch (role) switch (role)
{ {

View File

@ -70,7 +70,7 @@ public:
virtual bool isLoaded() = 0; virtual bool isLoaded() = 0;
//! Gets the version at the given index. //! Gets the version at the given index.
virtual const BaseVersionPtr at(int i) const = 0; virtual const BaseVersion::Ptr at(int i) const = 0;
//! Returns the number of versions in the list. //! Returns the number of versions in the list.
virtual int count() const = 0; virtual int count() const = 0;
@ -90,13 +90,13 @@ public:
* \return A const pointer to the version with the given descriptor. NULL if * \return A const pointer to the version with the given descriptor. NULL if
* one doesn't exist. * one doesn't exist.
*/ */
virtual BaseVersionPtr findVersion(const QString &descriptor); virtual BaseVersion::Ptr findVersion(const QString &descriptor);
/*! /*!
* \brief Gets the recommended version from this list * \brief Gets the recommended version from this list
* If the list doesn't support recommended versions, this works exactly as getLatestStable * If the list doesn't support recommended versions, this works exactly as getLatestStable
*/ */
virtual BaseVersionPtr getRecommended() const; virtual BaseVersion::Ptr getRecommended() const;
/*! /*!
* Sorts the version list. * Sorts the version list.
@ -117,5 +117,5 @@ slots:
* then copies the versions and sets their parents correctly. * then copies the versions and sets their parents correctly.
* \param versions List of versions whose parents should be set. * \param versions List of versions whose parents should be set.
*/ */
virtual void updateListData(QList<BaseVersionPtr> versions) = 0; virtual void updateListData(QList<BaseVersion::Ptr> versions) = 0;
}; };

View File

@ -73,7 +73,7 @@ void JavaInstallList::load()
} }
} }
const BaseVersionPtr JavaInstallList::at(int i) const const BaseVersion::Ptr JavaInstallList::at(int i) const
{ {
return m_vlist.at(i); return m_vlist.at(i);
} }
@ -122,7 +122,7 @@ BaseVersionList::RoleList JavaInstallList::providesRoles() const
} }
void JavaInstallList::updateListData(QList<BaseVersionPtr> versions) void JavaInstallList::updateListData(QList<BaseVersion::Ptr> versions)
{ {
beginResetModel(); beginResetModel();
m_vlist = versions; m_vlist = versions;
@ -137,7 +137,7 @@ void JavaInstallList::updateListData(QList<BaseVersionPtr> versions)
m_loadTask.reset(); m_loadTask.reset();
} }
bool sortJavas(BaseVersionPtr left, BaseVersionPtr right) bool sortJavas(BaseVersion::Ptr left, BaseVersion::Ptr right)
{ {
auto rleft = std::dynamic_pointer_cast<JavaInstall>(right); auto rleft = std::dynamic_pointer_cast<JavaInstall>(right);
auto rright = std::dynamic_pointer_cast<JavaInstall>(left); auto rright = std::dynamic_pointer_cast<JavaInstall>(left);
@ -210,11 +210,11 @@ void JavaListLoadTask::javaCheckerFinished()
} }
} }
QList<BaseVersionPtr> javas_bvp; QList<BaseVersion::Ptr> javas_bvp;
for (auto java : candidates) for (auto java : candidates)
{ {
//qDebug() << java->id << java->arch << " at " << java->path; //qDebug() << java->id << java->arch << " at " << java->path;
BaseVersionPtr bp_java = std::dynamic_pointer_cast<BaseVersion>(java); BaseVersion::Ptr bp_java = std::dynamic_pointer_cast<BaseVersion>(java);
if (bp_java) if (bp_java)
{ {

View File

@ -42,7 +42,7 @@ public:
Task::Ptr getLoadTask() override; Task::Ptr getLoadTask() override;
bool isLoaded() override; bool isLoaded() override;
const BaseVersionPtr at(int i) const override; const BaseVersion::Ptr at(int i) const override;
int count() const override; int count() const override;
void sortVersions() override; void sortVersions() override;
@ -50,7 +50,7 @@ public:
RoleList providesRoles() const override; RoleList providesRoles() const override;
public slots: public slots:
void updateListData(QList<BaseVersionPtr> versions) override; void updateListData(QList<BaseVersion::Ptr> versions) override;
protected: protected:
void load(); void load();
@ -59,7 +59,7 @@ protected:
protected: protected:
Status m_status = Status::NotDone; Status m_status = Status::NotDone;
shared_qobject_ptr<JavaListLoadTask> m_loadTask; shared_qobject_ptr<JavaListLoadTask> m_loadTask;
QList<BaseVersionPtr> m_vlist; QList<BaseVersion::Ptr> m_vlist;
}; };
class JavaListLoadTask : public Task class JavaListLoadTask : public Task

View File

@ -24,7 +24,7 @@ Index::Index(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
} }
Index::Index(const QVector<VersionListPtr> &lists, QObject *parent) Index::Index(const QVector<VersionList::Ptr> &lists, QObject *parent)
: QAbstractListModel(parent), m_lists(lists) : QAbstractListModel(parent), m_lists(lists)
{ {
for (int i = 0; i < m_lists.size(); ++i) for (int i = 0; i < m_lists.size(); ++i)
@ -41,7 +41,7 @@ QVariant Index::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
VersionListPtr list = m_lists.at(index.row()); VersionList::Ptr list = m_lists.at(index.row());
switch (role) switch (role)
{ {
case Qt::DisplayRole: case Qt::DisplayRole:
@ -81,9 +81,9 @@ bool Index::hasUid(const QString &uid) const
return m_uids.contains(uid); return m_uids.contains(uid);
} }
VersionListPtr Index::get(const QString &uid) VersionList::Ptr Index::get(const QString &uid)
{ {
VersionListPtr out = m_uids.value(uid, nullptr); VersionList::Ptr out = m_uids.value(uid, nullptr);
if(!out) if(!out)
{ {
out = std::make_shared<VersionList>(uid); out = std::make_shared<VersionList>(uid);
@ -92,7 +92,7 @@ VersionListPtr Index::get(const QString &uid)
return out; return out;
} }
VersionPtr Index::get(const QString &uid, const QString &version) Version::Ptr Index::get(const QString &uid, const QString &version)
{ {
auto list = get(uid); auto list = get(uid);
return list->getVersion(version); return list->getVersion(version);
@ -105,7 +105,7 @@ void Index::parse(const QJsonObject& obj)
void Index::merge(const std::shared_ptr<Index> &other) void Index::merge(const std::shared_ptr<Index> &other)
{ {
const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists; const QVector<VersionList::Ptr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
// initial load, no need to merge // initial load, no need to merge
if (m_lists.isEmpty()) if (m_lists.isEmpty())
{ {
@ -120,7 +120,7 @@ void Index::merge(const std::shared_ptr<Index> &other)
} }
else else
{ {
for (const VersionListPtr &list : lists) for (const VersionList::Ptr &list : lists)
{ {
if (m_uids.contains(list->uid())) if (m_uids.contains(list->uid()))
{ {
@ -138,7 +138,7 @@ void Index::merge(const std::shared_ptr<Index> &other)
} }
} }
void Index::connectVersionList(const int row, const VersionListPtr &list) void Index::connectVersionList(const int row, const VersionList::Ptr &list)
{ {
connect(list.get(), &VersionList::nameChanged, this, [this, row]() connect(list.get(), &VersionList::nameChanged, this, [this, row]()
{ {

View File

@ -19,20 +19,19 @@
#include <memory> #include <memory>
#include "BaseEntity.h" #include "BaseEntity.h"
#include "meta/VersionList.h"
class Task; class Task;
namespace Meta namespace Meta
{ {
using VersionListPtr = std::shared_ptr<class VersionList>;
using VersionPtr = std::shared_ptr<class Version>;
class Index : public QAbstractListModel, public BaseEntity class Index : public QAbstractListModel, public BaseEntity
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Index(QObject *parent = nullptr); explicit Index(QObject *parent = nullptr);
explicit Index(const QVector<VersionListPtr> &lists, QObject *parent = nullptr); explicit Index(const QVector<VersionList::Ptr> &lists, QObject *parent = nullptr);
enum enum
{ {
@ -49,21 +48,21 @@ public:
QString localFilename() const override { return "index.json"; } QString localFilename() const override { return "index.json"; }
// queries // queries
VersionListPtr get(const QString &uid); VersionList::Ptr get(const QString &uid);
VersionPtr get(const QString &uid, const QString &version); Version::Ptr get(const QString &uid, const QString &version);
bool hasUid(const QString &uid) const; bool hasUid(const QString &uid) const;
QVector<VersionListPtr> lists() const { return m_lists; } QVector<VersionList::Ptr> lists() const { return m_lists; }
public: // for usage by parsers only public: // for usage by parsers only
void merge(const std::shared_ptr<Index> &other); void merge(const std::shared_ptr<Index> &other);
void parse(const QJsonObject &obj) override; void parse(const QJsonObject &obj) override;
private: private:
QVector<VersionListPtr> m_lists; QVector<VersionList::Ptr> m_lists;
QHash<QString, VersionListPtr> m_uids; QHash<QString, VersionList::Ptr> m_uids;
void connectVersionList(const int row, const VersionListPtr &list); void connectVersionList(const int row, const VersionList::Ptr &list);
}; };
} }

View File

@ -37,11 +37,11 @@ MetadataVersion currentFormatVersion()
static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj) static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
{ {
const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages"); const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages");
QVector<VersionListPtr> lists; QVector<VersionList::Ptr> lists;
lists.reserve(objects.size()); lists.reserve(objects.size());
std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj)
{ {
VersionListPtr list = std::make_shared<VersionList>(requireString(obj, "uid")); VersionList::Ptr list = std::make_shared<VersionList>(requireString(obj, "uid"));
list->setName(ensureString(obj, "name", QString())); list->setName(ensureString(obj, "name", QString()));
return list; return list;
}); });
@ -49,9 +49,9 @@ static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
} }
// Version // Version
static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) static Version::Ptr parseCommonVersion(const QString &uid, const QJsonObject &obj)
{ {
VersionPtr version = std::make_shared<Version>(uid, requireString(obj, "version")); Version::Ptr version = std::make_shared<Version>(uid, requireString(obj, "version"));
version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000); version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000);
version->setType(ensureString(obj, "type", QString())); version->setType(ensureString(obj, "type", QString()));
version->setRecommended(ensureBoolean(obj, QString("recommended"), false)); version->setRecommended(ensureBoolean(obj, QString("recommended"), false));
@ -63,9 +63,9 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
return version; return version;
} }
static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj) static Version::Ptr parseVersionInternal(const QJsonObject &obj)
{ {
VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); Version::Ptr version = parseCommonVersion(requireString(obj, "uid"), obj);
version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj),
QString("%1/%2.json").arg(version->uid(), version->version()), QString("%1/%2.json").arg(version->uid(), version->version()),
@ -74,12 +74,12 @@ static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj)
} }
// Version list / package // Version list / package
static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &obj) static VersionList::Ptr parseVersionListInternal(const QJsonObject &obj)
{ {
const QString uid = requireString(obj, "uid"); const QString uid = requireString(obj, "uid");
const QVector<QJsonObject> versionsRaw = requireIsArrayOf<QJsonObject>(obj, "versions"); const QVector<QJsonObject> versionsRaw = requireIsArrayOf<QJsonObject>(obj, "versions");
QVector<VersionPtr> versions; QVector<Version::Ptr> versions;
versions.reserve(versionsRaw.size()); versions.reserve(versionsRaw.size());
std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [uid](const QJsonObject &vObj) std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [uid](const QJsonObject &vObj)
{ {
@ -88,7 +88,7 @@ static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &
return version; return version;
}); });
VersionListPtr list = std::make_shared<VersionList>(uid); VersionList::Ptr list = std::make_shared<VersionList>(uid);
list->setName(ensureString(obj, "name", QString())); list->setName(ensureString(obj, "name", QString()));
list->setVersions(versions); list->setVersions(versions);
return list; return list;

View File

@ -54,7 +54,7 @@ void Meta::Version::parse(const QJsonObject& obj)
parseVersion(obj, this); parseVersion(obj, this);
} }
void Meta::Version::mergeFromList(const Meta::VersionPtr& other) void Meta::Version::mergeFromList(const Meta::Version::Ptr& other)
{ {
if(other->m_providesRecommendations) if(other->m_providesRecommendations)
{ {
@ -85,7 +85,7 @@ void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
} }
} }
void Meta::Version::merge(const VersionPtr &other) void Meta::Version::merge(const Version::Ptr &other)
{ {
mergeFromList(other); mergeFromList(other);
if(other->m_data) if(other->m_data)

View File

@ -30,13 +30,14 @@
namespace Meta namespace Meta
{ {
using VersionPtr = std::shared_ptr<class Version>;
class Version : public QObject, public BaseVersion, public BaseEntity class Version : public QObject, public BaseVersion, public BaseEntity
{ {
Q_OBJECT Q_OBJECT
public: /* con/des */ public:
using Ptr = std::shared_ptr<Version>;
explicit Version(const QString &uid, const QString &version); explicit Version(const QString &uid, const QString &version);
virtual ~Version(); virtual ~Version();
@ -78,8 +79,8 @@ public: /* con/des */
return m_data != nullptr; return m_data != nullptr;
} }
void merge(const VersionPtr &other); void merge(const Version::Ptr &other);
void mergeFromList(const VersionPtr &other); void mergeFromList(const Version::Ptr &other);
void parse(const QJsonObject &obj) override; void parse(const QJsonObject &obj) override;
QString localFilename() const override; QString localFilename() const override;
@ -113,4 +114,4 @@ private:
}; };
} }
Q_DECLARE_METATYPE(Meta::VersionPtr) Q_DECLARE_METATYPE(Meta::Version::Ptr)

View File

@ -40,7 +40,7 @@ bool VersionList::isLoaded()
return BaseEntity::isLoaded(); return BaseEntity::isLoaded();
} }
const BaseVersionPtr VersionList::at(int i) const const BaseVersion::Ptr VersionList::at(int i) const
{ {
return m_versions.at(i); return m_versions.at(i);
} }
@ -52,7 +52,7 @@ int VersionList::count() const
void VersionList::sortVersions() void VersionList::sortVersions()
{ {
beginResetModel(); beginResetModel();
std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b) std::sort(m_versions.begin(), m_versions.end(), [](const Version::Ptr &a, const Version::Ptr &b)
{ {
return *a.get() < *b.get(); return *a.get() < *b.get();
}); });
@ -66,7 +66,7 @@ QVariant VersionList::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
VersionPtr version = m_versions.at(index.row()); Version::Ptr version = m_versions.at(index.row());
switch (role) switch (role)
{ {
@ -129,9 +129,9 @@ QString VersionList::humanReadable() const
return m_name.isEmpty() ? m_uid : m_name; return m_name.isEmpty() ? m_uid : m_name;
} }
VersionPtr VersionList::getVersion(const QString &version) Version::Ptr VersionList::getVersion(const QString &version)
{ {
VersionPtr out = m_lookup.value(version, nullptr); Version::Ptr out = m_lookup.value(version, nullptr);
if(!out) if(!out)
{ {
out = std::make_shared<Version>(m_uid, version); out = std::make_shared<Version>(m_uid, version);
@ -143,7 +143,7 @@ VersionPtr VersionList::getVersion(const QString &version)
bool VersionList::hasVersion(QString version) const bool VersionList::hasVersion(QString version) const
{ {
auto ver = std::find_if(m_versions.constBegin(), m_versions.constEnd(), auto ver = std::find_if(m_versions.constBegin(), m_versions.constEnd(),
[&](Meta::VersionPtr const& a){ return a->version() == version; }); [&](Meta::Version::Ptr const& a){ return a->version() == version; });
return (ver != m_versions.constEnd()); return (ver != m_versions.constEnd());
} }
@ -153,11 +153,11 @@ void VersionList::setName(const QString &name)
emit nameChanged(name); emit nameChanged(name);
} }
void VersionList::setVersions(const QVector<VersionPtr> &versions) void VersionList::setVersions(const QVector<Version::Ptr> &versions)
{ {
beginResetModel(); beginResetModel();
m_versions = versions; m_versions = versions;
std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b) std::sort(m_versions.begin(), m_versions.end(), [](const Version::Ptr &a, const Version::Ptr &b)
{ {
return a->rawTime() > b->rawTime(); return a->rawTime() > b->rawTime();
}); });
@ -168,7 +168,7 @@ void VersionList::setVersions(const QVector<VersionPtr> &versions)
} }
// FIXME: this is dumb, we have 'recommended' as part of the metadata already... // FIXME: this is dumb, we have 'recommended' as part of the metadata already...
auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const VersionPtr &ptr) { return ptr->type() == "release"; }); auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const Version::Ptr &ptr) { return ptr->type() == "release"; });
m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt; m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt;
endResetModel(); endResetModel();
} }
@ -179,7 +179,7 @@ void VersionList::parse(const QJsonObject& obj)
} }
// FIXME: this is dumb, we have 'recommended' as part of the metadata already... // FIXME: this is dumb, we have 'recommended' as part of the metadata already...
static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const Meta::VersionPtr &b) static const Meta::Version::Ptr &getBetterVersion(const Meta::Version::Ptr &a, const Meta::Version::Ptr &b)
{ {
if(!a) if(!a)
return b; return b;
@ -194,7 +194,7 @@ static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const
return (a->type() == "release" ? a : b); return (a->type() == "release" ? a : b);
} }
void VersionList::mergeFromIndex(const VersionListPtr &other) void VersionList::mergeFromIndex(const VersionList::Ptr &other)
{ {
if (m_name != other->m_name) if (m_name != other->m_name)
{ {
@ -202,7 +202,7 @@ void VersionList::mergeFromIndex(const VersionListPtr &other)
} }
} }
void VersionList::merge(const VersionListPtr &other) void VersionList::merge(const VersionList::Ptr &other)
{ {
if (m_name != other->m_name) if (m_name != other->m_name)
{ {
@ -216,7 +216,7 @@ void VersionList::merge(const VersionListPtr &other)
{ {
qWarning() << "Empty list loaded ..."; qWarning() << "Empty list loaded ...";
} }
for (const VersionPtr &version : other->m_versions) for (const Version::Ptr &version : other->m_versions)
{ {
// we already have the version. merge the contents // we already have the version. merge the contents
if (m_lookup.contains(version->version())) if (m_lookup.contains(version->version()))
@ -235,7 +235,7 @@ void VersionList::merge(const VersionListPtr &other)
endResetModel(); endResetModel();
} }
void VersionList::setupAddedVersion(const int row, const VersionPtr &version) void VersionList::setupAddedVersion(const int row, const Version::Ptr &version)
{ {
// FIXME: do not disconnect from everythin, disconnect only the lambdas here // FIXME: do not disconnect from everythin, disconnect only the lambdas here
version->disconnect(); version->disconnect();
@ -244,7 +244,7 @@ void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); }); connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TypeRole); });
} }
BaseVersionPtr VersionList::getRecommended() const BaseVersion::Ptr VersionList::getRecommended() const
{ {
return m_recommended; return m_recommended;
} }

View File

@ -20,10 +20,10 @@
#include <QJsonObject> #include <QJsonObject>
#include <memory> #include <memory>
#include "meta/Version.h"
namespace Meta namespace Meta
{ {
using VersionPtr = std::shared_ptr<class Version>;
using VersionListPtr = std::shared_ptr<class VersionList>;
class VersionList : public BaseVersionList, public BaseEntity class VersionList : public BaseVersionList, public BaseEntity
{ {
@ -33,6 +33,8 @@ class VersionList : public BaseVersionList, public BaseEntity
public: public:
explicit VersionList(const QString &uid, QObject *parent = nullptr); explicit VersionList(const QString &uid, QObject *parent = nullptr);
using Ptr = std::shared_ptr<VersionList>;
enum Roles enum Roles
{ {
UidRole = Qt::UserRole + 100, UidRole = Qt::UserRole + 100,
@ -43,11 +45,11 @@ public:
Task::Ptr getLoadTask() override; Task::Ptr getLoadTask() override;
bool isLoaded() override; bool isLoaded() override;
const BaseVersionPtr at(int i) const override; const BaseVersion::Ptr at(int i) const override;
int count() const override; int count() const override;
void sortVersions() override; void sortVersions() override;
BaseVersionPtr getRecommended() const override; BaseVersion::Ptr getRecommended() const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
RoleList providesRoles() const override; RoleList providesRoles() const override;
@ -65,38 +67,38 @@ public:
} }
QString humanReadable() const; QString humanReadable() const;
VersionPtr getVersion(const QString &version); Version::Ptr getVersion(const QString &version);
bool hasVersion(QString version) const; bool hasVersion(QString version) const;
QVector<VersionPtr> versions() const QVector<Version::Ptr> versions() const
{ {
return m_versions; return m_versions;
} }
public: // for usage only by parsers public: // for usage only by parsers
void setName(const QString &name); void setName(const QString &name);
void setVersions(const QVector<VersionPtr> &versions); void setVersions(const QVector<Version::Ptr> &versions);
void merge(const VersionListPtr &other); void merge(const VersionList::Ptr &other);
void mergeFromIndex(const VersionListPtr &other); void mergeFromIndex(const VersionList::Ptr &other);
void parse(const QJsonObject &obj) override; void parse(const QJsonObject &obj) override;
signals: signals:
void nameChanged(const QString &name); void nameChanged(const QString &name);
protected slots: protected slots:
void updateListData(QList<BaseVersionPtr>) override void updateListData(QList<BaseVersion::Ptr>) override
{ {
} }
private: private:
QVector<VersionPtr> m_versions; QVector<Version::Ptr> m_versions;
QHash<QString, VersionPtr> m_lookup; QHash<QString, Version::Ptr> m_lookup;
QString m_uid; QString m_uid;
QString m_name; QString m_name;
VersionPtr m_recommended; Version::Ptr m_recommended;
void setupAddedVersion(const int row, const VersionPtr &version); void setupAddedVersion(const int row, const Version::Ptr &version);
}; };
} }
Q_DECLARE_METATYPE(Meta::VersionListPtr) Q_DECLARE_METATYPE(Meta::VersionList::Ptr)

View File

@ -7,7 +7,7 @@
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
VanillaCreationTask::VanillaCreationTask(BaseVersionPtr version, QString loader, BaseVersionPtr loader_version) VanillaCreationTask::VanillaCreationTask(BaseVersion::Ptr version, QString loader, BaseVersion::Ptr loader_version)
: InstanceCreationTask(), m_version(std::move(version)), m_using_loader(true), m_loader(std::move(loader)), m_loader_version(std::move(loader_version)) : InstanceCreationTask(), m_version(std::move(version)), m_using_loader(true), m_loader(std::move(loader)), m_loader_version(std::move(loader_version))
{} {}

View File

@ -7,16 +7,16 @@
class VanillaCreationTask final : public InstanceCreationTask { class VanillaCreationTask final : public InstanceCreationTask {
Q_OBJECT Q_OBJECT
public: public:
VanillaCreationTask(BaseVersionPtr version) : InstanceCreationTask(), m_version(std::move(version)) {} VanillaCreationTask(BaseVersion::Ptr version) : InstanceCreationTask(), m_version(std::move(version)) {}
VanillaCreationTask(BaseVersionPtr version, QString loader, BaseVersionPtr loader_version); VanillaCreationTask(BaseVersion::Ptr version, QString loader, BaseVersion::Ptr loader_version);
bool createInstance() override; bool createInstance() override;
private: private:
// Version to update to / create of the instance. // Version to update to / create of the instance.
BaseVersionPtr m_version; BaseVersion::Ptr m_version;
bool m_using_loader = false; bool m_using_loader = false;
QString m_loader; QString m_loader;
BaseVersionPtr m_loader_version; BaseVersion::Ptr m_loader_version;
}; };

View File

@ -58,7 +58,7 @@
namespace ATLauncher { namespace ATLauncher {
static Meta::VersionPtr getComponentVersion(const QString& uid, const QString& version); static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& version);
PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString packName, QString version, InstallMode installMode) PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString packName, QString version, InstallMode installMode)
{ {
@ -1037,7 +1037,7 @@ void PackInstallTask::install()
emitSucceeded(); emitSucceeded();
} }
static Meta::VersionPtr getComponentVersion(const QString& uid, const QString& version) static Meta::Version::Ptr getComponentVersion(const QString& uid, const QString& version)
{ {
auto vlist = APPLICATION->metadataIndex()->get(uid); auto vlist = APPLICATION->metadataIndex()->get(uid);
if (!vlist) if (!vlist)

View File

@ -68,7 +68,7 @@ public:
* Requests a user interaction to select a component version from a given version list * Requests a user interaction to select a component version from a given version list
* and constrained to a given Minecraft version. * and constrained to a given Minecraft version.
*/ */
virtual QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) = 0; virtual QString chooseVersion(Meta::VersionList::Ptr vlist, QString minecraftVersion) = 0;
/** /**
* Requests a user interaction to display a message. * Requests a user interaction to display a message.
@ -137,8 +137,8 @@ private:
QString archivePath; QString archivePath;
QStringList jarmods; QStringList jarmods;
Meta::VersionPtr minecraftVersion; Meta::Version::Ptr minecraftVersion;
QMap<QString, Meta::VersionPtr> componentsToInstall; QMap<QString, Meta::Version::Ptr> componentsToInstall;
QFuture<std::optional<QStringList>> m_extractFuture; QFuture<std::optional<QStringList>> m_extractFuture;
QFutureWatcher<std::optional<QStringList>> m_extractFutureWatcher; QFutureWatcher<std::optional<QStringList>> m_extractFutureWatcher;

View File

@ -120,7 +120,7 @@ void VersionSelectDialog::selectRecommended()
m_versionWidget->selectRecommended(); m_versionWidget->selectRecommended();
} }
BaseVersionPtr VersionSelectDialog::selectedVersion() const BaseVersion::Ptr VersionSelectDialog::selectedVersion() const
{ {
return m_versionWidget->selectedVersion(); return m_versionWidget->selectedVersion();
} }

View File

@ -44,7 +44,7 @@ public:
int exec() override; int exec() override;
BaseVersionPtr selectedVersion() const; BaseVersion::Ptr selectedVersion() const;
void setCurrentVersion(const QString & version); void setCurrentVersion(const QString & version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter); void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);

View File

@ -187,12 +187,12 @@ void VanillaPage::retranslate()
ui->retranslateUi(this); ui->retranslateUi(this);
} }
BaseVersionPtr VanillaPage::selectedVersion() const BaseVersion::Ptr VanillaPage::selectedVersion() const
{ {
return m_selectedVersion; return m_selectedVersion;
} }
BaseVersionPtr VanillaPage::selectedLoaderVersion() const BaseVersion::Ptr VanillaPage::selectedLoaderVersion() const
{ {
return m_selectedLoaderVersion; return m_selectedLoaderVersion;
} }
@ -227,14 +227,14 @@ void VanillaPage::suggestCurrent()
dialog->setSuggestedIcon("default"); dialog->setSuggestedIcon("default");
} }
void VanillaPage::setSelectedVersion(BaseVersionPtr version) void VanillaPage::setSelectedVersion(BaseVersion::Ptr version)
{ {
m_selectedVersion = version; m_selectedVersion = version;
suggestCurrent(); suggestCurrent();
loaderFilterChanged(); loaderFilterChanged();
} }
void VanillaPage::setSelectedLoaderVersion(BaseVersionPtr version) void VanillaPage::setSelectedLoaderVersion(BaseVersion::Ptr version)
{ {
m_selectedLoaderVersion = version; m_selectedLoaderVersion = version;
suggestCurrent(); suggestCurrent();

View File

@ -76,13 +76,13 @@ public:
void openedImpl() override; void openedImpl() override;
BaseVersionPtr selectedVersion() const; BaseVersion::Ptr selectedVersion() const;
BaseVersionPtr selectedLoaderVersion() const; BaseVersion::Ptr selectedLoaderVersion() const;
QString selectedLoader() const; QString selectedLoader() const;
public slots: public slots:
void setSelectedVersion(BaseVersionPtr version); void setSelectedVersion(BaseVersion::Ptr version);
void setSelectedLoaderVersion(BaseVersionPtr version); void setSelectedLoaderVersion(BaseVersion::Ptr version);
private slots: private slots:
void filterChanged(); void filterChanged();
@ -98,7 +98,7 @@ private:
NewInstanceDialog *dialog = nullptr; NewInstanceDialog *dialog = nullptr;
Ui::VanillaPage *ui = nullptr; Ui::VanillaPage *ui = nullptr;
bool m_versionSetByUser = false; bool m_versionSetByUser = false;
BaseVersionPtr m_selectedVersion; BaseVersion::Ptr m_selectedVersion;
BaseVersionPtr m_selectedLoaderVersion; BaseVersion::Ptr m_selectedLoaderVersion;
QString m_selectedLoader; QString m_selectedLoader;
}; };

View File

@ -53,7 +53,7 @@ std::optional<QVector<QString>> AtlUserInteractionSupportImpl::chooseOptionalMod
return optionalModDialog.getResult(); return optionalModDialog.getResult();
} }
QString AtlUserInteractionSupportImpl::chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) QString AtlUserInteractionSupportImpl::chooseVersion(Meta::VersionList::Ptr vlist, QString minecraftVersion)
{ {
VersionSelectDialog vselect(vlist.get(), "Choose Version", m_parent, false); VersionSelectDialog vselect(vlist.get(), "Choose Version", m_parent, false);
if (minecraftVersion != nullptr) { if (minecraftVersion != nullptr) {

View File

@ -46,7 +46,7 @@ public:
AtlUserInteractionSupportImpl(QWidget* parent); AtlUserInteractionSupportImpl(QWidget* parent);
private: private:
QString chooseVersion(Meta::VersionListPtr vlist, QString minecraftVersion) override; QString chooseVersion(Meta::VersionList::Ptr vlist, QString minecraftVersion) override;
std::optional<QVector<QString>> chooseOptionalMods(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) override; std::optional<QVector<QString>> chooseOptionalMods(ATLauncher::PackVersion version, QVector<ATLauncher::VersionMod> mods) override;
void displayMessage(QString message) override; void displayMessage(QString message) override;

View File

@ -245,7 +245,7 @@ void JavaSettingsWidget::memoryValueChanged(int)
} }
} }
void JavaSettingsWidget::javaVersionSelected(BaseVersionPtr version) void JavaSettingsWidget::javaVersionSelected(BaseVersion::Ptr version)
{ {
auto java = std::dynamic_pointer_cast<JavaInstall>(version); auto java = std::dynamic_pointer_cast<JavaInstall>(version);
if(!java) if(!java)

View File

@ -60,7 +60,7 @@ public:
protected slots: protected slots:
void memoryValueChanged(int); void memoryValueChanged(int);
void javaPathEdited(const QString &path); void javaPathEdited(const QString &path);
void javaVersionSelected(BaseVersionPtr version); void javaVersionSelected(BaseVersion::Ptr version);
void on_javaBrowseBtn_clicked(); void on_javaBrowseBtn_clicked();
void on_javaStatusBtn_clicked(); void on_javaStatusBtn_clicked();
void checkFinished(JavaCheckResult result); void checkFinished(JavaCheckResult result);

View File

@ -49,7 +49,7 @@ public:
auto getFilter() -> std::shared_ptr<Filter>; auto getFilter() -> std::shared_ptr<Filter>;
auto changed() const -> bool { return m_last_version_id != m_version_id; } auto changed() const -> bool { return m_last_version_id != m_version_id; }
Meta::VersionListPtr versionList() { return m_version_list; } Meta::VersionList::Ptr versionList() { return m_version_list; }
private: private:
ModFilterWidget(Version def, QWidget* parent = nullptr); ModFilterWidget(Version def, QWidget* parent = nullptr);
@ -73,7 +73,7 @@ private:
/* Version stuff */ /* Version stuff */
QButtonGroup m_mcVersion_buttons; QButtonGroup m_mcVersion_buttons;
Meta::VersionListPtr m_version_list; Meta::VersionList::Ptr m_version_list;
/* Used to tell if the filter was changed since the last getFilter() call */ /* Used to tell if the filter was changed since the last getFilter() call */
VersionButtonID m_last_version_id = VersionButtonID::Strict; VersionButtonID m_last_version_id = VersionButtonID::Strict;

View File

@ -142,7 +142,7 @@ void VersionSelectWidget::changeProgress(qint64 current, qint64 total)
void VersionSelectWidget::currentRowChanged(const QModelIndex& current, const QModelIndex&) void VersionSelectWidget::currentRowChanged(const QModelIndex& current, const QModelIndex&)
{ {
auto variant = m_proxyModel->data(current, BaseVersionList::VersionPointerRole); auto variant = m_proxyModel->data(current, BaseVersionList::VersionPointerRole);
emit selectedVersionChanged(variant.value<BaseVersionPtr>()); emit selectedVersionChanged(variant.value<BaseVersion::Ptr>());
} }
void VersionSelectWidget::preselect() void VersionSelectWidget::preselect()
@ -186,11 +186,11 @@ bool VersionSelectWidget::hasVersions() const
return m_proxyModel->rowCount(QModelIndex()) != 0; return m_proxyModel->rowCount(QModelIndex()) != 0;
} }
BaseVersionPtr VersionSelectWidget::selectedVersion() const BaseVersion::Ptr VersionSelectWidget::selectedVersion() const
{ {
auto currentIndex = listView->selectionModel()->currentIndex(); auto currentIndex = listView->selectionModel()->currentIndex();
auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole); auto variant = m_proxyModel->data(currentIndex, BaseVersionList::VersionPointerRole);
return variant.value<BaseVersionPtr>(); return variant.value<BaseVersion::Ptr>();
} }
void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter) void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter)

View File

@ -40,7 +40,7 @@ public:
void loadList(); void loadList();
bool hasVersions() const; bool hasVersions() const;
BaseVersionPtr selectedVersion() const; BaseVersion::Ptr selectedVersion() const;
void selectRecommended(); void selectRecommended();
void selectCurrent(); void selectCurrent();
@ -54,7 +54,7 @@ public:
void setResizeOn(int column); void setResizeOn(int column);
signals: signals:
void selectedVersionChanged(BaseVersionPtr version); void selectedVersionChanged(BaseVersion::Ptr version);
protected: protected:
virtual void closeEvent ( QCloseEvent* ); virtual void closeEvent ( QCloseEvent* );