-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandLineOptions.cs
More file actions
325 lines (278 loc) · 11.5 KB
/
Copy pathCommandLineOptions.cs
File metadata and controls
325 lines (278 loc) · 11.5 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using BFGDL.NET.Models;
namespace BFGDL.NET;
public sealed record CommandLineOptions
{
public bool ShowHelp { get; init; }
public bool ShowVersion { get; init; }
public bool Download { get; init; }
public bool FetchFromInstallers { get; init; }
/// <summary>Fetch all catalog pages + game details + images and store them to disk.</summary>
public bool CacheCatalog { get; init; }
/// <summary>When combined with --cache-catalog, fetches all 10 supported languages.</summary>
public bool AllLanguages { get; init; }
/// <summary>Max concurrent game-detail/image fetches when running --cache-catalog (default 4).</summary>
public int CacheConcurrency
{
get;
init
{
ArgumentOutOfRangeException.ThrowIfLessThan(value, 1);
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 16);
field = value;
}
} = 4;
public string? ExportInstallersJson
{
get;
init
{
if (string.IsNullOrWhiteSpace(value))
{
field = null;
return;
}
var normalized = value.Trim().ToLowerInvariant();
field = normalized switch
{
"pretty" => "pretty",
"min" => "min",
_ => throw new ArgumentException("Invalid value for --export-installers-json. Use 'pretty' or 'min'.")
};
}
}
public int? ExportLimit
{
get;
init
{
if (value.HasValue)
ArgumentOutOfRangeException.ThrowIfLessThan(value.Value, 1);
field = value;
}
}
public int MaxConcurrentDownloads
{
get;
init
{
ArgumentOutOfRangeException.ThrowIfLessThan(value, 1);
ArgumentOutOfRangeException.ThrowIfGreaterThan(value, 64);
field = value;
}
} = 8;
public string? ConfigFilePath
{
get;
init => field = string.IsNullOrWhiteSpace(value) ? null : value.Trim();
}
public Platform? Platform { get; init; }
public Language? Language { get; init; }
public List<string> WrapIds
{
get;
init => field =
[.. value.Where(id => !string.IsNullOrWhiteSpace(id)).Select(id => id.Trim().ToUpperInvariant())];
} = [];
public static CommandLineOptions Parse(string[] args)
{
var options = new CommandLineOptions();
var wrapIds = new List<string>();
var download = false;
var fetchFromInstallers = false;
var cacheCatalog = false;
var allLanguages = false;
var showHelp = false;
var showVersion = false;
var maxConcurrent = 8;
var cacheConcurrency = 4;
string? configFilePath = null;
Platform? platform = null;
Language? language = null;
string? exportInstallersJson = null;
int? exportLimit = null;
for (var i = 0; i < args.Length; i++)
{
var arg = args[i];
switch (arg)
{
case "-h" or "--help":
showHelp = true;
break;
case "-v" or "--version":
showVersion = true;
break;
case "-d" or "--download":
download = true;
break;
case "-e" or "--extract":
fetchFromInstallers = true;
break;
case "-cc" or "--cache-catalog":
cacheCatalog = true;
break;
case "-al" or "--all-languages":
allLanguages = true;
break;
case "-cn" or "--concurrency":
if (i + 1 < args.Length && int.TryParse(args[i + 1], out var concurrency))
{
cacheConcurrency = concurrency;
i++;
}
else
{
throw new ArgumentException("Invalid value for -cn/--concurrency flag");
}
break;
case "-j" or "--jobs":
if (i + 1 < args.Length && int.TryParse(args[i + 1], out var jobs))
{
maxConcurrent = jobs;
i++; // Skip next arg
}
else
{
throw new ArgumentException("Invalid value for -j/--jobs flag");
}
break;
case "-c" or "--config":
if (i + 1 < args.Length)
{
configFilePath = args[i + 1];
i++; // Skip next arg
}
else
{
throw new ArgumentException("Missing value for -c/--config flag");
}
break;
case "-p" or "--platform":
if (i + 1 < args.Length)
{
platform = ParsePlatform(args[i + 1]);
i++; // Skip next arg
}
else
{
throw new ArgumentException("Missing value for -p/--platform flag");
}
break;
case "-l" or "--language":
if (i + 1 < args.Length)
{
language = ParseLanguage(args[i + 1]);
i++; // Skip next arg
}
else
{
throw new ArgumentException("Missing value for -l/--language flag");
}
break;
default:
if (arg.StartsWith("--export-installers-json=", StringComparison.OrdinalIgnoreCase))
{
exportInstallersJson = arg.Split('=', 2)[1];
break;
}
if (arg.StartsWith("--export-limit=", StringComparison.OrdinalIgnoreCase))
{
var value = arg.Split('=', 2)[1];
if (!int.TryParse(value, out var limit) || limit < 1)
throw new ArgumentException(
"Invalid value for --export-limit. Must be a positive integer.");
exportLimit = limit;
break;
}
if (!arg.StartsWith('-'))
wrapIds.Add(arg);
else
throw new ArgumentException($"Unknown argument: {arg}");
break;
}
}
return options with
{
ShowHelp = showHelp,
ShowVersion = showVersion,
Download = download,
FetchFromInstallers = fetchFromInstallers,
CacheCatalog = cacheCatalog,
AllLanguages = allLanguages,
CacheConcurrency = cacheConcurrency,
MaxConcurrentDownloads = maxConcurrent,
ConfigFilePath = configFilePath,
Platform = platform,
Language = language,
WrapIds = wrapIds,
ExportInstallersJson = exportInstallersJson,
ExportLimit = exportLimit
};
}
private static Platform ParsePlatform(string value)
{
return value.ToLowerInvariant() switch
{
"win" or "windows" => Models.Platform.Windows,
"mac" or "macos" => Models.Platform.Mac,
_ => throw new ArgumentException($"Invalid platform: {value}. Use 'win' or 'mac'.")
};
}
private static Language ParseLanguage(string value)
{
return value.ToLowerInvariant() switch
{
"eng" or "english" => Models.Language.English,
"ger" or "german" => Models.Language.German,
"spa" or "spanish" => Models.Language.Spanish,
"fre" or "french" => Models.Language.French,
"ita" or "italian" => Models.Language.Italian,
"jap" or "japanese" => Models.Language.Japanese,
"dut" or "dutch" => Models.Language.Dutch,
"swe" or "swedish" => Models.Language.Swedish,
"dan" or "danish" => Models.Language.Danish,
"por" or "portuguese" => Models.Language.Portuguese,
_ => throw new ArgumentException($"Invalid language: {value}")
};
}
public static void PrintHelp()
{
Console.WriteLine("""
BFGDL.NET - Big Fish Games Downloader
Usage: BFGDL.NET [OPTIONS] [WrapID...]
With no flags, BFGDL.NET will output a download list of links.
Options:
-h, --help Display this help message
-v, --version Display version information
-e, --extract Fetch links using installers in current directory
-d, --download Download files after fetching
-j, --jobs N Set number of concurrent downloads (default: 8, max: 64)
-c, --config FILE Load configuration from FILE (default: config.ini)
-p, --platform PLATFORM Set platform: win, mac (overrides config)
-l, --language LANG Set language: eng, ger, spa, fre, ita, jap, dut, swe, dan, por
-cc, --cache-catalog Fetch all catalog pages, game details, and images to disk
-al, --all-languages Used with --cache-catalog: fetch all 10 supported languages
-cn, --concurrency N Parallel game fetches per page for --cache-catalog (default: 4, max: 16)
--export-installers-json=pretty|min Export full (non-demo) installer segment lists grouped by WrapID language (L#)
--export-limit=N Limit number of games exported (for testing)
Examples:
Fetch links for specific games:
BFGDL.NET F15533T1L2 F7028T1L1 F1T1L1
Download one game with 4 concurrent downloads:
BFGDL.NET -d -j 4 F5260T1L1
Download games using installers in current directory:
BFGDL.NET -e -d
Cache entire catalog to disk (English only):
BFGDL.NET --cache-catalog
Cache entire catalog to disk in all 10 languages:
BFGDL.NET --cache-catalog --all-languages
Export Windows installer lists to JSON (pretty):
BFGDL.NET --export-installers-json=pretty -p win
Export limited sample (minified):
BFGDL.NET --export-installers-json=min --export-limit=50 -p win
""");
}
public static void PrintVersion()
{
Console.WriteLine("BFGDL.NET v1.0.0 - C# .NET 10 Implementation");
}
}