GH-1015 catch exceptions when doing profile reapply

This is a temporary solution.
This commit is contained in:
Petr Mrázek 2015-05-31 19:59:07 +02:00
parent b9e06b5da0
commit 99f248ecd4
3 changed files with 28 additions and 16 deletions

View File

@ -22,6 +22,7 @@
#include "minecraft/MinecraftProfile.h" #include "minecraft/MinecraftProfile.h"
#include "ProfileUtils.h" #include "ProfileUtils.h"
#include "NullProfileStrategy.h" #include "NullProfileStrategy.h"
#include "VersionBuildError.h"
MinecraftProfile::MinecraftProfile(ProfileStrategy *strategy) MinecraftProfile::MinecraftProfile(ProfileStrategy *strategy)
: QAbstractListModel() : QAbstractListModel()
@ -52,7 +53,7 @@ void MinecraftProfile::reload()
{ {
beginResetModel(); beginResetModel();
m_strategy->load(); m_strategy->load();
reapply(); reapplySafe();
endResetModel(); endResetModel();
} }
@ -109,7 +110,7 @@ bool MinecraftProfile::remove(const int index)
beginRemoveRows(QModelIndex(), index, index); beginRemoveRows(QModelIndex(), index, index);
VersionPatches.removeAt(index); VersionPatches.removeAt(index);
endRemoveRows(); endRemoveRows();
reapply(); reapplySafe();
saveCurrentOrder(); saveCurrentOrder();
return true; return true;
} }
@ -141,7 +142,7 @@ bool MinecraftProfile::customize(int index)
qCritical() << "Patch" << patch->getPatchID() << "could not be customized"; qCritical() << "Patch" << patch->getPatchID() << "could not be customized";
return false; return false;
} }
reapply(); reapplySafe();
saveCurrentOrder(); saveCurrentOrder();
// FIXME: maybe later in unstable // FIXME: maybe later in unstable
// emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1)); // 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"; qCritical() << "Patch" << patch->getPatchID() << "could not be reverted";
return false; return false;
} }
reapply(); reapplySafe();
saveCurrentOrder(); saveCurrentOrder();
// FIXME: maybe later in unstable // FIXME: maybe later in unstable
// emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1)); // emit dataChanged(createIndex(index, 0), createIndex(index, columnCount(QModelIndex()) - 1));
@ -221,13 +222,13 @@ bool MinecraftProfile::revertToVanilla()
if(!remove(it->getPatchID())) if(!remove(it->getPatchID()))
{ {
qWarning() << "Couldn't remove" << it->getPatchID() << "from profile!"; qWarning() << "Couldn't remove" << it->getPatchID() << "from profile!";
reapply(); reapplySafe();
saveCurrentOrder(); saveCurrentOrder();
return false; return false;
} }
} }
} }
reapply(); reapplySafe();
saveCurrentOrder(); saveCurrentOrder();
return true; return true;
} }
@ -398,8 +399,8 @@ void MinecraftProfile::move(const int index, const MoveDirection direction)
beginMoveRows(QModelIndex(), index, index, QModelIndex(), togap); beginMoveRows(QModelIndex(), index, index, QModelIndex(), togap);
VersionPatches.swap(index, theirIndex); VersionPatches.swap(index, theirIndex);
endMoveRows(); endMoveRows();
reapplySafe();
saveCurrentOrder(); saveCurrentOrder();
reapply();
} }
void MinecraftProfile::resetOrder() void MinecraftProfile::resetOrder()
{ {
@ -417,6 +418,21 @@ void MinecraftProfile::reapply()
finalize(); 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() void MinecraftProfile::finalize()
{ {
// HACK: deny april fools. my head hurts enough already. // HACK: deny april fools. my head hurts enough already.

View File

@ -82,9 +82,12 @@ public:
/// clear the profile /// clear the profile
void clear(); void clear();
/// apply the patches /// apply the patches. Throws all sorts of errors.
void reapply(); 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) /// do a finalization step (should always be done after applying all patches to profile)
void finalize(); void finalize();

View File

@ -389,14 +389,7 @@ bool OneSixProfileStrategy::installJarMods(QStringList filepaths)
profile->appendPatch(f); profile->appendPatch(f);
} }
profile->saveCurrentOrder(); profile->saveCurrentOrder();
try profile->reapplySafe();
{
profile->reapply();
}
catch (VersionIncomplete &error)
{
qDebug() << "Version was incomplete:" << error.cause();
}
return true; return true;
} }