-
Notifications
You must be signed in to change notification settings - Fork 4
/
MainForm.Exports.cs
172 lines (149 loc) · 6.07 KB
/
MainForm.Exports.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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;
using TaikoSoundEditor.Collections;
using TaikoSoundEditor.Commons;
using TaikoSoundEditor.Commons.IO;
using TaikoSoundEditor.Commons.Utils;
using TaikoSoundEditor.Data;
namespace TaikoSoundEditor
{
partial class MainForm
{
private void ExportDatatable(string path)
{
Logger.Info($"Exporting Datatable to '{path}'");
var mi = new MusicInfos();
mi.Items.AddRange(MusicInfos.Items);
mi.Items.AddRange(AddedMusic.Select(_ => _.MusicInfo));
var ma = new MusicAttributes();
ma.Items.AddRange(MusicAttributes.Items);
//ma.Items.AddRange(AddedMusic.Select(_ => _.MusicAttribute));
var mo = new MusicOrders();
mo.Items.AddRange(MusicOrderViewer.SongCards.Select(_ => _.MusicOrder));
var wl = new WordList();
wl.Items.AddRange(WordList.Items);
Config.DatatableIO.DynamicSerialize(Path.Combine(path, "musicinfo.bin"), mi.Cast(DatatableTypes.MusicInfo) , indented: !DatatableSpaces.Checked);
Config.DatatableIO.DynamicSerialize(Path.Combine(path, "music_attribute.bin"), ma.Cast(DatatableTypes.MusicAttribute), fixBools: true);
Config.DatatableIO.DynamicSerialize(Path.Combine(path, "music_order.bin"), mo.Cast(DatatableTypes.MusicOrder));
Config.DatatableIO.DynamicSerialize(Path.Combine(path, "wordlist.bin"), wl.Cast(DatatableTypes.Word), indented: true);
}
private void ExportNusBanks(string path)
{
Logger.Info($"Exporting NUS3BaNKS to '{path}'");
foreach (var ns in AddedMusic)
{
File.WriteAllBytes(Path.Combine(path, $"song_{ns.Id}.nus3bank"), ns.Nus3Bank);
}
}
private void ExportSoundBinaries(string path)
{
Logger.Info($"Exporting Sound .bin's to '{path}'");
foreach (var ns in AddedMusic)
{
var sdir = Path.Combine(path, ns.Id);
if (!Directory.Exists(sdir))
Directory.CreateDirectory(sdir);
void Save(string suffix, byte[] bytes)
{
if (UseEncryptionBox.Checked)
bytes = SSL.EncryptFumen(bytes);
File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_{suffix}.bin"), bytes);
}
Save("e", ns.EBin);
Save("n", ns.NBin);
Save("h", ns.HBin);
Save("m", ns.MBin);
Save("e_1", ns.EBin1);
Save("n_1", ns.NBin1);
Save("h_1", ns.HBin1);
Save("m_1", ns.MBin1);
Save("e_2", ns.EBin2);
Save("n_2", ns.NBin2);
Save("h_2", ns.HBin2);
Save("m_2", ns.MBin2);
if (ns.MusicAttribute.CanPlayUra)
{
Save("x", ns.XBin);
Save("x_1", ns.XBin1);
Save("x_2", ns.XBin2);
}
}
}
private void ExportDatatableButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() =>
{
Logger.Info($"Clicked ExportDatatableButton");
var path = PickPath();
if (path == null)
{
MessageBox.Show("No path chosen. Operation canceled");
return;
}
ExportDatatable(path);
MessageBox.Show("Done");
if (ExportOpenOnFinished.Checked)
Process.Start($"explorer.exe", path);
});
private void ExportSoundFoldersButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() =>
{
Logger.Info($"Clicked ExportSoundFoldersButton");
var path = PickPath();
if (path == null)
{
MessageBox.Show("No path chosen. Operation canceled");
return;
}
ExportSoundBinaries(path);
MessageBox.Show("Done");
if (ExportOpenOnFinished.Checked)
Process.Start($"explorer.exe", path);
});
private void ExportSoundBanksButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() =>
{
Logger.Info($"Clicked ExportSoundBanksButton");
var path = PickPath();
if (path == null)
{
MessageBox.Show("No path chosen. Operation canceled");
return;
}
ExportNusBanks(path);
MessageBox.Show("Done");
if (ExportOpenOnFinished.Checked)
Process.Start($"explorer.exe", path);
});
private static string PickPath()
{
Logger.Info($"Picking path dialog");
var picker = new FolderPicker();
if (picker.ShowDialog() == true)
return picker.ResultPath;
return null;
}
private void ExportAllButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() =>
{
Logger.Info($"Clicked Export All");
var path = PickPath();
if (path == null)
{
MessageBox.Show("No path chosen. Operation canceled");
return;
}
var dtpath = Path.Combine(path, "datatable");
if (!Directory.Exists(dtpath)) Directory.CreateDirectory(dtpath);
var nupath = Path.Combine(path, "sound");
if (!Directory.Exists(nupath)) Directory.CreateDirectory(nupath);
var sbpath = Path.Combine(path, "fumen");
if (!Directory.Exists(sbpath)) Directory.CreateDirectory(sbpath);
ExportDatatable(dtpath);
ExportSoundBinaries(sbpath);
ExportNusBanks(nupath);
MessageBox.Show("Done");
if (ExportOpenOnFinished.Checked)
Process.Start($"explorer.exe", path);
});
}
}