// Actual worker for GetPreferredInstance() internal GameInstance _GetPreferredInstance() { foreach (IGame game in knownGames) { // TODO: Check which ones match, prompt user if >1 // First check if we're part of a portable install // Note that this *does not* register in the config. string path = GameInstance.PortableDir(game); if (path != null) { GameInstance portableInst = new GameInstance(game, path, "portable", User); if (portableInst.Valid) { return(portableInst); } } } // If we only know of a single instance, return that. if (instances.Count == 1 && instances.First().Value.Valid) { return(instances.First().Value); } // Return the autostart, if we can find it. // We check both null and "" as we can't write NULL to the config, so we write an empty string instead // This is necessary so we can indicate that the user wants to reset the current AutoStartInstance without clearing the config! if (!string.IsNullOrEmpty(AutoStartInstance) && instances[AutoStartInstance].Valid) { return(instances[AutoStartInstance]); } // If we know of no instances, try to find one. // Otherwise, we know of too many instances! // We don't know which one to pick, so we return null. return(!instances.Any() ? FindAndRegisterDefaultInstance() : null); }