-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProgram.cs
More file actions
152 lines (133 loc) · 4.78 KB
/
Copy pathProgram.cs
File metadata and controls
152 lines (133 loc) · 4.78 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
using CommandLine;
using System.Runtime.InteropServices;
namespace Titanfall2_SkinTool
{
public class Options
{
[Value(0, HelpText = "Path/To/Game/Directory", Required = true)]
public string GamePath { get; set; }
[Value(1, HelpText = "List of <path/to/skin.zip> to install.", Required = true)]
public IEnumerable<string> InputFiles { get; set; }
[Option('v', "verbose", Required = false, HelpText = "Enable verbose logging")]
public bool Verbose { get; set; }
[Option('q', "quit", Required = false, HelpText = "Don't wait for user interaction before closing console window")]
public bool Quit { get; set; }
}
public static class GlobalFunAndVar
{
public static int GetTextureType(string Name)
{
if (Name != null && Name.Length == 0)
{
return 0;
}
if (Name.Contains("Stim_") || Name.Contains("PhaseShift_") || Name.Contains("HoloPilot_")
|| Name.Contains("PulseBlade_") || Name.Contains("Grapple_") || Name.Contains("AWall_")
|| Name.Contains("Cloak_") || Name.Contains("Pilot_"))
{
return 2;
}
else if (Name.Contains("Titan_"))
{
return 3;
}
else
{
return 1;
}
}
public static string[] GetTextureName(string name)
{
string[] s = new string[3];
int toname = name.LastIndexOf("\\") + 1;
string str = name.Substring(toname, name.Length - toname);
toname = str.IndexOf("_");
string temp = str.Substring(toname, str.Length - toname);
s[0] = str;
s[1] = str.Replace(temp, "");
s[2] = temp;
return s;
}
}
static class Program
{
/// <summary>
/// Used to display console if used with commandline arguments
/// </summary>
/// <returns></returns>
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static int Main(string[] args)
{
if (0 < args.Length)
{
// args -> is commandline
return CommandlineMain(args);
}
else
{
// no args -> default windowed application
UiMain();
return 0;
}
}
static int CommandlineMain(string[] args)
{
bool wait = false;
int code = 0; // 0 = succes; -1 = install failed; -2 = invalid arguments
AllocConsole();
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed(o =>
{
wait = !o.Quit;
Action<string> messageHandler = o.Verbose ? m => { Console.WriteLine(m); } : m => { };
// debug: print args
// messageHandler($"GamePath={o.GamePath}");
// messageHandler($"InputFiles=[{string.Join(", ", o.InputFiles)}]");
// messageHandler($"Verbos={o.Verbose}");
try
{
SkinTool tool = new SkinTool(o.GamePath, messageHandler);
foreach (string file in o.InputFiles)
{
tool.InstallSkin(file);
}
}
catch (Exception ex) // Catches MyException as well
{
Console.Error.WriteLine(ex.ToString());
wait = true; // let user see
code = -1;
}
}).WithNotParsed(_ =>
{
// argument parsing failed -> print error
Console.Error.WriteLine($"Parsing options failed. See above for more information on how to use.");
wait = true; // let user see error
code = -2;
});
// maybe wait for user input before closing
if (wait)
{
Console.Write("Press any key to exit...");
Console.Read();
}
return code;
}
static void UiMain()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainWindow());
}
}
}