forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
96 lines (82 loc) · 2.68 KB
/
Program.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using OpenRA.FileSystem;
namespace OpenRA.Utility
{
class Program
{
static readonly Dictionary<string, Action<string[]>> Actions = new Dictionary<string, Action<string[]>>()
{
{ "--settings-value", Command.Settings },
{ "--shp", Command.ConvertPngToShp },
{ "--png", Command.ConvertSpriteToPng },
{ "--extract", Command.ExtractFiles },
{ "--remap", Command.RemapShp },
{ "--transpose", Command.TransposeShp },
{ "--docs", Command.ExtractTraitDocs },
{ "--lua-docs", Command.ExtractLuaDocs },
{ "--map-hash", Command.GetMapHash },
{ "--map-preview", Command.GenerateMinimap },
{ "--map-upgrade-v5", Command.UpgradeV5Map },
{ "--upgrade-map", UpgradeRules.UpgradeMap },
{ "--upgrade-mod", UpgradeRules.UpgradeMod },
{ "--map-import", Command.ImportLegacyMap },
{ "--extract-language-strings", ExtractLanguageStrings.FromMod }
};
static void Main(string[] args)
{
if (args.Length == 0) { PrintUsage(); return; }
AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly;
Log.LogPath = Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar;
Log.AddChannel("perf", null);
try
{
var action = Exts.WithDefault(_ => PrintUsage(), () => Actions[args[0]]);
action(args);
}
catch (Exception e)
{
Log.AddChannel("utility", "utility.log");
Log.Write("utility", "Received args: {0}", args.JoinWith(" "));
Log.Write("utility", "{0}", e);
Console.WriteLine("Error: Utility application crashed. See utility.log for details");
throw;
}
}
static void PrintUsage()
{
Console.WriteLine("Usage: OpenRA.Utility.exe [OPTION] [ARGS]");
Console.WriteLine();
foreach (var a in Actions)
{
var descParts = a.Value.Method.GetCustomAttributes<DescAttribute>(true)
.SelectMany(d => d.Lines);
if (!descParts.Any())
continue;
var args = descParts.Take(descParts.Count() - 1).JoinWith(" ");
var desc = descParts.Last();
Console.WriteLine(" {0} {1} ({2})", a.Key, args, desc);
}
}
static string GetNamedArg(string[] args, string arg)
{
if (args.Length < 2)
return null;
var i = Array.IndexOf(args, arg);
if (i < 0 || i == args.Length - 1) // doesnt exist, or doesnt have a value.
return null;
return args[i + 1];
}
}
}