From a98e1df10cef774672e919497c43373e86c77f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 28 May 2015 09:36:58 +0200 Subject: GH-1011 fetch missing versions when customizing/reverting Minecraft patches --- application/pages/VersionPage.cpp | 30 ++++++++++++++++++++++++++++-- application/pages/VersionPage.h | 1 + logic/minecraft/MinecraftVersionList.cpp | 1 + logic/minecraft/OneSixProfileStrategy.cpp | 22 +++++++++++----------- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/application/pages/VersionPage.cpp b/application/pages/VersionPage.cpp index bb310eea..831408f6 100644 --- a/application/pages/VersionPage.cpp +++ b/application/pages/VersionPage.cpp @@ -44,6 +44,8 @@ #include "liteloader/LiteLoaderInstaller.h" #include "auth/MojangAccountList.h" #include "minecraft/Mod.h" +#include +#include #include "icons/IconList.h" @@ -224,16 +226,21 @@ void VersionPage::on_changeVersionBtn_clicked() reloadMinecraftProfile(); } m_inst->setIntendedVersionId(vselect.selectedVersion()->descriptor()); + doUpdate(); +} +int VersionPage::doUpdate() +{ auto updateTask = m_inst->doUpdate(); if (!updateTask) { - return; + return 1; } ProgressDialog tDialog(this); connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString))); - tDialog.exec(updateTask.get()); + int ret = tDialog.exec(updateTask.get()); updateButtons(); + return ret; } void VersionPage::on_forgeBtn_clicked() @@ -353,6 +360,16 @@ void VersionPage::on_customizeBtn_clicked() { return; } + //HACK HACK remove, this is dumb + auto patch = m_version->versionPatch(version); + auto mc = std::dynamic_pointer_cast(patch); + if(mc && mc->needsUpdate()) + { + if(!doUpdate()) + { + return; + } + } if(!m_version->customize(version)) { // TODO: some error box here @@ -384,6 +401,15 @@ void VersionPage::on_revertBtn_clicked() { return; } + auto mcraw = MMC->minecraftlist()->findVersion(m_inst->intendedVersionId()); + auto mc = std::dynamic_pointer_cast(mcraw); + if(mc && mc->needsUpdate()) + { + if(!doUpdate()) + { + return; + } + } if(!m_version->revert(version)) { // TODO: some error box here diff --git a/application/pages/VersionPage.h b/application/pages/VersionPage.h index f3b49544..49837f80 100644 --- a/application/pages/VersionPage.h +++ b/application/pages/VersionPage.h @@ -69,6 +69,7 @@ private: int currentRow(); void updateButtons(int row = -1); void preselect(int row = 0); + int doUpdate(); protected: /// FIXME: this shouldn't be necessary! diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp index 90ef5ebe..c20534e9 100644 --- a/logic/minecraft/MinecraftVersionList.cpp +++ b/logic/minecraft/MinecraftVersionList.cpp @@ -599,6 +599,7 @@ void MinecraftVersionList::saveCachedList() QJsonObject entryObj; entryObj.insert("id", mcversion->descriptor()); + entryObj.insert("version", mcversion->descriptor()); entryObj.insert("time", mcversion->m_updateTimeString); entryObj.insert("releaseTime", mcversion->m_releaseTimeString); entryObj.insert("type", mcversion->m_type); diff --git a/logic/minecraft/OneSixProfileStrategy.cpp b/logic/minecraft/OneSixProfileStrategy.cpp index b7ba2bf6..cd8fd976 100644 --- a/logic/minecraft/OneSixProfileStrategy.cpp +++ b/logic/minecraft/OneSixProfileStrategy.cpp @@ -275,19 +275,19 @@ bool OneSixProfileStrategy::customizePatch(ProfilePatchPtr patch) { return false; } - QSaveFile jsonFile(filename); - if(!jsonFile.open(QIODevice::WriteOnly)) - { - return false; - } - auto document = patch->toJson(true); - jsonFile.write(document.toJson()); - if(!jsonFile.commit()) - { - return false; - } try { + QSaveFile jsonFile(filename); + if(!jsonFile.open(QIODevice::WriteOnly)) + { + return false; + } + auto document = patch->toJson(true); + jsonFile.write(document.toJson()); + if(!jsonFile.commit()) + { + return false; + } load(); } catch (VersionIncomplete &error) -- cgit v1.2.3