mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2024-09-02 13:09:22 +00:00
NOISSUE share logic for new attributes between mojang and onesix format
This commit is contained in:
parent
9e3534f2f6
commit
ec6204e447
@ -76,7 +76,7 @@ public: /* methods */
|
||||
return true;
|
||||
}
|
||||
|
||||
VersionFilePtr getVersionFile();
|
||||
virtual VersionFilePtr getVersionFile() override;
|
||||
|
||||
// virtual QJsonDocument toJson(bool saveOrder) override;
|
||||
|
||||
|
@ -508,7 +508,7 @@ void MCVListVersionUpdateTask::json_downloaded()
|
||||
file->fileId = "net.minecraft";
|
||||
|
||||
// now dump the file to disk
|
||||
auto doc = OneSixVersionFormat::profilePatchToJson(file, false);
|
||||
auto doc = OneSixVersionFormat::versionFileToJson(file, false);
|
||||
auto newdata = doc.toBinaryData();
|
||||
auto id = updatedVersion->descriptor();
|
||||
QString targetPath = "versions/" + id + "/" + id + ".dat";
|
||||
|
@ -128,6 +128,68 @@ QJsonObject assetIndexToJson(MojangAssetIndexInfo::Ptr info)
|
||||
return out;
|
||||
}
|
||||
|
||||
void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFile *out)
|
||||
{
|
||||
Bits::readString(in, "id", out->id);
|
||||
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(PROBLEM_ERROR, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments));
|
||||
}
|
||||
}
|
||||
Bits::readString(in, "type", out->type);
|
||||
|
||||
if(in.contains("assetIndex"))
|
||||
{
|
||||
out->mojangAssetIndex = assetIndexFromJson(requireObject(in, "assetIndex"));
|
||||
}
|
||||
Bits::readString(in, "assets", out->assets);
|
||||
|
||||
out->m_releaseTime = timeFromS3Time(in.value("releaseTime").toString(""));
|
||||
out->m_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(
|
||||
PROBLEM_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());
|
||||
@ -142,38 +204,13 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
||||
|
||||
QJsonObject root = doc.object();
|
||||
|
||||
readVersionProperties(root, out.get());
|
||||
|
||||
out->name = "Minecraft";
|
||||
out->fileId = "net.minecraft";
|
||||
out->version = root.value("version").toString();
|
||||
out->version = out->id;
|
||||
out->filename = filename;
|
||||
|
||||
Bits::readString(root, "id", out->id);
|
||||
|
||||
Bits::readString(root, "mainClass", out->mainClass);
|
||||
Bits::readString(root, "minecraftArguments", out->minecraftArguments);
|
||||
Bits::readString(root, "type", out->type);
|
||||
|
||||
if(root.contains("assetIndex"))
|
||||
{
|
||||
out->mojangAssetIndex = assetIndexFromJson(requireObject(root, "assetIndex"));
|
||||
}
|
||||
Bits::readString(root, "assets", out->assets);
|
||||
|
||||
out->m_releaseTime = timeFromS3Time(root.value("releaseTime").toString(""));
|
||||
out->m_updateTime = timeFromS3Time(root.value("time").toString(""));
|
||||
|
||||
if (root.contains("minimumLauncherVersion"))
|
||||
{
|
||||
out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion"));
|
||||
if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION)
|
||||
{
|
||||
out->addProblem(
|
||||
PROBLEM_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 (root.contains("libraries"))
|
||||
{
|
||||
@ -185,34 +222,41 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
||||
out->libraries.append(lib);
|
||||
}
|
||||
}
|
||||
if(root.contains("downloads"))
|
||||
{
|
||||
auto downloadsObj = requireObject(root, "downloads");
|
||||
for(auto iter = downloadsObj.begin(); iter != downloadsObj.end(); iter++)
|
||||
{
|
||||
auto classifier = iter.key();
|
||||
auto classifierObj = requireObject(iter.value());
|
||||
out->mojangDownloads[classifier] = downloadInfoFromJson(classifierObj);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
QJsonDocument versionFileToJson(VersionFilePtr patch)
|
||||
void MojangVersionFormat::writeVersionProperties(const VersionFile* in, QJsonObject& out)
|
||||
{
|
||||
writeString(out, "id", in->id);
|
||||
writeString(out, "mainClass", in->mainClass);
|
||||
writeString(out, "minecraftArguments", in->minecraftArguments);
|
||||
writeString(out, "type", in->type);
|
||||
writeString(out, "assets", in->assets);
|
||||
writeString(out, "releaseTime", timeToS3Time(in->m_releaseTime));
|
||||
writeString(out, "time", timeToS3Time(in->m_updateTime));
|
||||
if(in->minimumLauncherVersion != -1)
|
||||
{
|
||||
out.insert("minimumLauncherVersion", in->minimumLauncherVersion);
|
||||
}
|
||||
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;
|
||||
writeString(root, "id", patch->id);
|
||||
writeString(root, "mainClass", patch->mainClass);
|
||||
writeString(root, "minecraftArguments", patch->minecraftArguments);
|
||||
writeString(root, "type", patch->type);
|
||||
writeString(root, "assets", patch->assets);
|
||||
writeString(root, "releaseTime", timeToS3Time(patch->m_releaseTime));
|
||||
writeString(root, "time", timeToS3Time(patch->m_updateTime));
|
||||
if(patch->minimumLauncherVersion != -1)
|
||||
{
|
||||
root.insert("minimumLauncherVersion", patch->minimumLauncherVersion);
|
||||
}
|
||||
|
||||
writeVersionProperties(patch.get(), root);
|
||||
if (!patch->libraries.isEmpty())
|
||||
{
|
||||
QJsonArray array;
|
||||
@ -222,19 +266,7 @@ QJsonDocument versionFileToJson(VersionFilePtr patch)
|
||||
}
|
||||
root.insert("libraries", array);
|
||||
}
|
||||
if(patch->mojangAssetIndex && patch->mojangAssetIndex->known)
|
||||
{
|
||||
root.insert("assetIndex", assetIndexToJson(patch->mojangAssetIndex));
|
||||
}
|
||||
if(patch->mojangDownloads.size())
|
||||
{
|
||||
QJsonObject downloadsOut;
|
||||
for(auto iter = patch->mojangDownloads.begin(); iter != patch->mojangDownloads.end(); iter++)
|
||||
{
|
||||
downloadsOut.insert(iter.key(), downloadInfoToJson(iter.value()));
|
||||
}
|
||||
root.insert("downloads", downloadsOut);
|
||||
}
|
||||
|
||||
// write the contents to a json document.
|
||||
{
|
||||
QJsonDocument out;
|
||||
@ -243,33 +275,6 @@ QJsonDocument versionFileToJson(VersionFilePtr patch)
|
||||
}
|
||||
}
|
||||
|
||||
static QJsonDocument minecraftVersionToJson(MinecraftVersionPtr patch)
|
||||
{
|
||||
if(patch->getVersionSource() == Local && patch->getVersionFile())
|
||||
{
|
||||
return MojangVersionFormat::profilePatchToJson(patch->getVersionFile());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(patch->name()));
|
||||
}
|
||||
}
|
||||
|
||||
QJsonDocument MojangVersionFormat::profilePatchToJson(const ProfilePatchPtr &patch)
|
||||
{
|
||||
auto vfile = std::dynamic_pointer_cast<VersionFile>(patch);
|
||||
if(vfile)
|
||||
{
|
||||
return versionFileToJson(vfile);
|
||||
}
|
||||
auto mversion = std::dynamic_pointer_cast<MinecraftVersion>(patch);
|
||||
if(mversion)
|
||||
{
|
||||
return minecraftVersionToJson(mversion);
|
||||
}
|
||||
throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getName()));
|
||||
}
|
||||
|
||||
LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
|
||||
{
|
||||
LibraryPtr out(new Library());
|
||||
|
@ -8,10 +8,16 @@
|
||||
|
||||
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 profilePatchToJson(const ProfilePatchPtr &patch);
|
||||
static QJsonDocument versionFileToJson(const VersionFilePtr &patch);
|
||||
|
||||
// libraries
|
||||
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <QList>
|
||||
#include <QJsonDocument>
|
||||
#include <QDateTime>
|
||||
#include "JarMod.h"
|
||||
|
||||
class MinecraftProfile;
|
||||
@ -43,7 +44,7 @@ private:
|
||||
QString m_description;
|
||||
};
|
||||
|
||||
class ProfilePatch
|
||||
class ProfilePatch : public std::enable_shared_from_this<ProfilePatch>
|
||||
{
|
||||
public:
|
||||
virtual ~ProfilePatch(){};
|
||||
@ -73,6 +74,8 @@ public:
|
||||
|
||||
virtual VersionSource getVersionSource() = 0;
|
||||
|
||||
virtual std::shared_ptr<class VersionFile> getVersionFile() = 0;
|
||||
|
||||
virtual const QList<PatchProblem>& getProblems()
|
||||
{
|
||||
return m_problems;
|
||||
|
@ -63,6 +63,10 @@ public: /* methods */
|
||||
return Local;
|
||||
}
|
||||
|
||||
std::shared_ptr<class VersionFile> getVersionFile() override
|
||||
{
|
||||
return std::dynamic_pointer_cast<VersionFile>(shared_from_this());
|
||||
}
|
||||
|
||||
virtual bool isCustom() override
|
||||
{
|
||||
|
@ -275,7 +275,7 @@ bool ForgeInstaller::add(OneSixInstance *to)
|
||||
<< "for reading:" << file.errorString();
|
||||
return false;
|
||||
}
|
||||
file.write(OneSixVersionFormat::profilePatchToJson(m_forge_json, true).toJson());
|
||||
file.write(OneSixVersionFormat::versionFileToJson(m_forge_json, true).toJson());
|
||||
file.commit();
|
||||
|
||||
return true;
|
||||
|
@ -56,7 +56,7 @@ void OneSixProfileStrategy::upgradeDeprecatedFiles()
|
||||
file->fileId = "net.minecraft";
|
||||
file->version = file->id;
|
||||
file->name = "Minecraft";
|
||||
auto data = OneSixVersionFormat::profilePatchToJson(file, false).toJson();
|
||||
auto data = OneSixVersionFormat::versionFileToJson(file, false).toJson();
|
||||
QSaveFile newPatchFile(mcJson);
|
||||
if(!newPatchFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
@ -299,7 +299,12 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto document = OneSixVersionFormat::profilePatchToJson(patch, true);
|
||||
auto vfile = patch->getVersionFile();
|
||||
if(!vfile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto document = OneSixVersionFormat::versionFileToJson(vfile, true);
|
||||
jsonFile.write(document.toJson());
|
||||
if(!jsonFile.commit())
|
||||
{
|
||||
@ -402,7 +407,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
|
||||
<< "for reading:" << file.errorString();
|
||||
return false;
|
||||
}
|
||||
file.write(OneSixVersionFormat::profilePatchToJson(f, true).toJson());
|
||||
file.write(OneSixVersionFormat::versionFileToJson(f, true).toJson());
|
||||
file.close();
|
||||
profile->appendPatch(f);
|
||||
}
|
||||
|
@ -76,40 +76,10 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
||||
out->mcVersion = root.value("mcVersion").toString();
|
||||
out->filename = filename;
|
||||
|
||||
readString(root, "id", out->id);
|
||||
MojangVersionFormat::readVersionProperties(root, out.get());
|
||||
|
||||
readString(root, "mainClass", out->mainClass);
|
||||
// added for legacy Minecraft window embedding, TODO: remove
|
||||
readString(root, "appletClass", out->appletClass);
|
||||
readString(root, "minecraftArguments", out->minecraftArguments);
|
||||
if(out->minecraftArguments.isEmpty())
|
||||
{
|
||||
QString processArguments;
|
||||
readString(root, "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(PROBLEM_ERROR, QObject::tr("processArguments is set to unknown value '%1'").arg(processArguments));
|
||||
}
|
||||
}
|
||||
|
||||
readString(root, "type", out->type);
|
||||
|
||||
out->m_releaseTime = timeFromS3Time(readStringRet(root, "releaseTime"));
|
||||
out->m_updateTime = timeFromS3Time(readStringRet(root, "time"));
|
||||
|
||||
readString(root, "assets", out->assets);
|
||||
|
||||
if (root.contains("+tweakers"))
|
||||
{
|
||||
@ -196,16 +166,7 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct libraryConversion
|
||||
{
|
||||
static QJsonObject convert(std::shared_ptr<Library> &value)
|
||||
{
|
||||
return OneSixVersionFormat::libraryToJson(value.get());
|
||||
}
|
||||
};
|
||||
|
||||
static QJsonDocument versionFileToJson(VersionFilePtr patch, bool saveOrder)
|
||||
QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch, bool saveOrder)
|
||||
{
|
||||
QJsonObject root;
|
||||
if (saveOrder)
|
||||
@ -216,17 +177,10 @@ static QJsonDocument versionFileToJson(VersionFilePtr patch, bool saveOrder)
|
||||
writeString(root, "fileId", patch->fileId);
|
||||
writeString(root, "version", patch->version);
|
||||
writeString(root, "mcVersion", patch->mcVersion);
|
||||
writeString(root, "id", patch->id);
|
||||
writeString(root, "mainClass", patch->mainClass);
|
||||
|
||||
MojangVersionFormat::writeVersionProperties(patch.get(), root);
|
||||
|
||||
writeString(root, "appletClass", patch->appletClass);
|
||||
writeString(root, "minecraftArguments", patch->minecraftArguments);
|
||||
writeString(root, "type", patch->type);
|
||||
writeString(root, "assets", patch->assets);
|
||||
if (patch->isMinecraftVersion())
|
||||
{
|
||||
writeString(root, "releaseTime", timeToS3Time(patch->m_releaseTime));
|
||||
writeString(root, "time", timeToS3Time(patch->m_updateTime));
|
||||
}
|
||||
writeStringList(root, "+tweakers", patch->addTweakers);
|
||||
writeStringList(root, "+traits", patch->traits.toList());
|
||||
if (!patch->libraries.isEmpty())
|
||||
@ -255,33 +209,6 @@ static QJsonDocument versionFileToJson(VersionFilePtr patch, bool saveOrder)
|
||||
}
|
||||
}
|
||||
|
||||
static QJsonDocument minecraftVersionToJson(MinecraftVersionPtr patch, bool saveOrder)
|
||||
{
|
||||
if(patch->getVersionSource() == Local && patch->getVersionFile())
|
||||
{
|
||||
return OneSixVersionFormat::profilePatchToJson(patch->getVersionFile(), saveOrder);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(patch->name()));
|
||||
}
|
||||
}
|
||||
|
||||
QJsonDocument OneSixVersionFormat::profilePatchToJson(const ProfilePatchPtr &patch, bool saveOrder)
|
||||
{
|
||||
auto vfile = std::dynamic_pointer_cast<VersionFile>(patch);
|
||||
if(vfile)
|
||||
{
|
||||
return versionFileToJson(vfile, saveOrder);
|
||||
}
|
||||
auto mversion = std::dynamic_pointer_cast<MinecraftVersion>(patch);
|
||||
if(mversion)
|
||||
{
|
||||
return minecraftVersionToJson(mversion, saveOrder);
|
||||
}
|
||||
throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getName()));
|
||||
}
|
||||
|
||||
JarmodPtr OneSixVersionFormat::jarModFromJson(const QJsonObject &libObj, const QString &filename, const QString &originalName)
|
||||
{
|
||||
JarmodPtr out(new Jarmod());
|
||||
|
@ -10,7 +10,7 @@ class OneSixVersionFormat
|
||||
public:
|
||||
// version files / profile patches
|
||||
static VersionFilePtr versionFileFromJson(const QJsonDocument &doc, const QString &filename, const bool requireOrder);
|
||||
static QJsonDocument profilePatchToJson(const ProfilePatchPtr &patch, bool saveOrder);
|
||||
static QJsonDocument versionFileToJson(const VersionFilePtr &patch, bool saveOrder);
|
||||
|
||||
// libraries
|
||||
static LibraryPtr libraryFromJson(const QJsonObject &libObj, const QString &filename);
|
||||
|
@ -33,7 +33,7 @@ slots:
|
||||
|
||||
QJsonDocument doc = readJson("tests/data/1.9-simple.json");
|
||||
auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9-simple.json");
|
||||
auto doc2 = MojangVersionFormat::profilePatchToJson(vfile);
|
||||
auto doc2 = MojangVersionFormat::versionFileToJson(vfile);
|
||||
writeJson("1.9-simple-passthorugh.json", doc2);
|
||||
QCOMPARE(doc, doc2);
|
||||
}
|
||||
@ -43,7 +43,7 @@ slots:
|
||||
|
||||
QJsonDocument doc = readJson("tests/data/1.9.json");
|
||||
auto vfile = MojangVersionFormat::versionFileFromJson(doc, "1.9.json");
|
||||
auto doc2 = MojangVersionFormat::profilePatchToJson(vfile);
|
||||
auto doc2 = MojangVersionFormat::versionFileToJson(vfile);
|
||||
writeJson("1.9-passthorugh.json", doc2);
|
||||
QCOMPARE(doc, doc2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user