diff --git a/logic/minecraft/MinecraftProfile.cpp b/logic/minecraft/MinecraftProfile.cpp index 345930cae..0661aec13 100644 --- a/logic/minecraft/MinecraftProfile.cpp +++ b/logic/minecraft/MinecraftProfile.cpp @@ -22,6 +22,7 @@ #include "minecraft/MinecraftProfile.h" #include "ProfileUtils.h" #include "NullProfileStrategy.h" +#include "VersionBuildError.h" MinecraftProfile::MinecraftProfile(ProfileStrategy *strategy) : QAbstractListModel() @@ -52,7 +53,7 @@ void MinecraftProfile::reload() { beginResetModel(); m_strategy->load(); - reapply(); + reapplySafe(); endResetModel(); } @@ -109,7 +110,7 @@ bool MinecraftProfile::remove(const int index) beginRemoveRows(QModelIndex(), index, index); VersionPatches.removeAt(index); endRemoveRows(); - reapply(); + reapplySafe(); saveCurrentOrder(); return true; } @@ -141,7 +142,7 @@ bool MinecraftProfile::customize(int index) qCritical() << "Patch" << patch->getPatchID() << "could not be customized"; return false; } - reapply(); + reapplySafe(); saveCurrentOrder(); // FIXME: maybe later in unstable // emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1)); @@ -161,7 +162,7 @@ bool MinecraftProfile::revert(int index) qCritical() << "Patch" << patch->getPatchID() << "could not be reverted"; return false; } - reapply(); + reapplySafe(); saveCurrentOrder(); // FIXME: maybe later in unstable // emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1)); @@ -221,13 +222,13 @@ bool MinecraftProfile::revertToVanilla() if(!remove(it->getPatchID())) { qWarning() << "Couldn't remove" << it->getPatchID() << "from profile!"; - reapply(); + reapplySafe(); saveCurrentOrder(); return false; } } } - reapply(); + reapplySafe(); saveCurrentOrder(); return true; } @@ -398,8 +399,8 @@ void MinecraftProfile::move(const int index, const MoveDirection direction) beginMoveRows(QModelIndex(), index, index, QModelIndex(), togap); VersionPatches.swap(index, theirIndex); endMoveRows(); + reapplySafe(); saveCurrentOrder(); - reapply(); } void MinecraftProfile::resetOrder() { @@ -417,6 +418,21 @@ void MinecraftProfile::reapply() finalize(); } +bool MinecraftProfile::reapplySafe() +{ + try + { + reapply(); + } + catch(MMCError & error) + { + clear(); + qWarning() << "Couldn't apply profile patches because: " << error.cause(); + return false; + } + return true; +} + void MinecraftProfile::finalize() { // HACK: deny april fools. my head hurts enough already. diff --git a/logic/minecraft/MinecraftProfile.h b/logic/minecraft/MinecraftProfile.h index dba7d7447..d97f7bb8b 100644 --- a/logic/minecraft/MinecraftProfile.h +++ b/logic/minecraft/MinecraftProfile.h @@ -82,9 +82,12 @@ public: /// clear the profile void clear(); - /// apply the patches + /// apply the patches. Throws all sorts of errors. void reapply(); + /// apply the patches. Catches all the errors and returns true/false for success/failure + bool reapplySafe(); + /// do a finalization step (should always be done after applying all patches to profile) void finalize(); diff --git a/logic/minecraft/OneSixProfileStrategy.cpp b/logic/minecraft/OneSixProfileStrategy.cpp index 160e2c24b..e0ee4c219 100644 --- a/logic/minecraft/OneSixProfileStrategy.cpp +++ b/logic/minecraft/OneSixProfileStrategy.cpp @@ -389,14 +389,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths) profile->appendPatch(f); } profile->saveCurrentOrder(); - try - { - profile->reapply(); - } - catch (VersionIncomplete &error) - { - qDebug() << "Version was incomplete:" << error.cause(); - } + profile->reapplySafe(); return true; }