summaryrefslogtreecommitdiff
path: root/src/instancemanagerdialog.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-12-22 14:40:51 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-12-22 14:40:51 -0500
commitd08ed01438a1eb4c0b3f51d508d95ba4f489bb45 (patch)
tree2b7c67ad5fd5af2e06d09eccb2a84b2f98657e9a /src/instancemanagerdialog.cpp
parentf1ea330df01864f5781f59e9daa7a7e1d70f0493 (diff)
fixed instanceIcon() so it works when game plugins fail auto detection but the instance has a custom path
had to change PluginContainer to non const in a few places
Diffstat (limited to 'src/instancemanagerdialog.cpp')
-rw-r--r--src/instancemanagerdialog.cpp54
1 files changed, 46 insertions, 8 deletions
diff --git a/src/instancemanagerdialog.cpp b/src/instancemanagerdialog.cpp
index 2497d8d8..00dc57f7 100644
--- a/src/instancemanagerdialog.cpp
+++ b/src/instancemanagerdialog.cpp
@@ -16,17 +16,55 @@ using namespace MOBase;
// returns the icon for the given instance or an empty 32x32 icon if the game
// plugin couldn't be found
//
-QIcon instanceIcon(const PluginContainer& pc, const Instance& i)
+QIcon instanceIcon(PluginContainer& pc, const Instance& i)
{
- const auto* game = InstanceManager::singleton()
+ auto* game = InstanceManager::singleton()
.gamePluginForDirectory(i.directory(), pc);
- if (game)
- return game->gameIcon();
+ if (!game) {
+ QPixmap empty(32, 32);
+ empty.fill(QColor(0, 0, 0, 0));
+ return QIcon(empty);
+ }
+
+ // it's possible to have the game installed in a way that the game plugin
+ // couldn't auto detect; in this case, the instance would have a valid game
+ // directory, but the plugin wouldn't know about it
+ //
+ // it's also possible, but unlikely, to have multiple installations of the
+ // same game that have different icons for the same exe
+ //
+ // so the game directory specified for the instance needs to be given to the
+ // game plugin to get the appropriate icon, but since these game plugin
+ // objects are created on startup and are global, they should retain their
+ // auto detected path
+ //
+ // if not, creating a new instance for a specific plugin would use the game
+ // directory of the instance for which the icon was most recently shown, which
+ // would be really inconsistent
+ //
+ //
+ // this game plugin could also be the currently active plugin for the
+ // current instance, which should _definitely_ keep pointing to the same
+ // directory as before
+
+
+ // remember old game directory
+ //
+ // note that gameDirectory() returns a QDir, which doesn't support empty
+ // strings (they get converted to "." automatically!), but the plugin _will_
+ // try to return an empty string when the game has not been auto-detected
+ //
+ // so gameDirectory() _cannot_ reliably be used if `isInstalled()` is false
+ const QString old = game->isInstalled() ? game->gameDirectory().path() : "";
+
+ // revert
+ Guard g([&]{ game->setGamePath(old); });
+
+ // set directory for this instance
+ game->setGamePath(i.gameDirectory());
- QPixmap empty(32, 32);
- empty.fill(QColor(0, 0, 0, 0));
- return QIcon(empty);
+ return game->gameIcon();
}
// pops up a dialog to ask for an instance name when renaming
@@ -105,7 +143,7 @@ QString getInstanceName(
InstanceManagerDialog::~InstanceManagerDialog() = default;
InstanceManagerDialog::InstanceManagerDialog(
- const PluginContainer& pc, QWidget *parent) :
+ PluginContainer& pc, QWidget *parent) :
QDialog(parent), ui(new Ui::InstanceManagerDialog), m_pc(pc),
m_model(nullptr), m_restartOnSelect(true)
{