GH-1856 Fix metadata version and list loading
Shouldn't crash anymore, shouldn't overwrite data in some bad way anymore either.
This commit is contained in:
parent
d25a7ad3a6
commit
4fa3e2a714
@ -141,6 +141,17 @@ void Meta::BaseEntity::load()
|
|||||||
m_updateTask->start();
|
m_updateTask->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Meta::BaseEntity::isLoaded() const
|
||||||
|
{
|
||||||
|
return m_loadStatus > LoadStatus::NotLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Meta::BaseEntity::shouldStartRemoteUpdate() const
|
||||||
|
{
|
||||||
|
// TODO: version-locks and offline mode?
|
||||||
|
return m_updateStatus != UpdateStatus::InProgress;
|
||||||
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<Task> Meta::BaseEntity::getCurrentTask()
|
shared_qobject_ptr<Task> Meta::BaseEntity::getCurrentTask()
|
||||||
{
|
{
|
||||||
if(m_updateStatus == UpdateStatus::InProgress)
|
if(m_updateStatus == UpdateStatus::InProgress)
|
||||||
|
@ -51,15 +51,8 @@ public:
|
|||||||
virtual QString localFilename() const = 0;
|
virtual QString localFilename() const = 0;
|
||||||
virtual QUrl url() const;
|
virtual QUrl url() const;
|
||||||
|
|
||||||
bool isLoaded() const
|
bool isLoaded() const;
|
||||||
{
|
bool shouldStartRemoteUpdate() const;
|
||||||
return m_loadStatus > LoadStatus::NotLoaded;
|
|
||||||
}
|
|
||||||
bool shouldStartRemoteUpdate() const
|
|
||||||
{
|
|
||||||
// TODO: version-locks and offline mode?
|
|
||||||
return m_updateStatus != UpdateStatus::InProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
shared_qobject_ptr<Task> getCurrentTask();
|
shared_qobject_ptr<Task> getCurrentTask();
|
||||||
|
@ -25,6 +25,10 @@ Meta::Version::Version(const QString &uid, const QString &version)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Meta::Version::~Version()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QString Meta::Version::descriptor()
|
QString Meta::Version::descriptor()
|
||||||
{
|
{
|
||||||
return m_version;
|
return m_version;
|
||||||
@ -76,8 +80,10 @@ void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
|
|||||||
{
|
{
|
||||||
setParentUid(version->m_parentUid);
|
setParentUid(version->m_parentUid);
|
||||||
}
|
}
|
||||||
|
if(version->m_data)
|
||||||
setData(version->m_data);
|
{
|
||||||
|
setData(version->m_data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Meta::Version::localFilename() const
|
QString Meta::Version::localFilename() const
|
||||||
|
@ -38,6 +38,7 @@ class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public
|
|||||||
|
|
||||||
public: /* con/des */
|
public: /* con/des */
|
||||||
explicit Version(const QString &uid, const QString &version);
|
explicit Version(const QString &uid, const QString &version);
|
||||||
|
virtual ~Version();
|
||||||
|
|
||||||
QString descriptor() override;
|
QString descriptor() override;
|
||||||
QString name() override;
|
QString name() override;
|
||||||
@ -104,7 +105,7 @@ private:
|
|||||||
QString m_parentUid;
|
QString m_parentUid;
|
||||||
QString m_version;
|
QString m_version;
|
||||||
QString m_type;
|
QString m_type;
|
||||||
qint64 m_time;
|
qint64 m_time = 0;
|
||||||
QHash<QString, QString> m_requires;
|
QHash<QString, QString> m_requires;
|
||||||
VersionFilePtr m_data;
|
VersionFilePtr m_data;
|
||||||
};
|
};
|
||||||
|
@ -182,38 +182,35 @@ void VersionList::merge(const BaseEntity::Ptr &other)
|
|||||||
setParentUid(list->m_parentUid);
|
setParentUid(list->m_parentUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_versions.isEmpty())
|
// TODO: do not reset the whole model. maybe?
|
||||||
|
beginResetModel();
|
||||||
|
m_versions.clear();
|
||||||
|
for (const VersionPtr &version : list->m_versions)
|
||||||
{
|
{
|
||||||
setVersions(list->m_versions);
|
// we already have the version. merge the contents
|
||||||
}
|
if (m_lookup.contains(version->version()))
|
||||||
else
|
|
||||||
{
|
|
||||||
for (const VersionPtr &version : list->m_versions)
|
|
||||||
{
|
{
|
||||||
if (m_lookup.contains(version->version()))
|
m_lookup.value(version->version())->merge(version);
|
||||||
{
|
}
|
||||||
m_lookup.value(version->version())->merge(version);
|
else
|
||||||
}
|
{
|
||||||
else
|
m_lookup.insert(version->uid(), version);
|
||||||
{
|
}
|
||||||
beginInsertRows(QModelIndex(), m_versions.size(), m_versions.size());
|
// connect it.
|
||||||
setupAddedVersion(m_versions.size(), version);
|
setupAddedVersion(m_versions.size(), version);
|
||||||
m_versions.append(version);
|
m_versions.append(version);
|
||||||
m_lookup.insert(version->uid(), version);
|
if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime()))
|
||||||
endInsertRows();
|
{
|
||||||
|
m_recommended = version;
|
||||||
if (!m_recommended || (version->type() == "release" && version->rawTime() > m_recommended->rawTime()))
|
|
||||||
{
|
|
||||||
m_recommended = version;
|
|
||||||
emit dataChanged(index(0), index(m_versions.size() - 1), QVector<int>() << RecommendedRole);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
|
void VersionList::setupAddedVersion(const int row, const VersionPtr &version)
|
||||||
{
|
{
|
||||||
|
// FIXME: do not disconnect from everythin, disconnect only the lambdas here
|
||||||
|
version->disconnect();
|
||||||
connect(version.get(), &Version::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
|
connect(version.get(), &Version::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << RequiresRole); });
|
||||||
connect(version.get(), &Version::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TimeRole << SortRole); });
|
connect(version.get(), &Version::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector<int>() << TimeRole << SortRole); });
|
||||||
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); });
|
||||||
|
@ -385,6 +385,7 @@ bool MinecraftProfile::reapplyPatches()
|
|||||||
clear();
|
clear();
|
||||||
for(auto file: m_patches)
|
for(auto file: m_patches)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Applying" << file->getID() << (file->getProblemSeverity() == ProblemSeverity::Error ? "ERROR" : "GOOD");
|
||||||
file->applyTo(this);
|
file->applyTo(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -663,11 +664,6 @@ void MinecraftProfile::installJarMods(QStringList selectedFiles)
|
|||||||
m_strategy->installJarMods(selectedFiles);
|
m_strategy->installJarMods(selectedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MinecraftProfile::installVersion(BaseVersionPtr version)
|
|
||||||
{
|
|
||||||
// TODO: implement
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: get rid of this. Get rid of all order numbers.
|
* TODO: get rid of this. Get rid of all order numbers.
|
||||||
*/
|
*/
|
||||||
|
@ -58,9 +58,6 @@ public:
|
|||||||
/// install more jar mods
|
/// install more jar mods
|
||||||
void installJarMods(QStringList selectedFiles);
|
void installJarMods(QStringList selectedFiles);
|
||||||
|
|
||||||
/// install more jar mods
|
|
||||||
void installVersion(BaseVersionPtr version);
|
|
||||||
|
|
||||||
/// DEPRECATED, remove ASAP
|
/// DEPRECATED, remove ASAP
|
||||||
int getFreeOrderNumber();
|
int getFreeOrderNumber();
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@ ProfilePatch::ProfilePatch(std::shared_ptr<VersionFile> file, const QString& fil
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Meta::Version> ProfilePatch::getMeta()
|
||||||
|
{
|
||||||
|
return m_metaVersion;
|
||||||
|
}
|
||||||
|
|
||||||
void ProfilePatch::applyTo(MinecraftProfile* profile)
|
void ProfilePatch::applyTo(MinecraftProfile* profile)
|
||||||
{
|
{
|
||||||
auto vfile = getVersionFile();
|
auto vfile = getVersionFile();
|
||||||
|
@ -36,6 +36,7 @@ public:
|
|||||||
virtual QString getID();
|
virtual QString getID();
|
||||||
virtual QString getName();
|
virtual QString getName();
|
||||||
virtual QString getVersion();
|
virtual QString getVersion();
|
||||||
|
virtual std::shared_ptr<Meta::Version> getMeta();
|
||||||
virtual QDateTime getReleaseDateTime();
|
virtual QDateTime getReleaseDateTime();
|
||||||
|
|
||||||
virtual QString getFilename();
|
virtual QString getFilename();
|
||||||
|
@ -44,25 +44,36 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
|
|||||||
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
|
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a version update task, if necessary
|
// add metadata update tasks, if necessary
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* FIXME: there are some corner cases here that remain unhandled:
|
* FIXME: there are some corner cases here that remain unhandled:
|
||||||
* what if local load succeeds but remote fails? The version is still usable...
|
* what if local load succeeds but remote fails? The version is still usable...
|
||||||
|
* We should not rely on the remote to be there... and prefer local files if it does not respond.
|
||||||
*/
|
*/
|
||||||
// FIXME: derive this from the actual list of version patches...
|
qDebug() << "Updating patches...";
|
||||||
auto loadVersion = [&](const QString & uid, const QString & version)
|
auto profile = m_inst->getMinecraftProfile();
|
||||||
|
m_inst->reloadProfile();
|
||||||
|
for(int i = 0; i < profile->rowCount(); i++)
|
||||||
{
|
{
|
||||||
auto obj = ENV.metadataIndex()->get(uid, version);
|
auto patch = profile->versionPatch(i);
|
||||||
obj->load();
|
auto id = patch->getID();
|
||||||
auto task = obj->getCurrentTask();
|
auto metadata = patch->getMeta();
|
||||||
if(task)
|
if(metadata)
|
||||||
{
|
{
|
||||||
m_tasks.append(task.unwrap());
|
metadata->load();
|
||||||
|
auto task = metadata->getCurrentTask();
|
||||||
|
if(task)
|
||||||
|
{
|
||||||
|
qDebug() << "Loading remote meta patch" << id;
|
||||||
|
m_tasks.append(task.unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
else
|
||||||
loadVersion("org.lwjgl", m_inst->getComponentVersion("org.lwjgl"));
|
{
|
||||||
loadVersion("net.minecraft", m_inst->getComponentVersion("net.minecraft"));
|
qDebug() << "Ignoring local patch" << id;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// libraries download
|
// libraries download
|
||||||
|
Loading…
Reference in New Issue
Block a user