summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/MinecraftProfile.cpp
diff options
context:
space:
mode:
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()