-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (52 loc) · 2.12 KB
/
Program.cs
File metadata and controls
60 lines (52 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using TankLibHelper.Modes;
namespace TankLibHelper {
internal class Program {
public static void Main(string[] args) {
// TankLibHelper createclasses {out} [data dir]
// TankLibHelper updateclasses {out} [data dir]
// TankLibHelper testclasses [args]
// args:
// abc.003
// *.003
// *.003 6A0BTFA(instance hash)
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; //To fix float seperator :prophet:
if (args.Length < 1) {
Console.Out.WriteLine("Usage: TankLibHelper {mode} [mode args]");
return;
}
string mode = args[0];
IMode modeObject;
Dictionary<string, Type> modes = GetModes();
if (modes.ContainsKey(mode)) {
modeObject = (IMode)Activator.CreateInstance(modes[mode]);
} else {
Console.Out.WriteLine($"Unknown mode: {mode}");
Console.Out.WriteLine("Valid modes are:");
foreach (string modeName in modes.Keys) {
Console.Out.WriteLine($" {modeName}");
}
return;
}
ModeResult result = modeObject.Run(args);
if (result == ModeResult.Fail) {
Console.Out.WriteLine($"\r\n{mode} failed to execute successfully");
} else if (result == ModeResult.Success) {
Console.Out.WriteLine("\r\nDone");
}
}
public static Dictionary<string, Type> GetModes() {
Dictionary<string, Type> modes = new Dictionary<string, Type>();
foreach (Type modeType in typeof(IMode).Assembly.GetTypes().Where(x => typeof(IMode).IsAssignableFrom(x))) {
if (modeType.IsInterface) continue;
IMode inst = (IMode)Activator.CreateInstance(modeType);
modes[inst.Mode] = modeType;
}
return modes;
}
}
}