diff options
Diffstat (limited to 'api/logic')
-rw-r--r-- | api/logic/minecraft/Library.cpp | 5 | ||||
-rw-r--r-- | api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp | 152 | ||||
-rw-r--r-- | api/logic/minecraft/liteloader/LiteLoaderVersionList.h | 43 | ||||
-rw-r--r-- | api/logic/net/FileSink.cpp | 1 |
4 files changed, 126 insertions, 75 deletions
diff --git a/api/logic/minecraft/Library.cpp b/api/logic/minecraft/Library.cpp index 584c7ac5..c516edb7 100644 --- a/api/logic/minecraft/Library.cpp +++ b/api/logic/minecraft/Library.cpp @@ -72,12 +72,17 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na QList<NetActionPtr> Library::getDownloads(OpSys system, HttpMetaCache * cache, QStringList &failedFiles) const { QList<NetActionPtr> out; + bool isAlwaysStale = (hint() == "always-stale"); bool isLocal = (hint() == "local"); bool isForge = (hint() == "forge-pack-xz"); auto add_download = [&](QString storage, QString url, QString sha1 = QString()) { auto entry = cache->resolveEntry("libraries", storage); + if(isAlwaysStale) + { + entry->setStale(true); + } if (!entry->isStale()) return true; if(isLocal) diff --git a/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp b/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp index f8bf095f..f5c10777 100644 --- a/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp +++ b/api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp @@ -62,6 +62,20 @@ static bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) return left->timestamp > right->timestamp; } +VersionFilePtr LiteLoaderVersion::getVersionFile() +{ + auto f = std::make_shared<VersionFile>(); + f->mainClass = "net.minecraft.launchwrapper.Launch"; + f->addTweakers += tweakClass; + f->order = 10; + f->libraries = libraries; + f->name = "LiteLoader"; + f->fileId = "com.mumfrey.liteloader"; + f->version = version; + f->minecraftVersion = mcVersion; + return f; +} + void LiteLoaderVersionList::sortVersions() { beginResetModel(); @@ -92,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 @@ -110,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); } @@ -212,61 +232,99 @@ void LLListLoadTask::listDownloaded() for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt) { const QString mcVersion = vIt.key(); - QString latest; - const QJsonObject artefacts = vIt.value() - .toObject() - .value("artefacts") - .toObject() - .value("com.mumfrey:liteloader") - .toObject(); - QList<BaseVersionPtr> perMcVersionList; - for (auto aIt = artefacts.begin(); aIt != artefacts.end(); ++aIt) + const QJsonObject versionObject = vIt.value().toObject(); + + auto processArtefacts = [&](QJsonObject artefacts, bool notSnapshots, std::shared_ptr<LiteLoaderVersion> &latest) { - const QString identifier = aIt.key(); - const QJsonObject artefact = aIt.value().toObject(); - if (identifier == "latest") + QString latestVersion; + QList<BaseVersionPtr> perMcVersionList; + for (auto aIt = artefacts.begin(); aIt != artefacts.end(); ++aIt) { - latest = artefact.value("version").toString(); - continue; - } - LiteLoaderVersionPtr version(new LiteLoaderVersion()); - version->version = artefact.value("version").toString(); - version->file = artefact.value("file").toString(); - version->mcVersion = mcVersion; - version->md5 = artefact.value("md5").toString(); - version->timestamp = artefact.value("timestamp").toString().toInt(); - version->tweakClass = artefact.value("tweakClass").toString(); - version->authors = authors; - version->description = description; - version->defaultUrl = defaultUrl; - const QJsonArray libs = artefact.value("libraries").toArray(); - for (auto lIt = libs.begin(); lIt != libs.end(); ++lIt) - { - auto libobject = (*lIt).toObject(); - try + const QString identifier = aIt.key(); + const QJsonObject artefact = aIt.value().toObject(); + if (identifier == "latest") { - 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")) + 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().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) + { + 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) { - lib->setRepositoryURL("http://repo.maven.apache.org/maven2/"); + qCritical() << "Couldn't read JSON object:"; + continue; // FIXME: ignores bad libraries and continues loading } - version->libraries.append(lib); } - catch (Exception &e) + auto liteloaderLib = std::make_shared<Library>("com.mumfrey:liteloader:" + version->version); + liteloaderLib->setRepositoryURL("http://dl.liteloader.com/versions/"); + if(!notSnapshots) { - qCritical() << "Couldn't read JSON object:"; - continue; + liteloaderLib->setHint("always-stale"); + } + version->libraries.append(liteloaderLib); + perMcVersionList.append(version); + } + if(notSnapshots) + { + for (auto version : perMcVersionList) + { + auto v = std::dynamic_pointer_cast<LiteLoaderVersion>(version); + if(v->version == latestVersion) + { + latest = v; + } } } - perMcVersionList.append(version); + 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, latestRelease); + } + if(versionObject.contains("snapshots")) + { + QJsonObject artefacts = versionObject.value("snapshots").toObject().value("com.mumfrey:liteloader").toObject(); + processArtefacts(artefacts, false, latestSnapshot); + } + if(latestSnapshot) + { + latestSnapshot->isLatest = true; + } + else if(latestRelease) + { + latestRelease->isLatest = true; } - for (auto version : perMcVersionList) + if(latestRelease) { - auto v = std::dynamic_pointer_cast<LiteLoaderVersion>(version); - v->isLatest = v->version == latest; + latestRelease->isRecommended = true; } - tempList.append(perMcVersionList); } m_list->updateListData(tempList); diff --git a/api/logic/minecraft/liteloader/LiteLoaderVersionList.h b/api/logic/minecraft/liteloader/LiteLoaderVersionList.h index b85b9f0c..c0ba559c 100644 --- a/api/logic/minecraft/liteloader/LiteLoaderVersionList.h +++ b/api/logic/minecraft/liteloader/LiteLoaderVersionList.h @@ -50,30 +50,17 @@ public: { return version; } - VersionFilePtr getVersionFile() - { - auto f = std::make_shared<VersionFile>(); - f->mainClass = "net.minecraft.launchwrapper.Launch"; - f->addTweakers += tweakClass; - f->order = 10; - f->libraries = libraries; - auto liteloaderLib = std::make_shared<Library>("com.mumfrey:liteloader:" + version); - liteloaderLib->setAbsoluteUrl(QString("http://dl.liteloader.com/versions/com/mumfrey/liteloader/%1/%2").arg(mcVersion, file)); - f->libraries.append(liteloaderLib); - f->name = "LiteLoader"; - f->fileId = "com.mumfrey.liteloader"; - f->version = version; - f->minecraftVersion = mcVersion; - return f; - } + VersionFilePtr getVersionFile(); // important info QString version; - QString file; 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; @@ -92,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; @@ -109,7 +96,7 @@ protected: protected slots: - virtual void updateListData(QList<BaseVersionPtr> versions); + void updateListData(QList<BaseVersionPtr> versions) override; }; class LLListLoadTask : public Task diff --git a/api/logic/net/FileSink.cpp b/api/logic/net/FileSink.cpp index b4c418a5..e912b1c9 100644 --- a/api/logic/net/FileSink.cpp +++ b/api/logic/net/FileSink.cpp @@ -30,6 +30,7 @@ JobStatus FileSink::init(QNetworkRequest& request) qCritical() << "Could not create folder for " + m_filename; return Job_Failed; } + wroteAnyData = false; m_output_file.reset(new QSaveFile(m_filename)); if (!m_output_file->open(QIODevice::WriteOnly)) { |