MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / getGamePlugin

Method getGamePlugin

src/instancemanager.cpp:211–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211Instance::SetupResults Instance::getGamePlugin(PluginContainer& plugins)
212{
213 if (!m_gameName.isEmpty() && !m_gameDir.isEmpty()) {
214 // normal case: both the name and dir are in the ini
215
216 // find the plugin by name
217 for (IPluginGame* game : plugins.plugins<IPluginGame>()) {
218 if (m_gameName.compare(game->gameName(), Qt::CaseInsensitive) == 0) {
219 // plugin found, check if the game directory is valid
220
221 if (!game->looksValid(m_gameDir)) {
222 // the directory from the ini is not valid anymore
223 log::warn("game plugin {} says dir {} from ini {} is not valid",
224 game->gameName(), m_gameDir, iniPath());
225
226 // note that some plugins return true for isInstalled() if a path
227 // is found in the registry, but without actually checking if it's
228 // valid
229
230 if (game->isInstalled() && game->looksValid(game->gameDirectory())) {
231 // bad game directory but the plugin reports there's a valid one
232 // somewhere; take it instead
233 log::warn("game plugin {} found a game at {}, taking it", game->gameName(),
234 game->gameDirectory().absolutePath());
235
236 m_gameDir = game->gameDirectory().absolutePath();
237 } else {
238 // game seems to be gone completely
239 log::warn("game plugin {} found no game installation at all",
240 game->gameName());
241 return SetupResults::GameGone;
242 }
243 }
244
245 m_plugin = game;
246 return SetupResults::Okay;
247 }
248 }
249
250 log::warn("game plugin {} not found", m_gameName);
251 return SetupResults::PluginGone;
252 } else if (m_gameName.isEmpty() && !m_gameDir.isEmpty()) {
253 // the name is missing, but there's a directory; find a plugin that can
254 // handle it
255
256 log::warn("game name is missing from ini {} but dir {} is available", iniPath(),
257 m_gameDir);
258
259 for (IPluginGame* game : plugins.plugins<IPluginGame>()) {
260 if (game->looksValid(m_gameDir)) {
261 // take it
262 log::warn("found plugin {} that can use dir {}", game->gameName(), m_gameDir);
263
264 m_plugin = game;
265 m_gameName = game->gameName();
266
267 return SetupResults::Okay;
268 }

Callers

nothing calls this directly

Calls 5

compareMethod · 0.80
gameDirectoryMethod · 0.80
isEmptyMethod · 0.45
gameNameMethod · 0.45
absolutePathMethod · 0.45

Tested by

no test coverage detected