-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
124 lines (104 loc) · 3.75 KB
/
Program.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
using DumpCsv;
using SaintCoinach;
using SaintCoinach.Ex;
if (args.Length < 3)
{
Console.WriteLine("usage: dumpcsv path-to-game lang rawedx|allrawexd <out-path>");
return 0;
}
var dataPath = args[0];
var inputLang = args[1];
var type = args[2];
var outPath = args.Length > 3 ? args[3] : null;
Console.WriteLine("Loading game data ...");
var realm = new ARealmReversed(
dataPath,
@"SaintCoinach.History.zip",
inputLang == "ja" ? SaintCoinach.Ex.Language.Japanese :
inputLang == "en" ? SaintCoinach.Ex.Language.English :
inputLang == "chs" ? SaintCoinach.Ex.Language.ChineseSimplified :
SaintCoinach.Ex.Language.English,
@"app_data.sqlite"
);
realm.Packs.GetPack(
new SaintCoinach.IO.PackIdentifier("exd", SaintCoinach.IO.PackIdentifier.DefaultExpansion, 0)
).KeepInMemory = true;
Console.WriteLine("Game version: {0}", realm.GameVersion);
Console.WriteLine("Definition version: {0}", realm.DefinitionVersion);
if (string.IsNullOrEmpty(outPath))
{
outPath = realm.GameVersion;
}
if (type == "allrawexd")
{
const string CsvFileFormat = "raw-exd-all/{0}{1}.csv";
var filesToExport = realm.GameData.AvailableSheets;
// Action counts
var successCount = 0;
var failCount = 0;
var currentCount = 0;
var total = filesToExport.Count();
// Process game files.
foreach (var name in filesToExport)
{
currentCount++;
var sheet = realm.GameData.GetSheet(name);
// Loop through all available languages
foreach (var lang in sheet.Header.AvailableLanguages)
{
var code = lang.GetCode();
if (code.Length > 0)
code = "." + code;
var target = new FileInfo(Path.Combine(outPath, string.Format(CsvFileFormat, name, code)));
try
{
if (!target.Directory.Exists)
target.Directory.Create();
// Save
if (currentCount % 100 == 1)
Console.WriteLine($"[{currentCount}/{total}] Processing: {name} - Language: {lang.GetSuffix()}");
ExdHelper.SaveAsCsv(sheet, lang, target.FullName, true);
++successCount;
}
catch (Exception e)
{
Console.WriteLine($"Export of {name} failed: {e.Message}");
try { if (target.Exists) { target.Delete(); } } catch { }
++failCount;
}
}
}
Console.WriteLine($"{successCount} files exported, {failCount} failed");
}
else if (type == "rawexd")
{
const string CsvFileFormat = "rawexd/{0}.csv";
var filesToExport = realm.GameData.AvailableSheets;
var successCount = 0;
var failCount = 0;
var currentCount = 0;
var total = filesToExport.Count();
foreach (var name in filesToExport)
{
currentCount++;
var target = new FileInfo(Path.Combine(outPath, string.Format(CsvFileFormat, name)));
try
{
var sheet = realm.GameData.GetSheet(name);
if (!target.Directory.Exists)
target.Directory.Create();
if (currentCount % 100 == 1)
Console.WriteLine($"[{currentCount}/{total}] Processing: {name}");
ExdHelper.SaveAsCsv(sheet, SaintCoinach.Ex.Language.None, target.FullName, true);
++successCount;
}
catch (Exception e)
{
Console.WriteLine($"Export of {name} failed: {e.Message}");
try { if (target.Exists) { target.Delete(); } } catch { }
++failCount;
}
}
Console.WriteLine($"{successCount} files exported, {failCount} failed");
}
return 0;