Skip to content

Commit

Permalink
GH-1015 catch exceptions when doing profile reapply
Browse files Browse the repository at this point in the history
This is a temporary solution.
  • Loading branch information
peterix committed May 31, 2015
1 parent b9e06b5 commit 99f248e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
30 changes: 23 additions & 7 deletions logic/minecraft/MinecraftProfile.cpp
Expand Up @@ -22,6 +22,7 @@
#include "minecraft/MinecraftProfile.h"
#include "ProfileUtils.h"
#include "NullProfileStrategy.h"
#include "VersionBuildError.h"

MinecraftProfile::MinecraftProfile(ProfileStrategy *strategy)
: QAbstractListModel()
Expand Down Expand Up @@ -52,7 +53,7 @@ void MinecraftProfile::reload()
{
beginResetModel();
m_strategy->load();
reapply();
reapplySafe();
endResetModel();
}

Expand Down Expand Up @@ -109,7 +110,7 @@ bool MinecraftProfile::remove(const int index)
beginRemoveRows(QModelIndex(), index, index);
VersionPatches.removeAt(index);
endRemoveRows();
reapply();
reapplySafe();
saveCurrentOrder();
return true;
}
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()
{
Expand All @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion logic/minecraft/MinecraftProfile.h
Expand Up @@ -82,9 +82,12 @@ class MinecraftProfile : public QAbstractListModel
/// 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();

Expand Down
9 changes: 1 addition & 8 deletions logic/minecraft/OneSixProfileStrategy.cpp
Expand Up @@ -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;
}

0 comments on commit 99f248e

Please sign in to comment.