예제 #1
0
        public void LaunchGame()
        {
            var split = configuration.CommandLineArguments.Split(' ');

            if (split.Length == 0)
            {
                return;
            }

            var registry = RegistryManager.Instance(CurrentInstance).registry;

            var suppressedIdentifiers = CurrentInstance.GetSuppressedCompatWarningIdentifiers;
            var incomp = registry.IncompatibleInstalled(CurrentInstance.VersionCriteria())
                         .Where(m => !m.Module.IsDLC && !suppressedIdentifiers.Contains(m.identifier))
                         .ToList();

            if (incomp.Any())
            {
                // Warn that it might not be safe to run Game with incompatible modules installed
                string incompatDescrip = incomp
                                         .Select(m => $"{m.Module} ({registry.CompatibleGameVersions(CurrentInstance.game, m.Module)})")
                                         .Aggregate((a, b) => $"{a}{Environment.NewLine}{b}");
                var ver    = CurrentInstance.Version();
                var result = SuppressableYesNoDialog(
                    string.Format(Properties.Resources.MainLaunchWithIncompatible, incompatDescrip),
                    string.Format(Properties.Resources.MainLaunchDontShow,
                                  CurrentInstance.game.ShortName,
                                  new GameVersion(ver.Major, ver.Minor, ver.Patch)),
                    Properties.Resources.MainLaunch,
                    Properties.Resources.MainGoBack
                    );
                if (result.Item1 != DialogResult.Yes)
                {
                    return;
                }
                else if (result.Item2)
                {
                    CurrentInstance.AddSuppressedCompatWarningIdentifiers(
                        incomp.Select(m => m.identifier).ToHashSet()
                        );
                }
            }

            split = CurrentInstance.game.AdjustCommandLine(split,
                                                           Main.Instance.CurrentInstance.Version());
            var binary = split[0];
            var args   = string.Join(" ", split.Skip(1));

            try
            {
                Directory.SetCurrentDirectory(CurrentInstance.GameDir());
                Process.Start(binary, args);
            }
            catch (Exception exception)
            {
                currentUser.RaiseError(Properties.Resources.MainLaunchFailed, exception.Message);
            }
        }