From 743af4769ee59b5830d79139852dda0679b28a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 17 May 2015 23:38:28 +0200 Subject: GH-952 Hardcore version page tweakery Version patches get a lot of new flags that determine which actions are allowed Version page respects the flags Customize, revert and edit for version patches Builting patches can be customized --- logic/minecraft/MinecraftProfile.cpp | 87 +++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 30 deletions(-) (limited to 'logic/minecraft/MinecraftProfile.cpp') diff --git a/logic/minecraft/MinecraftProfile.cpp b/logic/minecraft/MinecraftProfile.cpp index acde7dc7..345930ca 100644 --- a/logic/minecraft/MinecraftProfile.cpp +++ b/logic/minecraft/MinecraftProfile.cpp @@ -91,22 +91,18 @@ void MinecraftProfile::appendPatch(ProfilePatchPtr patch) endInsertRows(); } -bool MinecraftProfile::canRemove(const int index) const -{ - return VersionPatches.at(index)->isMoveable(); -} - bool MinecraftProfile::remove(const int index) { - if (!canRemove(index)) + auto patch = versionPatch(index); + if (!patch->isRemovable()) { - qDebug() << "Patch" << index << "is non-removable"; + qDebug() << "Patch" << patch->getPatchID() << "is non-removable"; return false; } - if(!m_strategy->removePatch(VersionPatches.at(index))) + if(!m_strategy->removePatch(patch)) { - qCritical() << "Patch" << index << "could not be removed"; + qCritical() << "Patch" << patch->getPatchID() << "could not be removed"; return false; } @@ -132,6 +128,46 @@ bool MinecraftProfile::remove(const QString id) return false; } +bool MinecraftProfile::customize(int index) +{ + auto patch = versionPatch(index); + if (!patch->isCustomizable()) + { + qDebug() << "Patch" << patch->getPatchID() << "is not customizable"; + return false; + } + if(!m_strategy->customizePatch(patch)) + { + qCritical() << "Patch" << patch->getPatchID() << "could not be customized"; + return false; + } + reapply(); + saveCurrentOrder(); + // FIXME: maybe later in unstable + // emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1)); + return true; +} + +bool MinecraftProfile::revert(int index) +{ + auto patch = versionPatch(index); + if (!patch->isRevertible()) + { + qDebug() << "Patch" << patch->getPatchID() << "is not revertible"; + return false; + } + if(!m_strategy->revertPatch(patch)) + { + qCritical() << "Patch" << patch->getPatchID() << "could not be reverted"; + return false; + } + reapply(); + saveCurrentOrder(); + // FIXME: maybe later in unstable + // emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1)); + return true; +} + QString MinecraftProfile::versionFileId(const int index) const { if (index < 0 || index >= VersionPatches.size()) @@ -150,13 +186,13 @@ ProfilePatchPtr MinecraftProfile::versionPatch(const QString &id) return file; } } - return 0; + return nullptr; } ProfilePatchPtr MinecraftProfile::versionPatch(int index) { if(index < 0 || index >= VersionPatches.size()) - return 0; + return nullptr; return VersionPatches[index]; } @@ -172,37 +208,28 @@ bool MinecraftProfile::isVanilla() bool MinecraftProfile::revertToVanilla() { - /* - beginResetModel(); // remove patches, if present - auto it = VersionPatches.begin(); - while (it != VersionPatches.end()) + auto VersionPatchesCopy = VersionPatches; + for(auto & it: VersionPatchesCopy) { - if ((*it)->isMoveable()) + if (!it->isCustom()) { - if(!preremove(*it)) - { - endResetModel(); - saveCurrentOrder(); - return false; - } - if(!QFile::remove((*it)->getPatchFilename())) + continue; + } + if(it->isRevertible() || it->isRemovable()) + { + if(!remove(it->getPatchID())) { - endResetModel(); + qWarning() << "Couldn't remove" << it->getPatchID() << "from profile!"; + reapply(); saveCurrentOrder(); return false; } - it = VersionPatches.erase(it); } - else - it++; } reapply(); - endResetModel(); saveCurrentOrder(); return true; - */ - return false; } QList > MinecraftProfile::getActiveNormalLibs() -- cgit v1.2.3