returns the icon for the given instance or an empty 32x32 icon if the game plugin couldn't be found
| 18 | // plugin couldn't be found |
| 19 | // |
| 20 | QIcon instanceIcon(PluginContainer& pc, const Instance& i) |
| 21 | { |
| 22 | auto* game = InstanceManager::singleton().gamePluginForDirectory(i.directory(), pc); |
| 23 | |
| 24 | if (!game) { |
| 25 | QPixmap empty(32, 32); |
| 26 | empty.fill(QColor(0, 0, 0, 0)); |
| 27 | return QIcon(empty); |
| 28 | } |
| 29 | |
| 30 | // it's possible to have the game installed in a way that the game plugin |
| 31 | // couldn't auto detect; in this case, the instance would have a valid game |
| 32 | // directory, but the plugin wouldn't know about it |
| 33 | // |
| 34 | // it's also possible, but unlikely, to have multiple installations of the |
| 35 | // same game that have different icons for the same exe |
| 36 | // |
| 37 | // so the game directory specified for the instance needs to be given to the |
| 38 | // game plugin to get the appropriate icon, but since these game plugin |
| 39 | // objects are created on startup and are global, they should retain their |
| 40 | // auto detected path |
| 41 | // |
| 42 | // if not, creating a new instance for a specific plugin would use the game |
| 43 | // directory of the instance for which the icon was most recently shown, which |
| 44 | // would be really inconsistent |
| 45 | // |
| 46 | // |
| 47 | // this game plugin could also be the currently active plugin for the |
| 48 | // current instance, which should _definitely_ keep pointing to the same |
| 49 | // directory as before |
| 50 | |
| 51 | // remember old game directory |
| 52 | // |
| 53 | // note that gameDirectory() returns a QDir, which doesn't support empty |
| 54 | // strings (they get converted to "." automatically!), but the plugin _will_ |
| 55 | // try to return an empty string when the game has not been auto-detected |
| 56 | // |
| 57 | // so gameDirectory() _cannot_ reliably be used if `isInstalled()` is false |
| 58 | const QString old = game->isInstalled() ? game->gameDirectory().path() : ""; |
| 59 | |
| 60 | // revert |
| 61 | Guard g([&] { |
| 62 | game->setGamePath(old); |
| 63 | }); |
| 64 | |
| 65 | // set directory for this instance |
| 66 | game->setGamePath(i.gameDirectory()); |
| 67 | |
| 68 | return game->gameIcon(); |
| 69 | } |
| 70 | |
| 71 | // pops up a dialog to ask for an instance name when renaming |
| 72 | // |
no test coverage detected