From 746c3d068c988e1dcfefa8e865d4f8e78cc6b7ca Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 27 Jan 2011 19:34:52 +1300 Subject: [PATCH] Use the existing settings mechanism for --settings-value. Allows the defaults to be queried. --- Makefile | 2 +- OpenRA.Game/GameRules/Settings.cs | 5 ++-- OpenRA.Utility/Command.cs | 38 +++++-------------------------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 827b598655..80c1f6a3c4 100644 --- a/Makefile +++ b/Makefile @@ -157,7 +157,7 @@ PHONY += fixheader utility_SRCS = $(shell find OpenRA.Utility/ -iname '*.cs') utility_TARGET = OpenRA.Utility.exe utility_KIND = exe -utility_DEPS = $(fileformats_TARGET) +utility_DEPS = $(fileformats_TARGET) $(game_TARGET) utility_LIBS = $(COMMON_LIBS) $(utility_DEPS) thirdparty/ICSharpCode.SharpZipLib.dll System.Windows.Forms.dll PROGRAMS += utility utility: $(utility_TARGET) diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index da285f557a..e25fcc95fe 100755 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -93,7 +93,7 @@ namespace OpenRA.GameRules public ServerSettings Server = new ServerSettings(); public DebugSettings Debug = new DebugSettings(); - Dictionary Sections; + public Dictionary Sections; public Settings(string file, Arguments args) { SettingsFile = file; @@ -107,6 +107,7 @@ namespace OpenRA.GameRules {"Debug", Debug} }; + // Override fieldloader to ignore invalid entries var err1 = FieldLoader.UnknownFieldAction; var err2 = FieldLoader.InvalidValueAction; @@ -118,7 +119,7 @@ namespace OpenRA.GameRules if (File.Exists(SettingsFile)) { - Console.WriteLine("Loading settings file {0}",SettingsFile); + //Console.WriteLine("Loading settings file {0}",SettingsFile); var yaml = MiniYaml.DictFromFile(SettingsFile); foreach (var kv in Sections) diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index d416511a17..4d2d491b8c 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -18,6 +18,7 @@ using System.Windows.Forms; using ICSharpCode.SharpZipLib; using ICSharpCode.SharpZipLib.Zip; using OpenRA.FileFormats; +using OpenRA; namespace OpenRA.Utility { @@ -138,39 +139,12 @@ namespace OpenRA.Utility Console.WriteLine("Error: Invalid syntax"); return; } - + var section = args[2].Split('.')[0]; + var field = args[2].Split('.')[1]; string expandedPath = args[1].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal)); - - string settingsFile = expandedPath + Path.DirectorySeparatorChar + "settings.yaml"; - if (!File.Exists(settingsFile)) - { - Console.WriteLine("Error: Could not locate settings file at {0}", settingsFile); - return; - } - - List settingsYaml = MiniYaml.FromFile(settingsFile); - Queue settingKey = new Queue(args[2].Split('.')); - - string s = settingKey.Dequeue(); - MiniYaml n = settingsYaml.Where(x => x.Key == s).Select(x => x.Value).FirstOrDefault(); - - if (n == null) - { - Console.WriteLine("Error: Could not find {0} in {1}", args[2], settingsFile); - return; - } - - while (settingKey.Count > 0) - { - s = settingKey.Dequeue(); - if (!n.NodesDict.TryGetValue(s, out n)) - { - Console.WriteLine("Error: Could not find {0} in {1}", args[2], settingsFile); - return; - } - } - - Console.WriteLine(n.Value); + var settings = new OpenRA.GameRules.Settings(expandedPath + Path.DirectorySeparatorChar + "settings.yaml", new Arguments(new string[]{})); + var result = settings.Sections[section].GetType().GetField(field).GetValue(settings.Sections[section]); + Console.WriteLine(result); } public static void AuthenticateAndExtractZip(string[] args)