Use the existing settings mechanism for --settings-value. Allows the defaults to be queried.
This commit is contained in:
2
Makefile
2
Makefile
@@ -157,7 +157,7 @@ PHONY += fixheader
|
|||||||
utility_SRCS = $(shell find OpenRA.Utility/ -iname '*.cs')
|
utility_SRCS = $(shell find OpenRA.Utility/ -iname '*.cs')
|
||||||
utility_TARGET = OpenRA.Utility.exe
|
utility_TARGET = OpenRA.Utility.exe
|
||||||
utility_KIND = 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
|
utility_LIBS = $(COMMON_LIBS) $(utility_DEPS) thirdparty/ICSharpCode.SharpZipLib.dll System.Windows.Forms.dll
|
||||||
PROGRAMS += utility
|
PROGRAMS += utility
|
||||||
utility: $(utility_TARGET)
|
utility: $(utility_TARGET)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace OpenRA.GameRules
|
|||||||
public ServerSettings Server = new ServerSettings();
|
public ServerSettings Server = new ServerSettings();
|
||||||
public DebugSettings Debug = new DebugSettings();
|
public DebugSettings Debug = new DebugSettings();
|
||||||
|
|
||||||
Dictionary<string, object> Sections;
|
public Dictionary<string, object> Sections;
|
||||||
public Settings(string file, Arguments args)
|
public Settings(string file, Arguments args)
|
||||||
{
|
{
|
||||||
SettingsFile = file;
|
SettingsFile = file;
|
||||||
@@ -107,6 +107,7 @@ namespace OpenRA.GameRules
|
|||||||
{"Debug", Debug}
|
{"Debug", Debug}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Override fieldloader to ignore invalid entries
|
// Override fieldloader to ignore invalid entries
|
||||||
var err1 = FieldLoader.UnknownFieldAction;
|
var err1 = FieldLoader.UnknownFieldAction;
|
||||||
var err2 = FieldLoader.InvalidValueAction;
|
var err2 = FieldLoader.InvalidValueAction;
|
||||||
@@ -118,7 +119,7 @@ namespace OpenRA.GameRules
|
|||||||
|
|
||||||
if (File.Exists(SettingsFile))
|
if (File.Exists(SettingsFile))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Loading settings file {0}",SettingsFile);
|
//Console.WriteLine("Loading settings file {0}",SettingsFile);
|
||||||
var yaml = MiniYaml.DictFromFile(SettingsFile);
|
var yaml = MiniYaml.DictFromFile(SettingsFile);
|
||||||
|
|
||||||
foreach (var kv in Sections)
|
foreach (var kv in Sections)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using System.Windows.Forms;
|
|||||||
using ICSharpCode.SharpZipLib;
|
using ICSharpCode.SharpZipLib;
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA;
|
||||||
|
|
||||||
namespace OpenRA.Utility
|
namespace OpenRA.Utility
|
||||||
{
|
{
|
||||||
@@ -138,39 +139,12 @@ namespace OpenRA.Utility
|
|||||||
Console.WriteLine("Error: Invalid syntax");
|
Console.WriteLine("Error: Invalid syntax");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var section = args[2].Split('.')[0];
|
||||||
|
var field = args[2].Split('.')[1];
|
||||||
string expandedPath = args[1].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
|
string expandedPath = args[1].Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal));
|
||||||
|
var settings = new OpenRA.GameRules.Settings(expandedPath + Path.DirectorySeparatorChar + "settings.yaml", new Arguments(new string[]{}));
|
||||||
string settingsFile = expandedPath + Path.DirectorySeparatorChar + "settings.yaml";
|
var result = settings.Sections[section].GetType().GetField(field).GetValue(settings.Sections[section]);
|
||||||
if (!File.Exists(settingsFile))
|
Console.WriteLine(result);
|
||||||
{
|
|
||||||
Console.WriteLine("Error: Could not locate settings file at {0}", settingsFile);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MiniYamlNode> settingsYaml = MiniYaml.FromFile(settingsFile);
|
|
||||||
Queue<String> settingKey = new Queue<string>(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AuthenticateAndExtractZip(string[] args)
|
public static void AuthenticateAndExtractZip(string[] args)
|
||||||
|
|||||||
Reference in New Issue
Block a user