예제 #1
0
        /// <summary>
        /// Find and register default instances by running
        /// game autodetection code. Registers one per known game,
        /// uses first found as default.
        ///
        /// Returns the resulting game instance if found.
        /// </summary>
        public GameInstance FindAndRegisterDefaultInstance()
        {
            if (instances.Any())
            {
                throw new KSPManagerKraken("Attempted to scan for defaults with instances");
            }
            GameInstance val = null;

            foreach (IGame game in knownGames)
            {
                try
                {
                    string       gamedir   = GameInstance.FindGameDir(game);
                    GameInstance foundInst = new GameInstance(
                        game, gamedir, $"Auto {game.ShortName}", User);
                    if (foundInst.Valid)
                    {
                        var inst = AddInstance(foundInst);
                        val = val ?? inst;
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    // Thrown if no folder found for a game
                }
                catch (NotKSPDirKraken)
                {
                }
            }
            return(val);
        }