mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-12-14 04:32:14 +00:00
Compare commits
5 Commits
0.6.15
...
feature/ar
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75edfc8d08 | ||
|
|
0272d6d7f7 | ||
|
|
406203e76b | ||
|
|
2bcd255909 | ||
|
|
d5d710b89e |
@@ -267,8 +267,6 @@ set(MINECRAFT_SOURCES
|
|||||||
minecraft/MinecraftLoadAndCheck.cpp
|
minecraft/MinecraftLoadAndCheck.cpp
|
||||||
minecraft/MinecraftUpdate.h
|
minecraft/MinecraftUpdate.h
|
||||||
minecraft/MinecraftUpdate.cpp
|
minecraft/MinecraftUpdate.cpp
|
||||||
minecraft/MojangVersionFormat.cpp
|
|
||||||
minecraft/MojangVersionFormat.h
|
|
||||||
minecraft/Rule.cpp
|
minecraft/Rule.cpp
|
||||||
minecraft/Rule.h
|
minecraft/Rule.h
|
||||||
minecraft/OneSixVersionFormat.cpp
|
minecraft/OneSixVersionFormat.cpp
|
||||||
@@ -319,12 +317,6 @@ add_unit_test(GradleSpecifier
|
|||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
)
|
)
|
||||||
|
|
||||||
add_unit_test(MojangVersionFormat
|
|
||||||
SOURCES minecraft/MojangVersionFormat_test.cpp
|
|
||||||
LIBS MultiMC_logic
|
|
||||||
DATA minecraft/testdata
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(Library
|
add_unit_test(Library
|
||||||
SOURCES minecraft/Library_test.cpp
|
SOURCES minecraft/Library_test.cpp
|
||||||
LIBS MultiMC_logic
|
LIBS MultiMC_logic
|
||||||
|
|||||||
@@ -991,7 +991,7 @@ bool ComponentList::removeComponent_internal(ComponentPtr patch)
|
|||||||
// FIXME: we need a generic way of removing local resources, not just jar mods...
|
// FIXME: we need a generic way of removing local resources, not just jar mods...
|
||||||
auto preRemoveJarMod = [&](LibraryPtr jarMod) -> bool
|
auto preRemoveJarMod = [&](LibraryPtr jarMod) -> bool
|
||||||
{
|
{
|
||||||
if (!jarMod->isLocal())
|
if (!jarMod->isInstanceLocal())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ struct GradleSpecifier
|
|||||||
}
|
}
|
||||||
bool matchName(const GradleSpecifier & other) const
|
bool matchName(const GradleSpecifier & other) const
|
||||||
{
|
{
|
||||||
return other.artifactId() == artifactId() && other.groupId() == groupId();
|
return other.artifactId() == artifactId() && other.groupId() == groupId() && other.classifier() == classifier();
|
||||||
}
|
}
|
||||||
bool operator==(const GradleSpecifier & other) const
|
bool operator==(const GradleSpecifier & other) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -162,12 +162,20 @@ const LibraryPtr LaunchProfile::getMainJar() const
|
|||||||
return m_mainJar;
|
return m_mainJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchProfile::applyMainJar(LibraryPtr jar)
|
void LaunchProfile::applyMainJar(LibraryPtr jar, bool removeMainJar)
|
||||||
{
|
{
|
||||||
if(jar)
|
if(removeMainJar)
|
||||||
|
{
|
||||||
|
m_mainJar.reset();
|
||||||
|
}
|
||||||
|
else if(jar)
|
||||||
{
|
{
|
||||||
m_mainJar = jar;
|
m_mainJar = jar;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// mainJar was not specified, NOOP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaunchProfile::applyProblemSeverity(ProblemSeverity severity)
|
void LaunchProfile::applyProblemSeverity(ProblemSeverity severity)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public: /* application of profile variables from patches */
|
|||||||
void applyJarMods(const QList<LibraryPtr> &jarMods);
|
void applyJarMods(const QList<LibraryPtr> &jarMods);
|
||||||
void applyMods(const QList<LibraryPtr> &jarMods);
|
void applyMods(const QList<LibraryPtr> &jarMods);
|
||||||
void applyLibrary(LibraryPtr library);
|
void applyLibrary(LibraryPtr library);
|
||||||
void applyMainJar(LibraryPtr jar);
|
void applyMainJar(LibraryPtr jar, bool removeMainJar);
|
||||||
void applyProblemSeverity(ProblemSeverity severity);
|
void applyProblemSeverity(ProblemSeverity severity);
|
||||||
/// clear the profile
|
/// clear the profile
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
@@ -8,13 +8,19 @@
|
|||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
|
|
||||||
|
|
||||||
void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32,
|
void Library::getApplicableFiles(
|
||||||
QStringList& native64, const QString &overridePath) const
|
OpSys system,
|
||||||
|
QStringList& jar,
|
||||||
|
QStringList& native,
|
||||||
|
QStringList& native32,
|
||||||
|
QStringList& native64,
|
||||||
|
const QString &overridePath
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
bool local = isLocal();
|
bool local = isInstanceLocal();
|
||||||
auto actualPath = [&](QString relPath)
|
auto actualPath = [&](QString relPath)
|
||||||
{
|
{
|
||||||
QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
|
QFileInfo out(FS::PathCombine("libraries", relPath));
|
||||||
if(local && !overridePath.isEmpty())
|
if(local && !overridePath.isEmpty())
|
||||||
{
|
{
|
||||||
QString fileName = out.fileName();
|
QString fileName = out.fileName();
|
||||||
@@ -54,9 +60,9 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
|
|||||||
{
|
{
|
||||||
QList<NetActionPtr> out;
|
QList<NetActionPtr> out;
|
||||||
bool stale = isAlwaysStale();
|
bool stale = isAlwaysStale();
|
||||||
bool local = isLocal();
|
bool instanceLocal = isInstanceLocal();
|
||||||
|
|
||||||
auto check_local_file = [&](QString storage)
|
auto check_instance_local_file = [&](QString storage)
|
||||||
{
|
{
|
||||||
QFileInfo fileinfo(storage);
|
QFileInfo fileinfo(storage);
|
||||||
QString fileName = fileinfo.fileName();
|
QString fileName = fileinfo.fileName();
|
||||||
@@ -72,9 +78,9 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
|
|||||||
|
|
||||||
auto add_download = [&](QString storage, QString url, QString sha1)
|
auto add_download = [&](QString storage, QString url, QString sha1)
|
||||||
{
|
{
|
||||||
if(local)
|
if(instanceLocal)
|
||||||
{
|
{
|
||||||
return check_local_file(storage);
|
return check_instance_local_file(storage);
|
||||||
}
|
}
|
||||||
auto entry = cache->resolveEntry("libraries", storage);
|
auto entry = cache->resolveEntry("libraries", storage);
|
||||||
if(stale)
|
if(stale)
|
||||||
@@ -82,7 +88,9 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(
|
|||||||
entry->setStale(true);
|
entry->setStale(true);
|
||||||
}
|
}
|
||||||
if (!entry->isStale())
|
if (!entry->isStale())
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
Net::Download::Options options;
|
Net::Download::Options options;
|
||||||
if(stale)
|
if(stale)
|
||||||
{
|
{
|
||||||
@@ -233,7 +241,7 @@ bool Library::isActive() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Library::isLocal() const
|
bool Library::isInstanceLocal() const
|
||||||
{
|
{
|
||||||
return m_hint == "local";
|
return m_hint == "local";
|
||||||
}
|
}
|
||||||
@@ -248,25 +256,6 @@ bool Library::isForge() const
|
|||||||
return m_hint == "forge-pack-xz";
|
return m_hint == "forge-pack-xz";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Library::setStoragePrefix(QString prefix)
|
|
||||||
{
|
|
||||||
m_storagePrefix = prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Library::defaultStoragePrefix()
|
|
||||||
{
|
|
||||||
return "libraries/";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Library::storagePrefix() const
|
|
||||||
{
|
|
||||||
if(m_storagePrefix.isEmpty())
|
|
||||||
{
|
|
||||||
return defaultStoragePrefix();
|
|
||||||
}
|
|
||||||
return m_storagePrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Library::filename(OpSys system) const
|
QString Library::filename(OpSys system) const
|
||||||
{
|
{
|
||||||
if(!m_filename.isEmpty())
|
if(!m_filename.isEmpty())
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public:
|
|||||||
newlib->m_extractExcludes = base->m_extractExcludes;
|
newlib->m_extractExcludes = base->m_extractExcludes;
|
||||||
newlib->m_nativeClassifiers = base->m_nativeClassifiers;
|
newlib->m_nativeClassifiers = base->m_nativeClassifiers;
|
||||||
newlib->m_rules = base->m_rules;
|
newlib->m_rules = base->m_rules;
|
||||||
newlib->m_storagePrefix = base->m_storagePrefix;
|
|
||||||
newlib->m_mojangDownloads = base->m_mojangDownloads;
|
newlib->m_mojangDownloads = base->m_mojangDownloads;
|
||||||
newlib->m_filename = base->m_filename;
|
newlib->m_filename = base->m_filename;
|
||||||
return newlib;
|
return newlib;
|
||||||
@@ -93,8 +92,6 @@ public: /* methods */
|
|||||||
return m_nativeClassifiers.size() != 0;
|
return m_nativeClassifiers.size() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStoragePrefix(QString prefix = QString());
|
|
||||||
|
|
||||||
/// Set the url base for downloads
|
/// Set the url base for downloads
|
||||||
void setRepositoryURL(const QString &base_url)
|
void setRepositoryURL(const QString &base_url)
|
||||||
{
|
{
|
||||||
@@ -146,7 +143,15 @@ public: /* methods */
|
|||||||
bool isActive() const;
|
bool isActive() const;
|
||||||
|
|
||||||
/// Returns true if the library is contained in an instance and false if it is shared
|
/// Returns true if the library is contained in an instance and false if it is shared
|
||||||
bool isLocal() const;
|
bool isInstanceLocal() const;
|
||||||
|
|
||||||
|
/// Returns true if the library cannot be downloaded (was built locally somehow)
|
||||||
|
bool isLocalBuilt() const;
|
||||||
|
|
||||||
|
bool isLocal() const
|
||||||
|
{
|
||||||
|
return isInstanceLocal() || isLocalBuilt();
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if the library is to always be checked for updates
|
/// Returns true if the library is to always be checked for updates
|
||||||
bool isAlwaysStale() const;
|
bool isAlwaysStale() const;
|
||||||
@@ -159,11 +164,6 @@ public: /* methods */
|
|||||||
QStringList & failedLocalFiles, const QString & overridePath) const;
|
QStringList & failedLocalFiles, const QString & overridePath) const;
|
||||||
|
|
||||||
private: /* methods */
|
private: /* methods */
|
||||||
/// the default storage prefix used by MultiMC
|
|
||||||
static QString defaultStoragePrefix();
|
|
||||||
|
|
||||||
/// Get the prefix - root of the storage to be used
|
|
||||||
QString storagePrefix() const;
|
|
||||||
|
|
||||||
/// Get the relative file path where the library should be saved
|
/// Get the relative file path where the library should be saved
|
||||||
QString storageSuffix(OpSys system) const;
|
QString storageSuffix(OpSys system) const;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include "TestUtil.h"
|
#include "TestUtil.h"
|
||||||
|
|
||||||
#include "minecraft/MojangVersionFormat.h"
|
|
||||||
#include "minecraft/OneSixVersionFormat.h"
|
#include "minecraft/OneSixVersionFormat.h"
|
||||||
#include "minecraft/Library.h"
|
#include "minecraft/Library.h"
|
||||||
#include "net/HttpMetaCache.h"
|
#include "net/HttpMetaCache.h"
|
||||||
@@ -18,7 +17,7 @@ private:
|
|||||||
jsonFile.open(QIODevice::ReadOnly);
|
jsonFile.open(QIODevice::ReadOnly);
|
||||||
auto data = jsonFile.readAll();
|
auto data = jsonFile.readAll();
|
||||||
jsonFile.close();
|
jsonFile.close();
|
||||||
return MojangVersionFormat::libraryFromJson(QJsonDocument::fromJson(data).object(), file);
|
return OneSixVersionFormat::libraryFromJson(QJsonDocument::fromJson(data).object(), file);
|
||||||
}
|
}
|
||||||
// get absolute path to expected storage, assuming default cache prefix
|
// get absolute path to expected storage, assuming default cache prefix
|
||||||
QStringList getStorage(QString relative)
|
QStringList getStorage(QString relative)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ struct MojangLibraryDownloadInfo
|
|||||||
{
|
{
|
||||||
return artifact.get();
|
return artifact.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
return classifiers[classifier].get();
|
return classifiers[classifier].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,379 +0,0 @@
|
|||||||
#include "MojangVersionFormat.h"
|
|
||||||
#include "OneSixVersionFormat.h"
|
|
||||||
#include "MojangDownloadInfo.h"
|
|
||||||
|
|
||||||
#include "Json.h"
|
|
||||||
using namespace Json;
|
|
||||||
#include "ParseUtils.h"
|
|
||||||
|
|
||||||
static const int CURRENT_MINIMUM_LAUNCHER_VERSION = 18;
|
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
|
||||||
variable = requireString(root.value(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void readDownloadInfo(MojangDownloadInfo::Ptr out, const QJsonObject &obj)
|
|
||||||
{
|
|
||||||
// optional, not used
|
|
||||||
readString(obj, "path", out->path);
|
|
||||||
// required!
|
|
||||||
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 libDownloadInfoToJson(MojangLibraryDownloadInfo::Ptr 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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFile *out)
|
|
||||||
{
|
|
||||||
Bits::readString(in, "id", out->minecraftVersion);
|
|
||||||
Bits::readString(in, "mainClass", out->mainClass);
|
|
||||||
Bits::readString(in, "minecraftArguments", out->minecraftArguments);
|
|
||||||
if(out->minecraftArguments.isEmpty())
|
|
||||||
{
|
|
||||||
QString processArguments;
|
|
||||||
Bits::readString(in, "processArguments", processArguments);
|
|
||||||
QString toCompare = processArguments.toLower();
|
|
||||||
if (toCompare == "legacy")
|
|
||||||
{
|
|
||||||
out->minecraftArguments = " ${auth_player_name} ${auth_session}";
|
|
||||||
}
|
|
||||||
else if (toCompare == "username_session")
|
|
||||||
{
|
|
||||||
out->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
|
|
||||||
}
|
|
||||||
else if (toCompare == "username_session_version")
|
|
||||||
{
|
|
||||||
out->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
|
|
||||||
}
|
|
||||||
else if (!toCompare.isEmpty())
|
|
||||||
{
|
|
||||||
out->addProblem(ProblemSeverity::Error, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Bits::readString(in, "type", out->type);
|
|
||||||
|
|
||||||
Bits::readString(in, "assets", out->assets);
|
|
||||||
if(in.contains("assetIndex"))
|
|
||||||
{
|
|
||||||
out->mojangAssetIndex = assetIndexFromJson(requireObject(in, "assetIndex"));
|
|
||||||
}
|
|
||||||
else if (!out->assets.isNull())
|
|
||||||
{
|
|
||||||
out->mojangAssetIndex = std::make_shared<MojangAssetIndexInfo>(out->assets);
|
|
||||||
}
|
|
||||||
|
|
||||||
out->releaseTime = timeFromS3Time(in.value("releaseTime").toString(""));
|
|
||||||
out->updateTime = timeFromS3Time(in.value("time").toString(""));
|
|
||||||
|
|
||||||
if (in.contains("minimumLauncherVersion"))
|
|
||||||
{
|
|
||||||
out->minimumLauncherVersion = requireInteger(in.value("minimumLauncherVersion"));
|
|
||||||
if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
|
||||||
{
|
|
||||||
out->addProblem(
|
|
||||||
ProblemSeverity::Warning,
|
|
||||||
QObject::tr("The 'minimumLauncherVersion' value of this version (%1) is higher than supported by MultiMC (%2). It might not work properly!")
|
|
||||||
.arg(out->minimumLauncherVersion)
|
|
||||||
.arg(CURRENT_MINIMUM_LAUNCHER_VERSION));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(in.contains("downloads"))
|
|
||||||
{
|
|
||||||
auto downloadsObj = requireObject(in, "downloads");
|
|
||||||
for(auto iter = downloadsObj.begin(); iter != downloadsObj.end(); iter++)
|
|
||||||
{
|
|
||||||
auto classifier = iter.key();
|
|
||||||
auto classifierObj = requireObject(iter.value());
|
|
||||||
out->mojangDownloads[classifier] = downloadInfoFromJson(classifierObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename)
|
|
||||||
{
|
|
||||||
VersionFilePtr out(new VersionFile());
|
|
||||||
if (doc.isEmpty() || doc.isNull())
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + " is empty or null");
|
|
||||||
}
|
|
||||||
if (!doc.isObject())
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + " is not an object");
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject root = doc.object();
|
|
||||||
|
|
||||||
readVersionProperties(root, out.get());
|
|
||||||
|
|
||||||
out->name = "Minecraft";
|
|
||||||
out->uid = "net.minecraft";
|
|
||||||
out->version = out->minecraftVersion;
|
|
||||||
// out->filename = filename;
|
|
||||||
|
|
||||||
|
|
||||||
if (root.contains("libraries"))
|
|
||||||
{
|
|
||||||
for (auto libVal : requireArray(root.value("libraries")))
|
|
||||||
{
|
|
||||||
auto libObj = requireObject(libVal);
|
|
||||||
|
|
||||||
auto lib = MojangVersionFormat::libraryFromJson(libObj, filename);
|
|
||||||
out->libraries.append(lib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MojangVersionFormat::writeVersionProperties(const VersionFile* in, QJsonObject& out)
|
|
||||||
{
|
|
||||||
writeString(out, "id", in->minecraftVersion);
|
|
||||||
writeString(out, "mainClass", in->mainClass);
|
|
||||||
writeString(out, "minecraftArguments", in->minecraftArguments);
|
|
||||||
writeString(out, "type", in->type);
|
|
||||||
if(!in->releaseTime.isNull())
|
|
||||||
{
|
|
||||||
writeString(out, "releaseTime", timeToS3Time(in->releaseTime));
|
|
||||||
}
|
|
||||||
if(!in->updateTime.isNull())
|
|
||||||
{
|
|
||||||
writeString(out, "time", timeToS3Time(in->updateTime));
|
|
||||||
}
|
|
||||||
if(in->minimumLauncherVersion != -1)
|
|
||||||
{
|
|
||||||
out.insert("minimumLauncherVersion", in->minimumLauncherVersion);
|
|
||||||
}
|
|
||||||
writeString(out, "assets", in->assets);
|
|
||||||
if(in->mojangAssetIndex && in->mojangAssetIndex->known)
|
|
||||||
{
|
|
||||||
out.insert("assetIndex", assetIndexToJson(in->mojangAssetIndex));
|
|
||||||
}
|
|
||||||
if(in->mojangDownloads.size())
|
|
||||||
{
|
|
||||||
QJsonObject downloadsOut;
|
|
||||||
for(auto iter = in->mojangDownloads.begin(); iter != in->mojangDownloads.end(); iter++)
|
|
||||||
{
|
|
||||||
downloadsOut.insert(iter.key(), downloadInfoToJson(iter.value()));
|
|
||||||
}
|
|
||||||
out.insert("downloads", downloadsOut);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonDocument MojangVersionFormat::versionFileToJson(const VersionFilePtr &patch)
|
|
||||||
{
|
|
||||||
QJsonObject root;
|
|
||||||
writeVersionProperties(patch.get(), root);
|
|
||||||
if (!patch->libraries.isEmpty())
|
|
||||||
{
|
|
||||||
QJsonArray array;
|
|
||||||
for (auto value: patch->libraries)
|
|
||||||
{
|
|
||||||
array.append(MojangVersionFormat::libraryToJson(value.get()));
|
|
||||||
}
|
|
||||||
root.insert("libraries", array);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the contents to a json document.
|
|
||||||
{
|
|
||||||
QJsonDocument out;
|
|
||||||
out.setObject(root);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
|
||||||
{
|
|
||||||
LibraryPtr out(new Library());
|
|
||||||
if (!libObj.contains("name"))
|
|
||||||
{
|
|
||||||
throw JSONValidationError(filename + "contains a library that doesn't have a 'name' field");
|
|
||||||
}
|
|
||||||
out->m_name = libObj.value("name").toString();
|
|
||||||
|
|
||||||
Bits::readString(libObj, "url", out->m_repositoryURL);
|
|
||||||
if (libObj.contains("extract"))
|
|
||||||
{
|
|
||||||
out->m_hasExcludes = true;
|
|
||||||
auto extractObj = requireObject(libObj.value("extract"));
|
|
||||||
for (auto excludeVal : requireArray(extractObj.value("exclude")))
|
|
||||||
{
|
|
||||||
out->m_extractExcludes.append(requireString(excludeVal));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (libObj.contains("natives"))
|
|
||||||
{
|
|
||||||
QJsonObject nativesObj = requireObject(libObj.value("natives"));
|
|
||||||
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
|
|
||||||
{
|
|
||||||
if (!it.value().isString())
|
|
||||||
{
|
|
||||||
qWarning() << filename << "contains an invalid native (skipping)";
|
|
||||||
}
|
|
||||||
OpSys opSys = OpSys_fromString(it.key());
|
|
||||||
if (opSys != Os_Other)
|
|
||||||
{
|
|
||||||
out->m_nativeClassifiers[opSys] = it.value().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (libObj.contains("rules"))
|
|
||||||
{
|
|
||||||
out->applyRules = true;
|
|
||||||
out->m_rules = rulesFromJsonV4(libObj);
|
|
||||||
}
|
|
||||||
if (libObj.contains("downloads"))
|
|
||||||
{
|
|
||||||
out->m_mojangDownloads = libDownloadInfoFromJson(libObj);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject MojangVersionFormat::libraryToJson(Library *library)
|
|
||||||
{
|
|
||||||
QJsonObject libRoot;
|
|
||||||
libRoot.insert("name", (QString)library->m_name);
|
|
||||||
if (!library->m_repositoryURL.isEmpty())
|
|
||||||
{
|
|
||||||
libRoot.insert("url", library->m_repositoryURL);
|
|
||||||
}
|
|
||||||
if (library->isNative())
|
|
||||||
{
|
|
||||||
QJsonObject nativeList;
|
|
||||||
auto iter = library->m_nativeClassifiers.begin();
|
|
||||||
while (iter != library->m_nativeClassifiers.end())
|
|
||||||
{
|
|
||||||
nativeList.insert(OpSys_toString(iter.key()), iter.value());
|
|
||||||
iter++;
|
|
||||||
}
|
|
||||||
libRoot.insert("natives", nativeList);
|
|
||||||
if (library->m_extractExcludes.size())
|
|
||||||
{
|
|
||||||
QJsonArray excludes;
|
|
||||||
QJsonObject extract;
|
|
||||||
for (auto exclude : library->m_extractExcludes)
|
|
||||||
{
|
|
||||||
excludes.append(exclude);
|
|
||||||
}
|
|
||||||
extract.insert("exclude", excludes);
|
|
||||||
libRoot.insert("extract", extract);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (library->m_rules.size())
|
|
||||||
{
|
|
||||||
QJsonArray allRules;
|
|
||||||
for (auto &rule : library->m_rules)
|
|
||||||
{
|
|
||||||
QJsonObject ruleObj = rule->toJson();
|
|
||||||
allRules.append(ruleObj);
|
|
||||||
}
|
|
||||||
libRoot.insert("rules", allRules);
|
|
||||||
}
|
|
||||||
if(library->m_mojangDownloads)
|
|
||||||
{
|
|
||||||
auto downloadsObj = libDownloadInfoToJson(library->m_mojangDownloads);
|
|
||||||
libRoot.insert("downloads", downloadsObj);
|
|
||||||
}
|
|
||||||
return libRoot;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <minecraft/VersionFile.h>
|
|
||||||
#include <minecraft/Library.h>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
#include "multimc_logic_export.h"
|
|
||||||
|
|
||||||
class MULTIMC_LOGIC_EXPORT MojangVersionFormat
|
|
||||||
{
|
|
||||||
friend class OneSixVersionFormat;
|
|
||||||
protected:
|
|
||||||
// does not include libraries
|
|
||||||
static void readVersionProperties(const QJsonObject& in, VersionFile* out);
|
|
||||||
// does not include libraries
|
|
||||||
static void writeVersionProperties(const VersionFile* in, QJsonObject& out);
|
|
||||||
public:
|
|
||||||
// version files / profile patches
|
|
||||||
static VersionFilePtr versionFileFromJson(const QJsonDocument &doc, const QString &filename);
|
|
||||||
static QJsonDocument versionFileToJson(const VersionFilePtr &patch);
|
|
||||||
|
|
||||||
// libraries
|
|
||||||
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
|
|
||||||
static QJsonObject libraryToJson(Library *library);
|
|
||||||
};
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
#include <QTest>
|
|
||||||
#include <QDebug>
|
|
||||||
#include "TestUtil.h"
|
|
||||||
|
|
||||||
#include "minecraft/MojangVersionFormat.h"
|
|
||||||
|
|
||||||
class MojangVersionFormatTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
static QJsonDocument readJson(const char *file)
|
|
||||||
{
|
|
||||||
auto path = QFINDTESTDATA(file);
|
|
||||||
QFile jsonFile(path);
|
|
||||||
jsonFile.open(QIODevice::ReadOnly);
|
|
||||||
auto data = jsonFile.readAll();
|
|
||||||
jsonFile.close();
|
|
||||||
return QJsonDocument::fromJson(data);
|
|
||||||
}
|
|
||||||
static void writeJson(const char *file, QJsonDocument doc)
|
|
||||||
{
|
|
||||||
QFile jsonFile(file);
|
|
||||||
jsonFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
||||||
auto data = doc.toJson(QJsonDocument::Indented);
|
|
||||||
qDebug() << QString::fromUtf8(data);
|
|
||||||
jsonFile.write(data);
|
|
||||||
jsonFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private
|
|
||||||
slots:
|
|
||||||
void test_Through_Simple()
|
|
||||||
{
|
|
||||||
QJsonDocument doc = readJson("data/1.9-simple.json");
|
|
||||||
auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9-simple.json");
|
|
||||||
auto doc2 = MojangVersionFormat::versionFileToJson(vfile);
|
|
||||||
writeJson("1.9-simple-passthorugh.json", doc2);
|
|
||||||
|
|
||||||
QCOMPARE(doc.toJson(), doc2.toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_Through()
|
|
||||||
{
|
|
||||||
QJsonDocument doc = readJson("data/1.9.json");
|
|
||||||
auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9.json");
|
|
||||||
auto doc2 = MojangVersionFormat::versionFileToJson(vfile);
|
|
||||||
writeJson("1.9-passthorugh.json", doc2);
|
|
||||||
QCOMPARE(doc.toJson(), doc2.toJson());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(MojangVersionFormatTest)
|
|
||||||
|
|
||||||
#include "MojangVersionFormat_test.moc"
|
|
||||||
|
|
||||||
@@ -1,21 +1,167 @@
|
|||||||
#include "OneSixVersionFormat.h"
|
#include "OneSixVersionFormat.h"
|
||||||
#include <Json.h>
|
#include <Json.h>
|
||||||
#include "minecraft/ParseUtils.h"
|
#include "minecraft/ParseUtils.h"
|
||||||
#include <minecraft/MojangVersionFormat.h>
|
|
||||||
|
class MojangVersionFormat
|
||||||
|
{
|
||||||
|
friend class OneSixVersionFormat;
|
||||||
|
protected:
|
||||||
|
// does not include libraries
|
||||||
|
static void readVersionProperties(const QJsonObject& in, VersionFile* out);
|
||||||
|
// does not include libraries
|
||||||
|
static void writeVersionProperties(const VersionFile* in, QJsonObject& out);
|
||||||
|
public:
|
||||||
|
// libraries
|
||||||
|
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
|
||||||
|
static QJsonObject libraryToJson(Library *library);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
using namespace Json;
|
using namespace Json;
|
||||||
|
|
||||||
static void readString(const QJsonObject &root, const QString &key, QString &variable)
|
static const int CURRENT_MINIMUM_LAUNCHER_VERSION = 18;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void readString(const QJsonObject &root, const QString &key, QString &variable)
|
||||||
{
|
{
|
||||||
if (root.contains(key))
|
if (root.contains(key))
|
||||||
{
|
{
|
||||||
variable = requireString(root.value(key));
|
variable = requireString(root.value(key));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readDownloadInfo(MojangDownloadInfo::Ptr out, const QJsonObject &obj)
|
||||||
|
{
|
||||||
|
// optional, not used
|
||||||
|
readString(obj, "path", out->path);
|
||||||
|
// required!
|
||||||
|
out->sha1 = requireString(obj, "sha1");
|
||||||
|
out->url = ensureString(obj, "url", QString());
|
||||||
|
out->size = requireInteger(obj, "size");
|
||||||
|
}
|
||||||
|
|
||||||
|
void readAssetIndex(MojangAssetIndexInfo::Ptr out, const QJsonObject &obj)
|
||||||
|
{
|
||||||
|
out->totalSize = requireInteger(obj, "totalSize");
|
||||||
|
out->id = requireString(obj, "id");
|
||||||
|
// out->known = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MojangAssetIndexInfo::Ptr assetIndexFromJson(const QJsonObject &obj)
|
||||||
|
{
|
||||||
|
auto out = std::make_shared<MojangAssetIndexInfo>();
|
||||||
|
::readDownloadInfo(out, obj);
|
||||||
|
::readAssetIndex(out, obj);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
MojangDownloadInfo::Ptr downloadInfoFromJson(const QJsonObject &obj)
|
||||||
|
{
|
||||||
|
auto out = std::make_shared<MojangDownloadInfo>();
|
||||||
|
::readDownloadInfo(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
||||||
{
|
{
|
||||||
LibraryPtr out = MojangVersionFormat::libraryFromJson(libObj, filename);
|
LibraryPtr out(new Library());
|
||||||
|
if (!libObj.contains("name"))
|
||||||
|
{
|
||||||
|
throw JSONValidationError(filename + "contains a library that doesn't have a 'name' field");
|
||||||
|
}
|
||||||
|
out->m_name = libObj.value("name").toString();
|
||||||
|
|
||||||
|
::readString(libObj, "url", out->m_repositoryURL);
|
||||||
|
if (libObj.contains("extract"))
|
||||||
|
{
|
||||||
|
out->m_hasExcludes = true;
|
||||||
|
auto extractObj = requireObject(libObj.value("extract"));
|
||||||
|
for (auto excludeVal : requireArray(extractObj.value("exclude")))
|
||||||
|
{
|
||||||
|
out->m_extractExcludes.append(requireString(excludeVal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (libObj.contains("natives"))
|
||||||
|
{
|
||||||
|
QJsonObject nativesObj = requireObject(libObj.value("natives"));
|
||||||
|
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
|
||||||
|
{
|
||||||
|
if (!it.value().isString())
|
||||||
|
{
|
||||||
|
qWarning() << filename << "contains an invalid native (skipping)";
|
||||||
|
}
|
||||||
|
OpSys opSys = OpSys_fromString(it.key());
|
||||||
|
if (opSys != Os_Other)
|
||||||
|
{
|
||||||
|
out->m_nativeClassifiers[opSys] = it.value().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (libObj.contains("rules"))
|
||||||
|
{
|
||||||
|
out->applyRules = true;
|
||||||
|
out->m_rules = rulesFromJsonV4(libObj);
|
||||||
|
}
|
||||||
|
if (libObj.contains("downloads"))
|
||||||
|
{
|
||||||
|
out->m_mojangDownloads = libDownloadInfoFromJson(libObj);
|
||||||
|
}
|
||||||
|
|
||||||
readString(libObj, "MMC-hint", out->m_hint);
|
readString(libObj, "MMC-hint", out->m_hint);
|
||||||
readString(libObj, "MMC-absulute_url", out->m_absoluteURL);
|
readString(libObj, "MMC-absulute_url", out->m_absoluteURL);
|
||||||
readString(libObj, "MMC-absoluteUrl", out->m_absoluteURL);
|
readString(libObj, "MMC-absoluteUrl", out->m_absoluteURL);
|
||||||
@@ -24,20 +170,155 @@ LibraryPtr OneSixVersionFormat::libraryFromJson(const QJsonObject &libObj, const
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject libDownloadInfoToJson(MojangLibraryDownloadInfo::Ptr 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 OneSixVersionFormat::libraryToJson(Library *library)
|
QJsonObject OneSixVersionFormat::libraryToJson(Library *library)
|
||||||
{
|
{
|
||||||
QJsonObject libRoot = MojangVersionFormat::libraryToJson(library);
|
QJsonObject libRoot;
|
||||||
if (library->m_absoluteURL.size())
|
libRoot.insert("name", (QString)library->m_name);
|
||||||
|
if (!library->m_repositoryURL.isEmpty())
|
||||||
|
{
|
||||||
|
libRoot.insert("url", library->m_repositoryURL);
|
||||||
|
}
|
||||||
|
if (library->isNative())
|
||||||
|
{
|
||||||
|
QJsonObject nativeList;
|
||||||
|
auto iter = library->m_nativeClassifiers.begin();
|
||||||
|
while (iter != library->m_nativeClassifiers.end())
|
||||||
|
{
|
||||||
|
nativeList.insert(OpSys_toString(iter.key()), iter.value());
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
libRoot.insert("natives", nativeList);
|
||||||
|
if (library->m_extractExcludes.size())
|
||||||
|
{
|
||||||
|
QJsonArray excludes;
|
||||||
|
QJsonObject extract;
|
||||||
|
for (auto exclude : library->m_extractExcludes)
|
||||||
|
{
|
||||||
|
excludes.append(exclude);
|
||||||
|
}
|
||||||
|
extract.insert("exclude", excludes);
|
||||||
|
libRoot.insert("extract", extract);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (library->m_rules.size())
|
||||||
|
{
|
||||||
|
QJsonArray allRules;
|
||||||
|
for (auto &rule : library->m_rules)
|
||||||
|
{
|
||||||
|
QJsonObject ruleObj = rule->toJson();
|
||||||
|
allRules.append(ruleObj);
|
||||||
|
}
|
||||||
|
libRoot.insert("rules", allRules);
|
||||||
|
}
|
||||||
|
if(library->m_mojangDownloads)
|
||||||
|
{
|
||||||
|
auto downloadsObj = libDownloadInfoToJson(library->m_mojangDownloads);
|
||||||
|
libRoot.insert("downloads", downloadsObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// MultiMC extensions
|
||||||
|
if (library->m_absoluteURL.size()) {
|
||||||
libRoot.insert("MMC-absoluteUrl", library->m_absoluteURL);
|
libRoot.insert("MMC-absoluteUrl", library->m_absoluteURL);
|
||||||
if (library->m_hint.size())
|
}
|
||||||
|
if (library->m_hint.size()) {
|
||||||
libRoot.insert("MMC-hint", library->m_hint);
|
libRoot.insert("MMC-hint", library->m_hint);
|
||||||
if (library->m_filename.size())
|
}
|
||||||
|
if (library->m_filename.size()) {
|
||||||
libRoot.insert("MMC-filename", library->m_filename);
|
libRoot.insert("MMC-filename", library->m_filename);
|
||||||
if (library->m_displayname.size())
|
}
|
||||||
|
if (library->m_displayname.size()) {
|
||||||
libRoot.insert("MMC-displayname", library->m_displayname);
|
libRoot.insert("MMC-displayname", library->m_displayname);
|
||||||
|
}
|
||||||
|
|
||||||
return libRoot;
|
return libRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFile *out)
|
||||||
|
{
|
||||||
|
::readString(in, "id", out->minecraftVersion);
|
||||||
|
::readString(in, "mainClass", out->mainClass);
|
||||||
|
::readString(in, "minecraftArguments", out->minecraftArguments);
|
||||||
|
if(out->minecraftArguments.isEmpty())
|
||||||
|
{
|
||||||
|
QString processArguments;
|
||||||
|
::readString(in, "processArguments", processArguments);
|
||||||
|
QString toCompare = processArguments.toLower();
|
||||||
|
if (toCompare == "legacy")
|
||||||
|
{
|
||||||
|
out->minecraftArguments = " ${auth_player_name} ${auth_session}";
|
||||||
|
}
|
||||||
|
else if (toCompare == "username_session")
|
||||||
|
{
|
||||||
|
out->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
|
||||||
|
}
|
||||||
|
else if (toCompare == "username_session_version")
|
||||||
|
{
|
||||||
|
out->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
|
||||||
|
}
|
||||||
|
else if (!toCompare.isEmpty())
|
||||||
|
{
|
||||||
|
out->addProblem(ProblemSeverity::Error, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
::readString(in, "type", out->type);
|
||||||
|
|
||||||
|
::readString(in, "assets", out->assets);
|
||||||
|
if(in.contains("assetIndex"))
|
||||||
|
{
|
||||||
|
out->mojangAssetIndex = assetIndexFromJson(requireObject(in, "assetIndex"));
|
||||||
|
}
|
||||||
|
else if (!out->assets.isNull())
|
||||||
|
{
|
||||||
|
out->mojangAssetIndex = std::make_shared<MojangAssetIndexInfo>(out->assets);
|
||||||
|
}
|
||||||
|
|
||||||
|
out->releaseTime = timeFromS3Time(in.value("releaseTime").toString(""));
|
||||||
|
out->updateTime = timeFromS3Time(in.value("time").toString(""));
|
||||||
|
|
||||||
|
if (in.contains("minimumLauncherVersion"))
|
||||||
|
{
|
||||||
|
out->minimumLauncherVersion = requireInteger(in.value("minimumLauncherVersion"));
|
||||||
|
if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
||||||
|
{
|
||||||
|
out->addProblem(
|
||||||
|
ProblemSeverity::Warning,
|
||||||
|
QObject::tr("The 'minimumLauncherVersion' value of this version (%1) is higher than supported by MultiMC (%2). It might not work properly!")
|
||||||
|
.arg(out->minimumLauncherVersion)
|
||||||
|
.arg(CURRENT_MINIMUM_LAUNCHER_VERSION)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(in.contains("downloads"))
|
||||||
|
{
|
||||||
|
auto downloadsObj = requireObject(in, "downloads");
|
||||||
|
for(auto iter = downloadsObj.begin(); iter != downloadsObj.end(); iter++)
|
||||||
|
{
|
||||||
|
auto classifier = iter.key();
|
||||||
|
auto classifierObj = requireObject(iter.value());
|
||||||
|
out->mojangDownloads[classifier] = downloadInfoFromJson(classifierObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder)
|
VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder)
|
||||||
{
|
{
|
||||||
VersionFilePtr out(new VersionFile());
|
VersionFilePtr out(new VersionFile());
|
||||||
@@ -175,8 +456,16 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
// if we have mainJar, just use it
|
// if we have mainJar, just use it
|
||||||
if(root.contains("mainJar"))
|
if(root.contains("mainJar"))
|
||||||
{
|
{
|
||||||
QJsonObject libObj = requireObject(root, "mainJar");
|
auto val = root.value("mainJar");
|
||||||
out->mainJar = libraryFromJson(libObj, filename);
|
if(val.isNull())
|
||||||
|
{
|
||||||
|
out->removeMainJar = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QJsonObject libObj = requireObject(root, "mainJar");
|
||||||
|
out->mainJar = libraryFromJson(libObj, filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// else reconstruct it from downloads and id ... if that's available
|
// else reconstruct it from downloads and id ... if that's available
|
||||||
else if(!out->minecraftVersion.isEmpty())
|
else if(!out->minecraftVersion.isEmpty())
|
||||||
@@ -247,6 +536,40 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MojangVersionFormat::writeVersionProperties(const VersionFile* in, QJsonObject& out)
|
||||||
|
{
|
||||||
|
writeString(out, "id", in->minecraftVersion);
|
||||||
|
writeString(out, "mainClass", in->mainClass);
|
||||||
|
writeString(out, "minecraftArguments", in->minecraftArguments);
|
||||||
|
writeString(out, "type", in->type);
|
||||||
|
if(!in->releaseTime.isNull())
|
||||||
|
{
|
||||||
|
writeString(out, "releaseTime", timeToS3Time(in->releaseTime));
|
||||||
|
}
|
||||||
|
if(!in->updateTime.isNull())
|
||||||
|
{
|
||||||
|
writeString(out, "time", timeToS3Time(in->updateTime));
|
||||||
|
}
|
||||||
|
if(in->minimumLauncherVersion != -1)
|
||||||
|
{
|
||||||
|
out.insert("minimumLauncherVersion", in->minimumLauncherVersion);
|
||||||
|
}
|
||||||
|
writeString(out, "assets", in->assets);
|
||||||
|
if(in->mojangAssetIndex && in->mojangAssetIndex->known)
|
||||||
|
{
|
||||||
|
out.insert("assetIndex", assetIndexToJson(in->mojangAssetIndex));
|
||||||
|
}
|
||||||
|
if(in->mojangDownloads.size())
|
||||||
|
{
|
||||||
|
QJsonObject downloadsOut;
|
||||||
|
for(auto iter = in->mojangDownloads.begin(); iter != in->mojangDownloads.end(); iter++)
|
||||||
|
{
|
||||||
|
downloadsOut.insert(iter.key(), downloadInfoToJson(iter.value()));
|
||||||
|
}
|
||||||
|
out.insert("downloads", downloadsOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch)
|
QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch)
|
||||||
{
|
{
|
||||||
QJsonObject root;
|
QJsonObject root;
|
||||||
@@ -264,6 +587,10 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
|
|||||||
{
|
{
|
||||||
root.insert("mainJar", libraryToJson(patch->mainJar.get()));
|
root.insert("mainJar", libraryToJson(patch->mainJar.get()));
|
||||||
}
|
}
|
||||||
|
else if(patch->removeMainJar)
|
||||||
|
{
|
||||||
|
root.insert("mainJar", QJsonValue());
|
||||||
|
}
|
||||||
writeString(root, "appletClass", patch->appletClass);
|
writeString(root, "appletClass", patch->appletClass);
|
||||||
writeStringList(root, "+tweakers", patch->addTweakers);
|
writeStringList(root, "+tweakers", patch->addTweakers);
|
||||||
writeStringList(root, "+traits", patch->traits.toList());
|
writeStringList(root, "+traits", patch->traits.toList());
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <minecraft/Library.h>
|
#include <minecraft/Library.h>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
|
||||||
class OneSixVersionFormat
|
class MULTIMC_LOGIC_EXPORT OneSixVersionFormat
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// version files / profile patches
|
// version files / profile patches
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ void VersionFile::applyTo(LaunchProfile *profile)
|
|||||||
profile->applyMinecraftAssets(mojangAssetIndex);
|
profile->applyMinecraftAssets(mojangAssetIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
profile->applyMainJar(mainJar);
|
profile->applyMainJar(mainJar, removeMainJar);
|
||||||
profile->applyMainClass(mainClass);
|
profile->applyMainClass(mainClass);
|
||||||
profile->applyAppletClass(appletClass);
|
profile->applyAppletClass(appletClass);
|
||||||
profile->applyMinecraftArguments(minecraftArguments);
|
profile->applyMinecraftArguments(minecraftArguments);
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public: /* data */
|
|||||||
|
|
||||||
/// The main jar (Minecraft version library, normally)
|
/// The main jar (Minecraft version library, normally)
|
||||||
LibraryPtr mainJar;
|
LibraryPtr mainJar;
|
||||||
|
bool removeMainJar = false;
|
||||||
|
|
||||||
/// MultiMC: list of attached traits of this version file - used to enable features
|
/// MultiMC: list of attached traits of this version file - used to enable features
|
||||||
QSet<QString> traits;
|
QSet<QString> traits;
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ void LibrariesTask::executeTask()
|
|||||||
QList<LibraryPtr> libArtifactPool;
|
QList<LibraryPtr> libArtifactPool;
|
||||||
libArtifactPool.append(profile->getLibraries());
|
libArtifactPool.append(profile->getLibraries());
|
||||||
libArtifactPool.append(profile->getNativeLibraries());
|
libArtifactPool.append(profile->getNativeLibraries());
|
||||||
libArtifactPool.append(profile->getMainJar());
|
auto mainJar = profile->getMainJar();
|
||||||
|
if(mainJar)
|
||||||
|
{
|
||||||
|
libArtifactPool.append(mainJar);
|
||||||
|
}
|
||||||
processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath());
|
processArtifactPool(libArtifactPool, failedLocalLibraries, inst->getLocalLibraryPath());
|
||||||
|
|
||||||
QStringList failedLocalJarMods;
|
QStringList failedLocalJarMods;
|
||||||
|
|||||||
Reference in New Issue
Block a user