コード例 #1
0
        internal static async Task InstallIfNeededAndPlay(FanMission fm, bool askConfIfRequired = false, bool playMP = false)
        {
            if (!GameIsKnownAndSupported(fm.Game))
            {
                Log("Game is unknown or unsupported for FM " + (!fm.Archive.IsEmpty() ? fm.Archive : fm.InstalledDir) + "\r\n" +
                    "fm.Game was: " + fm.Game, stackTrace: true);
                Dialogs.ShowError(ErrorText.FMGameTypeUnknownOrUnsupported);
                return;
            }

            GameIndex gameIndex = GameToGameIndex(fm.Game);

            if (playMP && gameIndex != GameIndex.Thief2)
            {
                Log("playMP was true, but fm.Game was not Thief 2.\r\n" +
                    "fm: " + (!fm.Archive.IsEmpty() ? fm.Archive : fm.InstalledDir) + "\r\n" +
                    "fm.Game was: " + fm.Game, stackTrace: true);
                Dialogs.ShowError(ErrorText.MultiplayerForNonThief2);
                return;
            }

            if (askConfIfRequired && Config.ConfirmPlayOnDCOrEnter)
            {
                string message = fm.Installed
                    ? LText.AlertMessages.Play_ConfirmMessage
                    : LText.AlertMessages.Play_InstallAndPlayConfirmMessage;

                if (Core.View.GetSelectedFMOrNull() != fm)
                {
                    message += "\r\n\r\n" +
                               fm.Archive + "\r\n" +
                               fm.Title + "\r\n" +
                               fm.Author + "\r\n";
                }

                (bool cancel, bool dontAskAgain) = Dialogs.AskToContinueYesNoCustomStrings(
                    message: message,
                    title: LText.AlertMessages.Confirm,
                    icon: MessageBoxIcon.None,
                    showDontAskAgain: true,
                    yes: LText.Global.Yes,
                    no: LText.Global.No);

                if (cancel)
                {
                    return;
                }

                Config.ConfirmPlayOnDCOrEnter = !dontAskAgain;
            }

            if (!fm.Installed && !await InstallFM(fm))
            {
                return;
            }

            if (playMP && gameIndex == GameIndex.Thief2 && Config.GetT2MultiplayerExe_FromDisk().IsEmpty())
            {
                Log("Thief2MP.exe not found in Thief 2 game directory.\r\n" +
                    "Thief 2 game directory: " + Config.GetGamePath(GameIndex.Thief2));
                Dialogs.ShowError(LText.AlertMessages.Thief2_Multiplayer_ExecutableNotFound);
                return;
            }

            if (PlayFM(fm, playMP))
            {
                fm.LastPlayed.DateTime = DateTime.Now;
                Core.View.RefreshFM(fm);
                Ini.WriteFullFMDataIni();
            }
        }