diff options
-rw-r--r-- | api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp | 82 | ||||
-rw-r--r-- | api/logic/minecraft/liteloader/LiteLoaderVersionList.h | 25 |
2 files changed, 49 insertions, 58 deletions
diff --git a/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp b/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp index 760f357a..f5c10777 100644 --- a/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp +++ b/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp @@ -106,17 +106,23 @@ QVariant LiteLoaderVersionList::data(const QModelIndex &index, int role) const case ParentGameVersionRole: return version->mcVersion; - case RecommendedRole: + case LatestRole: return version->isLatest; + case RecommendedRole: + return version->isRecommended; + + case TypeRole: + return version->isSnapshot ? tr("Snapshot") : tr("Release"); + default: return QVariant(); } } -QList<BaseVersionList::ModelRoles> LiteLoaderVersionList::providesRoles() +BaseVersionList::RoleList LiteLoaderVersionList::providesRoles() const { - return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole}; + return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole, LatestRole, TypeRole}; } BaseVersionPtr LiteLoaderVersionList::getLatestStable() const @@ -124,7 +130,7 @@ BaseVersionPtr LiteLoaderVersionList::getLatestStable() const for (int i = 0; i < m_vlist.length(); i++) { auto ver = std::dynamic_pointer_cast<LiteLoaderVersion>(m_vlist.at(i)); - if (ver->isLatest) + if (ver->isRecommended) { return m_vlist.at(i); } @@ -228,9 +234,9 @@ void LLListLoadTask::listDownloaded() const QString mcVersion = vIt.key(); const QJsonObject versionObject = vIt.value().toObject(); - auto processArtefacts = [&](QJsonObject artefacts, bool notSnapshots) + auto processArtefacts = [&](QJsonObject artefacts, bool notSnapshots, std::shared_ptr<LiteLoaderVersion> &latest) { - QString latest; + QString latestVersion; QList<BaseVersionPtr> perMcVersionList; for (auto aIt = artefacts.begin(); aIt != artefacts.end(); ++aIt) { @@ -238,18 +244,19 @@ void LLListLoadTask::listDownloaded() const QJsonObject artefact = aIt.value().toObject(); if (identifier == "latest") { - latest = artefact.value("version").toString(); + latestVersion = artefact.value("version").toString(); continue; } LiteLoaderVersionPtr version(new LiteLoaderVersion()); version->version = artefact.value("version").toString(); version->mcVersion = mcVersion; version->md5 = artefact.value("md5").toString(); - version->timestamp = artefact.value("timestamp").toString().toInt(); + version->timestamp = artefact.value("timestamp").toString().toLong(); version->tweakClass = artefact.value("tweakClass").toString(); version->authors = authors; version->description = description; version->defaultUrl = defaultUrl; + version->isSnapshot = !notSnapshots; const QJsonArray libs = artefact.value("libraries").toArray(); for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) { @@ -284,58 +291,39 @@ void LLListLoadTask::listDownloaded() for (auto version : perMcVersionList) { auto v = std::dynamic_pointer_cast<LiteLoaderVersion>(version); - v->isLatest = v->version == latest; + if(v->version == latestVersion) + { + latest = v; + } } } tempList.append(perMcVersionList); }; + std::shared_ptr<LiteLoaderVersion> latestSnapshot; + std::shared_ptr<LiteLoaderVersion> latestRelease; // are there actually released versions for this mc version? if(versionObject.contains("artefacts")) { const QJsonObject artefacts = versionObject.value("artefacts").toObject().value("com.mumfrey:liteloader").toObject(); - processArtefacts(artefacts, true); + processArtefacts(artefacts, true, latestRelease); } if(versionObject.contains("snapshots")) { QJsonObject artefacts = versionObject.value("snapshots").toObject().value("com.mumfrey:liteloader").toObject(); - processArtefacts(artefacts, false); - /* - LiteLoaderVersionPtr version(new LiteLoaderVersion()); - version->version = mcVersion + "-SNAPSHOT"; - version->mcVersion = mcVersion; - version->md5 = QString(); // FIXME: not available, unable to check - version->timestamp = QDateTime::currentMSecsSinceEpoch() / 1000LL; - version->tweakClass = "com.mumfrey.liteloader.launch.LiteLoaderTweaker"; // FIXME: guessing here, no data available - version->authors = authors; - version->description = description; - version->defaultUrl = defaultUrl; - const QJsonArray libs = snapshots.value("libraries").toArray(); - for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) - { - auto libobject = (*lIt).toObject(); - try - { - auto lib = OneSixVersionFormat::libraryFromJson(libobject, "versions.json"); - // hack to make liteloader 1.7.10_00 work - if(lib->rawName() == GradleSpecifier("org.ow2.asm:asm-all:5.0.3")) - { - lib->setRepositoryURL("http://repo.maven.apache.org/maven2/"); - } - version->libraries.append(lib); - } - catch (Exception &e) - { - qCritical() << "Couldn't read JSON object:"; - continue; // FIXME: ignores bad libraries and continues loading - } - } - auto liteloaderLib = std::make_shared<Library>("com.mumfrey:liteloader:" + version->version); - liteloaderLib->setHint("always-stale"); - liteloaderLib->setRepositoryURL("http://dl.liteloader.com/versions/"); - version->libraries.append(liteloaderLib); - tempList.append(version); - */ + processArtefacts(artefacts, false, latestSnapshot); + } + if(latestSnapshot) + { + latestSnapshot->isLatest = true; + } + else if(latestRelease) + { + latestRelease->isLatest = true; + } + if(latestRelease) + { + latestRelease->isRecommended = true; } } m_list->updateListData(tempList); diff --git a/api/logic/minecraft/liteloader/LiteLoaderVersionList.h b/api/logic/minecraft/liteloader/LiteLoaderVersionList.h index fcbc4236..c0ba559c 100644 --- a/api/logic/minecraft/liteloader/LiteLoaderVersionList.h +++ b/api/logic/minecraft/liteloader/LiteLoaderVersionList.h @@ -56,8 +56,11 @@ public: QString version; QString mcVersion; QString md5; - int timestamp; - bool isLatest; + long timestamp = 0; + bool isLatest = false; + bool isRecommended = false; + bool isSnapshot = false; + QString tweakClass; QList<LibraryPtr> libraries; @@ -76,15 +79,15 @@ public: explicit LiteLoaderVersionList(QObject *parent = 0); - virtual Task *getLoadTask(); - virtual bool isLoaded(); - virtual const BaseVersionPtr at(int i) const; - virtual int count() const; - virtual void sortVersions(); - virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const; - virtual QList< ModelRoles > providesRoles(); + Task *getLoadTask() override; + bool isLoaded() override; + const BaseVersionPtr at(int i) const override; + int count() const override; + void sortVersions() override; + QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const override; + RoleList providesRoles() const override; - virtual BaseVersionPtr getLatestStable() const; + virtual BaseVersionPtr getLatestStable() const override; protected: QList<BaseVersionPtr> m_vlist; @@ -93,7 +96,7 @@ protected: protected slots: - virtual void updateListData(QList<BaseVersionPtr> versions); + void updateListData(QList<BaseVersionPtr> versions) override; }; class LLListLoadTask : public Task |