From 8cbe13c6560c3abe8ef73b8a376bd84dea281cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 6 Mar 2017 00:39:25 +0100 Subject: [PATCH 01/28] NOISSUE remove legacy version blacklist --- api/logic/minecraft/MinecraftVersionList.cpp | 12 ------------ api/logic/minecraft/VersionFilterData.cpp | 2 -- api/logic/minecraft/VersionFilterData.h | 2 -- 3 files changed, 16 deletions(-) diff --git a/api/logic/minecraft/MinecraftVersionList.cpp b/api/logic/minecraft/MinecraftVersionList.cpp index 2c9a8035..29fa840e 100644 --- a/api/logic/minecraft/MinecraftVersionList.cpp +++ b/api/logic/minecraft/MinecraftVersionList.cpp @@ -179,12 +179,6 @@ void MinecraftVersionList::loadBuiltinList() continue; } - if (g_VersionFilterData.legacyBlacklist.contains(versionID)) - { - qWarning() << "Blacklisted legacy version ignored: " << versionID; - continue; - } - // Now, we construct the version object and add it to the list. std::shared_ptr mcVersion(new MinecraftVersion()); mcVersion->m_name = mcVersion->m_descriptor = versionID; @@ -258,12 +252,6 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s continue; } - if (g_VersionFilterData.legacyBlacklist.contains(versionID)) - { - qWarning() << "Blacklisted legacy version ignored: " << versionID; - continue; - } - // Now, we construct the version object and add it to the list. std::shared_ptr mcVersion(new MinecraftVersion()); mcVersion->m_name = mcVersion->m_descriptor = versionID; diff --git a/api/logic/minecraft/VersionFilterData.cpp b/api/logic/minecraft/VersionFilterData.cpp index 0c4a6e3d..60c64473 100644 --- a/api/logic/minecraft/VersionFilterData.cpp +++ b/api/logic/minecraft/VersionFilterData.cpp @@ -58,8 +58,6 @@ VersionFilterData::VersionFilterData() // don't use installers for those. forgeInstallerBlacklist = QSet({"1.5.2"}); - // these won't show up in version lists because they are extremely bad and dangerous - legacyBlacklist = QSet({"rd-160052"}); /* * nothing older than this will be accepted from Mojang servers * (these versions need to be tested by us first) diff --git a/api/logic/minecraft/VersionFilterData.h b/api/logic/minecraft/VersionFilterData.h index f7d4ebe7..f4213e1a 100644 --- a/api/logic/minecraft/VersionFilterData.h +++ b/api/logic/minecraft/VersionFilterData.h @@ -20,8 +20,6 @@ struct VersionFilterData QMap> fmlLibsMapping; // set of minecraft versions for which using forge installers is blacklisted QSet forgeInstallerBlacklist; - // set of 'legacy' versions that will not show up in the version lists. - QSet legacyBlacklist; // no new versions below this date will be accepted from Mojang servers QDateTime legacyCutoffDate; // Libraries that belong to LWJGL From 7382360771f78e351740393262358bed3297d44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 6 Mar 2017 01:00:44 +0100 Subject: [PATCH 02/28] NOISSUE remove builtin Minecraft versions --- api/logic/minecraft/MinecraftVersionList.cpp | 51 -- api/logic/minecraft/MinecraftVersionList.h | 1 - api/logic/minecraft/VersionFilterData.cpp | 9 +- api/logic/minecraft/VersionFilterData.h | 2 - application/resources/versions/minecraft.json | 587 ------------------ application/resources/versions/versions.qrc | 2 - 6 files changed, 2 insertions(+), 650 deletions(-) delete mode 100644 application/resources/versions/minecraft.json diff --git a/api/logic/minecraft/MinecraftVersionList.cpp b/api/logic/minecraft/MinecraftVersionList.cpp index 29fa840e..0dc46289 100644 --- a/api/logic/minecraft/MinecraftVersionList.cpp +++ b/api/logic/minecraft/MinecraftVersionList.cpp @@ -26,7 +26,6 @@ #include "ParseUtils.h" #include "ProfileUtils.h" -#include "VersionFilterData.h" #include "onesix/OneSixVersionFormat.h" #include "MojangVersionFormat.h" #include @@ -89,7 +88,6 @@ public: MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent) { - loadBuiltinList(); loadCachedList(); } @@ -159,50 +157,6 @@ void MinecraftVersionList::loadCachedList() m_hasLocalIndex = true; } -void MinecraftVersionList::loadBuiltinList() -{ - qDebug() << "Loading builtin version list."; - // grab the version list data from internal resources. - const QJsonDocument doc = - Json::requireDocument(QString(":/versions/minecraft.json"), "builtin version list"); - const QJsonObject root = doc.object(); - - // parse all the versions - for (const auto version : Json::requireArray(root.value("versions"))) - { - QJsonObject versionObj = version.toObject(); - QString versionID = versionObj.value("id").toString(""); - QString versionTypeStr = versionObj.value("type").toString(""); - if (versionID.isEmpty() || versionTypeStr.isEmpty()) - { - qCritical() << "Parsed version is missing ID or type"; - continue; - } - - // Now, we construct the version object and add it to the list. - std::shared_ptr mcVersion(new MinecraftVersion()); - mcVersion->m_name = mcVersion->m_descriptor = versionID; - - // Parse the timestamp. - mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString("")); - mcVersion->m_versionFileURL = QString(); - mcVersion->m_versionSource = VersionSource::Builtin; - mcVersion->m_type = versionTypeStr; - mcVersion->m_appletClass = versionObj.value("appletClass").toString(""); - mcVersion->m_mainClass = versionObj.value("mainClass").toString(""); - mcVersion->m_jarChecksum = versionObj.value("checksum").toString(""); - if (versionObj.contains("+traits")) - { - for (auto traitVal : Json::requireArray(versionObj.value("+traits"))) - { - mcVersion->m_traits.insert(Json::requireString(traitVal)); - } - } - m_lookup[versionID] = mcVersion; - m_vlist.append(mcVersion); - } -} - void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource source) { qDebug() << "Loading" << ((source == VersionSource::Remote) ? "remote" : "local") << "version list."; @@ -259,11 +213,6 @@ void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource s mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString("")); mcVersion->m_updateTime = timeFromS3Time(versionObj.value("time").toString("")); - if (mcVersion->m_releaseTime < g_VersionFilterData.legacyCutoffDate) - { - continue; - } - // depends on where we load the version from -- network request or local file? mcVersion->m_versionSource = source; mcVersion->m_versionFileURL = versionObj.value("url").toString(""); diff --git a/api/logic/minecraft/MinecraftVersionList.h b/api/logic/minecraft/MinecraftVersionList.h index 42333678..fc421966 100644 --- a/api/logic/minecraft/MinecraftVersionList.h +++ b/api/logic/minecraft/MinecraftVersionList.h @@ -34,7 +34,6 @@ class MULTIMC_LOGIC_EXPORT MinecraftVersionList : public BaseVersionList Q_OBJECT private: void sortInternal(); - void loadBuiltinList(); void loadMojangList(QJsonDocument jsonDoc, VersionSource source); void loadCachedList(); void saveCachedList(); diff --git a/api/logic/minecraft/VersionFilterData.cpp b/api/logic/minecraft/VersionFilterData.cpp index 60c64473..5f4ceee6 100644 --- a/api/logic/minecraft/VersionFilterData.cpp +++ b/api/logic/minecraft/VersionFilterData.cpp @@ -58,16 +58,11 @@ VersionFilterData::VersionFilterData() // don't use installers for those. forgeInstallerBlacklist = QSet({"1.5.2"}); - /* - * nothing older than this will be accepted from Mojang servers - * (these versions need to be tested by us first) - */ + + // FIXME: remove, used for deciding when core mods should display legacyCutoffDate = timeFromS3Time("2013-06-25T15:08:56+02:00"); lwjglWhitelist = QSet{"net.java.jinput:jinput", "net.java.jinput:jinput-platform", "net.java.jutils:jutils", "org.lwjgl.lwjgl:lwjgl", "org.lwjgl.lwjgl:lwjgl_util", "org.lwjgl.lwjgl:lwjgl-platform"}; - - // Version list magic - recommendedMinecraftVersion = "1.7.10"; } diff --git a/api/logic/minecraft/VersionFilterData.h b/api/logic/minecraft/VersionFilterData.h index f4213e1a..2408e704 100644 --- a/api/logic/minecraft/VersionFilterData.h +++ b/api/logic/minecraft/VersionFilterData.h @@ -24,7 +24,5 @@ struct VersionFilterData QDateTime legacyCutoffDate; // Libraries that belong to LWJGL QSet lwjglWhitelist; - // Currently recommended minecraft version - QString recommendedMinecraftVersion; }; extern VersionFilterData MULTIMC_LOGIC_EXPORT g_VersionFilterData; diff --git a/application/resources/versions/minecraft.json b/application/resources/versions/minecraft.json deleted file mode 100644 index 9c08a83f..00000000 --- a/application/resources/versions/minecraft.json +++ /dev/null @@ -1,587 +0,0 @@ -{ -"versions": [ - { - "id": "1.5.2", - "checksum": "6897c3287fb971c9f362eb3ab20f5ddd", - "releaseTime": "2013-04-25T17:45:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.5.1", - "checksum": "5c1219d869b87d233de3033688ec7567", - "releaseTime": "2013-03-20T12:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.5", - "checksum": "fd11cbc5b01aae1d62cff0145171f3d9", - "releaseTime": "2013-03-07T00:00:00+02:00", - "type": "snapshot", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.7", - "checksum": "8e80fb01b321c6b3c7efca397a3eea35", - "releaseTime": "2012-12-28T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.6", - "checksum": "48677dc4c2b98c29918722b5ab27b4fd", - "releaseTime": "2012-12-20T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.5", - "checksum": "b15e2b2b6b4629f0d99a95b6b44412a0", - "releaseTime": "2012-11-20T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.4", - "checksum": "7aa46c8058cba2f38e9d2ddddcc77c72", - "releaseTime": "2012-11-14T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.3", - "checksum": "9cc3295931edb6339f22989fe1b612a6", - "releaseTime": "2012-11-01T00:00:00+02:00", - "type": "snapshot", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.2", - "checksum": "771175c01778ea67395bc6919a5a9dc5", - "releaseTime": "2012-10-25T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4.1", - "checksum": "542621a5298659dc65f383f35170fc4c", - "releaseTime": "2012-10-23T00:00:00+02:00", - "type": "snapshot", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.4", - "checksum": "32a654388b54d3e4bb29c1a46e7d6a12", - "releaseTime": "2012-10-19T00:00:00+02:00", - "type": "snapshot", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.3.2", - "checksum": "969699f13e5bbe7f12e40ac4f32b7d9a", - "releaseTime": "2012-08-16T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.3.1", - "checksum": "266ccbc9798afd2eadf3d6c01b4c562a", - "releaseTime": "2012-08-01T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.3", - "checksum": "a6effac1eaccf5d429aae340cf95ed5d", - "releaseTime": "2012-07-26T00:00:00+02:00", - "type": "snapshot", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.2.5", - "checksum": "8e8778078a175a33603a585257f28563", - "releaseTime": "2012-03-30T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.2.4", - "checksum": "25423eab6d8707f96cc6ad8a21a7250a", - "releaseTime": "2012-03-22T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.2.3", - "checksum": "12f6c4b1bdcc63f029e3c088a364b8e4", - "releaseTime": "2012-03-02T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.2.2", - "checksum": "6189e96efaea11e5164b4a4755574324", - "releaseTime": "2012-03-01T00:00:01+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.2.1", - "checksum": "97067a603eba2b6eb75d3194f81f6bcd", - "releaseTime": "2012-03-01T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.1", - "checksum": "e92302d2acdba7c97e0d8df1e10d2006", - "releaseTime": "2012-01-12T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "1.0", - "checksum": "3820d222b95d0b8c520d9596a756a6e6", - "releaseTime": "2011-11-18T00:00:00+02:00", - "type": "release", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.8.1", - "checksum": "f8c5a2ccd3bc996792bbe436d8cc08bc", - "releaseTime": "2011-09-19T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.8", - "checksum": "a59a9fd4c726a573b0a2bdd10d857f59", - "releaseTime": "2011-09-15T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.7.3", - "checksum": "eae3353fdaa7e10a59b4cb5b45bfa10d", - "releaseTime": "2011-07-08T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.7.2", - "checksum": "dd9215ab1141170d4871f42bff4ab302", - "releaseTime": "2011-07-01T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.7", - "checksum": "682419e9ed1a236c3067822d53cda1e4", - "releaseTime": "2011-06-30T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6.6", - "checksum": "ce80072464433cd5b05d505aa8ff29d1", - "releaseTime": "2011-05-31T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6.5", - "checksum": "2aba888864b32038c8d22ee5df71b7c8", - "releaseTime": "2011-05-28T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6.4", - "checksum": "5c4df6f120336f113180698613853dba", - "releaseTime": "2011-05-26T00:00:04+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6.3", - "checksum": "efc2becca965e4f8feb5b4210c6a4fd1", - "releaseTime": "2011-05-26T00:00:03+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6.2", - "checksum": "01330b1c930102a683a4dd8d792e632e", - "releaseTime": "2011-05-26T00:00:02+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6.1", - "checksum": "a7e82c441a57ef4068c533f4d777336a", - "releaseTime": "2011-05-26T00:00:01+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.6", - "checksum": "d531e221227a65392259d3141893280d", - "releaseTime": "2011-05-26T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.5_01", - "checksum": "d02fa9998e30693d8d989d5f88cf0040", - "releaseTime": "2011-04-20T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.5", - "checksum": "24289130902822d73f8722b52bc07cdb", - "releaseTime": "2011-04-19T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.4_01", - "checksum": "9379e54b581ba4ef3acc3e326e87db91", - "releaseTime": "2011-04-05T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.4", - "checksum": "71e64b61175b371ed148b385f2d14ebf", - "releaseTime": "2011-03-31T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.3_01", - "checksum": "4203826f35e1036f089919032c3d19d1", - "releaseTime": "2011-02-23T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.3b", - "checksum": "de2164df461d028229ed2e101181bbd4", - "releaseTime": "2011-02-22T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.2_02", - "checksum": "1736c5ba4f63a981220c2a18a4120180", - "releaseTime": "2011-01-21T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.2_01", - "checksum": "486d83ec00554b45ffa21af2faa0116a", - "releaseTime": "2011-01-14T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.2", - "checksum": "6426223efe23c3931a4ef89685be3349", - "releaseTime": "2011-01-13T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.1_02", - "checksum": "7d547e495a770c62054ef136add43034", - "releaseTime": "2010-12-22T00:00:01+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.1_01", - "checksum": "1f9331f2bfca81b6ce2acdfc1f105837", - "releaseTime": "2010-12-22T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.0.2", - "checksum": "d200c465b8c167cc8df6537531fc9a48", - "releaseTime": "2010-12-21T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.0_01", - "checksum": "03bd20b870dbbd121de5dca98af4e1ce", - "releaseTime": "2010-12-20T00:00:01+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "b1.0", - "checksum": "5f8733dbbf09b4e7c874661a3c29c239", - "releaseTime": "2010-12-20T00:00:00+02:00", - "type": "old_beta", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.6", - "checksum": "ddd5e39467f28d1ea1a03b4d9e790867", - "releaseTime": "2010-12-03T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.5", - "checksum": "7d3a43037190970ff2e11153b5718b74", - "releaseTime": "2010-12-01T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.4_01", - "checksum": "0a1cc8c668faa6dc93fc418e8b4b097a", - "releaseTime": "2010-11-30T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.3_04", - "checksum": "b2c25a753c82a1cd228ce71469829dc1", - "releaseTime": "2010-11-26T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.3_02", - "checksum": "3ad4808ef2ac3b65d10305315260da03", - "releaseTime": "2010-11-25T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.3_01", - "checksum": "70cbab762b17c5b11fefea9b12564119", - "releaseTime": "2010-11-24T00:00:01+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.3", - "checksum": "25f053114e34b915e675f82d58f08711", - "releaseTime": "2010-11-24T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.2b", - "checksum": "6250fb17f8898c4d970d6bd03c229177", - "releaseTime": "2010-11-10T00:00:01+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.2a", - "checksum": "0f9fe018b344fd9dd849005f9bdca803", - "releaseTime": "2010-11-10T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "texturepacks"] - }, - { - "id": "a1.2.1_01", - "checksum": "0a496e44a7b4e2f493b5893d8e5845bd", - "releaseTime": "2010-11-05T00:00:01+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.2.1", - "checksum": "0a496e44a7b4e2f493b5893d8e5845bd", - "releaseTime": "2010-11-05T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.2.0_02", - "checksum": "f5bcb4d0c0e78bc220f164b89ae9bd60", - "releaseTime": "2010-11-04T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.2.0_01", - "checksum": "b2e9333e967cb89488884c2e5c715d4f", - "releaseTime": "2010-10-31T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.2.0", - "checksum": "44c384dae02390f700458b95d82c3e2a", - "releaseTime": "2010-10-30T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.1.2_01", - "checksum": "94346e1b8f6ad0e4a284314f0e29207b", - "releaseTime": "2010-09-23T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.1.2", - "checksum": "72ba1f834327805cb44164a42b331522", - "releaseTime": "2010-09-20T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.1.0", - "checksum": "891fd93e04f5daaf35d73c58e45c01b1", - "releaseTime": "2010-09-13T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.17_04", - "checksum": "16ed7dc58244772847991e504afcf02f", - "releaseTime": "2010-08-23T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.17_02", - "checksum": "d89760b0871ef61a55c9f336c0439d58", - "releaseTime": "2010-08-20T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.16", - "checksum": "6bbde02c13aed5766275f4398ede6aae", - "releaseTime": "2010-08-12T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.15", - "checksum": "ade257d2080d56fa983763f9c701fa14", - "releaseTime": "2010-08-04T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.14", - "checksum": "227d0c6fa896a231de6269a074c9a458", - "releaseTime": "2010-07-30T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.11", - "checksum": "6f1b1dd157fa0df39760f5be3eab01b0", - "releaseTime": "2010-07-23T00:00:00+02:00", - "type": "old_alpha", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.5_01", - "checksum": "ae5f606caa18222e7568819c910ee423", - "releaseTime": "2010-07-13T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "y", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "a1.0.4", - "checksum": "13ce7935c3670e7494e26b2704bfa3e9", - "releaseTime": "2010-07-09T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "ax", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "inf-20100618", - "checksum": "f5f5aa34760facc10486e906a7c60196", - "releaseTime": "2010-06-16T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "net.minecraft.client.d", - "appletClass": "net.minecraft.client.MinecraftApplet", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "c0.30_01c", - "checksum": "fcfd7f83a6b27503cf48202381a5adf2", - "releaseTime": "2009-12-22T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.minecraft.l", - "appletClass": "com.mojang.minecraft.MinecraftApplet", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "c0.0.13a_03", - "checksum": "a9527cb5aef198e0f53e235ebe13dc75", - "releaseTime": "2009-05-22T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.minecraft.c", - "appletClass": "com.mojang.minecraft.MinecraftApplet", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "c0.0.13a", - "checksum": "3617fbf5fbfd2b837ebf5ceb63584908", - "releaseTime": "2009-05-31T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.minecraft.Minecraft", - "appletClass": "com.mojang.minecraft.MinecraftApplet", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "c0.0.11a", - "checksum": "a6e03c2eaf74709facc0d2477648e999", - "releaseTime": "2009-05-17T00:00:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.minecraft.Minecraft", - "appletClass": "com.mojang.minecraft.MinecraftApplet", - "+traits": ["legacyLaunch", "no-texturepacks"] - }, - { - "id": "rd-161348", - "checksum": "80882b8936a5c8d91500838a6660b504", - "releaseTime": "2009-05-16T13:48:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.minecraft.RubyDung", - "+traits": ["no-texturepacks"] - }, - { - "id": "rd-160052", - "checksum": "24c5cc99a2a612697ed2f7d5d04242fe", - "releaseTime": "2009-05-16T00:52:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.rubydung.RubyDung", - "+traits": ["no-texturepacks"] - }, - { - "id": "rd-132328", - "checksum": "70e33a81c541b13a477e68c1207124eb", - "releaseTime": "2009-05-13T23:28:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.rubydung.RubyDung", - "+traits": ["no-texturepacks"] - }, - { - "id": "rd-132211", - "checksum": "99fdaea10c494b9c3c3254636b98b799", - "releaseTime": "2009-05-13T22:11:00+02:00", - "type": "old_alpha", - "mainClass": "com.mojang.rubydung.RubyDung", - "+traits": ["no-texturepacks"] - } -] -} diff --git a/application/resources/versions/versions.qrc b/application/resources/versions/versions.qrc index e9621e97..d9596942 100644 --- a/application/resources/versions/versions.qrc +++ b/application/resources/versions/versions.qrc @@ -1,8 +1,6 @@ - - minecraft.json LWJGL/2.9.0.json LWJGL/2.9.1-nightly-20130708-debug3.json From 1fbe03f982f130bf675b7f94dd9c06aee62da54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 10 Mar 2017 23:34:03 +0100 Subject: [PATCH 03/28] NOISSUE remove unused wonkoclient --- CMakeLists.txt | 1 - wonkoclient/CMakeLists.txt | 10 ----- wonkoclient/WonkoClient.cpp | 84 ------------------------------------- wonkoclient/WonkoClient.h | 36 ---------------- wonkoclient/main.cpp | 29 ------------- 5 files changed, 160 deletions(-) delete mode 100644 wonkoclient/CMakeLists.txt delete mode 100644 wonkoclient/WonkoClient.cpp delete mode 100644 wonkoclient/WonkoClient.h delete mode 100644 wonkoclient/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d3dcac78..86f8e20a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,4 +109,3 @@ add_subdirectory(api/logic) add_subdirectory(api/gui) add_subdirectory(application) -add_subdirectory(wonkoclient) diff --git a/wonkoclient/CMakeLists.txt b/wonkoclient/CMakeLists.txt deleted file mode 100644 index 381857e0..00000000 --- a/wonkoclient/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -project(wonkoclient) - -SET( SRC_FILES -main.cpp -WonkoClient.cpp -WonkoClient.h -) - -add_executable(MMCClient ${SRC_FILES}) -target_link_libraries(MMCClient MultiMC_logic) diff --git a/wonkoclient/WonkoClient.cpp b/wonkoclient/WonkoClient.cpp deleted file mode 100644 index a45939b3..00000000 --- a/wonkoclient/WonkoClient.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// -// Created by robotbrain on 3/27/16. -// - -#include -#include -#include -#include -#include -#include -#include -#include "WonkoClient.h" - -WonkoClient &WonkoClient::getInstance() { - static WonkoClient instance; - return instance; -} - -void WonkoClient::registerLists() { - ENV.initHttpMetaCache(); - auto mcList = std::make_shared(); - ENV.registerVersionList("net.minecraft", mcList); - runTask(mcList->getLoadTask()); - auto llList = std::make_shared(); - ENV.registerVersionList("com.mumfrey.liteloader", llList); - runTask(llList->getLoadTask()); - auto forgeList = std::make_shared(); - ENV.registerVersionList("net.minecraftforge", forgeList); - runTask(forgeList->getLoadTask()); - auto lwjglList = std::make_shared(); - ENV.registerVersionList("org.lwjgl.legacy", lwjglList); - runTask(lwjglList->getLoadTask()); - auto javaList = std::make_shared(); - ENV.registerVersionList("com.java", javaList); -} - -WonkoClient::WonkoClient() { - m_settings.reset(new INISettingsObject("multimc.cfg", this)); - m_instanceList.reset(new InstanceList(m_settings, ".", this)); -} - -void WonkoClient::runTask(Task *pTask) { - if (pTask == nullptr) - return; - QEventLoop loop; - QObject::connect(pTask, &Task::finished, &loop, &QEventLoop::quit); - pTask->start(); - loop.exec(); - delete pTask; -} - -void WonkoClient::initGlobalSettings() -{ - m_settings->registerSetting("ShowConsole", true); - m_settings->registerSetting("AutoCloseConsole", true); - m_settings->registerSetting("LogPrePostOutput", true); - // Window Size - m_settings->registerSetting({"LaunchMaximized", "MCWindowMaximize"}, false); - m_settings->registerSetting({"MinecraftWinWidth", "MCWindowWidth"}, 854); - m_settings->registerSetting({"MinecraftWinHeight", "MCWindowHeight"}, 480); - - // Memory - m_settings->registerSetting({"MinMemAlloc", "MinMemoryAlloc"}, 512); - m_settings->registerSetting({"MaxMemAlloc", "MaxMemoryAlloc"}, 1024); - m_settings->registerSetting("PermGen", 128); - - // Java Settings - m_settings->registerSetting("JavaPath", ""); - m_settings->registerSetting("JavaTimestamp", 0); - m_settings->registerSetting("JavaArchitecture", ""); - m_settings->registerSetting("JavaVersion", ""); - m_settings->registerSetting("LastHostname", ""); - m_settings->registerSetting("JvmArgs", ""); - - // Wrapper command for launch - m_settings->registerSetting("WrapperCommand", ""); - - // Custom Commands - m_settings->registerSetting({"PreLaunchCommand", "PreLaunchCmd"}, ""); - m_settings->registerSetting({"PostExitCommand", "PostExitCmd"}, ""); - - // Minecraft launch method - m_settings->registerSetting("MCLaunchMethod", "LauncherPart"); -} diff --git a/wonkoclient/WonkoClient.h b/wonkoclient/WonkoClient.h deleted file mode 100644 index e6b35805..00000000 --- a/wonkoclient/WonkoClient.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// Created by robotbrain on 3/27/16. -// - -#pragma once - -#include -#include - -#if defined(MMCC) -#undef MMCC -#endif -#define MMCC (WonkoClient::getInstance()) - -class WonkoClient : public QObject { -Q_OBJECT - -private: - WonkoClient(); - -public: - static WonkoClient &getInstance(); - - void registerLists(); - void initGlobalSettings(); - - std::shared_ptr instances() const { - return m_instanceList; - } - -private: - std::shared_ptr m_instanceList; - std::shared_ptr m_settings; - - void runTask(Task *pTask); -}; diff --git a/wonkoclient/main.cpp b/wonkoclient/main.cpp deleted file mode 100644 index eaf92c5d..00000000 --- a/wonkoclient/main.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Created by robotbrain on 3/26/16. -// - -#include "WonkoClient.h" -#include -#include -#include -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - if (a.arguments().contains("-d")) - { - int i = a.arguments().lastIndexOf("-d") + 1; - if (i < a.arguments().length()) - { - QDir dir = QDir::current(); - dir.cd(a.arguments()[i]); - QDir::setCurrent(dir.absolutePath()); - qDebug() << "Using " << dir.absolutePath(); - } - } - MMCC.initGlobalSettings(); - MMCC.registerLists(); - return a.exec(); -} From ab868df50eb6f9f3958bdc0a7ab9199dcdf46b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 11 Mar 2017 01:39:45 +0100 Subject: [PATCH 04/28] NOISSUE Wonko is the new Meta And then Wonko was the Meta. --- api/logic/CMakeLists.txt | 50 +++---- api/logic/Env.cpp | 27 ++-- api/logic/Env.h | 11 +- .../BaseEntity.cpp} | 17 ++- .../BaseWonkoEntity.h => meta/BaseEntity.h} | 12 +- .../{wonko/WonkoIndex.cpp => meta/Index.cpp} | 57 ++++---- .../{wonko/WonkoIndex.h => meta/Index.h} | 28 ++-- api/logic/meta/Index_test.cpp | 50 +++++++ .../WonkoReference.cpp => meta/Reference.cpp} | 18 ++- .../WonkoReference.h => meta/Reference.h} | 15 +- .../{wonko/WonkoUtil.cpp => meta/Util.cpp} | 13 +- api/logic/{wonko/WonkoUtil.h => meta/Util.h} | 4 +- .../WonkoVersion.cpp => meta/Version.cpp} | 47 ++++--- .../{wonko/WonkoVersion.h => meta/Version.h} | 26 ++-- .../VersionList.cpp} | 99 ++++++------- .../WonkoVersionList.h => meta/VersionList.h} | 37 ++--- api/logic/meta/format/Format.cpp | 84 +++++++++++ api/logic/meta/format/Format.h | 57 ++++++++ .../format/FormatV1.cpp} | 53 +++---- .../format/FormatV1.h} | 19 +-- api/logic/meta/tasks/LocalLoadTask.cpp | 123 ++++++++++++++++ .../tasks/LocalLoadTask.h} | 35 ++--- api/logic/meta/tasks/RemoteLoadTask.cpp | 132 ++++++++++++++++++ .../tasks/RemoteLoadTask.h} | 39 +++--- api/logic/wonko/WonkoIndex_test.cpp | 50 ------- api/logic/wonko/format/WonkoFormat.cpp | 80 ----------- api/logic/wonko/format/WonkoFormat.h | 54 ------- .../tasks/BaseWonkoEntityLocalLoadTask.cpp | 117 ---------------- .../tasks/BaseWonkoEntityRemoteLoadTask.cpp | 126 ----------------- application/BuildConfig.cpp.in | 1 - application/BuildConfig.h | 5 - application/CMakeLists.txt | 11 +- application/WonkoGui.cpp | 74 ---------- application/WonkoGui.h | 29 ---- .../{WonkoPage.cpp => MetadataPage.cpp} | 74 +++++----- .../global/{WonkoPage.h => MetadataPage.h} | 14 +- .../global/{WonkoPage.ui => MetadataPage.ui} | 4 +- 37 files changed, 820 insertions(+), 872 deletions(-) rename api/logic/{wonko/BaseWonkoEntity.cpp => meta/BaseEntity.cpp} (69%) rename api/logic/{wonko/BaseWonkoEntity.h => meta/BaseEntity.h} (86%) rename api/logic/{wonko/WonkoIndex.cpp => meta/Index.cpp} (57%) rename api/logic/{wonko/WonkoIndex.h => meta/Index.h} (65%) create mode 100644 api/logic/meta/Index_test.cpp rename api/logic/{wonko/WonkoReference.cpp => meta/Reference.cpp} (70%) rename api/logic/{wonko/WonkoReference.h => meta/Reference.h} (77%) rename api/logic/{wonko/WonkoUtil.cpp => meta/Util.cpp} (89%) rename api/logic/{wonko/WonkoUtil.h => meta/Util.h} (93%) rename api/logic/{wonko/WonkoVersion.cpp => meta/Version.cpp} (52%) rename api/logic/{wonko/WonkoVersion.h => meta/Version.h} (74%) rename api/logic/{wonko/WonkoVersionList.cpp => meta/VersionList.cpp} (62%) rename api/logic/{wonko/WonkoVersionList.h => meta/VersionList.h} (67%) create mode 100644 api/logic/meta/format/Format.cpp create mode 100644 api/logic/meta/format/Format.h rename api/logic/{wonko/format/WonkoFormatV1.cpp => meta/format/FormatV1.cpp} (69%) rename api/logic/{wonko/format/WonkoFormatV1.h => meta/format/FormatV1.h} (53%) create mode 100644 api/logic/meta/tasks/LocalLoadTask.cpp rename api/logic/{wonko/tasks/BaseWonkoEntityLocalLoadTask.h => meta/tasks/LocalLoadTask.h} (61%) create mode 100644 api/logic/meta/tasks/RemoteLoadTask.cpp rename api/logic/{wonko/tasks/BaseWonkoEntityRemoteLoadTask.h => meta/tasks/RemoteLoadTask.h} (61%) delete mode 100644 api/logic/wonko/WonkoIndex_test.cpp delete mode 100644 api/logic/wonko/format/WonkoFormat.cpp delete mode 100644 api/logic/wonko/format/WonkoFormat.h delete mode 100644 api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp delete mode 100644 api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp delete mode 100644 application/WonkoGui.cpp delete mode 100644 application/WonkoGui.h rename application/pages/global/{WonkoPage.cpp => MetadataPage.cpp} (71%) rename application/pages/global/{WonkoPage.h => MetadataPage.h} (82%) rename application/pages/global/{WonkoPage.ui => MetadataPage.ui} (99%) diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index bcf4b65a..1827b497 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -430,32 +430,32 @@ set(TOOLS_SOURCES tools/MCEditTool.h ) -set(WONKO_SOURCES - # Wonko - wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp - wonko/tasks/BaseWonkoEntityRemoteLoadTask.h - wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp - wonko/tasks/BaseWonkoEntityLocalLoadTask.h - wonko/format/WonkoFormatV1.cpp - wonko/format/WonkoFormatV1.h - wonko/format/WonkoFormat.cpp - wonko/format/WonkoFormat.h - wonko/BaseWonkoEntity.cpp - wonko/BaseWonkoEntity.h - wonko/WonkoVersionList.cpp - wonko/WonkoVersionList.h - wonko/WonkoVersion.cpp - wonko/WonkoVersion.h - wonko/WonkoIndex.cpp - wonko/WonkoIndex.h - wonko/WonkoUtil.cpp - wonko/WonkoUtil.h - wonko/WonkoReference.cpp - wonko/WonkoReference.h +set(META_SOURCES + # Metadata sources + meta/tasks/RemoteLoadTask.cpp + meta/tasks/RemoteLoadTask.h + meta/tasks/LocalLoadTask.cpp + meta/tasks/LocalLoadTask.h + meta/format/FormatV1.cpp + meta/format/FormatV1.h + meta/format/Format.cpp + meta/format/Format.h + meta/BaseEntity.cpp + meta/BaseEntity.h + meta/VersionList.cpp + meta/VersionList.h + meta/Version.cpp + meta/Version.h + meta/Index.cpp + meta/Index.h + meta/Util.cpp + meta/Util.h + meta/Reference.cpp + meta/Reference.h ) -add_unit_test(WonkoIndex - SOURCES wonko/WonkoIndex_test.cpp +add_unit_test(Index + SOURCES meta/Index_test.cpp LIBS MultiMC_logic ) @@ -480,7 +480,7 @@ set(LOGIC_SOURCES ${JAVA_SOURCES} ${TRANSLATIONS_SOURCES} ${TOOLS_SOURCES} - ${WONKO_SOURCES} + ${META_SOURCES} ${ICONS_SOURCES} ) diff --git a/api/logic/Env.cpp b/api/logic/Env.cpp index a6341ebd..903f1d8a 100644 --- a/api/logic/Env.cpp +++ b/api/logic/Env.cpp @@ -7,7 +7,7 @@ #include #include #include "tasks/Task.h" -#include "wonko/WonkoIndex.h" +#include "meta/Index.h" #include @@ -18,8 +18,7 @@ public: shared_qobject_ptr m_metacache; std::shared_ptr m_iconlist; QMap> m_versionLists; - shared_qobject_ptr m_wonkoIndex; - QString m_wonkoRootUrl; + shared_qobject_ptr m_metadataIndex; }; static Env * instance; @@ -99,13 +98,13 @@ void Env::registerVersionList(QString name, std::shared_ptr< BaseVersionList > v d->m_versionLists[name] = vlist; } -shared_qobject_ptr Env::wonkoIndex() +shared_qobject_ptr Env::metadataIndex() { - if (!d->m_wonkoIndex) + if (!d->m_metadataIndex) { - d->m_wonkoIndex.reset(new WonkoIndex()); + d->m_metadataIndex.reset(new Meta::Index()); } - return d->m_wonkoIndex; + return d->m_metadataIndex; } @@ -125,7 +124,7 @@ void Env::initHttpMetaCache() m_metacache->addBase("root", QDir::currentPath()); m_metacache->addBase("translations", QDir("translations").absolutePath()); m_metacache->addBase("icons", QDir("cache/icons").absolutePath()); - m_metacache->addBase("wonko", QDir("cache/wonko").absolutePath()); + m_metacache->addBase("meta", QDir("cache/meta").absolutePath()); m_metacache->Load(); } @@ -191,14 +190,4 @@ void Env::updateProxySettings(QString proxyTypeStr, QString addr, int port, QStr qDebug() << proxyDesc; } -QString Env::wonkoRootUrl() const -{ - return d->m_wonkoRootUrl; -} - -void Env::setWonkoRootUrl(const QString& url) -{ - d->m_wonkoRootUrl = url; -} - -#include "Env.moc" \ No newline at end of file +#include "Env.moc" diff --git a/api/logic/Env.h b/api/logic/Env.h index c72447ce..75ebe4a0 100644 --- a/api/logic/Env.h +++ b/api/logic/Env.h @@ -13,7 +13,11 @@ class QNetworkAccessManager; class HttpMetaCache; class BaseVersionList; class BaseVersion; -class WonkoIndex; + +namespace Meta +{ +class Index; +} #if defined(ENV) #undef ENV @@ -53,10 +57,7 @@ public: void registerIconList(std::shared_ptr iconlist); - shared_qobject_ptr wonkoIndex(); - - QString wonkoRootUrl() const; - void setWonkoRootUrl(const QString &url); + shared_qobject_ptr metadataIndex(); protected: Private * d; diff --git a/api/logic/wonko/BaseWonkoEntity.cpp b/api/logic/meta/BaseEntity.cpp similarity index 69% rename from api/logic/wonko/BaseWonkoEntity.cpp rename to api/logic/meta/BaseEntity.cpp index e6a0e41e..fd44e29c 100644 --- a/api/logic/wonko/BaseWonkoEntity.cpp +++ b/api/logic/meta/BaseEntity.cpp @@ -13,27 +13,30 @@ * limitations under the License. */ -#include "BaseWonkoEntity.h" +#include "BaseEntity.h" #include "Json.h" -#include "WonkoUtil.h" +#include "Util.h" -BaseWonkoEntity::~BaseWonkoEntity() +namespace Meta +{ +BaseEntity::~BaseEntity() { } -void BaseWonkoEntity::store() const +void BaseEntity::store() const { - Json::write(serialized(), Wonko::localWonkoDir().absoluteFilePath(localFilename())); + Json::write(serialized(), Meta::localDir().absoluteFilePath(localFilename())); } -void BaseWonkoEntity::notifyLocalLoadComplete() +void BaseEntity::notifyLocalLoadComplete() { m_localLoaded = true; store(); } -void BaseWonkoEntity::notifyRemoteLoadComplete() +void BaseEntity::notifyRemoteLoadComplete() { m_remoteLoaded = true; store(); } +} diff --git a/api/logic/wonko/BaseWonkoEntity.h b/api/logic/meta/BaseEntity.h similarity index 86% rename from api/logic/wonko/BaseWonkoEntity.h rename to api/logic/meta/BaseEntity.h index c6e8c832..b7a241c6 100644 --- a/api/logic/wonko/BaseWonkoEntity.h +++ b/api/logic/meta/BaseEntity.h @@ -21,17 +21,18 @@ #include "multimc_logic_export.h" class Task; - -class MULTIMC_LOGIC_EXPORT BaseWonkoEntity +namespace Meta +{ +class MULTIMC_LOGIC_EXPORT BaseEntity { public: - virtual ~BaseWonkoEntity(); + virtual ~BaseEntity(); - using Ptr = std::shared_ptr; + using Ptr = std::shared_ptr; virtual std::unique_ptr remoteUpdateTask() = 0; virtual std::unique_ptr localUpdateTask() = 0; - virtual void merge(const std::shared_ptr &other) = 0; + virtual void merge(const std::shared_ptr &other) = 0; void store() const; virtual QString localFilename() const = 0; @@ -49,3 +50,4 @@ private: bool m_localLoaded = false; bool m_remoteLoaded = false; }; +} diff --git a/api/logic/wonko/WonkoIndex.cpp b/api/logic/meta/Index.cpp similarity index 57% rename from api/logic/wonko/WonkoIndex.cpp rename to api/logic/meta/Index.cpp index f6ad201a..8a6b1355 100644 --- a/api/logic/wonko/WonkoIndex.cpp +++ b/api/logic/meta/Index.cpp @@ -13,18 +13,20 @@ * limitations under the License. */ -#include "WonkoIndex.h" +#include "Index.h" -#include "WonkoVersionList.h" -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "format/WonkoFormat.h" +#include "VersionList.h" +#include "tasks/LocalLoadTask.h" +#include "tasks/RemoteLoadTask.h" +#include "format/Format.h" -WonkoIndex::WonkoIndex(QObject *parent) +namespace Meta +{ +Index::Index(QObject *parent) : QAbstractListModel(parent) { } -WonkoIndex::WonkoIndex(const QVector &lists, QObject *parent) +Index::Index(const QVector &lists, QObject *parent) : QAbstractListModel(parent), m_lists(lists) { for (int i = 0; i < m_lists.size(); ++i) @@ -34,14 +36,14 @@ WonkoIndex::WonkoIndex(const QVector &lists, QObject *paren } } -QVariant WonkoIndex::data(const QModelIndex &index, int role) const +QVariant Index::data(const QModelIndex &index, int role) const { if (index.parent().isValid() || index.row() < 0 || index.row() >= m_lists.size()) { return QVariant(); } - WonkoVersionListPtr list = m_lists.at(index.row()); + VersionListPtr list = m_lists.at(index.row()); switch (role) { case Qt::DisplayRole: @@ -56,15 +58,15 @@ QVariant WonkoIndex::data(const QModelIndex &index, int role) const } return QVariant(); } -int WonkoIndex::rowCount(const QModelIndex &parent) const +int Index::rowCount(const QModelIndex &parent) const { return m_lists.size(); } -int WonkoIndex::columnCount(const QModelIndex &parent) const +int Index::columnCount(const QModelIndex &parent) const { return 1; } -QVariant WonkoIndex::headerData(int section, Qt::Orientation orientation, int role) const +QVariant Index::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section == 0) { @@ -76,36 +78,36 @@ QVariant WonkoIndex::headerData(int section, Qt::Orientation orientation, int ro } } -std::unique_ptr WonkoIndex::remoteUpdateTask() +std::unique_ptr Index::remoteUpdateTask() { - return std::unique_ptr(new WonkoIndexRemoteLoadTask(this, this)); + return std::unique_ptr(new IndexRemoteLoadTask(this, this)); } -std::unique_ptr WonkoIndex::localUpdateTask() +std::unique_ptr Index::localUpdateTask() { - return std::unique_ptr(new WonkoIndexLocalLoadTask(this, this)); + return std::unique_ptr(new IndexLocalLoadTask(this, this)); } -QJsonObject WonkoIndex::serialized() const +QJsonObject Index::serialized() const { - return WonkoFormat::serializeIndex(this); + return Format::serializeIndex(this); } -bool WonkoIndex::hasUid(const QString &uid) const +bool Index::hasUid(const QString &uid) const { return m_uids.contains(uid); } -WonkoVersionListPtr WonkoIndex::getList(const QString &uid) const +VersionListPtr Index::getList(const QString &uid) const { return m_uids.value(uid, nullptr); } -WonkoVersionListPtr WonkoIndex::getListGuaranteed(const QString &uid) const +VersionListPtr Index::getListGuaranteed(const QString &uid) const { - return m_uids.value(uid, std::make_shared(uid)); + return m_uids.value(uid, std::make_shared(uid)); } -void WonkoIndex::merge(const Ptr &other) +void Index::merge(const Ptr &other) { - const QVector lists = std::dynamic_pointer_cast(other)->m_lists; + const QVector lists = std::dynamic_pointer_cast(other)->m_lists; // initial load, no need to merge if (m_lists.isEmpty()) { @@ -120,7 +122,7 @@ void WonkoIndex::merge(const Ptr &other) } else { - for (const WonkoVersionListPtr &list : lists) + for (const VersionListPtr &list : lists) { if (m_uids.contains(list->uid())) { @@ -138,10 +140,11 @@ void WonkoIndex::merge(const Ptr &other) } } -void WonkoIndex::connectVersionList(const int row, const WonkoVersionListPtr &list) +void Index::connectVersionList(const int row, const VersionListPtr &list) { - connect(list.get(), &WonkoVersionList::nameChanged, this, [this, row]() + connect(list.get(), &VersionList::nameChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << Qt::DisplayRole); }); } +} diff --git a/api/logic/wonko/WonkoIndex.h b/api/logic/meta/Index.h similarity index 65% rename from api/logic/wonko/WonkoIndex.h rename to api/logic/meta/Index.h index fe07c3ef..16e95d5a 100644 --- a/api/logic/wonko/WonkoIndex.h +++ b/api/logic/meta/Index.h @@ -18,19 +18,22 @@ #include #include -#include "BaseWonkoEntity.h" +#include "BaseEntity.h" #include "multimc_logic_export.h" class Task; -using WonkoVersionListPtr = std::shared_ptr; -class MULTIMC_LOGIC_EXPORT WonkoIndex : public QAbstractListModel, public BaseWonkoEntity +namespace Meta +{ +using VersionListPtr = std::shared_ptr; + +class MULTIMC_LOGIC_EXPORT Index : public QAbstractListModel, public BaseEntity { Q_OBJECT public: - explicit WonkoIndex(QObject *parent = nullptr); - explicit WonkoIndex(const QVector &lists, QObject *parent = nullptr); + explicit Index(QObject *parent = nullptr); + explicit Index(const QVector &lists, QObject *parent = nullptr); enum { @@ -52,17 +55,18 @@ public: // queries bool hasUid(const QString &uid) const; - WonkoVersionListPtr getList(const QString &uid) const; - WonkoVersionListPtr getListGuaranteed(const QString &uid) const; + VersionListPtr getList(const QString &uid) const; + VersionListPtr getListGuaranteed(const QString &uid) const; - QVector lists() const { return m_lists; } + QVector lists() const { return m_lists; } public: // for usage by parsers only - void merge(const BaseWonkoEntity::Ptr &other); + void merge(const BaseEntity::Ptr &other) override; private: - QVector m_lists; - QHash m_uids; + QVector m_lists; + QHash m_uids; - void connectVersionList(const int row, const WonkoVersionListPtr &list); + void connectVersionList(const int row, const VersionListPtr &list); }; +} diff --git a/api/logic/meta/Index_test.cpp b/api/logic/meta/Index_test.cpp new file mode 100644 index 00000000..d26700ca --- /dev/null +++ b/api/logic/meta/Index_test.cpp @@ -0,0 +1,50 @@ +#include +#include "TestUtil.h" + +#include "meta/Index.h" +#include "meta/VersionList.h" +#include "Env.h" + +class IndexTest : public QObject +{ + Q_OBJECT +private +slots: + void test_isProvidedByEnv() + { + QVERIFY(ENV.metadataIndex()); + QCOMPARE(ENV.metadataIndex(), ENV.metadataIndex()); + } + + void test_providesTasks() + { + QVERIFY(ENV.metadataIndex()->localUpdateTask() != nullptr); + QVERIFY(ENV.metadataIndex()->remoteUpdateTask() != nullptr); + } + + void test_hasUid_and_getList() + { + Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); + QVERIFY(windex.hasUid("list1")); + QVERIFY(!windex.hasUid("asdf")); + QVERIFY(windex.getList("list2") != nullptr); + QCOMPARE(windex.getList("list2")->uid(), QString("list2")); + QVERIFY(windex.getList("adsf") == nullptr); + } + + void test_merge() + { + Meta::Index windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); + QCOMPARE(windex.lists().size(), 3); + windex.merge(std::shared_ptr(new Meta::Index({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}))); + QCOMPARE(windex.lists().size(), 3); + windex.merge(std::shared_ptr(new Meta::Index({std::make_shared("list4"), std::make_shared("list2"), std::make_shared("list5")}))); + QCOMPARE(windex.lists().size(), 5); + windex.merge(std::shared_ptr(new Meta::Index({std::make_shared("list6")}))); + QCOMPARE(windex.lists().size(), 6); + } +}; + +QTEST_GUILESS_MAIN(IndexTest) + +#include "Index_test.moc" diff --git a/api/logic/wonko/WonkoReference.cpp b/api/logic/meta/Reference.cpp similarity index 70% rename from api/logic/wonko/WonkoReference.cpp rename to api/logic/meta/Reference.cpp index 7193e56e..c5cef172 100644 --- a/api/logic/wonko/WonkoReference.cpp +++ b/api/logic/meta/Reference.cpp @@ -13,32 +13,36 @@ * limitations under the License. */ -#include "WonkoReference.h" +#include "Reference.h" -WonkoReference::WonkoReference(const QString &uid) +namespace Meta +{ +Reference::Reference(const QString &uid) : m_uid(uid) { } -QString WonkoReference::uid() const +QString Reference::uid() const { return m_uid; } -QString WonkoReference::version() const +QString Reference::version() const { return m_version; } -void WonkoReference::setVersion(const QString &version) +void Reference::setVersion(const QString &version) { m_version = version; } -bool WonkoReference::operator==(const WonkoReference &other) const +bool Reference::operator==(const Reference &other) const { return m_uid == other.m_uid && m_version == other.m_version; } -bool WonkoReference::operator!=(const WonkoReference &other) const + +bool Reference::operator!=(const Reference &other) const { return m_uid != other.m_uid || m_version != other.m_version; } +} diff --git a/api/logic/wonko/WonkoReference.h b/api/logic/meta/Reference.h similarity index 77% rename from api/logic/wonko/WonkoReference.h rename to api/logic/meta/Reference.h index ba7427b3..027076cc 100644 --- a/api/logic/wonko/WonkoReference.h +++ b/api/logic/meta/Reference.h @@ -20,22 +20,25 @@ #include "multimc_logic_export.h" -class MULTIMC_LOGIC_EXPORT WonkoReference +namespace Meta +{ +class MULTIMC_LOGIC_EXPORT Reference { public: - WonkoReference() {} - explicit WonkoReference(const QString &uid); + Reference() {} + explicit Reference(const QString &uid); QString uid() const; QString version() const; void setVersion(const QString &version); - bool operator==(const WonkoReference &other) const; - bool operator!=(const WonkoReference &other) const; + bool operator==(const Reference &other) const; + bool operator!=(const Reference &other) const; private: QString m_uid; QString m_version; }; -Q_DECLARE_METATYPE(WonkoReference) +} +Q_DECLARE_METATYPE(Meta::Reference) diff --git a/api/logic/wonko/WonkoUtil.cpp b/api/logic/meta/Util.cpp similarity index 89% rename from api/logic/wonko/WonkoUtil.cpp rename to api/logic/meta/Util.cpp index 3b8049c4..2ccbe5c4 100644 --- a/api/logic/wonko/WonkoUtil.cpp +++ b/api/logic/meta/Util.cpp @@ -13,35 +13,38 @@ * limitations under the License. */ -#include "WonkoUtil.h" +#include "Util.h" #include #include #include "Env.h" -namespace Wonko +namespace Meta { QUrl rootUrl() { - return ENV.wonkoRootUrl(); + return QUrl("https://meta.multimc.org"); } + QUrl indexUrl() { return rootUrl().resolved(QStringLiteral("index.json")); } + QUrl versionListUrl(const QString &uid) { return rootUrl().resolved(uid + ".json"); } + QUrl versionUrl(const QString &uid, const QString &version) { return rootUrl().resolved(uid + "/" + version + ".json"); } -QDir localWonkoDir() +QDir localDir() { - return QDir("wonko"); + return QDir("meta"); } } diff --git a/api/logic/wonko/WonkoUtil.h b/api/logic/meta/Util.h similarity index 93% rename from api/logic/wonko/WonkoUtil.h rename to api/logic/meta/Util.h index fb58ba1f..28163fe4 100644 --- a/api/logic/wonko/WonkoUtil.h +++ b/api/logic/meta/Util.h @@ -21,11 +21,11 @@ class QUrl; class QString; class QDir; -namespace Wonko +namespace Meta { MULTIMC_LOGIC_EXPORT QUrl rootUrl(); MULTIMC_LOGIC_EXPORT QUrl indexUrl(); MULTIMC_LOGIC_EXPORT QUrl versionListUrl(const QString &uid); MULTIMC_LOGIC_EXPORT QUrl versionUrl(const QString &uid, const QString &version); -MULTIMC_LOGIC_EXPORT QDir localWonkoDir(); +MULTIMC_LOGIC_EXPORT QDir localDir(); } diff --git a/api/logic/wonko/WonkoVersion.cpp b/api/logic/meta/Version.cpp similarity index 52% rename from api/logic/wonko/WonkoVersion.cpp rename to api/logic/meta/Version.cpp index f5a063be..039f4fef 100644 --- a/api/logic/wonko/WonkoVersion.cpp +++ b/api/logic/meta/Version.cpp @@ -13,49 +13,51 @@ * limitations under the License. */ -#include "WonkoVersion.h" +#include "Version.h" #include -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "format/WonkoFormat.h" +#include "tasks/LocalLoadTask.h" +#include "tasks/RemoteLoadTask.h" +#include "format/Format.h" -WonkoVersion::WonkoVersion(const QString &uid, const QString &version) +namespace Meta +{ +Version::Version(const QString &uid, const QString &version) : BaseVersion(), m_uid(uid), m_version(version) { } -QString WonkoVersion::descriptor() +QString Version::descriptor() { return m_version; } -QString WonkoVersion::name() +QString Version::name() { return m_version; } -QString WonkoVersion::typeString() const +QString Version::typeString() const { return m_type; } -QDateTime WonkoVersion::time() const +QDateTime Version::time() const { return QDateTime::fromMSecsSinceEpoch(m_time * 1000, Qt::UTC); } -std::unique_ptr WonkoVersion::remoteUpdateTask() +std::unique_ptr Version::remoteUpdateTask() { - return std::unique_ptr(new WonkoVersionRemoteLoadTask(this, this)); + return std::unique_ptr(new VersionRemoteLoadTask(this, this)); } -std::unique_ptr WonkoVersion::localUpdateTask() +std::unique_ptr Version::localUpdateTask() { - return std::unique_ptr(new WonkoVersionLocalLoadTask(this, this)); + return std::unique_ptr(new VersionLocalLoadTask(this, this)); } -void WonkoVersion::merge(const std::shared_ptr &other) +void Version::merge(const std::shared_ptr &other) { - WonkoVersionPtr version = std::dynamic_pointer_cast(other); + VersionPtr version = std::dynamic_pointer_cast(other); if (m_type != version->m_type) { setType(version->m_type); @@ -72,31 +74,32 @@ void WonkoVersion::merge(const std::shared_ptr &other) setData(version->m_data); } -QString WonkoVersion::localFilename() const +QString Version::localFilename() const { return m_uid + '/' + m_version + ".json"; } -QJsonObject WonkoVersion::serialized() const +QJsonObject Version::serialized() const { - return WonkoFormat::serializeVersion(this); + return Format::serializeVersion(this); } -void WonkoVersion::setType(const QString &type) +void Version::setType(const QString &type) { m_type = type; emit typeChanged(); } -void WonkoVersion::setTime(const qint64 time) +void Version::setTime(const qint64 time) { m_time = time; emit timeChanged(); } -void WonkoVersion::setRequires(const QVector &requires) +void Version::setRequires(const QVector &requires) { m_requires = requires; emit requiresChanged(); } -void WonkoVersion::setData(const VersionFilePtr &data) +void Version::setData(const VersionFilePtr &data) { m_data = data; } +} diff --git a/api/logic/wonko/WonkoVersion.h b/api/logic/meta/Version.h similarity index 74% rename from api/logic/wonko/WonkoVersion.h rename to api/logic/meta/Version.h index 397ff14e..4a791880 100644 --- a/api/logic/wonko/WonkoVersion.h +++ b/api/logic/meta/Version.h @@ -16,7 +16,6 @@ #pragma once #include "BaseVersion.h" -#include "BaseWonkoEntity.h" #include #include @@ -24,22 +23,26 @@ #include #include "minecraft/VersionFile.h" -#include "WonkoReference.h" + +#include "BaseEntity.h" +#include "Reference.h" #include "multimc_logic_export.h" -using WonkoVersionPtr = std::shared_ptr; +namespace Meta +{ +using VersionPtr = std::shared_ptr; -class MULTIMC_LOGIC_EXPORT WonkoVersion : public QObject, public BaseVersion, public BaseWonkoEntity +class MULTIMC_LOGIC_EXPORT Version : public QObject, public BaseVersion, public BaseEntity { Q_OBJECT Q_PROPERTY(QString uid READ uid CONSTANT) Q_PROPERTY(QString version READ version CONSTANT) Q_PROPERTY(QString type READ type NOTIFY typeChanged) Q_PROPERTY(QDateTime time READ time NOTIFY timeChanged) - Q_PROPERTY(QVector requires READ requires NOTIFY requiresChanged) + Q_PROPERTY(QVector requires READ requires NOTIFY requiresChanged) public: - explicit WonkoVersion(const QString &uid, const QString &version); + explicit Version(const QString &uid, const QString &version); QString descriptor() override; QString name() override; @@ -50,12 +53,12 @@ public: QString type() const { return m_type; } QDateTime time() const; qint64 rawTime() const { return m_time; } - QVector requires() const { return m_requires; } + QVector requires() const { return m_requires; } VersionFilePtr data() const { return m_data; } std::unique_ptr remoteUpdateTask() override; std::unique_ptr localUpdateTask() override; - void merge(const std::shared_ptr &other) override; + void merge(const std::shared_ptr &other) override; QString localFilename() const override; QJsonObject serialized() const override; @@ -63,7 +66,7 @@ public: public: // for usage by format parsers only void setType(const QString &type); void setTime(const qint64 time); - void setRequires(const QVector &requires); + void setRequires(const QVector &requires); void setData(const VersionFilePtr &data); signals: @@ -76,8 +79,9 @@ private: QString m_version; QString m_type; qint64 m_time; - QVector m_requires; + QVector m_requires; VersionFilePtr m_data; }; +} -Q_DECLARE_METATYPE(WonkoVersionPtr) +Q_DECLARE_METATYPE(Meta::VersionPtr) diff --git a/api/logic/wonko/WonkoVersionList.cpp b/api/logic/meta/VersionList.cpp similarity index 62% rename from api/logic/wonko/WonkoVersionList.cpp rename to api/logic/meta/VersionList.cpp index 191e00f9..11e20c12 100644 --- a/api/logic/wonko/WonkoVersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -13,21 +13,24 @@ * limitations under the License. */ -#include "WonkoVersionList.h" +#include "VersionList.h" #include -#include "WonkoVersion.h" -#include "tasks/BaseWonkoEntityRemoteLoadTask.h" -#include "tasks/BaseWonkoEntityLocalLoadTask.h" -#include "format/WonkoFormat.h" -#include "WonkoReference.h" +#include "Version.h" +#include "tasks/RemoteLoadTask.h" +#include "tasks/LocalLoadTask.h" +#include "format/Format.h" +#include "Reference.h" + +namespace Meta +{ class WVLLoadTask : public Task { Q_OBJECT public: - explicit WVLLoadTask(WonkoVersionList *list, QObject *parent = nullptr) + explicit WVLLoadTask(VersionList *list, QObject *parent = nullptr) : Task(parent), m_list(list) { } @@ -69,53 +72,53 @@ private: m_currentTask->start(); } - WonkoVersionList *m_list; + VersionList *m_list; std::unique_ptr m_currentTask; }; -WonkoVersionList::WonkoVersionList(const QString &uid, QObject *parent) +VersionList::VersionList(const QString &uid, QObject *parent) : BaseVersionList(parent), m_uid(uid) { - setObjectName("Wonko version list: " + uid); + setObjectName("Version list: " + uid); } -Task *WonkoVersionList::getLoadTask() +Task *VersionList::getLoadTask() { return new WVLLoadTask(this); } -bool WonkoVersionList::isLoaded() +bool VersionList::isLoaded() { return isLocalLoaded() && isRemoteLoaded(); } -const BaseVersionPtr WonkoVersionList::at(int i) const +const BaseVersionPtr VersionList::at(int i) const { return m_versions.at(i); } -int WonkoVersionList::count() const +int VersionList::count() const { return m_versions.size(); } -void WonkoVersionList::sortVersions() +void VersionList::sortVersions() { beginResetModel(); - std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b) + std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b) { return *a.get() < *b.get(); }); endResetModel(); } -QVariant WonkoVersionList::data(const QModelIndex &index, int role) const +QVariant VersionList::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.row() < 0 || index.row() >= m_versions.size() || index.parent().isValid()) { return QVariant(); } - WonkoVersionPtr version = m_versions.at(index.row()); + VersionPtr version = m_versions.at(index.row()); switch (role) { @@ -127,7 +130,7 @@ QVariant WonkoVersionList::data(const QModelIndex &index, int role) const { const auto end = version->requires().end(); const auto it = std::find_if(version->requires().begin(), end, - [](const WonkoReference &ref) { return ref.uid() == "net.minecraft"; }); + [](const Reference &ref) { return ref.uid() == "net.minecraft"; }); if (it != end) { return (*it).version(); @@ -140,21 +143,21 @@ QVariant WonkoVersionList::data(const QModelIndex &index, int role) const case TimeRole: return version->time(); case RequiresRole: return QVariant::fromValue(version->requires()); case SortRole: return version->rawTime(); - case WonkoVersionPtrRole: return QVariant::fromValue(version); + case VersionPtrRole: return QVariant::fromValue(version); case RecommendedRole: return version == getRecommended(); case LatestRole: return version == getLatestStable(); default: return QVariant(); } } -BaseVersionList::RoleList WonkoVersionList::providesRoles() const +BaseVersionList::RoleList VersionList::providesRoles() const { return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, TypeRole, UidRole, TimeRole, RequiresRole, SortRole, - RecommendedRole, LatestRole, WonkoVersionPtrRole}; + RecommendedRole, LatestRole, VersionPtrRole}; } -QHash WonkoVersionList::roleNames() const +QHash VersionList::roleNames() const { QHash roles = BaseVersionList::roleNames(); roles.insert(UidRole, "uid"); @@ -164,48 +167,48 @@ QHash WonkoVersionList::roleNames() const return roles; } -std::unique_ptr WonkoVersionList::remoteUpdateTask() +std::unique_ptr VersionList::remoteUpdateTask() { - return std::unique_ptr(new WonkoVersionListRemoteLoadTask(this, this)); + return std::unique_ptr(new VersionListRemoteLoadTask(this, this)); } -std::unique_ptr WonkoVersionList::localUpdateTask() +std::unique_ptr VersionList::localUpdateTask() { - return std::unique_ptr(new WonkoVersionListLocalLoadTask(this, this)); + return std::unique_ptr(new VersionListLocalLoadTask(this, this)); } -QString WonkoVersionList::localFilename() const +QString VersionList::localFilename() const { return m_uid + ".json"; } -QJsonObject WonkoVersionList::serialized() const +QJsonObject VersionList::serialized() const { - return WonkoFormat::serializeVersionList(this); + return Format::serializeVersionList(this); } -QString WonkoVersionList::humanReadable() const +QString VersionList::humanReadable() const { return m_name.isEmpty() ? m_uid : m_name; } -bool WonkoVersionList::hasVersion(const QString &version) const +bool VersionList::hasVersion(const QString &version) const { return m_lookup.contains(version); } -WonkoVersionPtr WonkoVersionList::getVersion(const QString &version) const +VersionPtr VersionList::getVersion(const QString &version) const { return m_lookup.value(version); } -void WonkoVersionList::setName(const QString &name) +void VersionList::setName(const QString &name) { m_name = name; emit nameChanged(name); } -void WonkoVersionList::setVersions(const QVector &versions) +void VersionList::setVersions(const QVector &versions) { beginResetModel(); m_versions = versions; - std::sort(m_versions.begin(), m_versions.end(), [](const WonkoVersionPtr &a, const WonkoVersionPtr &b) + std::sort(m_versions.begin(), m_versions.end(), [](const VersionPtr &a, const VersionPtr &b) { return a->rawTime() > b->rawTime(); }); @@ -216,14 +219,14 @@ void WonkoVersionList::setVersions(const QVector &versions) } m_latest = m_versions.isEmpty() ? nullptr : m_versions.first(); - auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const WonkoVersionPtr &ptr) { return ptr->type() == "release"; }); + auto recommendedIt = std::find_if(m_versions.constBegin(), m_versions.constEnd(), [](const VersionPtr &ptr) { return ptr->type() == "release"; }); m_recommended = recommendedIt == m_versions.constEnd() ? nullptr : *recommendedIt; endResetModel(); } -void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other) +void VersionList::merge(const BaseEntity::Ptr &other) { - const WonkoVersionListPtr list = std::dynamic_pointer_cast(other); + const VersionListPtr list = std::dynamic_pointer_cast(other); if (m_name != list->m_name) { setName(list->m_name); @@ -235,7 +238,7 @@ void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other) } else { - for (const WonkoVersionPtr &version : list->m_versions) + for (const VersionPtr &version : list->m_versions) { if (m_lookup.contains(version->version())) { @@ -264,20 +267,22 @@ void WonkoVersionList::merge(const BaseWonkoEntity::Ptr &other) } } -void WonkoVersionList::setupAddedVersion(const int row, const WonkoVersionPtr &version) +void VersionList::setupAddedVersion(const int row, const VersionPtr &version) { - connect(version.get(), &WonkoVersion::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << RequiresRole); }); - connect(version.get(), &WonkoVersion::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TimeRole << SortRole); }); - connect(version.get(), &WonkoVersion::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TypeRole); }); + connect(version.get(), &Version::requiresChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << RequiresRole); }); + connect(version.get(), &Version::timeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TimeRole << SortRole); }); + connect(version.get(), &Version::typeChanged, this, [this, row]() { emit dataChanged(index(row), index(row), QVector() << TypeRole); }); } -BaseVersionPtr WonkoVersionList::getLatestStable() const +BaseVersionPtr VersionList::getLatestStable() const { return m_latest; } -BaseVersionPtr WonkoVersionList::getRecommended() const +BaseVersionPtr VersionList::getRecommended() const { return m_recommended; } -#include "WonkoVersionList.moc" +} + +#include "VersionList.moc" diff --git a/api/logic/wonko/WonkoVersionList.h b/api/logic/meta/VersionList.h similarity index 67% rename from api/logic/wonko/WonkoVersionList.h rename to api/logic/meta/VersionList.h index 43cf73fc..0eb85bf8 100644 --- a/api/logic/wonko/WonkoVersionList.h +++ b/api/logic/meta/VersionList.h @@ -16,26 +16,28 @@ #pragma once #include "BaseVersionList.h" -#include "BaseWonkoEntity.h" +#include "BaseEntity.h" #include -using WonkoVersionPtr = std::shared_ptr; -using WonkoVersionListPtr = std::shared_ptr; +namespace Meta +{ +using VersionPtr = std::shared_ptr; +using VersionListPtr = std::shared_ptr; -class MULTIMC_LOGIC_EXPORT WonkoVersionList : public BaseVersionList, public BaseWonkoEntity +class MULTIMC_LOGIC_EXPORT VersionList : public BaseVersionList, public BaseEntity { Q_OBJECT Q_PROPERTY(QString uid READ uid CONSTANT) Q_PROPERTY(QString name READ name NOTIFY nameChanged) public: - explicit WonkoVersionList(const QString &uid, QObject *parent = nullptr); + explicit VersionList(const QString &uid, QObject *parent = nullptr); enum Roles { UidRole = Qt::UserRole + 100, TimeRole, RequiresRole, - WonkoVersionPtrRole + VersionPtrRole }; Task *getLoadTask() override; @@ -62,31 +64,32 @@ public: QString humanReadable() const; bool hasVersion(const QString &version) const; - WonkoVersionPtr getVersion(const QString &version) const; + VersionPtr getVersion(const QString &version) const; - QVector versions() const { return m_versions; } + QVector versions() const { return m_versions; } public: // for usage only by parsers void setName(const QString &name); - void setVersions(const QVector &versions); - void merge(const BaseWonkoEntity::Ptr &other); + void setVersions(const QVector &versions); + void merge(const BaseEntity::Ptr &other) override; signals: void nameChanged(const QString &name); protected slots: - void updateListData(QList versions) override {} + void updateListData(QList) override {} private: - QVector m_versions; - QHash m_lookup; + QVector m_versions; + QHash m_lookup; QString m_uid; QString m_name; - WonkoVersionPtr m_recommended; - WonkoVersionPtr m_latest; + VersionPtr m_recommended; + VersionPtr m_latest; - void setupAddedVersion(const int row, const WonkoVersionPtr &version); + void setupAddedVersion(const int row, const VersionPtr &version); }; -Q_DECLARE_METATYPE(WonkoVersionListPtr) +} +Q_DECLARE_METATYPE(Meta::VersionListPtr) diff --git a/api/logic/meta/format/Format.cpp b/api/logic/meta/format/Format.cpp new file mode 100644 index 00000000..a3f9f730 --- /dev/null +++ b/api/logic/meta/format/Format.cpp @@ -0,0 +1,84 @@ +/* Copyright 2015-2017 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Format.h" + +#include "FormatV1.h" + +#include "meta/Index.h" +#include "meta/Version.h" +#include "meta/VersionList.h" + +namespace Meta +{ + +static int formatVersion(const QJsonObject &obj) +{ + if (!obj.contains("formatVersion")) { + throw ParseException(QObject::tr("Missing required field: 'formatVersion'")); + } + if (!obj.value("formatVersion").isDouble()) { + throw ParseException(QObject::tr("Required field has invalid type: 'formatVersion'")); + } + return obj.value("formatVersion").toInt(); +} + +void Format::parseIndex(const QJsonObject &obj, Index *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 1: + ptr->merge(FormatV1().parseIndexInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} +void Format::parseVersion(const QJsonObject &obj, Version *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 1: + ptr->merge(FormatV1().parseVersionInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} +void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 10: + ptr->merge(FormatV1().parseVersionListInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} + +QJsonObject Format::serializeIndex(const Index *ptr) +{ + return FormatV1().serializeIndexInternal(ptr); +} +QJsonObject Format::serializeVersion(const Version *ptr) +{ + return FormatV1().serializeVersionInternal(ptr); +} +QJsonObject Format::serializeVersionList(const VersionList *ptr) +{ + return FormatV1().serializeVersionListInternal(ptr); +} +} diff --git a/api/logic/meta/format/Format.h b/api/logic/meta/format/Format.h new file mode 100644 index 00000000..79605a6f --- /dev/null +++ b/api/logic/meta/format/Format.h @@ -0,0 +1,57 @@ +/* Copyright 2015-2017 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "Exception.h" +#include "meta/BaseEntity.h" + +namespace Meta +{ +class Index; +class Version; +class VersionList; + +class ParseException : public Exception +{ +public: + using Exception::Exception; +}; + +class Format +{ +public: + virtual ~Format() {} + + static void parseIndex(const QJsonObject &obj, Index *ptr); + static void parseVersion(const QJsonObject &obj, Version *ptr); + static void parseVersionList(const QJsonObject &obj, VersionList *ptr); + + static QJsonObject serializeIndex(const Index *ptr); + static QJsonObject serializeVersion(const Version *ptr); + static QJsonObject serializeVersionList(const VersionList *ptr); + +protected: + virtual BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) const = 0; + virtual BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) const = 0; + virtual BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const = 0; + virtual QJsonObject serializeIndexInternal(const Index *ptr) const = 0; + virtual QJsonObject serializeVersionInternal(const Version *ptr) const = 0; + virtual QJsonObject serializeVersionListInternal(const VersionList *ptr) const = 0; +}; +} diff --git a/api/logic/wonko/format/WonkoFormatV1.cpp b/api/logic/meta/format/FormatV1.cpp similarity index 69% rename from api/logic/wonko/format/WonkoFormatV1.cpp rename to api/logic/meta/format/FormatV1.cpp index 4cecb42f..23f57100 100644 --- a/api/logic/wonko/format/WonkoFormatV1.cpp +++ b/api/logic/meta/format/FormatV1.cpp @@ -13,31 +13,33 @@ * limitations under the License. */ -#include "WonkoFormatV1.h" +#include "FormatV1.h" #include #include "Json.h" -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" +#include "meta/Index.h" +#include "meta/Version.h" +#include "meta/VersionList.h" #include "Env.h" using namespace Json; -static WonkoVersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) +namespace Meta +{ +static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) { const QVector requiresRaw = obj.contains("requires") ? requireIsArrayOf(obj, "requires") : QVector(); - QVector requires; + QVector requires; requires.reserve(requiresRaw.size()); std::transform(requiresRaw.begin(), requiresRaw.end(), std::back_inserter(requires), [](const QJsonObject &rObj) { - WonkoReference ref(requireString(rObj, "uid")); + Reference ref(requireString(rObj, "uid")); ref.setVersion(ensureString(rObj, "version", QString())); return ref; }); - WonkoVersionPtr version = std::make_shared(uid, requireString(obj, "version")); + VersionPtr version = std::make_shared(uid, requireString(obj, "version")); if (obj.value("time").isString()) { version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000); @@ -50,10 +52,10 @@ static WonkoVersionPtr parseCommonVersion(const QString &uid, const QJsonObject version->setRequires(requires); return version; } -static void serializeCommonVersion(const WonkoVersion *version, QJsonObject &obj) +static void serializeCommonVersion(const Version *version, QJsonObject &obj) { QJsonArray requires; - for (const WonkoReference &ref : version->requires()) + for (const Reference &ref : version->requires()) { if (ref.version().isEmpty()) { @@ -76,48 +78,48 @@ static void serializeCommonVersion(const WonkoVersion *version, QJsonObject &obj obj.insert("requires", requires); } -BaseWonkoEntity::Ptr WonkoFormatV1::parseIndexInternal(const QJsonObject &obj) const +BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const { const QVector objects = requireIsArrayOf(obj, "index"); - QVector lists; + QVector lists; lists.reserve(objects.size()); std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) { - WonkoVersionListPtr list = std::make_shared(requireString(obj, "uid")); + VersionListPtr list = std::make_shared(requireString(obj, "uid")); list->setName(ensureString(obj, "name", QString())); return list; }); - return std::make_shared(lists); + return std::make_shared(lists); } -BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionInternal(const QJsonObject &obj) const +BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const { - WonkoVersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); + VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), QString("%1/%2.json").arg(version->uid(), version->version()), obj.contains("order"))); return version; } -BaseWonkoEntity::Ptr WonkoFormatV1::parseVersionListInternal(const QJsonObject &obj) const +BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const { const QString uid = requireString(obj, "uid"); const QVector versionsRaw = requireIsArrayOf(obj, "versions"); - QVector versions; + QVector versions; versions.reserve(versionsRaw.size()); std::transform(versionsRaw.begin(), versionsRaw.end(), std::back_inserter(versions), [this, uid](const QJsonObject &vObj) { return parseCommonVersion(uid, vObj); }); - WonkoVersionListPtr list = std::make_shared(uid); + VersionListPtr list = std::make_shared(uid); list->setName(ensureString(obj, "name", QString())); list->setVersions(versions); return list; } -QJsonObject WonkoFormatV1::serializeIndexInternal(const WonkoIndex *ptr) const +QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const { QJsonArray index; - for (const WonkoVersionListPtr &list : ptr->lists()) + for (const VersionListPtr &list : ptr->lists()) { QJsonObject out; out["uid"] = list->uid(); @@ -129,21 +131,21 @@ QJsonObject WonkoFormatV1::serializeIndexInternal(const WonkoIndex *ptr) const out["index"] = index; return out; } -QJsonObject WonkoFormatV1::serializeVersionInternal(const WonkoVersion *ptr) const +QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const { QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); serializeCommonVersion(ptr, obj); obj.insert("formatVersion", 1); obj.insert("uid", ptr->uid()); // TODO: the name should be looked up in the UI based on the uid - obj.insert("name", ENV.wonkoIndex()->getListGuaranteed(ptr->uid())->name()); + obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name()); return obj; } -QJsonObject WonkoFormatV1::serializeVersionListInternal(const WonkoVersionList *ptr) const +QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const { QJsonArray versions; - for (const WonkoVersionPtr &version : ptr->versions()) + for (const VersionPtr &version : ptr->versions()) { QJsonObject obj; serializeCommonVersion(version.get(), obj); @@ -156,3 +158,4 @@ QJsonObject WonkoFormatV1::serializeVersionListInternal(const WonkoVersionList * out["versions"] = versions; return out; } +} diff --git a/api/logic/wonko/format/WonkoFormatV1.h b/api/logic/meta/format/FormatV1.h similarity index 53% rename from api/logic/wonko/format/WonkoFormatV1.h rename to api/logic/meta/format/FormatV1.h index 2ae3acd1..ab986083 100644 --- a/api/logic/wonko/format/WonkoFormatV1.h +++ b/api/logic/meta/format/FormatV1.h @@ -15,16 +15,19 @@ #pragma once -#include "WonkoFormat.h" +#include "Format.h" -class WonkoFormatV1 : public WonkoFormat +namespace Meta +{ +class FormatV1 : public Format { public: - BaseWonkoEntity::Ptr parseIndexInternal(const QJsonObject &obj) const override; - BaseWonkoEntity::Ptr parseVersionInternal(const QJsonObject &obj) const override; - BaseWonkoEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const override; + BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) const override; + BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) const override; + BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const override; - QJsonObject serializeIndexInternal(const WonkoIndex *ptr) const override; - QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const override; - QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const override; + QJsonObject serializeIndexInternal(const Index *ptr) const override; + QJsonObject serializeVersionInternal(const Version *ptr) const override; + QJsonObject serializeVersionListInternal(const VersionList *ptr) const override; }; +} diff --git a/api/logic/meta/tasks/LocalLoadTask.cpp b/api/logic/meta/tasks/LocalLoadTask.cpp new file mode 100644 index 00000000..33ea8016 --- /dev/null +++ b/api/logic/meta/tasks/LocalLoadTask.cpp @@ -0,0 +1,123 @@ +/* Copyright 2015-2017 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LocalLoadTask.h" + +#include + +#include "meta/format/Format.h" +#include "meta/Util.h" +#include "meta/Index.h" +#include "meta/Version.h" +#include "meta/VersionList.h" +#include "Env.h" +#include "Json.h" + +namespace Meta +{ +LocalLoadTask::LocalLoadTask(BaseEntity *entity, QObject *parent) + : Task(parent), m_entity(entity) +{ +} + +void LocalLoadTask::executeTask() +{ + const QString fname = Meta::localDir().absoluteFilePath(filename()); + if (!QFile::exists(fname)) + { + emitFailed(tr("File doesn't exist")); + return; + } + + setStatus(tr("Reading %1...").arg(name())); + setProgress(0, 0); + + try + { + parse(Json::requireObject(Json::requireDocument(fname, name()), name())); + m_entity->notifyLocalLoadComplete(); + emitSucceeded(); + } + catch (Exception &e) + { + emitFailed(tr("Unable to parse file %1: %2").arg(fname, e.cause())); + } +} + + +// INDEX +IndexLocalLoadTask::IndexLocalLoadTask(Index *index, QObject *parent) + : LocalLoadTask(index, parent) +{ +} +QString IndexLocalLoadTask::filename() const +{ + return "index.json"; +} +QString IndexLocalLoadTask::name() const +{ + return tr("Metadata Index"); +} +void IndexLocalLoadTask::parse(const QJsonObject &obj) const +{ + Format::parseIndex(obj, dynamic_cast(entity())); +} + + +// VERSION LIST +VersionListLocalLoadTask::VersionListLocalLoadTask(VersionList *list, QObject *parent) + : LocalLoadTask(list, parent) +{ +} +QString VersionListLocalLoadTask::filename() const +{ + return list()->uid() + ".json"; +} +QString VersionListLocalLoadTask::name() const +{ + return tr("Version List for %1").arg(list()->humanReadable()); +} +void VersionListLocalLoadTask::parse(const QJsonObject &obj) const +{ + Format::parseVersionList(obj, list()); +} +VersionList *VersionListLocalLoadTask::list() const +{ + return dynamic_cast(entity()); +} + + +// VERSION +VersionLocalLoadTask::VersionLocalLoadTask(Version *version, QObject *parent) + : LocalLoadTask(version, parent) +{ +} +QString VersionLocalLoadTask::filename() const +{ + return version()->uid() + "/" + version()->version() + ".json"; +} +QString VersionLocalLoadTask::name() const +{ + return tr(" Version for %1").arg(version()->name()); +} +void VersionLocalLoadTask::parse(const QJsonObject &obj) const +{ + Format::parseVersion(obj, version()); +} +Version *VersionLocalLoadTask::version() const +{ + return dynamic_cast(entity()); +} +} diff --git a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h b/api/logic/meta/tasks/LocalLoadTask.h similarity index 61% rename from api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h rename to api/logic/meta/tasks/LocalLoadTask.h index a4f530c7..36ae1b6f 100644 --- a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.h +++ b/api/logic/meta/tasks/LocalLoadTask.h @@ -18,64 +18,67 @@ #include "tasks/Task.h" #include -class BaseWonkoEntity; -class WonkoIndex; -class WonkoVersionList; -class WonkoVersion; +namespace Meta +{ +class BaseEntity; +class Index; +class VersionList; +class Version; -class BaseWonkoEntityLocalLoadTask : public Task +class LocalLoadTask : public Task { Q_OBJECT public: - explicit BaseWonkoEntityLocalLoadTask(BaseWonkoEntity *entity, QObject *parent = nullptr); + explicit LocalLoadTask(BaseEntity *entity, QObject *parent = nullptr); protected: virtual QString filename() const = 0; virtual QString name() const = 0; virtual void parse(const QJsonObject &obj) const = 0; - BaseWonkoEntity *entity() const { return m_entity; } + BaseEntity *entity() const { return m_entity; } private: void executeTask() override; - BaseWonkoEntity *m_entity; + BaseEntity *m_entity; }; -class WonkoIndexLocalLoadTask : public BaseWonkoEntityLocalLoadTask +class IndexLocalLoadTask : public LocalLoadTask { Q_OBJECT public: - explicit WonkoIndexLocalLoadTask(WonkoIndex *index, QObject *parent = nullptr); + explicit IndexLocalLoadTask(Index *index, QObject *parent = nullptr); private: QString filename() const override; QString name() const override; void parse(const QJsonObject &obj) const override; }; -class WonkoVersionListLocalLoadTask : public BaseWonkoEntityLocalLoadTask +class VersionListLocalLoadTask : public LocalLoadTask { Q_OBJECT public: - explicit WonkoVersionListLocalLoadTask(WonkoVersionList *list, QObject *parent = nullptr); + explicit VersionListLocalLoadTask(VersionList *list, QObject *parent = nullptr); private: QString filename() const override; QString name() const override; void parse(const QJsonObject &obj) const override; - WonkoVersionList *list() const; + VersionList *list() const; }; -class WonkoVersionLocalLoadTask : public BaseWonkoEntityLocalLoadTask +class VersionLocalLoadTask : public LocalLoadTask { Q_OBJECT public: - explicit WonkoVersionLocalLoadTask(WonkoVersion *version, QObject *parent = nullptr); + explicit VersionLocalLoadTask(Version *version, QObject *parent = nullptr); private: QString filename() const override; QString name() const override; void parse(const QJsonObject &obj) const override; - WonkoVersion *version() const; + Version *version() const; }; +} diff --git a/api/logic/meta/tasks/RemoteLoadTask.cpp b/api/logic/meta/tasks/RemoteLoadTask.cpp new file mode 100644 index 00000000..69a59c07 --- /dev/null +++ b/api/logic/meta/tasks/RemoteLoadTask.cpp @@ -0,0 +1,132 @@ +/* Copyright 2015-2017 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "RemoteLoadTask.h" + +#include "net/Download.h" +#include "net/HttpMetaCache.h" +#include "net/NetJob.h" +#include "meta/format/Format.h" +#include "meta/Util.h" +#include "meta/Index.h" +#include "meta/Version.h" +#include "meta/VersionList.h" +#include "Env.h" +#include "Json.h" + +namespace Meta +{ + +RemoteLoadTask::RemoteLoadTask(BaseEntity *entity, QObject *parent) + : Task(parent), m_entity(entity) +{ +} + +void RemoteLoadTask::executeTask() +{ + NetJob *job = new NetJob(name()); + + auto entry = ENV.metacache()->resolveEntry("meta", url().toString()); + entry->setStale(true); + m_dl = Net::Download::makeCached(url(), entry); + job->addNetAction(m_dl); + connect(job, &NetJob::failed, this, &RemoteLoadTask::emitFailed); + connect(job, &NetJob::succeeded, this, &RemoteLoadTask::networkFinished); + connect(job, &NetJob::status, this, &RemoteLoadTask::setStatus); + connect(job, &NetJob::progress, this, &RemoteLoadTask::setProgress); + job->start(); +} + +void RemoteLoadTask::networkFinished() +{ + setStatus(tr("Parsing...")); + setProgress(0, 0); + + try + { + parse(Json::requireObject(Json::requireDocument(m_dl->getTargetFilepath(), name()), name())); + m_entity->notifyRemoteLoadComplete(); + emitSucceeded(); + } + catch (Exception &e) + { + emitFailed(tr("Unable to parse response: %1").arg(e.cause())); + } +} + +// INDEX +IndexRemoteLoadTask::IndexRemoteLoadTask(Index *index, QObject *parent) + : RemoteLoadTask(index, parent) +{ +} +QUrl IndexRemoteLoadTask::url() const +{ + return Meta::indexUrl(); +} +QString IndexRemoteLoadTask::name() const +{ + return tr("Metadata Index"); +} +void IndexRemoteLoadTask::parse(const QJsonObject &obj) const +{ + Format::parseIndex(obj, dynamic_cast(entity())); +} + + +// VERSION LIST +VersionListRemoteLoadTask::VersionListRemoteLoadTask(VersionList *list, QObject *parent) + : RemoteLoadTask(list, parent) +{ +} +QUrl VersionListRemoteLoadTask::url() const +{ + return Meta::versionListUrl(list()->uid()); +} +QString VersionListRemoteLoadTask::name() const +{ + return tr("Version List for %1").arg(list()->humanReadable()); +} +void VersionListRemoteLoadTask::parse(const QJsonObject &obj) const +{ + Format::parseVersionList(obj, list()); +} +VersionList* Meta::VersionListRemoteLoadTask::list() const +{ + return dynamic_cast(entity()); +} + + +// VERSION +VersionRemoteLoadTask::VersionRemoteLoadTask(Version *version, QObject *parent) + : RemoteLoadTask(version, parent) +{ +} +QUrl VersionRemoteLoadTask::url() const +{ + return Meta::versionUrl(version()->uid(), version()->version()); +} +QString VersionRemoteLoadTask::name() const +{ + return tr("Meta Version for %1").arg(version()->name()); +} +void VersionRemoteLoadTask::parse(const QJsonObject &obj) const +{ + Format::parseVersion(obj, version()); +} +Version *VersionRemoteLoadTask::version() const +{ + return dynamic_cast(entity()); +} +} diff --git a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h b/api/logic/meta/tasks/RemoteLoadTask.h similarity index 61% rename from api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h rename to api/logic/meta/tasks/RemoteLoadTask.h index 0eab089a..3b09404f 100644 --- a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.h +++ b/api/logic/meta/tasks/RemoteLoadTask.h @@ -20,26 +20,28 @@ namespace Net { - class Download; +class Download; } -class BaseWonkoEntity; -class WonkoIndex; -class WonkoVersionList; -class WonkoVersion; +namespace Meta +{ +class BaseEntity; +class Index; +class VersionList; +class Version; -class BaseWonkoEntityRemoteLoadTask : public Task +class RemoteLoadTask : public Task { Q_OBJECT public: - explicit BaseWonkoEntityRemoteLoadTask(BaseWonkoEntity *entity, QObject *parent = nullptr); + explicit RemoteLoadTask(BaseEntity *entity, QObject *parent = nullptr); protected: virtual QUrl url() const = 0; virtual QString name() const = 0; virtual void parse(const QJsonObject &obj) const = 0; - BaseWonkoEntity *entity() const { return m_entity; } + BaseEntity *entity() const { return m_entity; } private slots: void networkFinished(); @@ -47,44 +49,47 @@ private slots: private: void executeTask() override; - BaseWonkoEntity *m_entity; + BaseEntity *m_entity; std::shared_ptr m_dl; }; -class WonkoIndexRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask +class IndexRemoteLoadTask : public RemoteLoadTask { Q_OBJECT public: - explicit WonkoIndexRemoteLoadTask(WonkoIndex *index, QObject *parent = nullptr); + explicit IndexRemoteLoadTask(Index *index, QObject *parent = nullptr); private: QUrl url() const override; QString name() const override; void parse(const QJsonObject &obj) const override; }; -class WonkoVersionListRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask + +class VersionListRemoteLoadTask : public RemoteLoadTask { Q_OBJECT public: - explicit WonkoVersionListRemoteLoadTask(WonkoVersionList *list, QObject *parent = nullptr); + explicit VersionListRemoteLoadTask(VersionList *list, QObject *parent = nullptr); private: QUrl url() const override; QString name() const override; void parse(const QJsonObject &obj) const override; - WonkoVersionList *list() const; + VersionList *list() const; }; -class WonkoVersionRemoteLoadTask : public BaseWonkoEntityRemoteLoadTask + +class VersionRemoteLoadTask : public RemoteLoadTask { Q_OBJECT public: - explicit WonkoVersionRemoteLoadTask(WonkoVersion *version, QObject *parent = nullptr); + explicit VersionRemoteLoadTask(Version *version, QObject *parent = nullptr); private: QUrl url() const override; QString name() const override; void parse(const QJsonObject &obj) const override; - WonkoVersion *version() const; + Version *version() const; }; +} diff --git a/api/logic/wonko/WonkoIndex_test.cpp b/api/logic/wonko/WonkoIndex_test.cpp deleted file mode 100644 index d7b92f21..00000000 --- a/api/logic/wonko/WonkoIndex_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include "TestUtil.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersionList.h" -#include "Env.h" - -class WonkoIndexTest : public QObject -{ - Q_OBJECT -private -slots: - void test_isProvidedByEnv() - { - QVERIFY(ENV.wonkoIndex()); - QCOMPARE(ENV.wonkoIndex(), ENV.wonkoIndex()); - } - - void test_providesTasks() - { - QVERIFY(ENV.wonkoIndex()->localUpdateTask() != nullptr); - QVERIFY(ENV.wonkoIndex()->remoteUpdateTask() != nullptr); - } - - void test_hasUid_and_getList() - { - WonkoIndex windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); - QVERIFY(windex.hasUid("list1")); - QVERIFY(!windex.hasUid("asdf")); - QVERIFY(windex.getList("list2") != nullptr); - QCOMPARE(windex.getList("list2")->uid(), QString("list2")); - QVERIFY(windex.getList("adsf") == nullptr); - } - - void test_merge() - { - WonkoIndex windex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr(new WonkoIndex({std::make_shared("list1"), std::make_shared("list2"), std::make_shared("list3")}))); - QCOMPARE(windex.lists().size(), 3); - windex.merge(std::shared_ptr(new WonkoIndex({std::make_shared("list4"), std::make_shared("list2"), std::make_shared("list5")}))); - QCOMPARE(windex.lists().size(), 5); - windex.merge(std::shared_ptr(new WonkoIndex({std::make_shared("list6")}))); - QCOMPARE(windex.lists().size(), 6); - } -}; - -QTEST_GUILESS_MAIN(WonkoIndexTest) - -#include "WonkoIndex_test.moc" diff --git a/api/logic/wonko/format/WonkoFormat.cpp b/api/logic/wonko/format/WonkoFormat.cpp deleted file mode 100644 index a5d593ca..00000000 --- a/api/logic/wonko/format/WonkoFormat.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WonkoFormat.h" - -#include "WonkoFormatV1.h" - -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" - -static int formatVersion(const QJsonObject &obj) -{ - if (!obj.contains("formatVersion")) { - throw WonkoParseException(QObject::tr("Missing required field: 'formatVersion'")); - } - if (!obj.value("formatVersion").isDouble()) { - throw WonkoParseException(QObject::tr("Required field has invalid type: 'formatVersion'")); - } - return obj.value("formatVersion").toInt(); -} - -void WonkoFormat::parseIndex(const QJsonObject &obj, WonkoIndex *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 1: - ptr->merge(WonkoFormatV1().parseIndexInternal(obj)); - break; - default: - throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} -void WonkoFormat::parseVersion(const QJsonObject &obj, WonkoVersion *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 1: - ptr->merge(WonkoFormatV1().parseVersionInternal(obj)); - break; - default: - throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} -void WonkoFormat::parseVersionList(const QJsonObject &obj, WonkoVersionList *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 10: - ptr->merge(WonkoFormatV1().parseVersionListInternal(obj)); - break; - default: - throw WonkoParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} - -QJsonObject WonkoFormat::serializeIndex(const WonkoIndex *ptr) -{ - return WonkoFormatV1().serializeIndexInternal(ptr); -} -QJsonObject WonkoFormat::serializeVersion(const WonkoVersion *ptr) -{ - return WonkoFormatV1().serializeVersionInternal(ptr); -} -QJsonObject WonkoFormat::serializeVersionList(const WonkoVersionList *ptr) -{ - return WonkoFormatV1().serializeVersionListInternal(ptr); -} diff --git a/api/logic/wonko/format/WonkoFormat.h b/api/logic/wonko/format/WonkoFormat.h deleted file mode 100644 index 63ea9473..00000000 --- a/api/logic/wonko/format/WonkoFormat.h +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "Exception.h" -#include "wonko/BaseWonkoEntity.h" - -class WonkoIndex; -class WonkoVersion; -class WonkoVersionList; - -class WonkoParseException : public Exception -{ -public: - using Exception::Exception; -}; - -class WonkoFormat -{ -public: - virtual ~WonkoFormat() {} - - static void parseIndex(const QJsonObject &obj, WonkoIndex *ptr); - static void parseVersion(const QJsonObject &obj, WonkoVersion *ptr); - static void parseVersionList(const QJsonObject &obj, WonkoVersionList *ptr); - - static QJsonObject serializeIndex(const WonkoIndex *ptr); - static QJsonObject serializeVersion(const WonkoVersion *ptr); - static QJsonObject serializeVersionList(const WonkoVersionList *ptr); - -protected: - virtual BaseWonkoEntity::Ptr parseIndexInternal(const QJsonObject &obj) const = 0; - virtual BaseWonkoEntity::Ptr parseVersionInternal(const QJsonObject &obj) const = 0; - virtual BaseWonkoEntity::Ptr parseVersionListInternal(const QJsonObject &obj) const = 0; - virtual QJsonObject serializeIndexInternal(const WonkoIndex *ptr) const = 0; - virtual QJsonObject serializeVersionInternal(const WonkoVersion *ptr) const = 0; - virtual QJsonObject serializeVersionListInternal(const WonkoVersionList *ptr) const = 0; -}; diff --git a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp b/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp deleted file mode 100644 index caffa744..00000000 --- a/api/logic/wonko/tasks/BaseWonkoEntityLocalLoadTask.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "BaseWonkoEntityLocalLoadTask.h" - -#include - -#include "wonko/format/WonkoFormat.h" -#include "wonko/WonkoUtil.h" -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" -#include "Env.h" -#include "Json.h" - -BaseWonkoEntityLocalLoadTask::BaseWonkoEntityLocalLoadTask(BaseWonkoEntity *entity, QObject *parent) - : Task(parent), m_entity(entity) -{ -} - -void BaseWonkoEntityLocalLoadTask::executeTask() -{ - const QString fname = Wonko::localWonkoDir().absoluteFilePath(filename()); - if (!QFile::exists(fname)) - { - emitFailed(tr("File doesn't exist")); - return; - } - - setStatus(tr("Reading %1...").arg(name())); - setProgress(0, 0); - - try - { - parse(Json::requireObject(Json::requireDocument(fname, name()), name())); - m_entity->notifyLocalLoadComplete(); - emitSucceeded(); - } - catch (Exception &e) - { - emitFailed(tr("Unable to parse file %1: %2").arg(fname, e.cause())); - } -} - -// WONKO INDEX // -WonkoIndexLocalLoadTask::WonkoIndexLocalLoadTask(WonkoIndex *index, QObject *parent) - : BaseWonkoEntityLocalLoadTask(index, parent) -{ -} -QString WonkoIndexLocalLoadTask::filename() const -{ - return "index.json"; -} -QString WonkoIndexLocalLoadTask::name() const -{ - return tr("Wonko Index"); -} -void WonkoIndexLocalLoadTask::parse(const QJsonObject &obj) const -{ - WonkoFormat::parseIndex(obj, dynamic_cast(entity())); -} - -// WONKO VERSION LIST // -WonkoVersionListLocalLoadTask::WonkoVersionListLocalLoadTask(WonkoVersionList *list, QObject *parent) - : BaseWonkoEntityLocalLoadTask(list, parent) -{ -} -QString WonkoVersionListLocalLoadTask::filename() const -{ - return list()->uid() + ".json"; -} -QString WonkoVersionListLocalLoadTask::name() const -{ - return tr("Wonko Version List for %1").arg(list()->humanReadable()); -} -void WonkoVersionListLocalLoadTask::parse(const QJsonObject &obj) const -{ - WonkoFormat::parseVersionList(obj, list()); -} -WonkoVersionList *WonkoVersionListLocalLoadTask::list() const -{ - return dynamic_cast(entity()); -} - -// WONKO VERSION // -WonkoVersionLocalLoadTask::WonkoVersionLocalLoadTask(WonkoVersion *version, QObject *parent) - : BaseWonkoEntityLocalLoadTask(version, parent) -{ -} -QString WonkoVersionLocalLoadTask::filename() const -{ - return version()->uid() + "/" + version()->version() + ".json"; -} -QString WonkoVersionLocalLoadTask::name() const -{ - return tr("Wonko Version for %1").arg(version()->name()); -} -void WonkoVersionLocalLoadTask::parse(const QJsonObject &obj) const -{ - WonkoFormat::parseVersion(obj, version()); -} -WonkoVersion *WonkoVersionLocalLoadTask::version() const -{ - return dynamic_cast(entity()); -} diff --git a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp b/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp deleted file mode 100644 index 999d245b..00000000 --- a/api/logic/wonko/tasks/BaseWonkoEntityRemoteLoadTask.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright 2015-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "BaseWonkoEntityRemoteLoadTask.h" - -#include "net/Download.h" -#include "net/HttpMetaCache.h" -#include "net/NetJob.h" -#include "wonko/format/WonkoFormat.h" -#include "wonko/WonkoUtil.h" -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersion.h" -#include "wonko/WonkoVersionList.h" -#include "Env.h" -#include "Json.h" - -BaseWonkoEntityRemoteLoadTask::BaseWonkoEntityRemoteLoadTask(BaseWonkoEntity *entity, QObject *parent) - : Task(parent), m_entity(entity) -{ -} - -void BaseWonkoEntityRemoteLoadTask::executeTask() -{ - NetJob *job = new NetJob(name()); - - auto entry = ENV.metacache()->resolveEntry("wonko", url().toString()); - entry->setStale(true); - m_dl = Net::Download::makeCached(url(), entry); - job->addNetAction(m_dl); - connect(job, &NetJob::failed, this, &BaseWonkoEntityRemoteLoadTask::emitFailed); - connect(job, &NetJob::succeeded, this, &BaseWonkoEntityRemoteLoadTask::networkFinished); - connect(job, &NetJob::status, this, &BaseWonkoEntityRemoteLoadTask::setStatus); - connect(job, &NetJob::progress, this, &BaseWonkoEntityRemoteLoadTask::setProgress); - job->start(); -} - -void BaseWonkoEntityRemoteLoadTask::networkFinished() -{ - setStatus(tr("Parsing...")); - setProgress(0, 0); - - try - { - parse(Json::requireObject(Json::requireDocument(m_dl->getTargetFilepath(), name()), name())); - m_entity->notifyRemoteLoadComplete(); - emitSucceeded(); - } - catch (Exception &e) - { - emitFailed(tr("Unable to parse response: %1").arg(e.cause())); - } -} - -// WONKO INDEX // -WonkoIndexRemoteLoadTask::WonkoIndexRemoteLoadTask(WonkoIndex *index, QObject *parent) - : BaseWonkoEntityRemoteLoadTask(index, parent) -{ -} -QUrl WonkoIndexRemoteLoadTask::url() const -{ - return Wonko::indexUrl(); -} -QString WonkoIndexRemoteLoadTask::name() const -{ - return tr("Wonko Index"); -} -void WonkoIndexRemoteLoadTask::parse(const QJsonObject &obj) const -{ - WonkoFormat::parseIndex(obj, dynamic_cast(entity())); -} - -// WONKO VERSION LIST // -WonkoVersionListRemoteLoadTask::WonkoVersionListRemoteLoadTask(WonkoVersionList *list, QObject *parent) - : BaseWonkoEntityRemoteLoadTask(list, parent) -{ -} -QUrl WonkoVersionListRemoteLoadTask::url() const -{ - return Wonko::versionListUrl(list()->uid()); -} -QString WonkoVersionListRemoteLoadTask::name() const -{ - return tr("Wonko Version List for %1").arg(list()->humanReadable()); -} -void WonkoVersionListRemoteLoadTask::parse(const QJsonObject &obj) const -{ - WonkoFormat::parseVersionList(obj, list()); -} -WonkoVersionList *WonkoVersionListRemoteLoadTask::list() const -{ - return dynamic_cast(entity()); -} - -// WONKO VERSION // -WonkoVersionRemoteLoadTask::WonkoVersionRemoteLoadTask(WonkoVersion *version, QObject *parent) - : BaseWonkoEntityRemoteLoadTask(version, parent) -{ -} -QUrl WonkoVersionRemoteLoadTask::url() const -{ - return Wonko::versionUrl(version()->uid(), version()->version()); -} -QString WonkoVersionRemoteLoadTask::name() const -{ - return tr("Wonko Version for %1").arg(version()->name()); -} -void WonkoVersionRemoteLoadTask::parse(const QJsonObject &obj) const -{ - WonkoFormat::parseVersion(obj, version()); -} -WonkoVersion *WonkoVersionRemoteLoadTask::version() const -{ - return dynamic_cast(entity()); -} diff --git a/application/BuildConfig.cpp.in b/application/BuildConfig.cpp.in index 70bc93d3..99551867 100644 --- a/application/BuildConfig.cpp.in +++ b/application/BuildConfig.cpp.in @@ -33,7 +33,6 @@ Config::Config() VERSION_STR = "@MultiMC_VERSION_STRING@"; NEWS_RSS_URL = "@MultiMC_NEWS_RSS_URL@"; PASTE_EE_KEY = "@MultiMC_PASTE_EE_API_KEY@"; - WONKO_ROOT_URL = "@MultiMC_WONKO_ROOT_URL@"; } QString Config::printableVersionString() const diff --git a/application/BuildConfig.h b/application/BuildConfig.h index 75109b1c..1c9466ba 100644 --- a/application/BuildConfig.h +++ b/application/BuildConfig.h @@ -60,11 +60,6 @@ public: */ QString PASTE_EE_KEY; - /** - * Root URL for wonko things. Other wonko URLs will be resolved relative to this. - */ - QString WONKO_ROOT_URL; - /** * \brief Converts the Version to a string. * \return The version number in string format (major.minor.revision.build). diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 90fa1aca..55457b1c 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -30,9 +30,6 @@ set(MultiMC_ANALYTICS_ID "" CACHE STRING "ID you can get from Google analytics") include(GetGitRevisionDescription) get_git_head_revision(MultiMC_GIT_REFSPEC MultiMC_GIT_COMMIT) -# Root URL for wonko files -set(MultiMC_WONKO_ROOT_URL "" CACHE STRING "Root URL for wonko stuff") - message(STATUS "Git commit: ${MultiMC_GIT_COMMIT}") message(STATUS "Git refspec: ${MultiMC_GIT_REFSPEC}") @@ -99,8 +96,6 @@ SET(MULTIMC_SOURCES VersionProxyModel.cpp ColorCache.h ColorCache.cpp - WonkoGui.h - WonkoGui.cpp # GUI - windows MainWindow.h @@ -189,8 +184,8 @@ SET(MULTIMC_SOURCES pages/global/ProxyPage.h pages/global/PasteEEPage.cpp pages/global/PasteEEPage.h - pages/global/WonkoPage.cpp - pages/global/WonkoPage.h + pages/global/MetadataPage.cpp + pages/global/MetadataPage.h # GUI - dialogs dialogs/AboutDialog.cpp @@ -289,7 +284,7 @@ SET(MULTIMC_UIS pages/global/MultiMCPage.ui pages/global/ProxyPage.ui pages/global/PasteEEPage.ui - pages/global/WonkoPage.ui + pages/global/MetadataPage.ui # Dialogs dialogs/CopyInstanceDialog.ui diff --git a/application/WonkoGui.cpp b/application/WonkoGui.cpp deleted file mode 100644 index 4d376fdc..00000000 --- a/application/WonkoGui.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "WonkoGui.h" - -#include "dialogs/ProgressDialog.h" -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersionList.h" -#include "wonko/WonkoVersion.h" -#include "Env.h" - -WonkoIndexPtr Wonko::ensureIndexLoaded(QWidget *parent) -{ - if (!ENV.wonkoIndex()->isLocalLoaded()) - { - ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->localUpdateTask()); - if (!ENV.wonkoIndex()->isRemoteLoaded() && ENV.wonkoIndex()->lists().size() == 0) - { - ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->remoteUpdateTask()); - } - } - return ENV.wonkoIndex(); -} - -WonkoVersionListPtr Wonko::ensureVersionListExists(const QString &uid, QWidget *parent) -{ - ensureIndexLoaded(parent); - if (!ENV.wonkoIndex()->isRemoteLoaded() && !ENV.wonkoIndex()->hasUid(uid)) - { - ProgressDialog(parent).execWithTask(ENV.wonkoIndex()->remoteUpdateTask()); - } - return ENV.wonkoIndex()->getList(uid); -} -WonkoVersionListPtr Wonko::ensureVersionListLoaded(const QString &uid, QWidget *parent) -{ - WonkoVersionListPtr list = ensureVersionListExists(uid, parent); - if (!list) - { - return nullptr; - } - if (!list->isLocalLoaded()) - { - ProgressDialog(parent).execWithTask(list->localUpdateTask()); - if (!list->isLocalLoaded()) - { - ProgressDialog(parent).execWithTask(list->remoteUpdateTask()); - } - } - return list->isComplete() ? list : nullptr; -} - -WonkoVersionPtr Wonko::ensureVersionExists(const QString &uid, const QString &version, QWidget *parent) -{ - WonkoVersionListPtr list = ensureVersionListLoaded(uid, parent); - if (!list) - { - return nullptr; - } - return list->getVersion(version); -} -WonkoVersionPtr Wonko::ensureVersionLoaded(const QString &uid, const QString &version, QWidget *parent, const UpdateType update) -{ - WonkoVersionPtr vptr = ensureVersionExists(uid, version, parent); - if (!vptr) - { - return nullptr; - } - if (!vptr->isLocalLoaded() || update == AlwaysUpdate) - { - ProgressDialog(parent).execWithTask(vptr->localUpdateTask()); - if (!vptr->isLocalLoaded() || update == AlwaysUpdate) - { - ProgressDialog(parent).execWithTask(vptr->remoteUpdateTask()); - } - } - return vptr->isComplete() ? vptr : nullptr; -} diff --git a/application/WonkoGui.h b/application/WonkoGui.h deleted file mode 100644 index ad0bee89..00000000 --- a/application/WonkoGui.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include "QObjectPtr.h" - -class QWidget; -class QString; - -using WonkoIndexPtr = shared_qobject_ptr; -using WonkoVersionListPtr = std::shared_ptr; -using WonkoVersionPtr = std::shared_ptr; - -namespace Wonko -{ -enum UpdateType -{ - AlwaysUpdate, - UpdateIfNeeded -}; - -/// Ensures that the index has been loaded, either from the local cache or remotely -WonkoIndexPtr ensureIndexLoaded(QWidget *parent); -/// Ensures that the given uid exists. Returns a nullptr if it doesn't. -WonkoVersionListPtr ensureVersionListExists(const QString &uid, QWidget *parent); -/// Ensures that the given uid exists and is loaded, either from the local cache or remotely. Returns nullptr if it doesn't exist or couldn't be loaded. -WonkoVersionListPtr ensureVersionListLoaded(const QString &uid, QWidget *parent); -WonkoVersionPtr ensureVersionExists(const QString &uid, const QString &version, QWidget *parent); -WonkoVersionPtr ensureVersionLoaded(const QString &uid, const QString &version, QWidget *parent, const UpdateType update = UpdateIfNeeded); -} diff --git a/application/pages/global/WonkoPage.cpp b/application/pages/global/MetadataPage.cpp similarity index 71% rename from application/pages/global/WonkoPage.cpp rename to application/pages/global/MetadataPage.cpp index 1a72b18d..4e355997 100644 --- a/application/pages/global/WonkoPage.cpp +++ b/application/pages/global/MetadataPage.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "WonkoPage.h" -#include "ui_WonkoPage.h" +#include "MetadataPage.h" +#include "ui_MetadataPage.h" #include #include @@ -23,18 +23,20 @@ #include "dialogs/ProgressDialog.h" #include "VersionProxyModel.h" -#include "wonko/WonkoIndex.h" -#include "wonko/WonkoVersionList.h" -#include "wonko/WonkoVersion.h" +#include "meta/Index.h" +#include "meta/VersionList.h" +#include "meta/Version.h" #include "Env.h" #include "MultiMC.h" -static QString formatRequires(const WonkoVersionPtr &version) +using namespace Meta; + +static QString formatRequires(const VersionPtr &version) { QStringList lines; - for (const WonkoReference &ref : version->requires()) + for (const Reference &ref : version->requires()) { - const QString readable = ENV.wonkoIndex()->hasUid(ref.uid()) ? ENV.wonkoIndex()->getList(ref.uid())->humanReadable() : ref.uid(); + const QString readable = ENV.metadataIndex()->hasUid(ref.uid()) ? ENV.metadataIndex()->getList(ref.uid())->humanReadable() : ref.uid(); if (ref.version().isEmpty()) { lines.append(readable); @@ -47,9 +49,9 @@ static QString formatRequires(const WonkoVersionPtr &version) return lines.join('\n'); } -WonkoPage::WonkoPage(QWidget *parent) : +MetadataPage::MetadataPage(QWidget *parent) : QWidget(parent), - ui(new Ui::WonkoPage) + ui(new Ui::MetadataPage) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -61,11 +63,11 @@ WonkoPage::WonkoPage(QWidget *parent) : m_fileProxy->setFilterRole(Qt::DisplayRole); m_fileProxy->setFilterKeyColumn(0); m_fileProxy->sort(0); - m_fileProxy->setSourceModel(ENV.wonkoIndex().get()); + m_fileProxy->setSourceModel(ENV.metadataIndex().get()); ui->indexView->setModel(m_fileProxy); m_filterProxy = new QSortFilterProxyModel(this); - m_filterProxy->setSortRole(WonkoVersionList::SortRole); + m_filterProxy->setSortRole(VersionList::SortRole); m_filterProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); m_filterProxy->setFilterRole(Qt::DisplayRole); m_filterProxy->setFilterKeyColumn(0); @@ -75,40 +77,40 @@ WonkoPage::WonkoPage(QWidget *parent) : m_versionProxy = new VersionProxyModel(this); m_filterProxy->setSourceModel(m_versionProxy); - connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WonkoPage::updateCurrentVersionList); - connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &WonkoPage::updateVersion); - connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &WonkoPage::versionListDataChanged); + connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateCurrentVersionList); + connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateVersion); + connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &MetadataPage::versionListDataChanged); updateCurrentVersionList(QModelIndex()); updateVersion(); } -WonkoPage::~WonkoPage() +MetadataPage::~MetadataPage() { delete ui; } -QIcon WonkoPage::icon() const +QIcon MetadataPage::icon() const { return MMC->getThemedIcon("looney"); } -void WonkoPage::on_refreshIndexBtn_clicked() +void MetadataPage::on_refreshIndexBtn_clicked() { - ProgressDialog(this).execWithTask(ENV.wonkoIndex()->remoteUpdateTask()); + ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); } -void WonkoPage::on_refreshFileBtn_clicked() +void MetadataPage::on_refreshFileBtn_clicked() { - WonkoVersionListPtr list = ui->indexView->currentIndex().data(WonkoIndex::ListPtrRole).value(); + VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value(); if (!list) { return; } ProgressDialog(this).execWithTask(list->remoteUpdateTask()); } -void WonkoPage::on_refreshVersionBtn_clicked() +void MetadataPage::on_refreshVersionBtn_clicked() { - WonkoVersionPtr version = ui->versionsView->currentIndex().data(WonkoVersionList::WonkoVersionPtrRole).value(); + VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value(); if (!version) { return; @@ -116,7 +118,7 @@ void WonkoPage::on_refreshVersionBtn_clicked() ProgressDialog(this).execWithTask(version->remoteUpdateTask()); } -void WonkoPage::on_fileSearchEdit_textChanged(const QString &search) +void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) { if (search.isEmpty()) { @@ -129,7 +131,7 @@ void WonkoPage::on_fileSearchEdit_textChanged(const QString &search) m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); } } -void WonkoPage::on_versionSearchEdit_textChanged(const QString &search) +void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) { if (search.isEmpty()) { @@ -143,11 +145,11 @@ void WonkoPage::on_versionSearchEdit_textChanged(const QString &search) } } -void WonkoPage::updateCurrentVersionList(const QModelIndex &index) +void MetadataPage::updateCurrentVersionList(const QModelIndex &index) { if (index.isValid()) { - WonkoVersionListPtr list = index.data(WonkoIndex::ListPtrRole).value(); + VersionListPtr list = index.data(Index::ListPtrRole).value(); ui->versionsBox->setEnabled(true); ui->refreshFileBtn->setEnabled(true); ui->fileUidLabel->setEnabled(true); @@ -183,7 +185,7 @@ void WonkoPage::updateCurrentVersionList(const QModelIndex &index) } } -void WonkoPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) +void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) { if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex())) { @@ -191,10 +193,10 @@ void WonkoPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex } } -void WonkoPage::updateVersion() +void MetadataPage::updateVersion() { - WonkoVersionPtr version = std::dynamic_pointer_cast( - ui->versionsView->currentIndex().data(WonkoVersionList::VersionPointerRole).value()); + VersionPtr version = std::dynamic_pointer_cast( + ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value()); if (version) { ui->refreshVersionBtn->setEnabled(true); @@ -223,16 +225,16 @@ void WonkoPage::updateVersion() } } -void WonkoPage::opened() +void MetadataPage::opened() { - if (!ENV.wonkoIndex()->isLocalLoaded()) + if (!ENV.metadataIndex()->isLocalLoaded()) { - std::unique_ptr task = ENV.wonkoIndex()->localUpdateTask(); + std::unique_ptr task = ENV.metadataIndex()->localUpdateTask(); connect(task.get(), &Task::finished, this, [this]() { - if (!ENV.wonkoIndex()->isRemoteLoaded()) + if (!ENV.metadataIndex()->isRemoteLoaded()) { - ProgressDialog(this).execWithTask(ENV.wonkoIndex()->remoteUpdateTask()); + ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); } }); ProgressDialog(this).execWithTask(task); diff --git a/application/pages/global/WonkoPage.h b/application/pages/global/MetadataPage.h similarity index 82% rename from application/pages/global/WonkoPage.h rename to application/pages/global/MetadataPage.h index 1d576c15..f75b4952 100644 --- a/application/pages/global/WonkoPage.h +++ b/application/pages/global/MetadataPage.h @@ -20,21 +20,21 @@ #include "pages/BasePage.h" namespace Ui { -class WonkoPage; +class MetadataPage; } class QSortFilterProxyModel; class VersionProxyModel; -class WonkoPage : public QWidget, public BasePage +class MetadataPage : public QWidget, public BasePage { Q_OBJECT public: - explicit WonkoPage(QWidget *parent = 0); - ~WonkoPage(); + explicit MetadataPage(QWidget *parent = 0); + ~MetadataPage(); - QString id() const override { return "wonko-global"; } - QString displayName() const override { return tr("Wonko"); } + QString id() const override { return "metadata-global"; } + QString displayName() const override { return tr("Metadata"); } QIcon icon() const override; void opened() override; @@ -48,7 +48,7 @@ private slots: void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br); private: - Ui::WonkoPage *ui; + Ui::MetadataPage *ui; QSortFilterProxyModel *m_fileProxy; QSortFilterProxyModel *m_filterProxy; VersionProxyModel *m_versionProxy; diff --git a/application/pages/global/WonkoPage.ui b/application/pages/global/MetadataPage.ui similarity index 99% rename from application/pages/global/WonkoPage.ui rename to application/pages/global/MetadataPage.ui index 2d14ceca..0bd33f32 100644 --- a/application/pages/global/WonkoPage.ui +++ b/application/pages/global/MetadataPage.ui @@ -1,7 +1,7 @@ - WonkoPage - + MetadataPage + 0 From 8321187a20eec9871f327aa23f421e79dcfdd409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 12 Mar 2017 16:00:06 +0100 Subject: [PATCH 05/28] NOISSUE fix downloading of metadata files --- api/logic/meta/Util.cpp | 2 +- api/logic/meta/VersionList.cpp | 2 +- api/logic/meta/format/Format.cpp | 40 +++--- api/logic/meta/format/FormatV1.cpp | 119 ++++++++++-------- application/CMakeLists.txt | 6 +- application/MultiMC.cpp | 2 + application/VersionProxyModel.cpp | 2 +- .../{MetadataPage.cpp => PackagesPage.cpp} | 42 +++---- .../global/{MetadataPage.h => PackagesPage.h} | 14 +-- .../{MetadataPage.ui => PackagesPage.ui} | 12 +- 10 files changed, 129 insertions(+), 112 deletions(-) rename application/pages/global/{MetadataPage.cpp => PackagesPage.cpp} (86%) rename application/pages/global/{MetadataPage.h => PackagesPage.h} (82%) rename application/pages/global/{MetadataPage.ui => PackagesPage.ui} (97%) diff --git a/api/logic/meta/Util.cpp b/api/logic/meta/Util.cpp index 2ccbe5c4..76941f83 100644 --- a/api/logic/meta/Util.cpp +++ b/api/logic/meta/Util.cpp @@ -34,7 +34,7 @@ QUrl indexUrl() QUrl versionListUrl(const QString &uid) { - return rootUrl().resolved(uid + ".json"); + return rootUrl().resolved(uid + "/index.json"); } QUrl versionUrl(const QString &uid, const QString &version) diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 11e20c12..aab3e0f7 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -178,7 +178,7 @@ std::unique_ptr VersionList::localUpdateTask() QString VersionList::localFilename() const { - return m_uid + ".json"; + return m_uid + "/index.json"; } QJsonObject VersionList::serialized() const { diff --git a/api/logic/meta/format/Format.cpp b/api/logic/meta/format/Format.cpp index a3f9f730..e0fddb0b 100644 --- a/api/logic/meta/format/Format.cpp +++ b/api/logic/meta/format/Format.cpp @@ -39,29 +39,19 @@ void Format::parseIndex(const QJsonObject &obj, Index *ptr) { const int version = formatVersion(obj); switch (version) { - case 1: + case 0: ptr->merge(FormatV1().parseIndexInternal(obj)); break; default: throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); } } -void Format::parseVersion(const QJsonObject &obj, Version *ptr) -{ - const int version = formatVersion(obj); - switch (version) { - case 1: - ptr->merge(FormatV1().parseVersionInternal(obj)); - break; - default: - throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); - } -} + void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr) { const int version = formatVersion(obj); switch (version) { - case 10: + case 0: ptr->merge(FormatV1().parseVersionListInternal(obj)); break; default: @@ -69,16 +59,32 @@ void Format::parseVersionList(const QJsonObject &obj, VersionList *ptr) } } +void Format::parseVersion(const QJsonObject &obj, Version *ptr) +{ + const int version = formatVersion(obj); + switch (version) { + case 0: + ptr->merge(FormatV1().parseVersionInternal(obj)); + break; + default: + throw ParseException(QObject::tr("Unknown formatVersion: %1").arg(version)); + } +} + + QJsonObject Format::serializeIndex(const Index *ptr) { return FormatV1().serializeIndexInternal(ptr); } -QJsonObject Format::serializeVersion(const Version *ptr) -{ - return FormatV1().serializeVersionInternal(ptr); -} + QJsonObject Format::serializeVersionList(const VersionList *ptr) { return FormatV1().serializeVersionListInternal(ptr); } + +QJsonObject Format::serializeVersion(const Version *ptr) +{ + return FormatV1().serializeVersionInternal(ptr); +} + } diff --git a/api/logic/meta/format/FormatV1.cpp b/api/logic/meta/format/FormatV1.cpp index 23f57100..ee2c5291 100644 --- a/api/logic/meta/format/FormatV1.cpp +++ b/api/logic/meta/format/FormatV1.cpp @@ -27,6 +27,44 @@ using namespace Json; namespace Meta { + +static const int currentFormatVersion = 0; + +// Index + +BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const +{ + const QVector objects = requireIsArrayOf(obj, "packages"); + QVector lists; + lists.reserve(objects.size()); + std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) + { + VersionListPtr list = std::make_shared(requireString(obj, "uid")); + list->setName(ensureString(obj, "name", QString())); + return list; + }); + return std::make_shared(lists); +} + +QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const +{ + QJsonArray packages; + for (const VersionListPtr &list : ptr->lists()) + { + QJsonObject out; + out["uid"] = list->uid(); + out["name"] = list->name(); + packages.append(out); + } + QJsonObject out; + out["formatVersion"] = currentFormatVersion; + out["packages"] = packages; + return out; +} + + +// Version + static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) { const QVector requiresRaw = obj.contains("requires") ? requireIsArrayOf(obj, "requires") : QVector(); @@ -40,18 +78,22 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) }); VersionPtr version = std::make_shared(uid, requireString(obj, "version")); - if (obj.value("time").isString()) - { - version->setTime(QDateTime::fromString(requireString(obj, "time"), Qt::ISODate).toMSecsSinceEpoch() / 1000); - } - else - { - version->setTime(requireInteger(obj, "time")); - } + version->setTime(QDateTime::fromString(requireString(obj, "releaseTime"), Qt::ISODate).toMSecsSinceEpoch() / 1000); version->setType(ensureString(obj, "type", QString())); version->setRequires(requires); return version; } + +BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const +{ + VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); + + version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), + QString("%1/%2.json").arg(version->uid(), version->version()), + obj.contains("order"))); + return version; +} + static void serializeCommonVersion(const Version *version, QJsonObject &obj) { QJsonArray requires; @@ -74,32 +116,25 @@ static void serializeCommonVersion(const Version *version, QJsonObject &obj) obj.insert("version", version->version()); obj.insert("type", version->type()); - obj.insert("time", version->time().toString(Qt::ISODate)); + obj.insert("releaseTime", version->time().toString(Qt::ISODate)); obj.insert("requires", requires); } -BaseEntity::Ptr FormatV1::parseIndexInternal(const QJsonObject &obj) const +QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const { - const QVector objects = requireIsArrayOf(obj, "index"); - QVector lists; - lists.reserve(objects.size()); - std::transform(objects.begin(), objects.end(), std::back_inserter(lists), [](const QJsonObject &obj) - { - VersionListPtr list = std::make_shared(requireString(obj, "uid")); - list->setName(ensureString(obj, "name", QString())); - return list; - }); - return std::make_shared(lists); -} -BaseEntity::Ptr FormatV1::parseVersionInternal(const QJsonObject &obj) const -{ - VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); + QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); + serializeCommonVersion(ptr, obj); + obj.insert("formatVersion", currentFormatVersion); + obj.insert("uid", ptr->uid()); + // TODO: the name should be looked up in the UI based on the uid + obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name()); - version->setData(OneSixVersionFormat::versionFileFromJson(QJsonDocument(obj), - QString("%1/%2.json").arg(version->uid(), version->version()), - obj.contains("order"))); - return version; + return obj; } + + +// Version list / package + BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const { const QString uid = requireString(obj, "uid"); @@ -116,32 +151,6 @@ BaseEntity::Ptr FormatV1::parseVersionListInternal(const QJsonObject &obj) const return list; } -QJsonObject FormatV1::serializeIndexInternal(const Index *ptr) const -{ - QJsonArray index; - for (const VersionListPtr &list : ptr->lists()) - { - QJsonObject out; - out["uid"] = list->uid(); - out["version"] = list->name(); - index.append(out); - } - QJsonObject out; - out["formatVersion"] = 1; - out["index"] = index; - return out; -} -QJsonObject FormatV1::serializeVersionInternal(const Version *ptr) const -{ - QJsonObject obj = OneSixVersionFormat::versionFileToJson(ptr->data(), true).object(); - serializeCommonVersion(ptr, obj); - obj.insert("formatVersion", 1); - obj.insert("uid", ptr->uid()); - // TODO: the name should be looked up in the UI based on the uid - obj.insert("name", ENV.metadataIndex()->getListGuaranteed(ptr->uid())->name()); - - return obj; -} QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const { QJsonArray versions; @@ -152,7 +161,7 @@ QJsonObject FormatV1::serializeVersionListInternal(const VersionList *ptr) const versions.append(obj); } QJsonObject out; - out["formatVersion"] = 10; + out["formatVersion"] = currentFormatVersion; out["uid"] = ptr->uid(); out["name"] = ptr->name().isNull() ? QJsonValue() : ptr->name(); out["versions"] = versions; diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 55457b1c..1b6ff3fd 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -184,8 +184,8 @@ SET(MULTIMC_SOURCES pages/global/ProxyPage.h pages/global/PasteEEPage.cpp pages/global/PasteEEPage.h - pages/global/MetadataPage.cpp - pages/global/MetadataPage.h + pages/global/PackagesPage.cpp + pages/global/PackagesPage.h # GUI - dialogs dialogs/AboutDialog.cpp @@ -284,7 +284,7 @@ SET(MULTIMC_UIS pages/global/MultiMCPage.ui pages/global/ProxyPage.ui pages/global/PasteEEPage.ui - pages/global/MetadataPage.ui + pages/global/PackagesPage.ui # Dialogs dialogs/CopyInstanceDialog.ui diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 081de41c..3a91fb5f 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -10,6 +10,7 @@ #include "pages/global/ExternalToolsPage.h" #include "pages/global/AccountListPage.h" #include "pages/global/PasteEEPage.h" +#include "pages/global/PackagesPage.h" #include "themes/ITheme.h" #include "themes/SystemTheme.h" @@ -842,6 +843,7 @@ void MultiMC::initGlobalSettings() m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); + m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); m_globalSettingsProvider->addPage(); diff --git a/application/VersionProxyModel.cpp b/application/VersionProxyModel.cpp index 22df7e09..50b94d9e 100644 --- a/application/VersionProxyModel.cpp +++ b/application/VersionProxyModel.cpp @@ -313,9 +313,9 @@ void VersionProxyModel::setSourceModel(QAbstractItemModel *replacingRaw) auto replacing = dynamic_cast(replacingRaw); beginResetModel(); + m_columns.clear(); if(!replacing) { - m_columns.clear(); roles.clear(); filterModel->setSourceModel(replacing); return; diff --git a/application/pages/global/MetadataPage.cpp b/application/pages/global/PackagesPage.cpp similarity index 86% rename from application/pages/global/MetadataPage.cpp rename to application/pages/global/PackagesPage.cpp index 4e355997..52efaf9a 100644 --- a/application/pages/global/MetadataPage.cpp +++ b/application/pages/global/PackagesPage.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "MetadataPage.h" -#include "ui_MetadataPage.h" +#include "PackagesPage.h" +#include "ui_PackagesPage.h" #include #include @@ -49,9 +49,9 @@ static QString formatRequires(const VersionPtr &version) return lines.join('\n'); } -MetadataPage::MetadataPage(QWidget *parent) : +PackagesPage::PackagesPage(QWidget *parent) : QWidget(parent), - ui(new Ui::MetadataPage) + ui(new Ui::PackagesPage) { ui->setupUi(this); ui->tabWidget->tabBar()->hide(); @@ -77,29 +77,29 @@ MetadataPage::MetadataPage(QWidget *parent) : m_versionProxy = new VersionProxyModel(this); m_filterProxy->setSourceModel(m_versionProxy); - connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateCurrentVersionList); - connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &MetadataPage::updateVersion); - connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &MetadataPage::versionListDataChanged); + connect(ui->indexView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateCurrentVersionList); + connect(ui->versionsView->selectionModel(), &QItemSelectionModel::currentChanged, this, &PackagesPage::updateVersion); + connect(m_filterProxy, &QSortFilterProxyModel::dataChanged, this, &PackagesPage::versionListDataChanged); updateCurrentVersionList(QModelIndex()); updateVersion(); } -MetadataPage::~MetadataPage() +PackagesPage::~PackagesPage() { delete ui; } -QIcon MetadataPage::icon() const +QIcon PackagesPage::icon() const { - return MMC->getThemedIcon("looney"); + return MMC->getThemedIcon("packages"); } -void MetadataPage::on_refreshIndexBtn_clicked() +void PackagesPage::on_refreshIndexBtn_clicked() { ProgressDialog(this).execWithTask(ENV.metadataIndex()->remoteUpdateTask()); } -void MetadataPage::on_refreshFileBtn_clicked() +void PackagesPage::on_refreshFileBtn_clicked() { VersionListPtr list = ui->indexView->currentIndex().data(Index::ListPtrRole).value(); if (!list) @@ -108,7 +108,7 @@ void MetadataPage::on_refreshFileBtn_clicked() } ProgressDialog(this).execWithTask(list->remoteUpdateTask()); } -void MetadataPage::on_refreshVersionBtn_clicked() +void PackagesPage::on_refreshVersionBtn_clicked() { VersionPtr version = ui->versionsView->currentIndex().data(VersionList::VersionPtrRole).value(); if (!version) @@ -118,7 +118,7 @@ void MetadataPage::on_refreshVersionBtn_clicked() ProgressDialog(this).execWithTask(version->remoteUpdateTask()); } -void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) +void PackagesPage::on_fileSearchEdit_textChanged(const QString &search) { if (search.isEmpty()) { @@ -131,7 +131,7 @@ void MetadataPage::on_fileSearchEdit_textChanged(const QString &search) m_fileProxy->setFilterRegExp(".*" + parts.join(".*") + ".*"); } } -void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) +void PackagesPage::on_versionSearchEdit_textChanged(const QString &search) { if (search.isEmpty()) { @@ -145,7 +145,7 @@ void MetadataPage::on_versionSearchEdit_textChanged(const QString &search) } } -void MetadataPage::updateCurrentVersionList(const QModelIndex &index) +void PackagesPage::updateCurrentVersionList(const QModelIndex &index) { if (index.isValid()) { @@ -181,11 +181,11 @@ void MetadataPage::updateCurrentVersionList(const QModelIndex &index) ui->fileNameLabel->setEnabled(false); ui->fileName->clear(); m_versionProxy->setSourceModel(nullptr); - ui->refreshFileBtn->setText(tr("Refresh ___")); + ui->refreshFileBtn->setText(tr("Refresh")); } } -void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) +void PackagesPage::versionListDataChanged(const QModelIndex &tl, const QModelIndex &br) { if (QItemSelection(tl, br).contains(ui->versionsView->currentIndex())) { @@ -193,7 +193,7 @@ void MetadataPage::versionListDataChanged(const QModelIndex &tl, const QModelInd } } -void MetadataPage::updateVersion() +void PackagesPage::updateVersion() { VersionPtr version = std::dynamic_pointer_cast( ui->versionsView->currentIndex().data(VersionList::VersionPointerRole).value()); @@ -221,11 +221,11 @@ void MetadataPage::updateVersion() ui->versionType->clear(); ui->versionRequiresLabel->setEnabled(false); ui->versionRequires->clear(); - ui->refreshVersionBtn->setText(tr("Refresh ___")); + ui->refreshVersionBtn->setText(tr("Refresh")); } } -void MetadataPage::opened() +void PackagesPage::opened() { if (!ENV.metadataIndex()->isLocalLoaded()) { diff --git a/application/pages/global/MetadataPage.h b/application/pages/global/PackagesPage.h similarity index 82% rename from application/pages/global/MetadataPage.h rename to application/pages/global/PackagesPage.h index f75b4952..80c2886d 100644 --- a/application/pages/global/MetadataPage.h +++ b/application/pages/global/PackagesPage.h @@ -20,21 +20,21 @@ #include "pages/BasePage.h" namespace Ui { -class MetadataPage; +class PackagesPage; } class QSortFilterProxyModel; class VersionProxyModel; -class MetadataPage : public QWidget, public BasePage +class PackagesPage : public QWidget, public BasePage { Q_OBJECT public: - explicit MetadataPage(QWidget *parent = 0); - ~MetadataPage(); + explicit PackagesPage(QWidget *parent = 0); + ~PackagesPage(); - QString id() const override { return "metadata-global"; } - QString displayName() const override { return tr("Metadata"); } + QString id() const override { return "packages-global"; } + QString displayName() const override { return tr("Packages"); } QIcon icon() const override; void opened() override; @@ -48,7 +48,7 @@ private slots: void versionListDataChanged(const QModelIndex &tl, const QModelIndex &br); private: - Ui::MetadataPage *ui; + Ui::PackagesPage *ui; QSortFilterProxyModel *m_fileProxy; QSortFilterProxyModel *m_filterProxy; VersionProxyModel *m_versionProxy; diff --git a/application/pages/global/MetadataPage.ui b/application/pages/global/PackagesPage.ui similarity index 97% rename from application/pages/global/MetadataPage.ui rename to application/pages/global/PackagesPage.ui index 0bd33f32..158bf1b4 100644 --- a/application/pages/global/MetadataPage.ui +++ b/application/pages/global/PackagesPage.ui @@ -1,13 +1,13 @@ - MetadataPage - + PackagesPage + 0 0 - 640 - 480 + 636 + 621 @@ -67,7 +67,7 @@ - Refresh ___ + Refresh @@ -180,7 +180,7 @@ - Refresh ___ + Refresh From 2980322c3b34b252ead838daee7a844853feccf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 12 Mar 2017 19:45:28 +0100 Subject: [PATCH 06/28] NOISSUE Remove Minecraft version list and versions. --- api/logic/BaseInstance.cpp | 1 - api/logic/CMakeLists.txt | 4 - api/logic/InstanceCreationTask.cpp | 4 +- api/logic/minecraft/MinecraftInstance.cpp | 3 +- api/logic/minecraft/MinecraftVersion.cpp | 230 ------- api/logic/minecraft/MinecraftVersion.h | 132 ---- api/logic/minecraft/MinecraftVersionList.cpp | 614 ------------------ api/logic/minecraft/MinecraftVersionList.h | 72 -- api/logic/minecraft/MojangVersionFormat.cpp | 1 - api/logic/minecraft/forge/ForgeInstaller.cpp | 9 +- .../minecraft/ftb/FTBInstanceProvider.cpp | 14 +- api/logic/minecraft/ftb/FTBPlugin.cpp | 2 - .../minecraft/ftb/FTBProfileStrategy.cpp | 1 - api/logic/minecraft/ftb/FTBVersion.h | 32 - api/logic/minecraft/legacy/LegacyUpdate.cpp | 1 - .../onesix/OneSixProfileStrategy.cpp | 3 +- api/logic/minecraft/onesix/OneSixUpdate.cpp | 3 +- .../minecraft/onesix/OneSixVersionFormat.cpp | 1 - application/MainWindow.cpp | 17 +- application/MainWindow.h | 1 - application/MultiMC.cpp | 12 - application/MultiMC.h | 3 - application/dialogs/NewInstanceDialog.cpp | 11 +- application/pages/VersionPage.cpp | 8 +- 24 files changed, 33 insertions(+), 1146 deletions(-) delete mode 100644 api/logic/minecraft/MinecraftVersion.cpp delete mode 100644 api/logic/minecraft/MinecraftVersion.h delete mode 100644 api/logic/minecraft/MinecraftVersionList.cpp delete mode 100644 api/logic/minecraft/MinecraftVersionList.h delete mode 100644 api/logic/minecraft/ftb/FTBVersion.h diff --git a/api/logic/BaseInstance.cpp b/api/logic/BaseInstance.cpp index 6d719c32..ee9e919d 100644 --- a/api/logic/BaseInstance.cpp +++ b/api/logic/BaseInstance.cpp @@ -23,7 +23,6 @@ #include "settings/Setting.h" #include "settings/OverrideSetting.h" -#include "minecraft/MinecraftVersionList.h" #include "FileSystem.h" #include "Commandline.h" diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index 1827b497..f14b8662 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -252,10 +252,6 @@ set(MINECRAFT_SOURCES minecraft/JarMod.h minecraft/MinecraftInstance.cpp minecraft/MinecraftInstance.h - minecraft/MinecraftVersion.cpp - minecraft/MinecraftVersion.h - minecraft/MinecraftVersionList.cpp - minecraft/MinecraftVersionList.h minecraft/Rule.cpp minecraft/Rule.h minecraft/OpSys.cpp diff --git a/api/logic/InstanceCreationTask.cpp b/api/logic/InstanceCreationTask.cpp index 00156701..e7b0de7c 100644 --- a/api/logic/InstanceCreationTask.cpp +++ b/api/logic/InstanceCreationTask.cpp @@ -4,7 +4,6 @@ #include "FileSystem.h" //FIXME: remove this -#include "minecraft/MinecraftVersion.h" #include "minecraft/onesix/OneSixInstance.h" InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInstanceProvider* target, BaseVersionPtr version, @@ -21,12 +20,14 @@ InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInsta void InstanceCreationTask::executeTask() { setStatus(tr("Creating instance from version %1").arg(m_version->name())); + /* auto minecraftVersion = std::dynamic_pointer_cast(m_version); if(!minecraftVersion) { emitFailed(tr("The supplied version is not a Minecraft version.")); return ; } + */ QString stagingPath = m_target->getStagedInstancePath(); QDir rootDir(stagingPath); @@ -34,7 +35,6 @@ void InstanceCreationTask::executeTask() auto instanceSettings = std::make_shared(FS::PathCombine(stagingPath, "instance.cfg")); instanceSettings->registerSetting("InstanceType", "Legacy"); - auto mcVer = std::dynamic_pointer_cast(m_version); instanceSettings->set("InstanceType", "OneSix"); InstancePtr inst(new OneSixInstance(m_globalSettings, instanceSettings, stagingPath)); inst->setIntendedVersionId(m_version->descriptor()); diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index 7b1aef1e..b88d0c2a 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -5,7 +5,6 @@ #include #include "settings/SettingsObject.h" #include "Env.h" -#include "minecraft/MinecraftVersionList.h" #include #include #include @@ -24,6 +23,8 @@ #include +#include + #define IBUS "@im=ibus" // all of this because keeping things compatible with deprecated old settings diff --git a/api/logic/minecraft/MinecraftVersion.cpp b/api/logic/minecraft/MinecraftVersion.cpp deleted file mode 100644 index 248c7eed..00000000 --- a/api/logic/minecraft/MinecraftVersion.cpp +++ /dev/null @@ -1,230 +0,0 @@ -#include "MinecraftVersion.h" -#include "MinecraftProfile.h" -#include "VersionBuildError.h" -#include "ProfileUtils.h" -#include "settings/SettingsObject.h" - -bool MinecraftVersion::usesLegacyLauncher() -{ - return m_traits.contains("legacyLaunch") || m_traits.contains("aplhaLaunch"); -} - -QString MinecraftVersion::descriptor() -{ - return m_descriptor; -} - -QString MinecraftVersion::name() -{ - return m_name; -} - -QString MinecraftVersion::typeString() const -{ - if(m_type == "snapshot") - { - return QObject::tr("Snapshot"); - } - else if (m_type == "release") - { - return QObject::tr("Regular release"); - } - else if (m_type == "old_alpha") - { - return QObject::tr("Alpha"); - } - else if (m_type == "old_beta") - { - return QObject::tr("Beta"); - } - else - { - return QString(); - } -} - -VersionSource MinecraftVersion::getVersionSource() -{ - return m_versionSource; -} - -bool MinecraftVersion::hasJarMods() -{ - return false; -} - -bool MinecraftVersion::isMinecraftVersion() -{ - return true; -} - -void MinecraftVersion::applyFileTo(MinecraftProfile *profile) -{ - if(m_versionSource == VersionSource::Local && getVersionFile()) - { - getVersionFile()->applyTo(profile); - } - else - { - throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name)); - } -} - -QString MinecraftVersion::getUrl() const -{ - // legacy fallback - if(m_versionFileURL.isEmpty()) - { - return QString("http://") + URLConstants::AWS_DOWNLOAD_VERSIONS + m_descriptor + "/" + m_descriptor + ".json"; - } - // current - return m_versionFileURL; -} - -VersionFilePtr MinecraftVersion::getVersionFile() -{ - QFileInfo versionFile(QString("versions/%1/%1.dat").arg(m_descriptor)); - m_problems.clear(); - m_problemSeverity = PROBLEM_NONE; - if(!versionFile.exists()) - { - if(m_loadedVersionFile) - { - m_loadedVersionFile.reset(); - } - addProblem(PROBLEM_WARNING, QObject::tr("The patch file doesn't exist locally. It's possible it just needs to be downloaded.")); - } - else - { - try - { - if(versionFile.lastModified() != m_loadedVersionFileTimestamp) - { - auto loadedVersionFile = ProfileUtils::parseBinaryJsonFile(versionFile); - loadedVersionFile->name = "Minecraft"; - loadedVersionFile->setCustomizable(true); - m_loadedVersionFileTimestamp = versionFile.lastModified(); - m_loadedVersionFile = loadedVersionFile; - } - } - catch(Exception e) - { - m_loadedVersionFile.reset(); - addProblem(PROBLEM_ERROR, QObject::tr("The patch file couldn't be read:\n%1").arg(e.cause())); - } - } - return m_loadedVersionFile; -} - -bool MinecraftVersion::isCustomizable() -{ - switch(m_versionSource) - { - case VersionSource::Local: - case VersionSource::Remote: - // locally cached file, or a remote file that we can acquire can be customized - return true; - case VersionSource::Builtin: - // builtins do not follow the normal OneSix format. They are not customizable. - default: - // Everything else is undefined and therefore not customizable. - return false; - } - return false; -} - -const QList &MinecraftVersion::getProblems() -{ - if(m_versionSource != VersionSource::Builtin && getVersionFile()) - { - return getVersionFile()->getProblems(); - } - return ProfilePatch::getProblems(); -} - -ProblemSeverity MinecraftVersion::getProblemSeverity() -{ - if(m_versionSource != VersionSource::Builtin && getVersionFile()) - { - return getVersionFile()->getProblemSeverity(); - } - return ProfilePatch::getProblemSeverity(); -} - -void MinecraftVersion::applyTo(MinecraftProfile *profile) -{ - // do we have this one cached? - if (m_versionSource == VersionSource::Local) - { - applyFileTo(profile); - return; - } - // if not builtin, do not proceed any further. - if (m_versionSource != VersionSource::Builtin) - { - throw VersionIncomplete(QObject::tr( - "Minecraft version %1 could not be applied: version files are missing.").arg(m_descriptor)); - } - profile->applyMinecraftVersion(m_descriptor); - profile->applyMainClass(m_mainClass); - profile->applyAppletClass(m_appletClass); - profile->applyMinecraftArguments(" ${auth_player_name} ${auth_session}"); // all builtin versions are legacy - profile->applyMinecraftVersionType(m_type); - profile->applyTraits(m_traits); - profile->applyProblemSeverity(m_problemSeverity); -} - -int MinecraftVersion::getOrder() -{ - return order; -} - -void MinecraftVersion::setOrder(int order) -{ - this->order = order; -} - -QList MinecraftVersion::getJarMods() -{ - return QList(); -} - -QString MinecraftVersion::getName() -{ - return "Minecraft"; -} -QString MinecraftVersion::getVersion() -{ - return m_descriptor; -} -QString MinecraftVersion::getID() -{ - return "net.minecraft"; -} -QString MinecraftVersion::getFilename() -{ - return QString(); -} -QDateTime MinecraftVersion::getReleaseDateTime() -{ - return m_releaseTime; -} - - -bool MinecraftVersion::needsUpdate() -{ - return m_versionSource == VersionSource::Remote || hasUpdate(); -} - -bool MinecraftVersion::hasUpdate() -{ - return m_versionSource == VersionSource::Remote || (m_versionSource == VersionSource::Local && upstreamUpdate); -} - -bool MinecraftVersion::isCustom() -{ - // if we add any other source types, this will evaluate to false for them. - return m_versionSource != VersionSource::Builtin - && m_versionSource != VersionSource::Local - && m_versionSource != VersionSource::Remote; -} diff --git a/api/logic/minecraft/MinecraftVersion.h b/api/logic/minecraft/MinecraftVersion.h deleted file mode 100644 index 7ac9bcbb..00000000 --- a/api/logic/minecraft/MinecraftVersion.h +++ /dev/null @@ -1,132 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -#include "BaseVersion.h" -#include "ProfilePatch.h" -#include "VersionFile.h" - -#include "multimc_logic_export.h" - -class MinecraftProfile; -class MinecraftVersion; -typedef std::shared_ptr MinecraftVersionPtr; - -class MULTIMC_LOGIC_EXPORT MinecraftVersion : public BaseVersion, public ProfilePatch -{ -friend class MinecraftVersionList; - -public: /* methods */ - bool usesLegacyLauncher(); - virtual QString descriptor() override; - virtual QString name() override; - virtual QString typeString() const override; - virtual bool hasJarMods() override; - virtual bool isMinecraftVersion() override; - virtual void applyTo(MinecraftProfile *profile) override; - virtual int getOrder() override; - virtual void setOrder(int order) override; - virtual QList getJarMods() override; - virtual QString getID() override; - virtual QString getVersion() override; - virtual QString getName() override; - virtual QString getFilename() override; - QDateTime getReleaseDateTime() override; - VersionSource getVersionSource() override; - - bool needsUpdate(); - bool hasUpdate(); - virtual bool isCustom() override; - virtual bool isMoveable() override - { - return false; - } - virtual bool isCustomizable() override; - virtual bool isRemovable() override - { - return false; - } - virtual bool isRevertible() override - { - return false; - } - virtual bool isEditable() override - { - return false; - } - virtual bool isVersionChangeable() override - { - return true; - } - - virtual VersionFilePtr getVersionFile() override; - - // virtual QJsonDocument toJson(bool saveOrder) override; - - QString getUrl() const; - - virtual const QList &getProblems() override; - virtual ProblemSeverity getProblemSeverity() override; - -private: /* methods */ - void applyFileTo(MinecraftProfile *profile); - -protected: /* data */ - VersionSource m_versionSource = VersionSource::Builtin; - - /// The URL that this version will be downloaded from. - QString m_versionFileURL; - - /// the human readable version name - QString m_name; - - /// the version ID. - QString m_descriptor; - - /// version traits. added by MultiMC - QSet m_traits; - - /// The main class this version uses (if any, can be empty). - QString m_mainClass; - - /// The applet class this version uses (if any, can be empty). - QString m_appletClass; - - /// The type of this release - QString m_type; - - /// the time this version was actually released by Mojang - QDateTime m_releaseTime; - - /// the time this version was last updated by Mojang - QDateTime m_updateTime; - - /// MD5 hash of the minecraft jar - QString m_jarChecksum; - - /// order of this file... default = -2 - int order = -2; - - /// an update available from Mojang - MinecraftVersionPtr upstreamUpdate; - - QDateTime m_loadedVersionFileTimestamp; - mutable VersionFilePtr m_loadedVersionFile; -}; diff --git a/api/logic/minecraft/MinecraftVersionList.cpp b/api/logic/minecraft/MinecraftVersionList.cpp deleted file mode 100644 index 0dc46289..00000000 --- a/api/logic/minecraft/MinecraftVersionList.cpp +++ /dev/null @@ -1,614 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "Json.h" -#include -#include - -#include "Env.h" -#include "Exception.h" - -#include "MinecraftVersionList.h" -#include "net/URLConstants.h" - -#include "ParseUtils.h" -#include "ProfileUtils.h" -#include "onesix/OneSixVersionFormat.h" -#include "MojangVersionFormat.h" -#include - -static const char * localVersionCache = "versions/versions.dat"; - -class MCVListLoadTask : public Task -{ - Q_OBJECT - -public: - explicit MCVListLoadTask(MinecraftVersionList *vlist); - virtual ~MCVListLoadTask() override{}; - - virtual void executeTask() override; - -protected -slots: - void list_downloaded(); - -protected: - QNetworkReply *vlistReply; - MinecraftVersionList *m_list; - MinecraftVersion *m_currentStable; -}; - -class MCVListVersionUpdateTask : public Task -{ - Q_OBJECT - -public: - explicit MCVListVersionUpdateTask(MinecraftVersionList *vlist, std::shared_ptr updatedVersion); - virtual ~MCVListVersionUpdateTask() override{}; - virtual void executeTask() override; - bool canAbort() const override; - -public slots: - bool abort() override; - -protected -slots: - void json_downloaded(); - -protected: - NetJobPtr specificVersionDownloadJob; - QByteArray versionIndexData; - std::shared_ptr updatedVersion; - MinecraftVersionList *m_list; - bool m_aborted = false; -}; - -class ListLoadError : public Exception -{ -public: - ListLoadError(QString cause) : Exception(cause) {}; - virtual ~ListLoadError() noexcept - { - } -}; - -MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent) -{ - loadCachedList(); -} - -Task *MinecraftVersionList::getLoadTask() -{ - return new MCVListLoadTask(this); -} - -bool MinecraftVersionList::isLoaded() -{ - return m_loaded; -} - -const BaseVersionPtr MinecraftVersionList::at(int i) const -{ - return m_vlist.at(i); -} - -int MinecraftVersionList::count() const -{ - return m_vlist.count(); -} - -static bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second) -{ - auto left = std::dynamic_pointer_cast(first); - auto right = std::dynamic_pointer_cast(second); - return left->getReleaseDateTime() > right->getReleaseDateTime(); -} - -void MinecraftVersionList::sortInternal() -{ - qSort(m_vlist.begin(), m_vlist.end(), cmpVersions); -} - -void MinecraftVersionList::loadCachedList() -{ - QFile localIndex(localVersionCache); - if (!localIndex.exists()) - { - return; - } - if (!localIndex.open(QIODevice::ReadOnly)) - { - // FIXME: this is actually a very bad thing! How do we deal with this? - qCritical() << "The minecraft version cache can't be read."; - return; - } - auto data = localIndex.readAll(); - try - { - localIndex.close(); - QJsonDocument jsonDoc = QJsonDocument::fromBinaryData(data); - if (jsonDoc.isNull()) - { - throw ListLoadError(tr("Error reading the version list.")); - } - loadMojangList(jsonDoc, VersionSource::Local); - } - catch (Exception &e) - { - // the cache has gone bad for some reason... flush it. - qCritical() << "The minecraft version cache is corrupted. Flushing cache."; - localIndex.remove(); - return; - } - m_hasLocalIndex = true; -} - -void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource source) -{ - qDebug() << "Loading" << ((source == VersionSource::Remote) ? "remote" : "local") << "version list."; - - if (!jsonDoc.isObject()) - { - throw ListLoadError(tr("Error parsing version list JSON: jsonDoc is not an object")); - } - - QJsonObject root = jsonDoc.object(); - - try - { - QJsonObject latest = Json::requireObject(root.value("latest")); - m_latestReleaseID = Json::requireString(latest.value("release")); - m_latestSnapshotID = Json::requireString(latest.value("snapshot")); - } - catch (Exception &err) - { - qCritical() - << tr("Error parsing version list JSON: couldn't determine latest versions"); - } - - // Now, get the array of versions. - if (!root.value("versions").isArray()) - { - throw ListLoadError(tr("Error parsing version list JSON: version list object is " - "missing 'versions' array")); - } - QJsonArray versions = root.value("versions").toArray(); - - QList tempList; - for (auto version : versions) - { - // Load the version info. - if (!version.isObject()) - { - qCritical() << "Error while parsing version list : invalid JSON structure"; - continue; - } - - QJsonObject versionObj = version.toObject(); - QString versionID = versionObj.value("id").toString(""); - if (versionID.isEmpty()) - { - qCritical() << "Error while parsing version : version ID is missing"; - continue; - } - - // Now, we construct the version object and add it to the list. - std::shared_ptr mcVersion(new MinecraftVersion()); - mcVersion->m_name = mcVersion->m_descriptor = versionID; - - mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString("")); - mcVersion->m_updateTime = timeFromS3Time(versionObj.value("time").toString("")); - - // depends on where we load the version from -- network request or local file? - mcVersion->m_versionSource = source; - mcVersion->m_versionFileURL = versionObj.value("url").toString(""); - QString versionTypeStr = versionObj.value("type").toString(""); - if (versionTypeStr.isEmpty()) - { - qCritical() << "Ignoring" << versionID - << "because it doesn't have the version type set."; - continue; - } - // OneSix or Legacy. use filter to determine type - if (versionTypeStr == "release") - { - } - else if (versionTypeStr == "snapshot") // It's a snapshot... yay - { - } - else if (versionTypeStr == "old_alpha") - { - } - else if (versionTypeStr == "old_beta") - { - } - else - { - qCritical() << "Ignoring" << versionID - << "because it has an invalid version type."; - continue; - } - mcVersion->m_type = versionTypeStr; - qDebug() << "Loaded version" << versionID << "from" - << ((source == VersionSource::Remote) ? "remote" : "local") << "version list."; - tempList.append(mcVersion); - } - updateListData(tempList); - if(source == VersionSource::Remote) - { - m_loaded = true; - } -} - -void MinecraftVersionList::sortVersions() -{ - beginResetModel(); - sortInternal(); - endResetModel(); -} - -QVariant MinecraftVersionList::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); - switch (role) - { - case VersionPointerRole: - return qVariantFromValue(m_vlist[index.row()]); - - case VersionRole: - return version->name(); - - case VersionIdRole: - return version->descriptor(); - - case RecommendedRole: - return version->descriptor() == m_latestReleaseID; - - case LatestRole: - { - if(version->descriptor() != m_latestSnapshotID) - return false; - MinecraftVersionPtr latestRelease = std::dynamic_pointer_cast(getLatestStable()); - /* - if(latestRelease && latestRelease->m_releaseTime > version->m_releaseTime) - { - return false; - } - */ - return true; - } - - case TypeRole: - return version->typeString(); - - default: - return QVariant(); - } -} - -BaseVersionList::RoleList MinecraftVersionList::providesRoles() const -{ - return {VersionPointerRole, VersionRole, VersionIdRole, RecommendedRole, LatestRole, TypeRole}; -} - -BaseVersionPtr MinecraftVersionList::getLatestStable() const -{ - if(m_lookup.contains(m_latestReleaseID)) - return m_lookup[m_latestReleaseID]; - return BaseVersionPtr(); -} - -BaseVersionPtr MinecraftVersionList::getRecommended() const -{ - return getLatestStable(); -} - -void MinecraftVersionList::updateListData(QList versions) -{ - beginResetModel(); - for (auto version : versions) - { - auto descr = version->descriptor(); - - if (!m_lookup.contains(descr)) - { - m_lookup[version->descriptor()] = version; - m_vlist.append(version); - continue; - } - auto orig = std::dynamic_pointer_cast(m_lookup[descr]); - auto added = std::dynamic_pointer_cast(version); - // updateListData is called after Mojang list loads. those can be local or remote - // remote comes always after local - // any other options are ignored - if (orig->m_versionSource != VersionSource::Local || added->m_versionSource != VersionSource::Remote) - { - continue; - } - // alright, it's an update. put it inside the original, for further processing. - orig->upstreamUpdate = added; - } - sortInternal(); - endResetModel(); -} - -MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist) -{ - m_list = vlist; - m_currentStable = NULL; - vlistReply = nullptr; -} - -void MCVListLoadTask::executeTask() -{ - setStatus(tr("Loading instance version list...")); - vlistReply = ENV.qnam().get(QNetworkRequest(QUrl("https://launchermeta.mojang.com/mc/game/version_manifest.json"))); - connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded())); -} - -void MCVListLoadTask::list_downloaded() -{ - if (vlistReply->error() != QNetworkReply::NoError) - { - vlistReply->deleteLater(); - emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString()); - return; - } - - auto data = vlistReply->readAll(); - vlistReply->deleteLater(); - try - { - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - if (jsonError.error != QJsonParseError::NoError) - { - throw ListLoadError( - tr("Error parsing version list JSON: %1").arg(jsonError.errorString())); - } - m_list->loadMojangList(jsonDoc, VersionSource::Remote); - } - catch (Exception &e) - { - emitFailed(e.cause()); - return; - } - - emitSucceeded(); - return; -} - -MCVListVersionUpdateTask::MCVListVersionUpdateTask(MinecraftVersionList *vlist, std::shared_ptr updatedVersion) - : Task() -{ - m_list = vlist; - this->updatedVersion = updatedVersion; -} - -void MCVListVersionUpdateTask::executeTask() -{ - if(m_aborted) - { - emitFailed(tr("Task aborted.")); - return; - } - auto job = new NetJob("Version index"); - job->addNetAction(Net::Download::makeByteArray(QUrl(updatedVersion->getUrl()), &versionIndexData)); - specificVersionDownloadJob.reset(job); - connect(specificVersionDownloadJob.get(), SIGNAL(succeeded()), SLOT(json_downloaded())); - connect(specificVersionDownloadJob.get(), SIGNAL(failed(QString)), SIGNAL(failed(QString))); - connect(specificVersionDownloadJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - specificVersionDownloadJob->start(); -} - -bool MCVListVersionUpdateTask::canAbort() const -{ - return true; -} - -bool MCVListVersionUpdateTask::abort() -{ - m_aborted = true; - if(specificVersionDownloadJob) - { - return specificVersionDownloadJob->abort(); - } - return true; -} - -void MCVListVersionUpdateTask::json_downloaded() -{ - specificVersionDownloadJob.reset(); - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(versionIndexData, &jsonError); - versionIndexData.clear(); - - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed(tr("The download version file is not valid.")); - return; - } - VersionFilePtr file; - try - { - file = MojangVersionFormat::versionFileFromJson(jsonDoc, "net.minecraft.json"); - } - catch (Exception &e) - { - emitFailed(tr("Couldn't process version file: %1").arg(e.cause())); - return; - } - - // Strip LWJGL from the version file. We use our own. - ProfileUtils::removeLwjglFromPatch(file); - - // TODO: recognize and add LWJGL versions here. - - file->fileId = "net.minecraft"; - - // now dump the file to disk - auto doc = OneSixVersionFormat::versionFileToJson(file, false); - auto newdata = doc.toBinaryData(); - auto id = updatedVersion->descriptor(); - QString targetPath = "versions/" + id + "/" + id + ".dat"; - FS::ensureFilePathExists(targetPath); - QSaveFile vfile1(targetPath); - if (!vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly)) - { - emitFailed(tr("Can't open %1 for writing.").arg(targetPath)); - return; - } - qint64 actual = 0; - if ((actual = vfile1.write(newdata)) != newdata.size()) - { - emitFailed(tr("Failed to write into %1. Written %2 out of %3.") - .arg(targetPath) - .arg(actual) - .arg(newdata.size())); - return; - } - if (!vfile1.commit()) - { - emitFailed(tr("Can't commit changes to %1").arg(targetPath)); - return; - } - - m_list->finalizeUpdate(id); - emitSucceeded(); -} - -std::shared_ptr MinecraftVersionList::createUpdateTask(QString version) -{ - auto iter = m_lookup.find(version); - if(iter == m_lookup.end()) - return nullptr; - - auto mcversion = std::dynamic_pointer_cast(*iter); - if(!mcversion) - { - return nullptr; - } - - return std::shared_ptr(new MCVListVersionUpdateTask(this, mcversion)); -} - -void MinecraftVersionList::saveCachedList() -{ - // FIXME: throw. - if (!FS::ensureFilePathExists(localVersionCache)) - return; - QSaveFile tfile(localVersionCache); - if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) - return; - QJsonObject toplevel; - QJsonArray entriesArr; - for (auto version : m_vlist) - { - auto mcversion = std::dynamic_pointer_cast(version); - // do not save the remote versions. - if (mcversion->m_versionSource != VersionSource::Local) - continue; - QJsonObject entryObj; - - entryObj.insert("id", mcversion->descriptor()); - entryObj.insert("version", mcversion->descriptor()); - entryObj.insert("time", timeToS3Time(mcversion->m_updateTime)); - entryObj.insert("releaseTime", timeToS3Time(mcversion->m_releaseTime)); - entryObj.insert("url", mcversion->m_versionFileURL); - entryObj.insert("type", mcversion->m_type); - entriesArr.append(entryObj); - } - toplevel.insert("versions", entriesArr); - - { - bool someLatest = false; - QJsonObject latestObj; - if(!m_latestReleaseID.isNull()) - { - latestObj.insert("release", m_latestReleaseID); - someLatest = true; - } - if(!m_latestSnapshotID.isNull()) - { - latestObj.insert("snapshot", m_latestSnapshotID); - someLatest = true; - } - if(someLatest) - { - toplevel.insert("latest", latestObj); - } - } - - QJsonDocument doc(toplevel); - QByteArray jsonData = doc.toBinaryData(); - qint64 result = tfile.write(jsonData); - if (result == -1) - return; - if (result != jsonData.size()) - return; - tfile.commit(); -} - -void MinecraftVersionList::finalizeUpdate(QString version) -{ - int idx = -1; - for (int i = 0; i < m_vlist.size(); i++) - { - if (version == m_vlist[i]->descriptor()) - { - idx = i; - break; - } - } - if (idx == -1) - { - return; - } - - auto updatedVersion = std::dynamic_pointer_cast(m_vlist[idx]); - - // reject any updates to builtin versions. - if (updatedVersion->m_versionSource == VersionSource::Builtin) - return; - - // if we have an update for the version, replace it, make the update local - if (updatedVersion->upstreamUpdate) - { - auto updatedWith = updatedVersion->upstreamUpdate; - updatedWith->m_versionSource = VersionSource::Local; - m_vlist[idx] = updatedWith; - m_lookup[version] = updatedWith; - } - else - { - // otherwise, just set the version as local; - updatedVersion->m_versionSource = VersionSource::Local; - } - - dataChanged(index(idx), index(idx)); - - saveCachedList(); -} - -#include "MinecraftVersionList.moc" diff --git a/api/logic/minecraft/MinecraftVersionList.h b/api/logic/minecraft/MinecraftVersionList.h deleted file mode 100644 index fc421966..00000000 --- a/api/logic/minecraft/MinecraftVersionList.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -#include "BaseVersionList.h" -#include "tasks/Task.h" -#include "minecraft/MinecraftVersion.h" -#include - -#include "multimc_logic_export.h" - -class MCVListLoadTask; -class MCVListVersionUpdateTask; - -class MULTIMC_LOGIC_EXPORT MinecraftVersionList : public BaseVersionList -{ - Q_OBJECT -private: - void sortInternal(); - void loadMojangList(QJsonDocument jsonDoc, VersionSource source); - void loadCachedList(); - void saveCachedList(); - void finalizeUpdate(QString version); -public: - friend class MCVListLoadTask; - friend class MCVListVersionUpdateTask; - - explicit MinecraftVersionList(QObject *parent = 0); - - std::shared_ptr createUpdateTask(QString version); - - virtual Task *getLoadTask() override; - virtual bool isLoaded() override; - virtual const BaseVersionPtr at(int i) const override; - virtual int count() const override; - virtual void sortVersions() override; - virtual QVariant data(const QModelIndex & index, int role) const override; - virtual RoleList providesRoles() const override; - - virtual BaseVersionPtr getLatestStable() const override; - virtual BaseVersionPtr getRecommended() const override; - -protected: - QList m_vlist; - QMap m_lookup; - - bool m_loaded = false; - bool m_hasLocalIndex = false; - QString m_latestReleaseID = "INVALID"; - QString m_latestSnapshotID = "INVALID"; - -protected -slots: - virtual void updateListData(QList versions) override; -}; diff --git a/api/logic/minecraft/MojangVersionFormat.cpp b/api/logic/minecraft/MojangVersionFormat.cpp index 34129c9e..1312421f 100644 --- a/api/logic/minecraft/MojangVersionFormat.cpp +++ b/api/logic/minecraft/MojangVersionFormat.cpp @@ -1,6 +1,5 @@ #include "MojangVersionFormat.h" #include "onesix/OneSixVersionFormat.h" -#include "MinecraftVersion.h" #include "VersionBuildError.h" #include "MojangDownloadInfo.h" diff --git a/api/logic/minecraft/forge/ForgeInstaller.cpp b/api/logic/minecraft/forge/ForgeInstaller.cpp index a9c12fcd..f7ce4dec 100644 --- a/api/logic/minecraft/forge/ForgeInstaller.cpp +++ b/api/logic/minecraft/forge/ForgeInstaller.cpp @@ -23,7 +23,6 @@ #include "minecraft/onesix/OneSixInstance.h" #include #include "minecraft/VersionFilterData.h" -#include "minecraft/MinecraftVersion.h" #include "Env.h" #include "Exception.h" #include @@ -137,6 +136,9 @@ void ForgeInstaller::prepare(const QString &filename, const QString &universalUr bool ForgeInstaller::add(OneSixInstance *to) { + return false; + // TODO: move to python code. +/* if (!BaseInstaller::add(to)) { return false; @@ -286,10 +288,14 @@ bool ForgeInstaller::add(OneSixInstance *to) file.commit(); return true; + */ } bool ForgeInstaller::addLegacy(OneSixInstance *to) { + return false; + //FIXME: move to python code. + /* if (!BaseInstaller::add(to)) { return false; @@ -339,6 +345,7 @@ bool ForgeInstaller::addLegacy(OneSixInstance *to) file.write(QJsonDocument(obj).toJson()); file.close(); return true; + */ } class ForgeInstallTask : public Task diff --git a/api/logic/minecraft/ftb/FTBInstanceProvider.cpp b/api/logic/minecraft/ftb/FTBInstanceProvider.cpp index 1321ea1b..fe23a84e 100644 --- a/api/logic/minecraft/ftb/FTBInstanceProvider.cpp +++ b/api/logic/minecraft/ftb/FTBInstanceProvider.cpp @@ -9,7 +9,6 @@ #include #include "Env.h" -#include "minecraft/MinecraftVersion.h" #include "LegacyFTBInstance.h" #include "OneSixFTBInstance.h" @@ -246,17 +245,8 @@ InstancePtr FTBInstanceProvider::createInstance(const FTBRecord & record) const m_settings->registerSetting("InstanceType", "Legacy"); // all legacy versions are built in. therefore we can do this even if we don't have ALL the versions Mojang has on their servers. - auto mcVersion = std::dynamic_pointer_cast(ENV.getVersion("net.minecraft", record.mcVersion)); - if (mcVersion && mcVersion->usesLegacyLauncher()) - { - m_settings->set("InstanceType", "LegacyFTB"); - inst.reset(new LegacyFTBInstance(m_globalSettings, m_settings, record.instanceDir)); - } - else - { - m_settings->set("InstanceType", "OneSixFTB"); - inst.reset(new OneSixFTBInstance(m_globalSettings, m_settings, record.instanceDir)); - } + m_settings->set("InstanceType", "OneSixFTB"); + inst.reset(new OneSixFTBInstance(m_globalSettings, m_settings, record.instanceDir)); // initialize { diff --git a/api/logic/minecraft/ftb/FTBPlugin.cpp b/api/logic/minecraft/ftb/FTBPlugin.cpp index d14eea63..541879a1 100644 --- a/api/logic/minecraft/ftb/FTBPlugin.cpp +++ b/api/logic/minecraft/ftb/FTBPlugin.cpp @@ -1,11 +1,9 @@ #include "FTBPlugin.h" #include -#include "FTBVersion.h" #include "LegacyFTBInstance.h" #include "OneSixFTBInstance.h" #include #include -#include #include #include diff --git a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp index e4e6a6ae..92a1555a 100644 --- a/api/logic/minecraft/ftb/FTBProfileStrategy.cpp +++ b/api/logic/minecraft/ftb/FTBProfileStrategy.cpp @@ -2,7 +2,6 @@ #include "OneSixFTBInstance.h" #include "minecraft/VersionBuildError.h" -#include "minecraft/MinecraftVersionList.h" #include #include diff --git a/api/logic/minecraft/ftb/FTBVersion.h b/api/logic/minecraft/ftb/FTBVersion.h deleted file mode 100644 index 805319b4..00000000 --- a/api/logic/minecraft/ftb/FTBVersion.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include - -class FTBVersion : public BaseVersion -{ -public: - FTBVersion(MinecraftVersionPtr parent) : m_version(parent){}; - -public: - virtual QString descriptor() override - { - return m_version->descriptor(); - } - - virtual QString name() override - { - return m_version->name(); - } - - virtual QString typeString() const override - { - return m_version->typeString(); - } - - MinecraftVersionPtr getMinecraftVersion() - { - return m_version; - } - -private: - MinecraftVersionPtr m_version; -}; diff --git a/api/logic/minecraft/legacy/LegacyUpdate.cpp b/api/logic/minecraft/legacy/LegacyUpdate.cpp index fbef47f5..337a3e4e 100644 --- a/api/logic/minecraft/legacy/LegacyUpdate.cpp +++ b/api/logic/minecraft/legacy/LegacyUpdate.cpp @@ -27,7 +27,6 @@ #include "LegacyModList.h" #include "LwjglVersionList.h" -#include "minecraft/MinecraftVersionList.h" #include "LegacyInstance.h" #include diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index 07c9f075..2b023e82 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -3,7 +3,6 @@ #include "OneSixVersionFormat.h" #include "minecraft/VersionBuildError.h" -#include "minecraft/MinecraftVersionList.h" #include "Env.h" #include @@ -11,6 +10,8 @@ #include #include #include +#include +#include OneSixProfileStrategy::OneSixProfileStrategy(OneSixInstance* instance) { diff --git a/api/logic/minecraft/onesix/OneSixUpdate.cpp b/api/logic/minecraft/onesix/OneSixUpdate.cpp index 4bc80bfe..ec40e086 100644 --- a/api/logic/minecraft/onesix/OneSixUpdate.cpp +++ b/api/logic/minecraft/onesix/OneSixUpdate.cpp @@ -24,7 +24,6 @@ #include #include "BaseInstance.h" -#include "minecraft/MinecraftVersionList.h" #include "minecraft/MinecraftProfile.h" #include "minecraft/Library.h" #include "net/URLConstants.h" @@ -44,6 +43,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent) // add a version update task, if necessary { + /* auto list = std::dynamic_pointer_cast(ENV.getVersionList("net.minecraft")); auto version = std::dynamic_pointer_cast(list->findVersion(m_inst->intendedVersionId())); if (version == nullptr) @@ -67,6 +67,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent) m_tasks.append(versionUpdateTask); } } + */ } // libraries download diff --git a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp index 541fb109..403eb112 100644 --- a/api/logic/minecraft/onesix/OneSixVersionFormat.cpp +++ b/api/logic/minecraft/onesix/OneSixVersionFormat.cpp @@ -1,7 +1,6 @@ #include "OneSixVersionFormat.h" #include #include "minecraft/ParseUtils.h" -#include #include #include diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 3bdf540d..9073c006 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -558,6 +557,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow // run the things that load and download other things... FIXME: this is NOT the place // FIXME: invisible actions in the background = NOPE. { + /* if (!MMC->minecraftlist()->isLoaded()) { m_versionLoadTask = MMC->minecraftlist()->getLoadTask(); @@ -567,6 +567,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow { MMC->lwjgllist()->loadList(); } + */ m_newsChecker->reloadNews(); updateNewsLabel(); @@ -1014,18 +1015,6 @@ void MainWindow::setCatBackground(bool enabled) } } -// FIXME: eliminate, should not be needed -void MainWindow::waitForMinecraftVersions() -{ - if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && m_versionLoadTask->isRunning()) - { - QEventLoop waitLoop; - waitLoop.connect(m_versionLoadTask, &Task::failed, &waitLoop, &QEventLoop::quit); - waitLoop.connect(m_versionLoadTask, &Task::succeeded, &waitLoop, &QEventLoop::quit); - waitLoop.exec(); - } -} - void MainWindow::runModalTask(Task *task) { connect(task, &Task::failed, [this](QString reason) @@ -1117,8 +1106,6 @@ void MainWindow::on_actionAddInstance_triggered() groupName = map["group"].toString(); } while(0); - waitForMinecraftVersions(); - if(groupName.isEmpty()) { groupName = MMC->settings()->get("LastUsedGroupForNewInstance").toString(); diff --git a/application/MainWindow.h b/application/MainWindow.h index 6b30c86e..a7ab9172 100644 --- a/application/MainWindow.h +++ b/application/MainWindow.h @@ -167,7 +167,6 @@ private: void updateInstanceToolIcon(QString new_icon); void setSelectedInstanceById(const QString &id); - void waitForMinecraftVersions(); void runModalTask(Task *task); void instanceFromVersion(QString instName, QString instGroup, QString instIcon, BaseVersionPtr version); void instanceFromZipPack(QString instName, QString instGroup, QString instIcon, QUrl url); diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 3a91fb5f..98b73a6e 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -42,7 +42,6 @@ #include "icons/IconList.h" //FIXME: get rid of this #include "minecraft/legacy/LwjglVersionList.h" -#include "minecraft/MinecraftVersionList.h" #include "minecraft/liteloader/LiteLoaderVersionList.h" #include "minecraft/forge/ForgeVersionList.h" @@ -338,7 +337,6 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) initIcons(); initThemes(); // make sure we have at least some minecraft versions before we init instances - minecraftlist(); initInstances(); initAccounts(); initNetwork(); @@ -890,16 +888,6 @@ std::shared_ptr MultiMC::liteloaderlist() return m_liteloaderlist; } -std::shared_ptr MultiMC::minecraftlist() -{ - if (!m_minecraftlist) - { - m_minecraftlist.reset(new MinecraftVersionList()); - ENV.registerVersionList("net.minecraft", m_minecraftlist); - } - return m_minecraftlist; -} - std::shared_ptr MultiMC::javalist() { if (!m_javalist) diff --git a/application/MultiMC.h b/application/MultiMC.h index d8062bb5..8dc2e609 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -18,7 +18,6 @@ class SetupWizard; class FolderInstanceProvider; class GenericPageProvider; class QFile; -class MinecraftVersionList; class LWJGLVersionList; class HttpMetaCache; class SettingsObject; @@ -96,7 +95,6 @@ public: } std::shared_ptr translations(); - std::shared_ptr minecraftlist(); std::shared_ptr lwjgllist(); std::shared_ptr forgelist(); std::shared_ptr liteloaderlist(); @@ -204,7 +202,6 @@ private: std::shared_ptr m_lwjgllist; std::shared_ptr m_forgelist; std::shared_ptr m_liteloaderlist; - std::shared_ptr m_minecraftlist; std::shared_ptr m_javalist; std::shared_ptr m_translations; std::shared_ptr m_globalSettingsProvider; diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp index d53e1959..2e8e3ff7 100644 --- a/application/dialogs/NewInstanceDialog.cpp +++ b/application/dialogs/NewInstanceDialog.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -62,7 +61,12 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, QWidget *pare resize(minimumSizeHint()); layout()->setSizeConstraint(QLayout::SetFixedSize); - setSelectedVersion(MMC->minecraftlist()->getRecommended()); + // FIXME: bring this back... + auto vlist = ENV.getVersionList("net.minecraft"); + if(vlist) + { + setSelectedVersion(vlist->getRecommended()); + } InstIconKey = "default"; ui->iconButton->setIcon(MMC->icons()->getIcon(InstIconKey)); @@ -192,8 +196,7 @@ BaseVersionPtr NewInstanceDialog::selectedVersion() const void NewInstanceDialog::on_btnChangeVersion_clicked() { - VersionSelectDialog vselect(MMC->minecraftlist().get(), tr("Change Minecraft version"), - this); + VersionSelectDialog vselect(ENV.getVersionList("net.minecraft").get(), tr("Change Minecraft version"), this); vselect.exec(); if (vselect.result() == QDialog::Accepted) { diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index 8decc649..b90b3e43 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -42,8 +42,6 @@ #include "minecraft/liteloader/LiteLoaderInstaller.h" #include "minecraft/auth/MojangAccountList.h" #include "minecraft/Mod.h" -#include "minecraft/MinecraftVersion.h" -#include "minecraft/MinecraftVersionList.h" #include "icons/IconList.h" #include "Exception.h" @@ -489,6 +487,8 @@ int VersionPage::currentRow() void VersionPage::on_customizeBtn_clicked() { + // TODO: implement + /* auto version = currentRow(); if(version == -1) { @@ -510,6 +510,7 @@ void VersionPage::on_customizeBtn_clicked() } updateButtons(); preselect(currentIdx); + */ } void VersionPage::on_editBtn_clicked() @@ -530,6 +531,8 @@ void VersionPage::on_editBtn_clicked() void VersionPage::on_revertBtn_clicked() { + // TODO: implement + /* auto version = currentRow(); if(version == -1) { @@ -551,6 +554,7 @@ void VersionPage::on_revertBtn_clicked() updateButtons(); preselect(currentIdx); m_container->refreshContainer(); + */ } #include "VersionPage.moc" From f6eb8fa1e43a412edb49401107de30d497f0f593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 12 Mar 2017 20:08:56 +0100 Subject: [PATCH 07/28] NOISSUE Remove hardcoded LWJGL (modern) --- .../onesix/OneSixProfileStrategy.cpp | 8 +--- application/CMakeLists.txt | 1 - application/main.cpp | 1 - .../resources/versions/LWJGL/2.9.0.json | 45 ------------------- .../LWJGL/2.9.1-nightly-20130708-debug3.json | 45 ------------------- .../resources/versions/LWJGL/2.9.1.json | 45 ------------------- .../LWJGL/2.9.2-nightly-20140822.json | 45 ------------------- application/resources/versions/versions.qrc | 10 ----- 8 files changed, 2 insertions(+), 198 deletions(-) delete mode 100644 application/resources/versions/LWJGL/2.9.0.json delete mode 100644 application/resources/versions/LWJGL/2.9.1-nightly-20130708-debug3.json delete mode 100644 application/resources/versions/LWJGL/2.9.1.json delete mode 100644 application/resources/versions/LWJGL/2.9.2-nightly-20140822.json delete mode 100644 application/resources/versions/versions.qrc diff --git a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp index 2b023e82..e3d3f674 100644 --- a/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/api/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -121,12 +121,8 @@ void OneSixProfileStrategy::loadDefaultBuiltinPatches() } else { - // NOTE: this is obviously fake, is fixed in unstable. - QResource LWJGL(":/versions/LWJGL/2.9.1.json"); - auto lwjgl = ProfileUtils::parseJsonFile(LWJGL.absoluteFilePath(), false); - lwjgl->setVanilla(true); - lwjgl->setCustomizable(true); - lwjglPatch = std::dynamic_pointer_cast(lwjgl); + auto lwjglversion = ENV.getVersion("org.lwjgl", "2.9.1" /*m_instance->intendedVersionId()*/); + lwjglPatch = std::dynamic_pointer_cast(lwjglversion); } if (!lwjglPatch) { diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 1b6ff3fd..f03225da 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -313,7 +313,6 @@ set(MULTIMC_QRCS resources/pe_blue/pe_blue.qrc resources/OSX/OSX.qrc resources/iOS/iOS.qrc - resources/versions/versions.qrc resources/certs/certs.qrc ) diff --git a/application/main.cpp b/application/main.cpp index fde9e10d..0f258926 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -38,7 +38,6 @@ int main(int argc, char *argv[]) { Q_INIT_RESOURCE(multimc); Q_INIT_RESOURCE(backgrounds); - Q_INIT_RESOURCE(versions); Q_INIT_RESOURCE(pe_dark); Q_INIT_RESOURCE(pe_light); diff --git a/application/resources/versions/LWJGL/2.9.0.json b/application/resources/versions/LWJGL/2.9.0.json deleted file mode 100644 index 5dbd624e..00000000 --- a/application/resources/versions/LWJGL/2.9.0.json +++ /dev/null @@ -1,45 +0,0 @@ - { - "fileId": "org.lwjgl", - "name": "LWJGL", - "version": "2.9.0", - "+libraries": [ - { - "name": "net.java.jinput:jinput:2.0.5" - }, - { - "name": "net.java.jinput:jinput-platform:2.0.5", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - }, - { - "name": "net.java.jutils:jutils:1.0.0" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl:2.9.0" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.0" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.0", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - } - ] -} diff --git a/application/resources/versions/LWJGL/2.9.1-nightly-20130708-debug3.json b/application/resources/versions/LWJGL/2.9.1-nightly-20130708-debug3.json deleted file mode 100644 index 7265b3b0..00000000 --- a/application/resources/versions/LWJGL/2.9.1-nightly-20130708-debug3.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "fileId": "org.lwjgl", - "name": "LWJGL", - "version": "2.9.1-nightly-20130708-debug3", - "+libraries": [ - { - "name": "net.java.jinput:jinput:2.0.5" - }, - { - "name": "net.java.jinput:jinput-platform:2.0.5", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - }, - { - "name": "net.java.jutils:jutils:1.0.0" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.1-nightly-20130708-debug3" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.1-nightly-20130708-debug3", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - } - ] -} diff --git a/application/resources/versions/LWJGL/2.9.1.json b/application/resources/versions/LWJGL/2.9.1.json deleted file mode 100644 index e7f5e947..00000000 --- a/application/resources/versions/LWJGL/2.9.1.json +++ /dev/null @@ -1,45 +0,0 @@ - { - "fileId": "org.lwjgl", - "name": "LWJGL", - "version": "2.9.1", - "+libraries": [ - { - "name": "net.java.jinput:jinput:2.0.5" - }, - { - "name": "net.java.jinput:jinput-platform:2.0.5", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - }, - { - "name": "net.java.jutils:jutils:1.0.0" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl:2.9.1" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.1" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.1", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - } - ] -} diff --git a/application/resources/versions/LWJGL/2.9.2-nightly-20140822.json b/application/resources/versions/LWJGL/2.9.2-nightly-20140822.json deleted file mode 100644 index 25b22eb9..00000000 --- a/application/resources/versions/LWJGL/2.9.2-nightly-20140822.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "fileId": "org.lwjgl", - "name": "LWJGL", - "version": "2.9.2-nightly-20140822", - "+libraries": [ - { - "name": "net.java.jinput:jinput:2.0.5" - }, - { - "name": "net.java.jinput:jinput-platform:2.0.5", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - }, - { - "name": "net.java.jutils:jutils:1.0.0" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822" - }, - { - "name": "org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822", - "natives": { - "linux": "natives-linux", - "windows": "natives-windows", - "osx": "natives-osx" - }, - "extract": { - "exclude": [ - "META-INF/" - ] - } - } - ] -} diff --git a/application/resources/versions/versions.qrc b/application/resources/versions/versions.qrc deleted file mode 100644 index d9596942..00000000 --- a/application/resources/versions/versions.qrc +++ /dev/null @@ -1,10 +0,0 @@ - - - - - LWJGL/2.9.0.json - LWJGL/2.9.1-nightly-20130708-debug3.json - LWJGL/2.9.1.json - LWJGL/2.9.2-nightly-20140822.json - - From 40cf38bc3225c614e7e81d074f890e6f9da0507b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 12 Mar 2017 23:19:45 +0100 Subject: [PATCH 08/28] NOISSUE remove liteloader and forge --- api/logic/CMakeLists.txt | 14 +- api/logic/minecraft/MinecraftProfile.cpp | 5 + api/logic/minecraft/MinecraftProfile.h | 4 + api/logic/minecraft/forge/ForgeInstaller.cpp | 465 ------------------ api/logic/minecraft/forge/ForgeInstaller.h | 52 -- api/logic/minecraft/forge/ForgeVersion.cpp | 55 --- api/logic/minecraft/forge/ForgeVersion.h | 42 -- .../minecraft/forge/ForgeVersionList.cpp | 333 ------------- api/logic/minecraft/forge/ForgeVersionList.h | 90 ---- api/logic/minecraft/forge/LegacyForge.cpp | 56 --- api/logic/minecraft/forge/LegacyForge.h | 25 - .../liteloader/LiteLoaderInstaller.cpp | 106 ---- .../liteloader/LiteLoaderInstaller.h | 39 -- .../liteloader/LiteLoaderVersionList.cpp | 332 ------------- .../liteloader/LiteLoaderVersionList.h | 123 ----- application/MultiMC.cpp | 22 - application/MultiMC.h | 6 - application/pages/VersionPage.cpp | 33 +- 18 files changed, 26 insertions(+), 1776 deletions(-) delete mode 100644 api/logic/minecraft/forge/ForgeInstaller.cpp delete mode 100644 api/logic/minecraft/forge/ForgeInstaller.h delete mode 100644 api/logic/minecraft/forge/ForgeVersion.cpp delete mode 100644 api/logic/minecraft/forge/ForgeVersion.h delete mode 100644 api/logic/minecraft/forge/ForgeVersionList.cpp delete mode 100644 api/logic/minecraft/forge/ForgeVersionList.h delete mode 100644 api/logic/minecraft/forge/LegacyForge.cpp delete mode 100644 api/logic/minecraft/forge/LegacyForge.h delete mode 100644 api/logic/minecraft/liteloader/LiteLoaderInstaller.cpp delete mode 100644 api/logic/minecraft/liteloader/LiteLoaderInstaller.h delete mode 100644 api/logic/minecraft/liteloader/LiteLoaderVersionList.cpp delete mode 100644 api/logic/minecraft/liteloader/LiteLoaderVersionList.h diff --git a/api/logic/CMakeLists.txt b/api/logic/CMakeLists.txt index f14b8662..b605fbd3 100644 --- a/api/logic/CMakeLists.txt +++ b/api/logic/CMakeLists.txt @@ -296,22 +296,10 @@ set(MINECRAFT_SOURCES minecraft/AssetsUtils.cpp # Forge and all things forge related - minecraft/forge/ForgeVersion.h - minecraft/forge/ForgeVersion.cpp - minecraft/forge/ForgeVersionList.h - minecraft/forge/ForgeVersionList.cpp minecraft/forge/ForgeXzDownload.h minecraft/forge/ForgeXzDownload.cpp - minecraft/forge/LegacyForge.h - minecraft/forge/LegacyForge.cpp - minecraft/forge/ForgeInstaller.h - minecraft/forge/ForgeInstaller.cpp - # Liteloader and related things - minecraft/liteloader/LiteLoaderInstaller.h - minecraft/liteloader/LiteLoaderInstaller.cpp - minecraft/liteloader/LiteLoaderVersionList.h - minecraft/liteloader/LiteLoaderVersionList.cpp + # Skin upload utilities minecraft/SkinUpload.cpp minecraft/SkinUpload.h ) diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp index 46235a18..b74141d6 100644 --- a/api/logic/minecraft/MinecraftProfile.cpp +++ b/api/logic/minecraft/MinecraftProfile.cpp @@ -621,6 +621,11 @@ 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. */ diff --git a/api/logic/minecraft/MinecraftProfile.h b/api/logic/minecraft/MinecraftProfile.h index 392c8f5f..a6845e9c 100644 --- a/api/logic/minecraft/MinecraftProfile.h +++ b/api/logic/minecraft/MinecraftProfile.h @@ -24,6 +24,7 @@ #include "Library.h" #include "VersionFile.h" #include "JarMod.h" +#include "BaseVersion.h" #include "MojangDownloadInfo.h" #include "multimc_logic_export.h" @@ -58,6 +59,9 @@ public: /// install more jar mods void installJarMods(QStringList selectedFiles); + /// install more jar mods + void installVersion(BaseVersionPtr version); + /// DEPRECATED, remove ASAP int getFreeOrderNumber(); diff --git a/api/logic/minecraft/forge/ForgeInstaller.cpp b/api/logic/minecraft/forge/ForgeInstaller.cpp deleted file mode 100644 index f7ce4dec..00000000 --- a/api/logic/minecraft/forge/ForgeInstaller.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ForgeInstaller.h" -#include "ForgeVersionList.h" - -#include "minecraft/MinecraftProfile.h" -#include "minecraft/GradleSpecifier.h" -#include "net/HttpMetaCache.h" -#include "tasks/Task.h" -#include "minecraft/onesix/OneSixInstance.h" -#include -#include "minecraft/VersionFilterData.h" -#include "Env.h" -#include "Exception.h" -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -ForgeInstaller::ForgeInstaller() : BaseInstaller() -{ -} - -void ForgeInstaller::prepare(const QString &filename, const QString &universalUrl) -{ - VersionFilePtr newVersion; - m_universal_url = universalUrl; - - QuaZip zip(filename); - if (!zip.open(QuaZip::mdUnzip)) - return; - - QuaZipFile file(&zip); - - // read the install profile - if (!zip.setCurrentFile("install_profile.json")) - return; - - QJsonParseError jsonError; - if (!file.open(QIODevice::ReadOnly)) - return; - QJsonDocument jsonDoc = QJsonDocument::fromJson(file.readAll(), &jsonError); - file.close(); - if (jsonError.error != QJsonParseError::NoError) - return; - - if (!jsonDoc.isObject()) - return; - - QJsonObject root = jsonDoc.object(); - - auto installVal = root.value("install"); - auto versionInfoVal = root.value("versionInfo"); - if (!installVal.isObject() || !versionInfoVal.isObject()) - return; - - try - { - newVersion = OneSixVersionFormat::versionFileFromJson(QJsonDocument(versionInfoVal.toObject()), QString(), false); - } - catch(Exception &err) - { - qWarning() << "Forge: Fatal error while parsing version file:" << err.what(); - return; - } - - for(auto problem: newVersion->getProblems()) - { - qWarning() << "Forge: Problem found: " << problem.getDescription(); - } - if(newVersion->getProblemSeverity() == ProblemSeverity::PROBLEM_ERROR) - { - qWarning() << "Forge: Errors found while parsing version file"; - return; - } - - QJsonObject installObj = installVal.toObject(); - QString libraryName = installObj.value("path").toString(); - internalPath = installObj.value("filePath").toString(); - m_forgeVersionString = installObj.value("version").toString().remove("Forge", Qt::CaseInsensitive).trimmed(); - - // where do we put the library? decode the mojang path - GradleSpecifier lib(libraryName); - - auto cacheentry = ENV.metacache()->resolveEntry("libraries", lib.toPath()); - finalPath = "libraries/" + lib.toPath(); - if (!FS::ensureFilePathExists(finalPath)) - return; - - if (!zip.setCurrentFile(internalPath)) - return; - if (!file.open(QIODevice::ReadOnly)) - return; - { - QByteArray data = file.readAll(); - // extract file - QSaveFile extraction(finalPath); - if (!extraction.open(QIODevice::WriteOnly)) - return; - if (extraction.write(data) != data.size()) - return; - if (!extraction.commit()) - return; - QCryptographicHash md5sum(QCryptographicHash::Md5); - md5sum.addData(data); - - cacheentry->setStale(false); - cacheentry->setMD5Sum(md5sum.result().toHex().constData()); - ENV.metacache()->updateEntry(cacheentry); - } - file.close(); - - m_forge_json = newVersion; -} - -bool ForgeInstaller::add(OneSixInstance *to) -{ - return false; - // TODO: move to python code. -/* - if (!BaseInstaller::add(to)) - { - return false; - } - - if (!m_forge_json) - { - return false; - } - - // A blacklist - QSet blacklist{"authlib", "realms"}; - QList xzlist{"org.scala-lang", "com.typesafe"}; - - // get the minecraft version from the instance - VersionFilePtr minecraft; - auto minecraftPatch = to->getMinecraftProfile()->versionPatch("net.minecraft"); - if(minecraftPatch) - { - minecraft = std::dynamic_pointer_cast(minecraftPatch); - if(!minecraft) - { - auto mcWrap = std::dynamic_pointer_cast(minecraftPatch); - if(mcWrap) - { - minecraft = mcWrap->getVersionFile(); - } - } - } - - // for each library in the version we are adding (except for the blacklisted) - QMutableListIterator iter(m_forge_json->libraries); - while (iter.hasNext()) - { - auto library = iter.next(); - QString libName = library->artifactId(); - QString libVersion = library->version(); - QString rawName = library->rawName(); - - // ignore lwjgl libraries. - if (g_VersionFilterData.lwjglWhitelist.contains(library->artifactPrefix())) - { - iter.remove(); - continue; - } - // ignore other blacklisted (realms, authlib) - if (blacklist.contains(libName)) - { - iter.remove(); - continue; - } - // if minecraft version was found, ignore everything that is already in the minecraft version - if(minecraft) - { - bool found = false; - for (auto & lib: minecraft->libraries) - { - if(library->artifactPrefix() == lib->artifactPrefix() && library->version() == lib->version()) - { - found = true; - break; - } - } - if (found) - continue; - } - - // if this is the actual forge lib, set an absolute url for the download - if (m_forge_version->type == ForgeVersion::Gradle) - { - if (libName == "forge") - { - library->setClassifier("universal"); - } - else if (libName == "minecraftforge") - { - QString forgeCoord("net.minecraftforge:forge:%1:universal"); - // using insane form of the MC version... - QString longVersion = m_forge_version->mcver + "-" + m_forge_version->jobbuildver; - GradleSpecifier spec(forgeCoord.arg(longVersion)); - library->setRawName(spec); - } - } - else - { - if (libName.contains("minecraftforge")) - { - library->setAbsoluteUrl(m_universal_url); - } - } - - // mark bad libraries based on the xzlist above - for (auto entry : xzlist) - { - qDebug() << "Testing " << rawName << " : " << entry; - if (rawName.startsWith(entry)) - { - library->setHint("forge-pack-xz"); - break; - } - } - } - QString &args = m_forge_json->minecraftArguments; - QStringList tweakers; - { - QRegularExpression expression("--tweakClass ([a-zA-Z0-9\\.]*)"); - QRegularExpressionMatch match = expression.match(args); - while (match.hasMatch()) - { - tweakers.append(match.captured(1)); - args.remove(match.capturedStart(), match.capturedLength()); - match = expression.match(args); - } - if(tweakers.size()) - { - args.operator=(args.trimmed()); - m_forge_json->addTweakers = tweakers; - } - } - if(minecraft && args == minecraft->minecraftArguments) - { - args.clear(); - } - - m_forge_json->name = "Forge"; - m_forge_json->fileId = id(); - m_forge_json->version = m_forgeVersionString; - m_forge_json->dependsOnMinecraftVersion = to->intendedVersionId(); - m_forge_json->order = 5; - - // reset some things we do not want to be passed along. - m_forge_json->m_releaseTime = QDateTime(); - m_forge_json->m_updateTime = QDateTime(); - m_forge_json->minimumLauncherVersion = -1; - m_forge_json->type.clear(); - m_forge_json->minecraftArguments.clear(); - m_forge_json->minecraftVersion.clear(); - - QSaveFile file(filename(to->instanceRoot())); - if (!file.open(QFile::WriteOnly)) - { - qCritical() << "Error opening" << file.fileName() - << "for reading:" << file.errorString(); - return false; - } - file.write(OneSixVersionFormat::versionFileToJson(m_forge_json, true).toJson()); - file.commit(); - - return true; - */ -} - -bool ForgeInstaller::addLegacy(OneSixInstance *to) -{ - return false; - //FIXME: move to python code. - /* - if (!BaseInstaller::add(to)) - { - return false; - } - auto entry = ENV.metacache()->resolveEntry("minecraftforge", m_forge_version->filename()); - finalPath = FS::PathCombine(to->jarModsDir(), m_forge_version->filename()); - if (!FS::ensureFilePathExists(finalPath)) - { - return false; - } - if (!QFile::copy(entry->getFullPath(), finalPath)) - { - return false; - } - QJsonObject obj; - obj.insert("order", 5); - { - QJsonArray jarmodsPlus; - { - QJsonObject libObj; - libObj.insert("name", m_forge_version->universal_filename); - jarmodsPlus.append(libObj); - } - obj.insert("+jarMods", jarmodsPlus); - } - - obj.insert("name", QString("Forge")); - obj.insert("fileId", id()); - obj.insert("version", m_forge_version->jobbuildver); - obj.insert("mcVersion", to->intendedVersionId()); - if (g_VersionFilterData.fmlLibsMapping.contains(m_forge_version->mcver)) - { - QJsonArray traitsPlus; - traitsPlus.append(QString("legacyFML")); - obj.insert("+traits", traitsPlus); - } - auto fullversion = to->getMinecraftProfile(); - fullversion->remove("net.minecraftforge"); - - QFile file(filename(to->instanceRoot())); - if (!file.open(QFile::WriteOnly)) - { - qCritical() << "Error opening" << file.fileName() - << "for reading:" << file.errorString(); - return false; - } - file.write(QJsonDocument(obj).toJson()); - file.close(); - return true; - */ -} - -class ForgeInstallTask : public Task -{ - Q_OBJECT -public: - ForgeInstallTask(ForgeInstaller *installer, OneSixInstance *instance, - BaseVersionPtr version, QObject *parent = 0) - : Task(parent), m_installer(installer), m_instance(instance), m_version(version) - { - } - -protected: - void executeTask() override - { - setStatus(tr("Installing Forge...")); - ForgeVersionPtr forgeVersion = std::dynamic_pointer_cast(m_version); - if (!forgeVersion) - { - emitFailed(tr("Unknown error occured")); - return; - } - prepare(forgeVersion); - } - void prepare(ForgeVersionPtr forgeVersion) - { - auto entry = ENV.metacache()->resolveEntry("minecraftforge", forgeVersion->filename()); - auto installFunction = [this, entry, forgeVersion]() - { - if (!install(entry, forgeVersion)) - { - qCritical() << "Failure installing Forge"; - emitFailed(tr("Failure to install Forge")); - } - else - { - reload(); - } - }; - - /* - * HACK IF the local non-stale file is too small, mark is as stale - * - * This fixes some problems with bad files acquired because of unhandled HTTP redirects - * in old versions of MultiMC. - */ - if (!entry->isStale()) - { - QFileInfo localFile(entry->getFullPath()); - if (localFile.size() <= 0x4000) - { - entry->setStale(true); - } - } - - if (entry->isStale()) - { - NetJob *fjob = new NetJob("Forge download"); - fjob->addNetAction(Net::Download::makeCached(forgeVersion->url(), entry)); - connect(fjob, &NetJob::progress, this, &Task::setProgress); - connect(fjob, &NetJob::status, this, &Task::setStatus); - connect(fjob, &NetJob::failed, [this](QString reason) - { emitFailed(tr("Failure to download Forge:\n%1").arg(reason)); }); - connect(fjob, &NetJob::succeeded, installFunction); - fjob->start(); - } - else - { - installFunction(); - } - } - bool install(const std::shared_ptr &entry, const ForgeVersionPtr &forgeVersion) - { - if (forgeVersion->usesInstaller()) - { - QString forgePath = entry->getFullPath(); - m_installer->prepare(forgePath, forgeVersion->universal_url); - return m_installer->add(m_instance); - } - else - return m_installer->addLegacy(m_instance); - } - void reload() - { - try - { - m_instance->reloadProfile(); - emitSucceeded(); - } - catch (Exception &e) - { - emitFailed(e.cause()); - } - catch (...) - { - emitFailed(tr("Failed to load the version description file for reasons unknown.")); - } - } - -private: - ForgeInstaller *m_installer; - OneSixInstance *m_instance; - BaseVersionPtr m_version; -}; - -Task *ForgeInstaller::createInstallTask(OneSixInstance *instance, - BaseVersionPtr version, QObject *parent) -{ - if (!version) - { - return nullptr; - } - m_forge_version = std::dynamic_pointer_cast(version); - return new ForgeInstallTask(this, instance, version, parent); -} - -#include "ForgeInstaller.moc" diff --git a/api/logic/minecraft/forge/ForgeInstaller.h b/api/logic/minecraft/forge/ForgeInstaller.h deleted file mode 100644 index 26286be7..00000000 --- a/api/logic/minecraft/forge/ForgeInstaller.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "BaseInstaller.h" - -#include -#include - -#include "multimc_logic_export.h" - -class VersionFile; -class ForgeInstallTask; -struct ForgeVersion; - -class MULTIMC_LOGIC_EXPORT ForgeInstaller : public BaseInstaller -{ - friend class ForgeInstallTask; -public: - ForgeInstaller(); - virtual ~ForgeInstaller(){} - virtual Task *createInstallTask(OneSixInstance *instance, BaseVersionPtr version, QObject *parent) override; - virtual QString id() const override { return "net.minecraftforge"; } - -protected: - void prepare(const QString &filename, const QString &universalUrl); - bool add(OneSixInstance *to) override; - bool addLegacy(OneSixInstance *to); - -private: - // the parsed version json, read from the installer - std::shared_ptr m_forge_json; - // the actual forge version - std::shared_ptr m_forge_version; - QString internalPath; - QString finalPath; - QString m_forgeVersionString; - QString m_universal_url; -}; diff --git a/api/logic/minecraft/forge/ForgeVersion.cpp b/api/logic/minecraft/forge/ForgeVersion.cpp deleted file mode 100644 index b859a28c..00000000 --- a/api/logic/minecraft/forge/ForgeVersion.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "ForgeVersion.h" -#include "minecraft/VersionFilterData.h" -#include - -QString ForgeVersion::name() -{ - return "Forge " + jobbuildver; -} - -QString ForgeVersion::descriptor() -{ - return universal_filename; -} - -QString ForgeVersion::typeString() const -{ - if (is_recommended) - return QObject::tr("Recommended"); - return QString(); -} - -bool ForgeVersion::operator<(BaseVersion &a) -{ - ForgeVersion *pa = dynamic_cast(&a); - if (!pa) - return true; - return m_buildnr < pa->m_buildnr; -} - -bool ForgeVersion::operator>(BaseVersion &a) -{ - ForgeVersion *pa = dynamic_cast(&a); - if (!pa) - return false; - return m_buildnr > pa->m_buildnr; -} - -bool ForgeVersion::usesInstaller() -{ - if(installer_url.isEmpty()) - return false; - if(g_VersionFilterData.forgeInstallerBlacklist.contains(mcver)) - return false; - return true; -} - -QString ForgeVersion::filename() -{ - return usesInstaller() ? installer_filename : universal_filename; -} - -QString ForgeVersion::url() -{ - return usesInstaller() ? installer_url : universal_url; -} diff --git a/api/logic/minecraft/forge/ForgeVersion.h b/api/logic/minecraft/forge/ForgeVersion.h deleted file mode 100644 index e77d32f1..00000000 --- a/api/logic/minecraft/forge/ForgeVersion.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include -#include -#include "BaseVersion.h" - -struct ForgeVersion; -typedef std::shared_ptr ForgeVersionPtr; - -struct ForgeVersion : public BaseVersion -{ - virtual QString descriptor() override; - virtual QString name() override; - virtual QString typeString() const override; - virtual bool operator<(BaseVersion &a) override; - virtual bool operator>(BaseVersion &a) override; - - QString filename(); - QString url(); - - enum - { - Invalid, - Legacy, - Gradle - } type = Invalid; - - bool usesInstaller(); - - int m_buildnr = 0; - QString branch; - QString universal_url; - QString changelog_url; - QString installer_url; - QString jobbuildver; - QString mcver; - QString mcver_sane; - QString universal_filename; - QString installer_filename; - bool is_recommended = false; -}; - -Q_DECLARE_METATYPE(ForgeVersionPtr) diff --git a/api/logic/minecraft/forge/ForgeVersionList.cpp b/api/logic/minecraft/forge/ForgeVersionList.cpp deleted file mode 100644 index 2fb3d012..00000000 --- a/api/logic/minecraft/forge/ForgeVersionList.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/* Copyright 2013-2017 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ForgeVersionList.h" -#include "ForgeVersion.h" - -#include "net/NetJob.h" -#include "net/URLConstants.h" -#include "Env.h" - -#include -#include -#include - -#include - -ForgeVersionList::ForgeVersionList(QObject *parent) : BaseVersionList(parent) -{ -} - -Task *ForgeVersionList::getLoadTask() -{ - return new ForgeListLoadTask(this); -} - -bool ForgeVersionList::isLoaded() -{ - return m_loaded; -} - -const BaseVersionPtr ForgeVersionList::at(int i) const -{ - return m_vlist.at(i); -} - -int ForgeVersionList::count() const -{ - return m_vlist.count(); -} - -int ForgeVersionList::columnCount(const QModelIndex &parent) const -{ - return 1; -} - -QVariant ForgeVersionList::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (index.row() > count()) - return QVariant(); - - auto version = std::dynamic_pointer_cast(m_vlist[index.row()]); - switch (role) - { - case VersionPointerRole: - return qVariantFromValue(m_vlist[index.row()]); - - case VersionRole: - return version->name(); - - case VersionIdRole: - return version->descriptor(); - - case ParentGameVersionRole: - return version->mcver_sane; - - case RecommendedRole: - return version->is_recommended; - - case BranchRole: - return version->branch; - - default: - return QVariant(); - } -} - -BaseVersionList::RoleList ForgeVersionList::providesRoles() const -{ - return {VersionPointerRole, VersionRole, VersionIdRole, ParentGameVersionRole, RecommendedRole, BranchRole}; -} - -BaseVersionPtr ForgeVersionList::getLatestStable() const -{ - return BaseVersionPtr(); -} - -void ForgeVersionList::updateListData(QList versions) -{ - beginResetModel(); - m_vlist = versions; - m_loaded = true; - endResetModel(); - // NOW SORT!! - // sort(); -} - -void ForgeVersionList::sortVersions() -{ - // NO-OP for now -} - -ForgeListLoadTask::ForgeListLoadTask(ForgeVersionList *vlist) : Task() -{ - m_list = vlist; -} - -void ForgeListLoadTask::executeTask() -{ - setStatus(tr("Fetching Forge version lists...")); - auto job = new NetJob("Version index"); - // we do not care if the version is stale or not. - auto forgeListEntry = ENV.metacache()->resolveEntry("minecraftforge", "list.json"); - auto gradleForgeListEntry = ENV.metacache()->resolveEntry("minecraftforge", "json"); - - // verify by poking the server. - forgeListEntry->setStale(true); - gradleForgeListEntry->setStale(true); - - job->addNetAction(listDownload = Net::Download::makeCached(QUrl(URLConstants::FORGE_LEGACY_URL),forgeListEntry)); - job->addNetAction(gradleListDownload = Net::Download::makeCached(QUrl(URLConstants::FORGE_GRADLE_URL), gradleForgeListEntry)); - - connect(listDownload.get(), SIGNAL(failed(int)), SLOT(listFailed())); - connect(gradleListDownload.get(), SIGNAL(failed(int)), SLOT(gradleListFailed())); - - listJob.reset(job); - connect(listJob.get(), SIGNAL(succeeded()), SLOT(listDownloaded())); - connect(listJob.get(), SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); - listJob->start(); -} - -bool ForgeListLoadTask::abort() -{ - return listJob->abort(); -} - -bool ForgeListLoadTask::parseForgeGradleList(QList &out) -{ - QMap> lookup; - QByteArray data; - { - auto filename = gradleListDownload->getTargetFilepath(); - QFile listFile(filename); - if (!listFile.open(QIODevice::ReadOnly)) - { - return false; - } - data = listFile.readAll(); - gradleListDownload.reset(); - } - - QJsonParseError jsonError; - QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError); - - if (jsonError.error != QJsonParseError::NoError) - { - emitFailed("Error parsing gradle version list JSON:" + jsonError.errorString()); - return false; - } - - if (!jsonDoc.isObject()) - { - emitFailed("Error parsing gradle version list JSON: JSON root is not an object"); - return false; - } - - QJsonObject root = jsonDoc.object(); - - // we probably could hard code these, but it might still be worth doing it this way - const QString webpath = root.value("webpath").toString(); - const QString artifact = root.value("artifact").toString(); - - QJsonObject numbers = root.value("number").toObject(); - for (auto it = numbers.begin(); it != numbers.end(); ++it) - { - QJsonObject number = it.value().toObject(); - std::shared_ptr fVersion(new ForgeVersion()); - fVersion->m_buildnr = number.value("build").toDouble(); - if(fVersion->m_buildnr >= 953 && fVersion->m_buildnr <= 965) - { - qDebug() << fVersion->m_buildnr; - } - fVersion->jobbuildver = number.value("version").toString(); - fVersion->branch = number.value("branch").toString(""); - fVersion->mcver = number.value("mcversion").toString(); - fVersion->universal_filename = ""; - fVersion->installer_filename = ""; - // HACK: here, we fix the minecraft version used by forge. - // HACK: this will inevitably break (later) - // FIXME: replace with a dictionary - fVersion->mcver_sane = fVersion->mcver; - fVersion->mcver_sane.replace("_pre", "-pre"); - - QString universal_filename, installer_filename; - QJsonArray files = number.value("files").toArray(); - for (auto fIt = files.begin(); fIt != files.end(); ++fIt) - { - // TODO with gradle we also get checksums, use them - QJsonArray file = (*fIt).toArray(); - if (file.size() < 3) - { - continue; - } - - QString extension = file.at(0).toString(); - QString part = file.at(1).toString(); - QString checksum = file.at(2).toString(); - - // insane form of mcver is used here - QString longVersion = fVersion->mcver + "-" + fVersion->jobbuildver; - if (!fVersion->branch.isEmpty()) - { - longVersion = longVersion + "-" + fVersion->branch; - } - QString filename = artifact + "-" + longVersion + "-" + part + "." + extension; - - QString url = QString("%1/%2/%3") - .arg(webpath) - .arg(longVersion) - .arg(filename); - - if (part == "installer") - { - fVersion->installer_url = url; - installer_filename = filename; - } - else if (part == "universal" || part == "client") - { - fVersion->universal_url = url; - universal_filename = filename; - } - else if (part == "changelog") - { - fVersion->changelog_url = url; - } - } - if (fVersion->installer_url.isEmpty() && fVersion->universal_url.isEmpty()) - { - continue; - } - fVersion->universal_filename = universal_filename; - fVersion->installer_filename = installer_filename; - fVersion->type = ForgeVersion::Gradle; - out.append(fVersion); - lookup[fVersion->m_buildnr] = fVersion; - } - QJsonObject promos = root.value("promos").toObject(); - for (auto it = promos.begin(); it != promos.end(); ++it) - { - QString key = it.key(); - int build = it.value().toInt(); - QRegularExpression regexp("^(?[0-9]+(.[0-9]+)*)-(?