diff options
Diffstat (limited to 'logic/minecraft')
-rw-r--r-- | logic/minecraft/MinecraftVersion.h | 2 | ||||
-rw-r--r-- | logic/minecraft/MinecraftVersionList.cpp | 2 | ||||
-rw-r--r-- | logic/minecraft/MojangVersionFormat.cpp | 181 | ||||
-rw-r--r-- | logic/minecraft/MojangVersionFormat.h | 8 | ||||
-rw-r--r-- | logic/minecraft/ProfilePatch.h | 5 | ||||
-rw-r--r-- | logic/minecraft/VersionFile.h | 4 | ||||
-rw-r--r-- | logic/minecraft/forge/ForgeInstaller.cpp | 2 | ||||
-rw-r--r-- | logic/minecraft/onesix/OneSixProfileStrategy.cpp | 11 | ||||
-rw-r--r-- | logic/minecraft/onesix/OneSixVersionFormat.cpp | 85 | ||||
-rw-r--r-- | logic/minecraft/onesix/OneSixVersionFormat.h | 2 |
10 files changed, 126 insertions, 176 deletions
diff --git a/logic/minecraft/MinecraftVersion.h b/logic/minecraft/MinecraftVersion.h index 2c1eb289..1539ffd8 100644 --- a/logic/minecraft/MinecraftVersion.h +++ b/logic/minecraft/MinecraftVersion.h @@ -76,7 +76,7 @@ public: /* methods */ return true; } - VersionFilePtr getVersionFile(); + virtual VersionFilePtr getVersionFile() override; // virtual QJsonDocument toJson(bool saveOrder) override; diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp index f219c782..62c588d1 100644 --- a/logic/minecraft/MinecraftVersionList.cpp +++ b/logic/minecraft/MinecraftVersionList.cpp @@ -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"; diff --git a/logic/minecraft/MojangVersionFormat.cpp b/logic/minecraft/MojangVersionFormat.cpp index a832e8c7..78447aa8 100644 --- a/logic/minecraft/MojangVersionFormat.cpp +++ b/logic/minecraft/MojangVersionFormat.cpp @@ -128,43 +128,47 @@ QJsonObject assetIndexToJson(MojangAssetIndexInfo::Ptr info) return out; } -VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename) +void MojangVersionFormat::readVersionProperties(const QJsonObject &in, VersionFile *out) { - VersionFilePtr out(new VersionFile()); - if (doc.isEmpty() || doc.isNull()) - { - throw JSONValidationError(filename + " is empty or null"); - } - if (!doc.isObject()) + Bits::readString(in, "id", out->id); + Bits::readString(in, "mainClass", out->mainClass); + Bits::readString(in, "minecraftArguments", out->minecraftArguments); + if(out->minecraftArguments.isEmpty()) { - throw JSONValidationError(filename + " is not an object"); + 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); - QJsonObject root = doc.object(); - - out->name = "Minecraft"; - out->fileId = "net.minecraft"; - out->version = root.value("version").toString(); - 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")) + if(in.contains("assetIndex")) { - out->mojangAssetIndex = assetIndexFromJson(requireObject(root, "assetIndex")); + out->mojangAssetIndex = assetIndexFromJson(requireObject(in, "assetIndex")); } - Bits::readString(root, "assets", out->assets); + Bits::readString(in, "assets", out->assets); - out->m_releaseTime = timeFromS3Time(root.value("releaseTime").toString("")); - out->m_updateTime = timeFromS3Time(root.value("time").toString("")); + out->m_releaseTime = timeFromS3Time(in.value("releaseTime").toString("")); + out->m_updateTime = timeFromS3Time(in.value("time").toString("")); - if (root.contains("minimumLauncherVersion")) + if (in.contains("minimumLauncherVersion")) { - out->minimumLauncherVersion = requireInteger(root.value("minimumLauncherVersion")); + out->minimumLauncherVersion = requireInteger(in.value("minimumLauncherVersion")); if (out->minimumLauncherVersion > CURRENT_MINIMUM_LAUNCHER_VERSION) { out->addProblem( @@ -174,20 +178,9 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc .arg(CURRENT_MINIMUM_LAUNCHER_VERSION)); } } - - 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); - } - } - if(root.contains("downloads")) + if(in.contains("downloads")) { - auto downloadsObj = requireObject(root, "downloads"); + auto downloadsObj = requireObject(in, "downloads"); for(auto iter = downloadsObj.begin(); iter != downloadsObj.end(); iter++) { auto classifier = iter.key(); @@ -195,79 +188,91 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc out->mojangDownloads[classifier] = downloadInfoFromJson(classifierObj); } } - return out; } -QJsonDocument versionFileToJson(VersionFilePtr patch) +VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc, const QString &filename) { - 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) + VersionFilePtr out(new VersionFile()); + if (doc.isEmpty() || doc.isNull()) { - root.insert("minimumLauncherVersion", patch->minimumLauncherVersion); + throw JSONValidationError(filename + " is empty or null"); + } + if (!doc.isObject()) + { + throw JSONValidationError(filename + " is not an object"); } - if (!patch->libraries.isEmpty()) + QJsonObject root = doc.object(); + + readVersionProperties(root, out.get()); + + out->name = "Minecraft"; + out->fileId = "net.minecraft"; + out->version = out->id; + out->filename = filename; + + + if (root.contains("libraries")) { - QJsonArray array; - for (auto value: patch->libraries) + for (auto libVal : requireArray(root.value("libraries"))) { - array.append(MojangVersionFormat::libraryToJson(value.get())); + auto libObj = requireObject(libVal); + + auto lib = MojangVersionFormat::libraryFromJson(libObj, filename); + out->libraries.append(lib); } - root.insert("libraries", array); } - if(patch->mojangAssetIndex && patch->mojangAssetIndex->known) + return out; +} + +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) { - root.insert("assetIndex", assetIndexToJson(patch->mojangAssetIndex)); + out.insert("assetIndex", assetIndexToJson(in->mojangAssetIndex)); } - if(patch->mojangDownloads.size()) + if(in->mojangDownloads.size()) { QJsonObject downloadsOut; - for(auto iter = patch->mojangDownloads.begin(); iter != patch->mojangDownloads.end(); iter++) + for(auto iter = in->mojangDownloads.begin(); iter != in->mojangDownloads.end(); iter++) { downloadsOut.insert(iter.key(), downloadInfoToJson(iter.value())); } - root.insert("downloads", downloadsOut); - } - // write the contents to a json document. - { - QJsonDocument out; - out.setObject(root); - return out; + out.insert("downloads", downloadsOut); } } -static QJsonDocument minecraftVersionToJson(MinecraftVersionPtr patch) +QJsonDocument MojangVersionFormat::versionFileToJson(const VersionFilePtr &patch) { - if(patch->getVersionSource() == Local && patch->getVersionFile()) - { - return MojangVersionFormat::profilePatchToJson(patch->getVersionFile()); - } - else + QJsonObject root; + writeVersionProperties(patch.get(), root); + if (!patch->libraries.isEmpty()) { - throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(patch->name())); + QJsonArray array; + for (auto value: patch->libraries) + { + array.append(MojangVersionFormat::libraryToJson(value.get())); + } + root.insert("libraries", array); } -} -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) + // write the contents to a json document. { - return minecraftVersionToJson(mversion); + QJsonDocument out; + out.setObject(root); + return out; } - throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getName())); } LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename) diff --git a/logic/minecraft/MojangVersionFormat.h b/logic/minecraft/MojangVersionFormat.h index a5a94095..4e141088 100644 --- a/logic/minecraft/MojangVersionFormat.h +++ b/logic/minecraft/MojangVersionFormat.h @@ -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); diff --git a/logic/minecraft/ProfilePatch.h b/logic/minecraft/ProfilePatch.h index 56bc58a7..fa2f0a0f 100644 --- a/logic/minecraft/ProfilePatch.h +++ b/logic/minecraft/ProfilePatch.h @@ -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; diff --git a/logic/minecraft/VersionFile.h b/logic/minecraft/VersionFile.h index 49c55646..7627cc96 100644 --- a/logic/minecraft/VersionFile.h +++ b/logic/minecraft/VersionFile.h @@ -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 { diff --git a/logic/minecraft/forge/ForgeInstaller.cpp b/logic/minecraft/forge/ForgeInstaller.cpp index 86ba6176..7957de0e 100644 --- a/logic/minecraft/forge/ForgeInstaller.cpp +++ b/logic/minecraft/forge/ForgeInstaller.cpp @@ -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; diff --git a/logic/minecraft/onesix/OneSixProfileStrategy.cpp b/logic/minecraft/onesix/OneSixProfileStrategy.cpp index 3ae055c0..aaaa9d97 100644 --- a/logic/minecraft/onesix/OneSixProfileStrategy.cpp +++ b/logic/minecraft/onesix/OneSixProfileStrategy.cpp @@ -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); } diff --git a/logic/minecraft/onesix/OneSixVersionFormat.cpp b/logic/minecraft/onesix/OneSixVersionFormat.cpp index e262cecd..d4b372c3 100644 --- a/logic/minecraft/onesix/OneSixVersionFormat.cpp +++ b/logic/minecraft/onesix/OneSixVersionFormat.cpp @@ -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()); diff --git a/logic/minecraft/onesix/OneSixVersionFormat.h b/logic/minecraft/onesix/OneSixVersionFormat.h index 3011688c..5696e79e 100644 --- a/logic/minecraft/onesix/OneSixVersionFormat.h +++ b/logic/minecraft/onesix/OneSixVersionFormat.h @@ -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); |