summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logic/minecraft/Library.h5
-rw-r--r--logic/minecraft/MojangDownloadInfo.h87
-rw-r--r--logic/minecraft/MojangVersionFormat.cpp277
-rw-r--r--logic/minecraft/MojangVersionFormat.h10
-rw-r--r--logic/minecraft/VersionFile.h6
5 files changed, 144 insertions, 241 deletions
diff --git a/logic/minecraft/Library.h b/logic/minecraft/Library.h
index 7ae126a9..891601be 100644
--- a/logic/minecraft/Library.h
+++ b/logic/minecraft/Library.h
@@ -11,10 +11,11 @@
#include "Rule.h"
#include "minecraft/OpSys.h"
#include "GradleSpecifier.h"
-#include "MojangDownloadInfo.h"
#include "net/URLConstants.h"
+class MojangLibraryDownloadInfo;
class Library;
+
typedef std::shared_ptr<Library> LibraryPtr;
class Library
@@ -186,5 +187,5 @@ protected: /* data */
QList<std::shared_ptr<Rule>> m_rules;
/// MOJANG: container with Mojang style download info
- MojangLibraryDownloadInfoPtr m_mojang_downloads;
+ std::shared_ptr<MojangLibraryDownloadInfo> m_mojang_downloads;
};
diff --git a/logic/minecraft/MojangDownloadInfo.h b/logic/minecraft/MojangDownloadInfo.h
index 780318b8..d8cd2e6d 100644
--- a/logic/minecraft/MojangDownloadInfo.h
+++ b/logic/minecraft/MojangDownloadInfo.h
@@ -2,42 +2,30 @@
#include <QString>
#include <memory>
-class MojangDownloadInfo
+struct MojangDownloadInfo
{
- friend class MojangVersionFormat;
-public:
- QString getUrl()
- {
- return m_url;
- }
-
- QString getSha1()
- {
- return m_sha1;
- }
+ // types
+ typedef std::shared_ptr<MojangDownloadInfo> Ptr;
- int getSize()
- {
- return m_size;
- }
-
-protected:
+ // data
/// Local filesystem path. WARNING: not used, only here so we can pass through mojang files unmolested!
- QString m_path;
+ QString path;
/// absolute URL of this file
- QString m_url;
+ QString url;
/// sha-1 checksum of the file
- QString m_sha1;
+ QString sha1;
/// size of the file in bytes
- int m_size;
+ int size;
};
-typedef std::shared_ptr<MojangDownloadInfo> MojangDownloadInfoPtr;
-class MojangLibraryDownloadInfo
+
+struct MojangLibraryDownloadInfo
{
- friend class MojangVersionFormat;
-public:
+ // types
+ typedef std::shared_ptr<MojangLibraryDownloadInfo> Ptr;
+
+ // methods
MojangDownloadInfo *getDownloadInfo(QString classifier)
{
if (classifier.isNull())
@@ -47,46 +35,33 @@ public:
return classifiers[classifier].get();
}
-private:
- MojangDownloadInfoPtr artifact;
- QMap<QString, MojangDownloadInfoPtr> classifiers;
+
+ // data
+ MojangDownloadInfo::Ptr artifact;
+ QMap<QString, MojangDownloadInfo::Ptr> classifiers;
};
-typedef std::shared_ptr<MojangLibraryDownloadInfo> MojangLibraryDownloadInfoPtr;
-class MojangAssetIndexInfo : public MojangDownloadInfo
+
+struct MojangAssetIndexInfo : public MojangDownloadInfo
{
- friend class MojangVersionFormat;
-public:
+ // types
+ typedef std::shared_ptr<MojangAssetIndexInfo> Ptr;
+
+ // methods
MojangAssetIndexInfo()
{
}
MojangAssetIndexInfo(QString id)
{
- m_id = id;
- m_url = "https://s3.amazonaws.com/Minecraft.Download/indexes/" + id + ".json";
- m_known = false;
- }
-
- int getTotalSize()
- {
- return m_totalSize;
- }
-
- QString getId()
- {
- return m_id;
- }
-
- bool sizeAndHashKnown()
- {
- return m_known;
+ this->id = id;
+ url = "https://s3.amazonaws.com/Minecraft.Download/indexes/" + id + ".json";
+ known = false;
}
-protected:
- int m_totalSize;
- QString m_id;
- bool m_known = true;
+ // data
+ int totalSize;
+ QString id;
+ bool known = true;
};
-typedef std::shared_ptr<MojangAssetIndexInfo> MojangAssetIndexInfoPtr;
diff --git a/logic/minecraft/MojangVersionFormat.cpp b/logic/minecraft/MojangVersionFormat.cpp
index 1b95a0ba..def388bf 100644
--- a/logic/minecraft/MojangVersionFormat.cpp
+++ b/logic/minecraft/MojangVersionFormat.cpp
@@ -2,6 +2,7 @@
#include "onesix/OneSixVersionFormat.h"
#include "MinecraftVersion.h"
#include "VersionBuildError.h"
+#include "MojangDownloadInfo.h"
#include "Json.h"
using namespace Json;
@@ -9,7 +10,15 @@ using namespace Json;
static const int CURRENT_MINIMUM_LAUNCHER_VERSION = 14;
-// FIXME: duplicated in OneSixVersionFormat!
+static MojangAssetIndexInfo::Ptr assetIndexFromJson (const QJsonObject &obj);
+static MojangDownloadInfo::Ptr downloadInfoFromJson (const QJsonObject &obj);
+static MojangLibraryDownloadInfo::Ptr libDownloadInfoFromJson (const QJsonObject &libObj);
+static QJsonObject assetIndexToJson (MojangAssetIndexInfo::Ptr assetidxinfo);
+static QJsonObject libDownloadInfoToJson (MojangLibraryDownloadInfo::Ptr libinfo);
+static QJsonObject downloadInfoToJson (MojangDownloadInfo::Ptr info);
+
+namespace Bits
+{
static void readString(const QJsonObject &root, const QString &key, QString &variable)
{
if (root.contains(key))
@@ -18,36 +27,106 @@ static void readString(const QJsonObject &root, const QString &key, QString &var
}
}
-MojangAssetIndexInfoPtr MojangVersionFormat::assetIndexFromJson(const QJsonObject &obj)
+static void readDownloadInfo(MojangDownloadInfo::Ptr out, const QJsonObject &obj)
{
- auto out = std::make_shared<MojangAssetIndexInfo>();
// optional, not used
- readString(obj, "path", out->m_path);
+ readString(obj, "path", out->path);
// required!
- out->m_sha1 = requireString(obj, "sha1");
- out->m_url = requireString(obj, "url");
- out->m_size = requireInteger(obj, "size");
- out->m_totalSize = requireInteger(obj, "totalSize");
- out->m_id = requireString(obj, "id");
- // out->m_known = true;
+ out->sha1 = requireString(obj, "sha1");
+ out->url = requireString(obj, "url");
+ out->size = requireInteger(obj, "size");
+}
+
+static void readAssetIndex(MojangAssetIndexInfo::Ptr out, const QJsonObject &obj)
+{
+ out->totalSize = requireInteger(obj, "totalSize");
+ out->id = requireString(obj, "id");
+ // out->known = true;
+}
+}
+
+MojangDownloadInfo::Ptr downloadInfoFromJson(const QJsonObject &obj)
+{
+ auto out = std::make_shared<MojangDownloadInfo>();
+ Bits::readDownloadInfo(out, obj);
+ return out;
+}
+
+MojangAssetIndexInfo::Ptr assetIndexFromJson(const QJsonObject &obj)
+{
+ auto out = std::make_shared<MojangAssetIndexInfo>();
+ Bits::readDownloadInfo(out, obj);
+ Bits::readAssetIndex(out, obj);
+ return out;
+}
+
+QJsonObject downloadInfoToJson(MojangDownloadInfo::Ptr info)
+{
+ QJsonObject out;
+ if(!info->path.isNull())
+ {
+ out.insert("path", info->path);
+ }
+ out.insert("sha1", info->sha1);
+ out.insert("size", info->size);
+ out.insert("url", info->url);
+ return out;
+}
+
+MojangLibraryDownloadInfo::Ptr libDownloadInfoFromJson(const QJsonObject &libObj)
+{
+ auto out = std::make_shared<MojangLibraryDownloadInfo>();
+ auto dlObj = requireObject(libObj.value("downloads"));
+ if(dlObj.contains("artifact"))
+ {
+ out->artifact = downloadInfoFromJson(requireObject(dlObj, "artifact"));
+ }
+ if(dlObj.contains("classifiers"))
+ {
+ auto classifiersObj = requireObject(dlObj, "classifiers");
+ for(auto iter = classifiersObj.begin(); iter != classifiersObj.end(); iter++)
+ {
+ auto classifier = iter.key();
+ auto classifierObj = requireObject(iter.value());
+ out->classifiers[classifier] = downloadInfoFromJson(classifierObj);
+ }
+ }
return out;
}
-QJsonObject MojangVersionFormat::assetIndexToJson(MojangAssetIndexInfoPtr info)
+QJsonObject libDownloadInfoToJson(MojangLibraryDownloadInfo::Ptr libinfo)
{
QJsonObject out;
- if(!info->m_path.isNull())
+ if(libinfo->artifact)
{
- out.insert("path", info->m_path);
+ out.insert("artifact", downloadInfoToJson(libinfo->artifact));
+ }
+ if(libinfo->classifiers.size())
+ {
+ QJsonObject classifiersOut;
+ for(auto iter = libinfo->classifiers.begin(); iter != libinfo->classifiers.end(); iter++)
+ {
+ classifiersOut.insert(iter.key(), downloadInfoToJson(iter.value()));
+ }
+ out.insert("classifiers", classifiersOut);
}
- out.insert("sha1", info->m_sha1);
- out.insert("size", info->m_size);
- out.insert("url", info->m_url);
- out.insert("totalSize", info->m_totalSize);
- out.insert("id", info->m_id);
return out;
}
+QJsonObject assetIndexToJson(MojangAssetIndexInfo::Ptr info)
+{
+ QJsonObject out;
+ if(!info->path.isNull())
+ {
+ out.insert("path", info->path);
+ }
+ out.insert("sha1", info->sha1);
+ out.insert("size", info->size);
+ out.insert("url", info->url);
+ out.insert("totalSize", info->totalSize);
+ out.insert("id", info->id);
+ return out;
+}
VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename)
{
@@ -68,17 +147,17 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
out->version = root.value("version").toString();
out->filename = filename;
- readString(root, "id", out->id);
+ Bits::readString(root, "id", out->id);
- readString(root, "mainClass", out->mainClass);
- readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
- readString(root, "type", out->type);
+ Bits::readString(root, "mainClass", out->mainClass);
+ Bits::readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
+ Bits::readString(root, "type", out->type);
if(root.contains("assetIndex"))
{
out->mojangAssetIndex = assetIndexFromJson(requireObject(root, "assetIndex"));
}
- readString(root, "assets", out->assets);
+ Bits::readString(root, "assets", out->assets);
out->m_releaseTime = timeFromS3Time(root.value("releaseTime").toString(""));
out->m_updateTime = timeFromS3Time(root.value("time").toString(""));
@@ -119,7 +198,7 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
return out;
}
-QJsonDocument MojangVersionFormat::versionFileToJson(VersionFilePtr patch)
+QJsonDocument versionFileToJson(VersionFilePtr patch)
{
QJsonObject root;
writeString(root, "id", patch->id);
@@ -144,9 +223,9 @@ QJsonDocument MojangVersionFormat::versionFileToJson(VersionFilePtr patch)
}
root.insert("libraries", array);
}
- if(patch->mojangAssetIndex && patch->mojangAssetIndex->sizeAndHashKnown())
+ if(patch->mojangAssetIndex && patch->mojangAssetIndex->known)
{
- root.insert("assetIndex", MojangVersionFormat::assetIndexToJson(patch->mojangAssetIndex));
+ root.insert("assetIndex", assetIndexToJson(patch->mojangAssetIndex));
}
if(patch->mojangDownloads.size())
{
@@ -192,118 +271,6 @@ QJsonDocument MojangVersionFormat::profilePatchToJson(const ProfilePatchPtr &pat
throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getPatchName()));
}
-/*
-class MojangDownloadInfo
-{
- friend class MojangVersionFormat;
-public:
- QString getUrl()
- {
- return m_url;
- }
-
- QString getSha1()
- {
- return m_sha1;
- }
-
- int getSize()
- {
- return m_size;
- }
-
-protected:
- QString m_url;
- QString m_sha1;
- int m_size;
-};
-*/
-
-MojangDownloadInfoPtr MojangVersionFormat::downloadInfoFromJson(const QJsonObject &obj)
-{
- auto out = std::make_shared<MojangDownloadInfo>();
- // optional, not used
- readString(obj, "path", out->m_path);
- // required!
- out->m_sha1 = requireString(obj, "sha1");
- out->m_url = requireString(obj, "url");
- out->m_size = requireInteger(obj, "size");
- return out;
-}
-
-/*
-class MojangLibraryDownloadInfo
-{
- friend class MojangVersionFormat;
-public:
- MojangDownloadInfo getDownloadInfo(QString classifier)
- {
- if (classifier.isNull())
- {
- return artifact;
- }
-
- return classifiers[classifier];
- }
-private:
- MojangDownloadInfo artifact;
- QMap<QString, MojangDownloadInfo> classifiers;
-};
-*/
-
-/*
- "downloads": {
- "artifact": {
- "path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar",
- "sha1": "b04f3ee8f5e43fa3b162981b50bb72fe1acabb33",
- "size": 22,
- "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209.jar"
- },
- "classifiers": {
- "natives-linux": {
- "path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-linux.jar",
- "sha1": "931074f46c795d2f7b30ed6395df5715cfd7675b",
- "size": 578680,
- "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-linux.jar"
- },
- "natives-osx": {
- "path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar",
- "sha1": "bcab850f8f487c3f4c4dbabde778bb82bd1a40ed",
- "size": 426822,
- "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar"
- },
- "natives-windows": {
- "path": "org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-windows.jar",
- "sha1": "b84d5102b9dbfabfeb5e43c7e2828d98a7fc80e0",
- "size": 613748,
- "url": "https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/lwjgl-platform-2.9.4-nightly-20150209-natives-windows.jar"
- }
- }
- },
-*/
-
-
-MojangLibraryDownloadInfoPtr MojangVersionFormat::libDownloadInfoFromJson(const QJsonObject &libObj)
-{
- auto out = std::make_shared<MojangLibraryDownloadInfo>();
- auto dlObj = requireObject(libObj.value("downloads"));
- if(dlObj.contains("artifact"))
- {
- out->artifact = downloadInfoFromJson(requireObject(dlObj, "artifact"));
- }
- if(dlObj.contains("classifiers"))
- {
- auto classifiersObj = requireObject(dlObj, "classifiers");
- for(auto iter = classifiersObj.begin(); iter != classifiersObj.end(); iter++)
- {
- auto classifier = iter.key();
- auto classifierObj = requireObject(iter.value());
- out->classifiers[classifier] = downloadInfoFromJson(classifierObj);
- }
- }
- return out;
-}
-
LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
{
LibraryPtr out(new Library());
@@ -313,7 +280,7 @@ LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const
}
out->m_name = libObj.value("name").toString();
- readString(libObj, "url", out->m_base_url);
+ Bits::readString(libObj, "url", out->m_base_url);
if (libObj.contains("extract"))
{
out->applyExcludes = true;
@@ -351,38 +318,6 @@ LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const
return out;
}
-QJsonObject MojangVersionFormat::downloadInfoToJson(MojangDownloadInfoPtr info)
-{
- QJsonObject out;
- if(!info->m_path.isNull())
- {
- out.insert("path", info->m_path);
- }
- out.insert("sha1", info->m_sha1);
- out.insert("size", info->m_size);
- out.insert("url", info->m_url);
- return out;
-}
-
-QJsonObject MojangVersionFormat::libDownloadInfoToJson(MojangLibraryDownloadInfoPtr libinfo)
-{
- QJsonObject out;
- if(libinfo->artifact)
- {
- out.insert("artifact", downloadInfoToJson(libinfo->artifact));
- }
- if(libinfo->classifiers.size())
- {
- QJsonObject classifiersOut;
- for(auto iter = libinfo->classifiers.begin(); iter != libinfo->classifiers.end(); iter++)
- {
- classifiersOut.insert(iter.key(), downloadInfoToJson(iter.value()));
- }
- out.insert("classifiers", classifiersOut);
- }
- return out;
-}
-
QJsonObject MojangVersionFormat::libraryToJson(Library *library)
{
QJsonObject libRoot;
diff --git a/logic/minecraft/MojangVersionFormat.h b/logic/minecraft/MojangVersionFormat.h
index 67066647..a5a94095 100644
--- a/logic/minecraft/MojangVersionFormat.h
+++ b/logic/minecraft/MojangVersionFormat.h
@@ -16,14 +16,4 @@ public:
// libraries
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
static QJsonObject libraryToJson(Library *library);
-
-private:
- static QJsonDocument versionFileToJson(VersionFilePtr patch);
-
- static MojangAssetIndexInfoPtr assetIndexFromJson (const QJsonObject &obj);
- static MojangDownloadInfoPtr downloadInfoFromJson (const QJsonObject &obj);
- static MojangLibraryDownloadInfoPtr libDownloadInfoFromJson (const QJsonObject &libObj);
- static QJsonObject assetIndexToJson (MojangAssetIndexInfoPtr assetidxinfo);
- static QJsonObject libDownloadInfoToJson (MojangLibraryDownloadInfoPtr libinfo);
- static QJsonObject downloadInfoToJson (MojangDownloadInfoPtr info);
};
diff --git a/logic/minecraft/VersionFile.h b/logic/minecraft/VersionFile.h
index 5e722dbf..6c0225b0 100644
--- a/logic/minecraft/VersionFile.h
+++ b/logic/minecraft/VersionFile.h
@@ -14,6 +14,8 @@
class MinecraftProfile;
class VersionFile;
+struct MojangDownloadInfo;
+struct MojangAssetIndexInfo;
typedef std::shared_ptr<VersionFile> VersionFilePtr;
class VersionFile : public ProfilePatch
@@ -181,10 +183,10 @@ public: /* data */
QList<JarmodPtr> jarMods;
// Mojang: list of 'downloads' - client jar, server jar, windows server exe, maybe more.
- QMap <QString, MojangDownloadInfoPtr> mojangDownloads;
+ QMap <QString, std::shared_ptr<MojangDownloadInfo>> mojangDownloads;
// Mojang: extended asset index download information
- MojangAssetIndexInfoPtr mojangAssetIndex;
+ std::shared_ptr<MojangAssetIndexInfo> mojangAssetIndex;
};