-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainForm.RequestFiles.cs
183 lines (155 loc) · 7.3 KB
/
MainForm.RequestFiles.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
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using TaikoSoundEditor.Collections;
using TaikoSoundEditor.Commons.Controls;
using TaikoSoundEditor.Commons.IO;
using TaikoSoundEditor.Commons.Utils;
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 };
Config.DatatablesPath = dir;
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]);
sels[i].Path = "";
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' ");
Config.DatatableIO.IsEncrypted = UseEncryptionBox.Checked;
SSL.LoadKeys();
try
{
MusicAttributes = Config.DatatableIO.DeserializeCollection<MusicAttributes, IMusicAttribute>(MusicAttributePath, DatatableTypes.MusicAttribute);
}
catch (Exception ex)
{
throw new Exception($"Failed to parse\n{MusicAttributePath}\nReason:\n{ex.InnerException}");
}
try
{
MusicOrders = Config.DatatableIO.DeserializeCollection<MusicOrders, IMusicOrder>(MusicOrderPath, DatatableTypes.MusicOrder);
}
catch (Exception ex)
{
throw;
throw new Exception($"Failed to parse\n{MusicOrderPath}\nReason:\n{ex.InnerException}");
}
try
{
MusicInfos = Config.DatatableIO.DeserializeCollection<MusicInfos, IMusicInfo>(MusicInfoPath, DatatableTypes.MusicInfo);
}
catch (Exception ex)
{
throw new Exception($"Failed to parse\n{MusicInfoPath}\nReason:\n{ex.InnerException}");
}
try
{
WordList = Config.DatatableIO.DeserializeCollection<WordList, IWord>(WordListPath, DatatableTypes.Word);
}
catch (Exception ex)
{
throw;
throw new Exception($"Failed to parse\n{WordListPath}\nReason:\n{ex.InnerException}");
}
Logger.Info($"Fixing Wordlist missing data");
foreach (var mi in MusicInfos.Items)
{
if (mi.UniqueId == 0) continue;
var songId = mi.Id;
if(MusicAttributes.GetByUniqueId(mi.UniqueId)==null)
{
Logger.Info($"Added missing music_attribute entry for {mi.UniqueId}.{songId}");
MusicAttributes.Items.Add(DatatableTypes.CreateMusicAttribute(songId, mi.UniqueId, false));
}
if(MusicOrders.GetByUniqueId(mi.UniqueId)==null)
{
Logger.Info($"Added missing music_order entry for {mi.UniqueId}.{songId}");
MusicOrders.Items.Add(DatatableTypes.CreateMusicOrder(mi.Genre, songId, mi.UniqueId));
}
if (WordList.GetBySong(songId) == null)
{
Logger.Info($"Added missing word title entry for {mi.UniqueId}.{songId}");
WordList.Items.Add(DatatableTypes.CreateWord($"song_{songId}", ""));
}
if (WordList.GetBySongSub(songId) == null)
{
Logger.Info($"Added missing word subtitle entry for {mi.UniqueId}.{songId}");
WordList.Items.Add(DatatableTypes.CreateWord($"song_sub_{songId}", ""));
}
if (WordList.GetBySongDetail(songId) == null)
{
Logger.Info($"Added missing word detail entry for {mi.UniqueId}.{songId}");
WordList.Items.Add(DatatableTypes.CreateWord($"song_detail_{songId}", ""));
}
}
Logger.Info($"Setting LoadedMusicBox DataSource");
LoadedMusicBinding = new BindingSource();
var cleanList = MusicInfos.Items.Where(mi => mi.UniqueId != 0).OrderBy(_ => _.UniqueId).ToList();
LoadedMusicBinding.DataSource = cleanList;
LoadedMusicBox.DataSource = LoadedMusicBinding;
TabControl.SelectedIndex = 1;
/*WordList.Items.RemoveAll(w =>
{
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);
});*/
MusicOrderViewer.WordList = WordList;
foreach (var musicOrder in MusicOrders.Items.Where(_ => MusicInfos.Items.Any(mi => mi.UniqueId == _.UniqueId))) MusicOrderViewer.AddSong(musicOrder);
MusicOrderViewer.SortSongs();
});
#endregion
}
}