Exemplo n.º 1
0
 public IEnumerable <DisplayMode> GetAvailableDisplayModes()
 {
     return(GamePlatform.GetAvailableDisplayModes(ActiveConfig.Monitor));
 }
Exemplo n.º 2
0
        protected override void Main(string[] args)
        {
            if (!args.Any())
            {
                Console.WriteLine("{0}: error: Too few arguments.", Name);
                Console.Write(_usage, Name);
                return;
            }

            RegisterSettings();

            var config = EntryPoint.CurrentApp.GetComponent <ConfigurationManager>();

            _config = config;

            var action     = args.First();
            var actionArgs = args.Skip(1).ToArray();

            if (action == "help")
            {
                Console.Write(_usage, Name);
                return;
            }

            if (action == "reset")
            {
                Console.WriteLine("Resetting all settings to their defaults...");
                _config.ResetToDefaults();
                return;
            }

            if (action == "info")
            {
                if (!actionArgs.Any())
                {
                    Console.WriteLine("{0}: error: {1}: Too few arguments.", Name, action);
                    Console.Write(_usage, Name);
                    return;
                }

                var setting = actionArgs.First();

                if (_settings.All(x => x.Key == setting))
                {
                    Console.WriteLine("{0}: error: {1} {2}: {2} is not a recognized setting.", Name, action, setting);
                    Console.WriteLine("Use {0} get-available for a list of available settings.");
                    return;
                }

                var info = _settings.First(x => x.Key == setting);

                Console.WriteLine(info.Key);

                for (var i = 0; i < info.Key.Length; i++)
                {
                    Console.Write("-");
                }

                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Description: &w{0}&W", info.Description);
                Console.WriteLine();
                Console.WriteLine("{0} set {1} <value>", Name, info.Key);
                Console.WriteLine("{0} get {1}", Name, info.Key);

                return;
            }

            if (action == "display-modes")
            {
                Console.WriteLine("Available display modes for {0}:", GamePlatform.GraphicsCardDescription);
                Console.WriteLine();

                foreach (var mode in GamePlatform.GetAvailableDisplayModes(config.ActiveConfig.Monitor))
                {
                    Console.WriteLine(" - {0}", mode);
                }

                return;
            }

            if (action == "get-available")
            {
                Console.WriteLine("Available settings: ");
                Console.WriteLine();

                var maxLen = _settings.OrderByDescending(x => x.Key.Length).First().Key.Length + 2;

                foreach (var setting in _settings.OrderBy(x => x.Key))
                {
                    Console.Write(" - {0}", setting.Key);

                    if (!string.IsNullOrWhiteSpace(setting.Description))
                    {
                        for (var i = 0; i < maxLen - setting.Key.Length; i++)
                        {
                            Console.Write(" ");
                        }

                        Console.Write(" - &w{0}&W", setting.Description);
                    }

                    Console.WriteLine();
                }

                return;
            }

            if (action == "get")
            {
                if (!actionArgs.Any())
                {
                    Console.WriteLine("{0}: error: {1}: Too few arguments.", Name, action);
                    Console.Write(_usage, Name);
                    return;
                }

                var setting = actionArgs.First();

                if (_settings.All(x => x.Key != setting))
                {
                    Console.WriteLine("{0}: error: {1} {2}: {2} is not a recognized setting.", Name, action, setting);
                    Console.WriteLine("Use {0} get-available to see a list of available settings.", Name);
                    return;
                }

                var info = _settings.First(x => x.Key == setting);

                var value = info.Getter();

                Console.Write("{0}={1}", setting, value);

                return;
            }

            if (action == "set")
            {
                if (actionArgs.Length < 2)
                {
                    Console.WriteLine("{0}: error: {1}: Too few arguments.", Name, action);
                    Console.Write(_usage, Name);
                    return;
                }

                var setting = actionArgs.First();
                var value   = string.Join(' ', actionArgs.Skip(1).ToArray());

                if (_settings.All(x => x.Key != setting))
                {
                    Console.WriteLine("{0}: error: {1}: '{2}' is not a recognized setting.", Name, action, setting);
                    Console.WriteLine("Run {0} get-available for a list of available settings.", Name);
                    return;
                }

                var settingInfo = _settings.First(x => x.Key == setting);

                var result = settingInfo.Setter(value);

                if (result)
                {
                    config.ApplyChanges();
                }
                else
                {
                    config.DiscardChanges();
                    Console.WriteLine("{0}: error: {1}: Couldn't set '{2}'. Settings not updated.", Name, action, setting);
                }

                return;
            }

            Console.WriteLine("{0}: error: Unrecognized command: {1}", Name, action);
            Console.Write(_usage, Name);
        }