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:
Petr Mrázek 2017-04-24 01:30:51 +02:00
parent d25a7ad3a6
commit 4fa3e2a714
10 changed files with 73 additions and 55 deletions

View File

@ -141,6 +141,17 @@ void Meta::BaseEntity::load()
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()
{
if(m_updateStatus == UpdateStatus::InProgress)

View File

@ -51,15 +51,8 @@ public:
virtual QString localFilename() const = 0;
virtual QUrl url() const;
bool isLoaded() const
{
return m_loadStatus > LoadStatus::NotLoaded;
}
bool shouldStartRemoteUpdate() const
{
// TODO: version-locks and offline mode?
return m_updateStatus != UpdateStatus::InProgress;
}
bool isLoaded() const;
bool shouldStartRemoteUpdate() const;
void load();
shared_qobject_ptr<Task> getCurrentTask();

View File

@ -25,6 +25,10 @@ Meta::Version::Version(const QString &uid, const QString &version)
{
}
Meta::Version::~Version()
{
}
QString Meta::Version::descriptor()
{
return m_version;
@ -76,8 +80,10 @@ void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
{
setParentUid(version->m_parentUid);
}
if(version->m_data)
{
setData(version->m_data);
}
}
QString Meta::Version::localFilename() const

View File

@ -38,6 +38,7 @@ class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public
public: /* con/des */
explicit Version(const QString &uid, const QString &version);
virtual ~Version();
QString descriptor() override;
QString name() override;
@ -104,7 +105,7 @@ private:
QString m_parentUid;
QString m_version;
QString m_type;
qint64 m_time;
qint64 m_time = 0;
QHash<QString, QString> m_requires;
VersionFilePtr m_data;
};

View File

@ -182,38 +182,35 @@ void VersionList::merge(const BaseEntity::Ptr &other)
setParentUid(list->m_parentUid);
}
if (m_versions.isEmpty())
{
setVersions(list->m_versions);
}
else
{
// TODO: do not reset the whole model. maybe?
beginResetModel();
m_versions.clear();
for (const VersionPtr &version : list->m_versions)
{
// we already have the version. merge the contents
if (m_lookup.contains(version->version()))
{
m_lookup.value(version->version())->merge(version);
}
else
{
beginInsertRows(QModelIndex(), m_versions.size(), m_versions.size());
m_lookup.insert(version->uid(), version);
}
// connect it.
setupAddedVersion(m_versions.size(), version);
m_versions.append(version);
m_lookup.insert(version->uid(), version);
endInsertRows();
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)
{
// 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::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); });

View File

@ -385,6 +385,7 @@ bool MinecraftProfile::reapplyPatches()
clear();
for(auto file: m_patches)
{
qDebug() << "Applying" << file->getID() << (file->getProblemSeverity() == ProblemSeverity::Error ? "ERROR" : "GOOD");
file->applyTo(this);
}
}
@ -663,11 +664,6 @@ void MinecraftProfile::installJarMods(QStringList selectedFiles)
m_strategy->installJarMods(selectedFiles);
}
void MinecraftProfile::installVersion(BaseVersionPtr version)
{
// TODO: implement
}
/*
* TODO: get rid of this. Get rid of all order numbers.
*/

View File

@ -58,9 +58,6 @@ public:
/// install more jar mods
void installJarMods(QStringList selectedFiles);
/// install more jar mods
void installVersion(BaseVersionPtr version);
/// DEPRECATED, remove ASAP
int getFreeOrderNumber();

View File

@ -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)
{
auto vfile = getVersionFile();

View File

@ -36,6 +36,7 @@ public:
virtual QString getID();
virtual QString getName();
virtual QString getVersion();
virtual std::shared_ptr<Meta::Version> getMeta();
virtual QDateTime getReleaseDateTime();
virtual QString getFilename();

View File

@ -44,25 +44,36 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
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:
* 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...
auto loadVersion = [&](const QString & uid, const QString & version)
qDebug() << "Updating patches...";
auto profile = m_inst->getMinecraftProfile();
m_inst->reloadProfile();
for(int i = 0; i < profile->rowCount(); i++)
{
auto obj = ENV.metadataIndex()->get(uid, version);
obj->load();
auto task = obj->getCurrentTask();
auto patch = profile->versionPatch(i);
auto id = patch->getID();
auto metadata = patch->getMeta();
if(metadata)
{
metadata->load();
auto task = metadata->getCurrentTask();
if(task)
{
qDebug() << "Loading remote meta patch" << id;
m_tasks.append(task.unwrap());
}
};
loadVersion("org.lwjgl", m_inst->getComponentVersion("org.lwjgl"));
loadVersion("net.minecraft", m_inst->getComponentVersion("net.minecraft"));
}
else
{
qDebug() << "Ignoring local patch" << id;
}
}
}
// libraries download