-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (88 loc) · 3.74 KB
/
Program.cs
File metadata and controls
100 lines (88 loc) · 3.74 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
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using Catel.IoC;
using CR2W2JSON.Core.Parser;
using WolvenKit.Common.Model.Cr2w;
using WolvenKit.Common.Services;
using WolvenKit.RED4.CR2W;
namespace CR2W2JSON.Core
{
internal class Json
{
[JsonInclude] [JsonPropertyName("RootType")] public string RootType;
[JsonInclude] [JsonPropertyName("Data")] public object Data;
}
internal static class Program
{
[SuppressMessage("ReSharper.DPA", "DPA0002: Excessive memory allocations in SOH", MessageId = "type: System.Reflection.CustomAttributeNamedParameter[]")]
private static int Main(string[] args)
{
var rootCommand = new RootCommand
{
new Argument<FileInfo>("input", "CR2W file"),
new Argument<FileInfo>("output", "JSON file")
};
var locator = ServiceLocator.Default;
locator.RegisterType<ILoggerService, LoggerService>();
rootCommand.Handler = CommandHandler.Create<FileInfo, FileInfo>((input, output) =>
{
try
{
var s = new Cp77FileService();
var CR2W = s.TryReadCr2WFile(
File.OpenRead(input.FullName)
);
var vcc = CR2W.Chunks[0].VirtualChildrenChunks[0];
var parser = GetParserByType(vcc.REDType, vcc);
if (parser == null)
{
Console.WriteLine("Unknown REDType: " + vcc.REDType);
Environment.Exit(1);
}
var json = new Json
{
RootType = vcc.REDType,
Data = parser.GetData()
};
if (parser.GetType() == typeof(SubtitlesMapParser))
{
if (input.DirectoryName == output.DirectoryName)
{
Console.WriteLine("To convert subtitles the output directory must be " +
"different from the input directory.");
Environment.Exit(2);
}
((SubtitlesMapParser)parser).
ParseSubtitleFiles(input.Directory, output.Directory);
}
File.WriteAllText(output.FullName, JsonSerializer.Serialize(json));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
});
return rootCommand.InvokeAsync(args).Result;
}
private static AbstractParser GetParserByType(string type, ICR2WExport chunk)
{
return type switch
{
"audioAudioEventArray" => new AudioEventArrayParser(chunk),
"localizationPersistenceOnScreenEntries" => new OnScreenParser(chunk),
"localizationPersistenceLocDataMap" => new LocDataMapAbstractParser(chunk),
"locVoLanguageDataMap" => new VoLanguageDataMapParser(chunk),
"locVoiceoverMap" => new VoMapParser(chunk),
"locVoiceoverLengthMap" => new StringIdVariantLengthsReportParser(chunk),
"localizationPersistenceSubtitleEntries" => new SubtitlesParser(chunk),
"localizationPersistenceSubtitleMap" => new SubtitlesMapParser(chunk),
_ => null
};
}
}
}