-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCommandLineHandler.cs
214 lines (171 loc) · 10.1 KB
/
CommandLineHandler.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using System.Collections.Generic;
using CommandLine;
using FileDBReader.src;
namespace FileDBReader {
internal class CommandLineHandler {
//VERB EXPLANATIONS
private const String DECOMPRESS_EXPL = "Decompress files from filedb compression to xml. Data will be represented as hex strings.";
private const String COMPRESS_EXPL = "Compress a file from xml to filedb. Expects data to be represented as hex strings.";
private const String INTERPRET_EXPL = "Interpret an xml file that uses hex strings as texts. An interpreter file is needed";
private const String REINTERPRET_EXPL = "Convert all text in an xml file to hex. An interpreter file is needed";
private const String VERSION_EXPL = "checks the compression version of each input file";
private const String INPUT_FILE_MESSAGE = "Input files";
private const String COMPRESSION_VERSION_MESSAGE = "File Version: \n1 for Anno 1800 files up to GU12 \n2for Anno 1800 files after GU12";
private const String INTERPRETER_FILE_HELP = "Interpreter Filepath";
private const String INTERPRETER_SKIP_HELP = "If provided, decompressing/reinterpreting is automatically done as a step-in-between and the program will print the interpreted/recompressed result.";
private const String OUTPUT_FILEFORMAT_HELP = "File extension for the output file";
#region CmdLineOptions
[Verb("decompress", HelpText = DECOMPRESS_EXPL)]
class DecompressOptions
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
[Option('c', "CompressionVersion", Required = false, HelpText = COMPRESSION_VERSION_MESSAGE)]
public int CompressionVersion { get; set; }
//optional interpreter file. If provided, it will directly interpret the decompressed file.
[Option('i', "interpreter", Required = false, HelpText = INTERPRETER_FILE_HELP + ". " + INTERPRETER_SKIP_HELP)]
public String Interpreter { get; set; }
[Option('y', "overwrite", Required = false, Default = false)]
public bool overwrite { get; set; }
[Option('z', "replace_Names", Required = false, HelpText = "String Tuples of names that should be replaced")]
public IEnumerable<String> ReplaceOperations { get; set; }
}
[Verb("compress", HelpText = COMPRESS_EXPL)]
class CompressOptions
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
[Option('o', "outputFileExtension", Required = false, HelpText = OUTPUT_FILEFORMAT_HELP)]
public String OutputFileExtension{ get; set; }
[Option('c', "CompressionVersion", Required = true, HelpText = COMPRESSION_VERSION_MESSAGE)]
public int CompressionVersion { get; set; }
//optional interpreter file. If provided, it will go directly from an interpreted file to final result
[Option('i', "interpreter", Required = false, HelpText = INTERPRETER_FILE_HELP + " | " + INTERPRETER_SKIP_HELP )]
public String Interpreter { get; set; }
[Option('y', "overwrite", Required = false, Default = false)]
public bool overwrite { get; set; }
[Option('z', "replace_Names", Required = false, HelpText = "String Tuples of names that should be replaced")]
public IEnumerable<String> ReplaceOperations { get; set; }
}
[Verb("interpret", HelpText = INTERPRET_EXPL)]
class InterpretOptions
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
[Option('i', "interpreter", Required = true, HelpText = INTERPRETER_FILE_HELP)]
public String Interpreter { get; set; }
[Option('y', "overwrite", Required = false, Default = false)]
public bool overwrite { get; set; }
[Option('z', "replace_Names", Required = false, HelpText = "String Tuples of names that should be replaced")]
public IEnumerable<String> ReplaceOperations { get; set; }
[Option('o', "outputFileExtension", Required = false, HelpText = OUTPUT_FILEFORMAT_HELP)]
public String OutputFileExtension { get; set; }
[Option('d', "in_is_out_dir", Required = false, Default = false, HelpText = "If set, the output directory becomes the input directory. This being an option is purely for backwards compabilities sake.")]
public bool InIsOut { get; set; }
}
[Verb("toHex", HelpText = REINTERPRET_EXPL)]
class toHexOptions
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
[Option('i', "interpreter", Required = true, HelpText = INTERPRETER_FILE_HELP)]
public String Interpreter { get; set; }
[Option('y', "overwrite", Required = false, Default = false)]
public bool overwrite { get; set; }
[Option('z', "replace_Names", Required = false, HelpText = "String Tuples of names that should be replaced")]
public IEnumerable<String> ReplaceOperations { get; set; }
[Option('d', "in_is_out_dir", Required = false, Default = false, HelpText = "If set, the output directory becomes the input directory. This being an option is purely for backwards compabilities sake.")]
public bool InIsOut { get; set; }
}
[Verb("check_fileversion", HelpText = VERSION_EXPL)]
class FileCheck_Options
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
}
[Verb("fctohex", HelpText = "Import an FC file to valid XML")]
class FcImportOptions
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
//optional interpreter file. If provided, the program will directly interpret the validated file.
[Option('i', "interpreter", Required = false, HelpText = INTERPRETER_FILE_HELP)]
public String Interpreter { get; set; }
[Option('y', "overwrite", Required = false, Default = false)]
public bool overwrite { get; set; }
[Option('d', "in_is_out_dir", Required = false, Default = false, HelpText = "If set, the output directory becomes the input directory. This being an option is purely for backwards compabilities sake.")]
public bool InIsOut { get; set; }
}
[Verb("hextofc", HelpText = "Reverse operation of fctohex.")]
class FcExportOptions
{
[Option('f', "files", Required = true, HelpText = INPUT_FILE_MESSAGE)]
public IEnumerable<String> InputFiles { get; set; }
//optional interpreter file. If provided, the program will directly interpret the validated file.
[Option('i', "interpreter", Required = false, HelpText = "Interpreter file")]
public String Interpreter { get; set; }
[Option('y', "overwrite", Required = false, Default = false)]
public bool overwrite { get; set; }
[Option('o', "outputFileExtension", Required = false, HelpText = OUTPUT_FILEFORMAT_HELP)]
public String OutputFileExtension { get; set; }
[Option('d', "in_is_out_dir", Required = false, Default = false, HelpText = "If set, the output directory becomes the input directory. This being an option is purely for backwards compabilities sake.")]
public bool InIsOut { get; set; }
}
#endregion
#region MainMethod
private static void Main(string[] args) {
var Functions = new ToolFunctions();
//todo make this pretty by adjusting writing to reading flow.
CommandLine.Parser.Default.ParseArguments
<
DecompressOptions,
CompressOptions,
InterpretOptions,
toHexOptions,
FileCheck_Options,
FcImportOptions,
FcExportOptions
>
(args).MapResult(
//OPTIONS FOR DECOMPRESSING
(DecompressOptions o) =>
{
return Functions.Decompress(o.InputFiles, o.Interpreter, o.overwrite, o.ReplaceOperations);
},
//OPTIONS FOR RECOMPRESSING
(CompressOptions o) =>
{
return Functions.Compress(o.InputFiles, o.Interpreter, o.OutputFileExtension, o.CompressionVersion, o.overwrite, o.ReplaceOperations);
},
//OPTIONS FOR INTERPRETATION ONLY
(InterpretOptions o) =>
{
return Functions.Interpret(o.InputFiles, o.Interpreter, o.overwrite, o.ReplaceOperations, o.InIsOut);
},
//OPTIONS FOR REINTERPRETATION ONLY
(toHexOptions o) =>
{
return Functions.Reinterpret(o.InputFiles, o.Interpreter, o.overwrite, o.ReplaceOperations, o.InIsOut);
},
//CHECK COMPRESSION VERSION
(FileCheck_Options o) =>
{
return Functions.CheckFileVersion(o.InputFiles);
},
//OPTIONS FOR FC FILE IMPORT
(FcImportOptions o) =>
{
return Functions.FcFileImport(o.InputFiles, o.Interpreter, o.overwrite, o.InIsOut);
},
//OPTIONS FOR FC FILE EXPORT
(FcExportOptions o) =>
{
return Functions.FcFileExport(o.InputFiles, o.Interpreter, o.overwrite, o.OutputFileExtension, o.InIsOut);
},
e => 1
) ;
}
#endregion Methods
}
}