summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/MinecraftProfile.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-05-17 23:38:28 +0200
committerPetr Mrázek <peterix@gmail.com>2015-05-17 23:38:28 +0200
commit743af4769ee59b5830d79139852dda0679b28a03 (patch)
tree939e150c6127c9bc64926da052fe56e2b483990d /logic/minecraft/MinecraftProfile.cpp
parent6ab6a450f6831c99ba507436ab15047cfa4d4528 (diff)
downloadMultiMC-743af4769ee59b5830d79139852dda0679b28a03.tar
MultiMC-743af4769ee59b5830d79139852dda0679b28a03.tar.gz
MultiMC-743af4769ee59b5830d79139852dda0679b28a03.tar.lz
MultiMC-743af4769ee59b5830d79139852dda0679b28a03.tar.xz
MultiMC-743af4769ee59b5830d79139852dda0679b28a03.zip
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
Diffstat (limited to 'logic/minecraft/MinecraftProfile.cpp')
-rw-r--r--logic/minecraft/MinecraftProfile.cpp87
1 files changed, 57 insertions, 30 deletions
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<std::shared_ptr<OneSixLibrary> > MinecraftProfile::getActiveNormalLibs()