|
1 | 1 | using System.Text; |
2 | 2 | using ValveKeyValue; |
| 3 | +using ConsoleAppFramework; |
3 | 4 |
|
4 | 5 | Console.OutputEncoding = Encoding.UTF8; |
5 | 6 |
|
6 | | -if (args.Length < 1) |
| 7 | +ConsoleApp.Run(args, Execute); |
| 8 | + |
| 9 | +/// <summary> |
| 10 | +/// Parse a KeyValues file and print to console. |
| 11 | +/// </summary> |
| 12 | +/// <param name="file">-f, Input file to be parsed.</param> |
| 13 | +/// <param name="escape">Whether the parser should translate escape sequences.</param> |
| 14 | +/// <param name="valve_null_bug">Whether invalid escape sequences should truncate strings rather than throwing.</param> |
| 15 | +static int Execute( |
| 16 | + string file, |
| 17 | + bool escape = false, |
| 18 | + bool valve_null_bug = false |
| 19 | +) |
7 | 20 | { |
8 | | - Console.Error.WriteLine("Provide path to a keyvalues file as the first argument."); |
9 | | - return 1; |
10 | | -} |
11 | | - |
12 | | -var file = args[0]; |
13 | | - |
14 | | -if (!File.Exists(file)) |
15 | | -{ |
16 | | - Console.Error.WriteLine($"File \"{file}\" does not exist."); |
17 | | - return 1; |
18 | | -} |
| 21 | + if (!File.Exists(file)) |
| 22 | + { |
| 23 | + Console.Error.WriteLine($"File \"{file}\" does not exist."); |
| 24 | + return 1; |
| 25 | + } |
19 | 26 |
|
20 | | -using var stream = File.OpenRead(file); |
| 27 | + using var stream = File.OpenRead(file); |
21 | 28 |
|
22 | | -var options = new KVSerializerOptions |
23 | | -{ |
24 | | - HasEscapeSequences = true, |
25 | | -}; |
26 | | -var serializer = KVSerializer.Create(KVSerializationFormat.KeyValues1Text); |
27 | | -var root = serializer.Deserialize(stream, options); |
| 29 | + var options = new KVSerializerOptions |
| 30 | + { |
| 31 | + HasEscapeSequences = escape, |
| 32 | + EnableValveNullByteBugBehavior = valve_null_bug |
| 33 | + }; |
| 34 | + var serializer = KVSerializer.Create(KVSerializationFormat.KeyValues1Text); |
| 35 | + var root = serializer.Deserialize(stream, options); |
28 | 36 |
|
29 | | -RecursivePrint(root); |
| 37 | + RecursivePrint(root); |
30 | 38 |
|
31 | | -return 0; |
| 39 | + return 0; |
| 40 | +} |
32 | 41 |
|
33 | 42 | static void RecursivePrint(KVObject obj, int indent = 0) |
34 | 43 | { |
|
0 commit comments