2023-07-28 18:02:47 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-10-01 18:40:41 +02:00
|
|
|
|
using System.IO;
|
2023-07-28 18:02:47 +02:00
|
|
|
|
using System.Linq;
|
2023-10-01 18:40:41 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using TaikoSoundEditor.Collections;
|
|
|
|
|
using TaikoSoundEditor.Commons.Controls;
|
2024-03-19 12:31:36 +01: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
|
|
|
|
|
{
|
|
|
|
|
#region Requesting Files
|
|
|
|
|
|
|
|
|
|
private void WordListPathSelector_PathChanged(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"WordListPathSelector_PathChanged : {WordListPathSelector.Path}");
|
|
|
|
|
WordListPath = WordListPathSelector.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MusicInfoPathSelector_PathChanged(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"MusicInfoPathSelector_PathChanged : {MusicInfoPathSelector.Path}");
|
|
|
|
|
MusicInfoPath = MusicInfoPathSelector.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MusicOrderPathSelector_PathChanged(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"MusicOrderPathSelector_PathChanged : {MusicOrderPathSelector.Path}");
|
|
|
|
|
MusicOrderPath = MusicOrderPathSelector.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MusicAttributePathSelector_PathChanged(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"MusicAttributePathSelector_PathChanged : {MusicAttributePathSelector.Path}");
|
|
|
|
|
MusicAttributePath = MusicAttributePathSelector.Path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DirSelector_PathChanged(object sender, EventArgs args) => ExceptionGuard.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"MusicAttributePathSelector_PathChanged : {DirSelector.Path}");
|
|
|
|
|
var dir = DirSelector.Path;
|
|
|
|
|
var files = new string[] { "music_attribute.bin", "music_order.bin", "musicinfo.bin", "wordlist.bin" };
|
|
|
|
|
var sels = new PathSelector[] { MusicAttributePathSelector, MusicOrderPathSelector, MusicInfoPathSelector, WordListPathSelector };
|
|
|
|
|
|
2024-03-21 12:02:33 +01:00
|
|
|
|
Config.DatatablesPath = dir;
|
|
|
|
|
|
2023-07-28 18:02:47 +02:00
|
|
|
|
List<string> NotFoundFiles = new List<string>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < files.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(dir, files[i]);
|
|
|
|
|
if (!File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
NotFoundFiles.Add(files[i]);
|
2024-03-21 12:34:20 +01:00
|
|
|
|
sels[i].Path = "";
|
2023-07-28 18:02:47 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
sels[i].Path = path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NotFoundFiles.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warning("The following files could not be found:\n\n" + String.Join("\n", NotFoundFiles));
|
|
|
|
|
MessageBox.Show("The following files could not be found:\n\n" + String.Join("\n", NotFoundFiles));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private void OkButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Clicked 'Looks good' ");
|
|
|
|
|
|
2023-09-18 17:53:43 +02:00
|
|
|
|
Config.DatatableIO.IsEncrypted = UseEncryptionBox.Checked;
|
2024-03-19 12:31:36 +01:00
|
|
|
|
|
|
|
|
|
SSL.LoadKeys();
|
|
|
|
|
|
2023-07-28 18:02:47 +02:00
|
|
|
|
try
|
2023-10-01 18:40:41 +02:00
|
|
|
|
{
|
|
|
|
|
MusicAttributes = Config.DatatableIO.DeserializeCollection<MusicAttributes, IMusicAttribute>(MusicAttributePath, DatatableTypes.MusicAttribute);
|
2023-07-28 18:02:47 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to parse\n{MusicAttributePath}\nReason:\n{ex.InnerException}");
|
|
|
|
|
}
|
|
|
|
|
try
|
2023-09-18 17:53:43 +02:00
|
|
|
|
{
|
2023-10-01 18:40:41 +02:00
|
|
|
|
MusicOrders = Config.DatatableIO.DeserializeCollection<MusicOrders, IMusicOrder>(MusicOrderPath, DatatableTypes.MusicOrder);
|
2023-07-28 18:02:47 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-10-01 18:40:41 +02:00
|
|
|
|
throw;
|
2023-07-28 18:02:47 +02:00
|
|
|
|
throw new Exception($"Failed to parse\n{MusicOrderPath}\nReason:\n{ex.InnerException}");
|
|
|
|
|
}
|
|
|
|
|
try
|
2023-10-01 18:40:41 +02:00
|
|
|
|
{
|
|
|
|
|
MusicInfos = Config.DatatableIO.DeserializeCollection<MusicInfos, IMusicInfo>(MusicInfoPath, DatatableTypes.MusicInfo);
|
2023-07-28 18:02:47 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"Failed to parse\n{MusicInfoPath}\nReason:\n{ex.InnerException}");
|
|
|
|
|
}
|
|
|
|
|
try
|
2023-10-01 18:40:41 +02:00
|
|
|
|
{
|
|
|
|
|
WordList = Config.DatatableIO.DeserializeCollection<WordList, IWord>(WordListPath, DatatableTypes.Word);
|
2023-07-28 18:02:47 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2023-10-01 18:40:41 +02:00
|
|
|
|
throw;
|
2023-07-28 18:02:47 +02:00
|
|
|
|
throw new Exception($"Failed to parse\n{WordListPath}\nReason:\n{ex.InnerException}");
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-30 08:21:29 +02:00
|
|
|
|
Logger.Info($"Fixing Wordlist missing data");
|
|
|
|
|
|
|
|
|
|
foreach (var mi in MusicInfos.Items)
|
|
|
|
|
{
|
2023-07-30 08:51:24 +02:00
|
|
|
|
if (mi.UniqueId == 0) continue;
|
2023-07-30 08:21:29 +02:00
|
|
|
|
var songId = mi.Id;
|
|
|
|
|
|
2023-07-30 08:51:24 +02:00
|
|
|
|
if(MusicAttributes.GetByUniqueId(mi.UniqueId)==null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Added missing music_attribute entry for {mi.UniqueId}.{songId}");
|
|
|
|
|
|
2023-10-01 18:40:41 +02:00
|
|
|
|
MusicAttributes.Items.Add(DatatableTypes.CreateMusicAttribute(songId, mi.UniqueId, false));
|
2023-07-30 08:51:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(MusicOrders.GetByUniqueId(mi.UniqueId)==null)
|
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Added missing music_order entry for {mi.UniqueId}.{songId}");
|
2023-10-01 18:40:41 +02:00
|
|
|
|
MusicOrders.Items.Add(DatatableTypes.CreateMusicOrder(mi.Genre, songId, mi.UniqueId));
|
2023-07-30 08:51:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-30 08:21:29 +02:00
|
|
|
|
if (WordList.GetBySong(songId) == null)
|
2023-07-30 08:51:24 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Added missing word title entry for {mi.UniqueId}.{songId}");
|
2023-10-01 18:40:41 +02:00
|
|
|
|
WordList.Items.Add(DatatableTypes.CreateWord($"song_{songId}", ""));
|
2023-07-30 08:51:24 +02:00
|
|
|
|
}
|
2023-07-30 08:21:29 +02:00
|
|
|
|
if (WordList.GetBySongSub(songId) == null)
|
2023-07-30 08:51:24 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Added missing word subtitle entry for {mi.UniqueId}.{songId}");
|
2023-10-01 18:40:41 +02:00
|
|
|
|
WordList.Items.Add(DatatableTypes.CreateWord($"song_sub_{songId}", ""));
|
2023-07-30 08:51:24 +02:00
|
|
|
|
}
|
2023-07-30 08:21:29 +02:00
|
|
|
|
if (WordList.GetBySongDetail(songId) == null)
|
2023-07-30 08:51:24 +02:00
|
|
|
|
{
|
|
|
|
|
Logger.Info($"Added missing word detail entry for {mi.UniqueId}.{songId}");
|
2023-10-01 18:40:41 +02:00
|
|
|
|
WordList.Items.Add(DatatableTypes.CreateWord($"song_detail_{songId}", ""));
|
2023-07-30 08:51:24 +02:00
|
|
|
|
}
|
2023-07-30 08:21:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 18:02:47 +02:00
|
|
|
|
Logger.Info($"Setting LoadedMusicBox DataSource");
|
|
|
|
|
|
|
|
|
|
LoadedMusicBinding = new BindingSource();
|
2023-07-29 07:58:11 +02:00
|
|
|
|
var cleanList = MusicInfos.Items.Where(mi => mi.UniqueId != 0).OrderBy(_ => _.UniqueId).ToList();
|
2023-07-28 21:28:05 +02:00
|
|
|
|
|
|
|
|
|
LoadedMusicBinding.DataSource = cleanList;
|
2023-07-28 18:02:47 +02:00
|
|
|
|
LoadedMusicBox.DataSource = LoadedMusicBinding;
|
|
|
|
|
TabControl.SelectedIndex = 1;
|
2023-07-28 21:28:05 +02:00
|
|
|
|
|
2023-07-30 07:11:24 +02:00
|
|
|
|
/*WordList.Items.RemoveAll(w =>
|
2023-07-29 08:15:24 +02:00
|
|
|
|
{
|
|
|
|
|
var key = w.Key;
|
|
|
|
|
|
|
|
|
|
var prefixes = new string[] { "song_sub_", "song_detail_", "song_" };
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
if (key.StartsWith(prefixes[i]))
|
|
|
|
|
{
|
|
|
|
|
key = key.Substring(prefixes[i].Length);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return !MusicInfos.Items.Any(mi => mi.Id == key);
|
2023-07-30 08:21:29 +02:00
|
|
|
|
});*/
|
2023-07-30 08:02:01 +02:00
|
|
|
|
|
2023-07-28 21:28:05 +02:00
|
|
|
|
MusicOrderViewer.WordList = WordList;
|
2024-03-21 17:32:32 +01:00
|
|
|
|
foreach (var musicOrder in MusicOrders.Items.Where(_ => MusicInfos.Items.Any(mi => mi.UniqueId == _.UniqueId))) MusicOrderViewer.AddSong(musicOrder);
|
|
|
|
|
MusicOrderViewer.SortSongs();
|
2023-07-29 07:58:11 +02:00
|
|
|
|
});
|
2023-07-28 18:02:47 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|