-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
96 lines (80 loc) · 3.6 KB
/
Program.cs
File metadata and controls
96 lines (80 loc) · 3.6 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
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Mutsuki.Lib;
using ShellProgressBar;
namespace Mutsuki;
using CommandLine;
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
public class Program
{
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Local")]
private class Options
{
[Option('i', "input", Required = true, HelpText = "Input file to be processed.")]
public string Input { set; get; } = null!;
[Option('o', "output", Required = true, HelpText = "Output folder to be written.")]
public string Output { set; get; } = null!;
[Option('m', "map", Required = true, HelpText = "Map file to be used.")]
public string Map { set; get; } = null!;
}
private static void Main(string[] args)
{
Parser
.Default.ParseArguments<Options>(args)
.WithParsed(opts =>
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
if (!Directory.Exists(opts.Output))
{
Directory.CreateDirectory(opts.Output);
}
var inputFile = File.OpenRead(opts.Input);
var parser = new SeenParser(inputFile);
var splitFolder = Path.Combine(opts.Output, "01_SPLIT");
Directory.CreateDirectory(splitFolder);
var decompressedFolder = Path.Combine(opts.Output, "02_DECOMPRESSED");
Directory.CreateDirectory(decompressedFolder);
var parsedFolder = Path.Combine(opts.Output, "03_PARSED");
Directory.CreateDirectory(parsedFolder);
var stringFolder = Path.Combine(opts.Output, "04_STRING");
Directory.CreateDirectory(stringFolder);
var options = new ProgressBarOptions
{
ProgressBarOnBottom = true,
ProgressCharacter = '─'
};
using var progressBar = new ProgressBar(
parser.FileCount * 3,
"Starting",
options
);
foreach (var (name, data) in parser.Files)
{
progressBar.Tick($"Writing Split {name}...");
var splitFilePath = Path.Combine(splitFolder, name);
File.WriteAllBytes(splitFilePath, data);
try
{
progressBar.Tick($"Decompressing {name}...");
var decompressedFilePath = Path.Combine(decompressedFolder, name);
var decompressed = Decompress.UnPack(data);
File.WriteAllBytes(decompressedFilePath, decompressed);
progressBar.Tick($"Parsing {name}...");
var parsedFilePath = Path.Combine(parsedFolder, name);
var parsed = new ScenarioParser(new MemoryStream(decompressed), opts.Map);
File.WriteAllText(parsedFilePath, parsed.FinalContent);
if (!string.IsNullOrEmpty(parsed.FinalString))
{
var stringFilePath = Path.Combine(stringFolder, name);
File.WriteAllText(stringFilePath, parsed.FinalString);
}
}
catch (Exception e)
{
Console.WriteLine($"Failed to decompress/parse {name}: {e.Message}");
throw;
}
}
});
}
}