1
0
mirror of synced 2024-11-30 14:14:29 +01:00
TaikoSoundEditor/MainForm.Exports.cs

173 lines
6.1 KiB
C#
Raw Normal View History

2023-10-01 18:40:41 +02:00
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
2023-10-01 21:40:27 +02:00
using System.Security.Cryptography;
2023-10-01 18:40:41 +02:00
using System.Windows.Forms;
using TaikoSoundEditor.Collections;
using TaikoSoundEditor.Commons;
2023-10-01 21:40:27 +02:00
using TaikoSoundEditor.Commons.IO;
2023-10-01 18:40:41 +02:00
using TaikoSoundEditor.Commons.Utils;
2023-07-28 18:02:47 +02:00
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);
2023-07-29 08:20:48 +02:00
//ma.Items.AddRange(AddedMusic.Select(_ => _.MusicAttribute));
2023-07-28 18:02:47 +02:00
var mo = new MusicOrders();
2023-07-29 08:20:48 +02:00
mo.Items.AddRange(MusicOrderViewer.SongCards.Select(_ => _.MusicOrder));
2023-07-28 18:02:47 +02:00
var wl = new WordList();
2023-10-01 21:40:27 +02:00
wl.Items.AddRange(WordList.Items);
2023-09-30 18:13:04 +02:00
2023-10-01 21:40:27 +02:00
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);
2023-07-28 18:02:47 +02:00
}
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);
2023-10-01 21:40:27 +02:00
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);
2023-07-28 18:02:47 +02:00
2023-10-01 21:40:27 +02:00
Save("e_1", ns.EBin1);
Save("n_1", ns.NBin1);
Save("h_1", ns.HBin1);
Save("m_1", ns.MBin1);
2023-07-28 18:02:47 +02:00
2023-10-01 21:40:27 +02:00
Save("e_2", ns.EBin2);
Save("n_2", ns.NBin2);
Save("h_2", ns.HBin2);
Save("m_2", ns.MBin2);
2023-07-28 18:02:47 +02:00
if (ns.MusicAttribute.CanPlayUra)
{
2023-10-01 21:40:27 +02:00
Save("x", ns.XBin);
Save("x_1", ns.XBin1);
Save("x_2", ns.XBin2);
2023-07-28 18:02:47 +02:00
}
}
}
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);
});
2023-10-01 18:40:41 +02:00
private static string PickPath()
2023-07-28 18:02:47 +02:00
{
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);
2023-09-30 18:13:04 +02:00
});
2023-07-28 18:02:47 +02:00
}
}