-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProgram.cs
284 lines (259 loc) · 11 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
using System.Reflection;
using System.Xml;
using ManyConsole;
using MaiLib;
using System.Text.Json;
using System.Text.Unicode;
using System.Text.Encodings.Web;
namespace MaichartConverter
{
/// <summary>
/// Main program of converter
/// </summary>
class Program
{
protected static string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
/// <summary>
/// Defines which path is using in programs
/// </summary>
public static string[] DefaultPaths =
[
$"{home}/MaiAnalysis/A000/",
$"{home}/MaiAnalysis/Sound/",
$"{home}/MaiAnalysis/Image/Texture2D/",
$"{home}/MaiAnalysis/DXBGA_HEVC/",
$"{home}/MaiAnalysis/Output/"
];
/// <summary>
/// Defines possible sorting scheme
/// </summary>
/// <value>Sorting scheme</value>
public static readonly string[] TrackCategorizeMethodSet =
["Genre", "Level", "Cabinet", "Composer", "BPM", "SD/DX Chart", "No Separate Folder"];
/// <summary>
/// Program will sort output according to this
/// </summary>
public static string GlobalTrackCategorizeMethod = TrackCategorizeMethodSet[0];
/// <summary>
/// Records total track number compiled by program
/// </summary>
public static int NumberTotalTrackCompiled;
public static Dictionary<int, string> CompiledTracks = [];
public static List<string> CompiledChart = [];
public static List<string> ErrorMessage = [];
public static Dictionary<string, string[]> CompiledTrackDetailSet = [];
public static XmlDocument BPMCollection = new XmlDocument();
public static XmlDocument DebugInformationTable = new XmlDocument();
/// <summary>
/// Main method to process charts
/// </summary>
/// <param name="args">Parameters to take in</param>
public static int Main(string[] args)
{
Console.WriteLine(ComposeHeader());
// XmlDeclaration xmlDecl = BPMCollection.CreateXmlDeclaration("1.0", "UTF-8", null);
// XmlDeclaration xmlDeclBPM = DebugInformationTable.CreateXmlDeclaration("1.0", "UTF-8", null);
// BPMCollection.AppendChild(xmlDecl);
// DebugInformationTable.AppendChild(xmlDeclBPM);
// XmlElement root = BPMCollection.CreateElement("BPM");
// XmlElement btRoot = DebugInformationTable.CreateElement("BPM-Table");
// BPMCollection.AppendChild(root);
// DebugInformationTable.AppendChild(btRoot);
//TestSpecificChart();
//TestSpecificChart(@"D:\PandoraCandidate.ma2");
//TestSpecificChart("000389", "4");
//CompileChartDatabase();
//CompileAssignedChartDatabase();
// CompileUtageChartDatabase();
//}
// return 0;
IEnumerable<ConsoleCommand>? commands = GetCommands();
// foreach (ConsoleCommand x in commands)
// {
// Console.WriteLine(x.Command.ToString());
// }
// Console.WriteLine(string.Join(' ',args));
return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
// else
// {
// ConsoleCommand reverseDatabase = new ReverseMa2FromSimaiDatabase();
// return reverseDatabase.Run(args);
// }
}
/// <summary>
/// Get commands
/// </summary>
/// <returns>ProperCommands</returns>
public static IEnumerable<ConsoleCommand> GetCommands()
{
return ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
}
/// <summary>
/// Compensate 0 for music IDs
/// </summary>
/// <param name="intake">Music ID</param>
/// <returns>0..+#Music ID and |Music ID|==6</returns>
public static string CompensateZero(string intake)
{
try
{
string result = intake;
while (result.Length < 6 && intake != null)
{
result = "0" + result;
}
return result;
}
catch (NullReferenceException ex)
{
return "Exception raised: " + ex.Message;
}
}
/// <summary>
/// Compensate 0 for short music IDs
/// </summary>
/// <param name="intake">Music ID</param>
/// <returns>0..+#Music ID and |Music ID|==4</returns>
public static string CompensateShortZero(string intake)
{
try
{
string result = intake;
while (result.Length < 4 && intake != null)
{
result = "0" + result;
}
return result;
}
catch (NullReferenceException ex)
{
return "Exception raised: " + ex.Message;
}
}
/// <summary>
/// Compose fancy header
/// </summary>
/// <returns>MaichartConverter.fancy</returns>
public static string ComposeHeader()
{
string result = "";
result +=
(@" _____ .__ .__ __ _________ __ " +
"\n");
result +=
(@" / \ _____ |__| ____ | |__ _____ ________/ |_ \_ ___ \ ____ _______ __ ____________/ |_ ___________ " +
"\n");
result +=
(@" / \ / \\__ \ | |/ ___\| | \\__ \\_ __ \ __\/ \ \/ / _ \ / \ \/ // __ \_ __ \ __\/ __ \_ __ \" +
"\n");
result +=
(@" / Y \/ __ \| \ \___| Y \/ __ \| | \/| | \ \___( <_> ) | \ /\ ___/| | \/| | \ ___/| | \/" +
"\n");
result +=
(@" \____|__ (____ /__|\___ >___| (____ /__| |__| \______ /\____/|___| /\_/ \___ >__| |__| \___ >__| " +
"\n");
result +=
(@" \/ \/ \/ \/ \/ \/ \/ \/ \/ " +
"\n");
result += "a GUtils component for rhythm games\n";
result += "Rev. " + Assembly.GetExecutingAssembly().GetName().Version + " by Neskol\n";
result += "Check https://github.com/Neskol/MaichartConverter for updates and instructions\n";
return result;
}
/// <summary>
/// Log to given position.
/// </summary>
/// <param name="outputLocation">Place to log</param>
public static void Log(string outputLocation)
{
StreamWriter sw = new StreamWriter(outputLocation + "log.txt", false);
int index = 1;
Console.WriteLine("Total music compiled: {0}", NumberTotalTrackCompiled);
foreach (KeyValuePair<int, string> pair in CompiledTracks)
{
sw.WriteLine($"[{index}]: {pair.Key} {pair.Value}");
index++;
}
sw.WriteLine();
if (ErrorMessage.Count > 0)
{
sw.WriteLine("Warnings:");
foreach (string error in ErrorMessage)
{
sw.WriteLine(error);
}
}
sw.Close();
// BPMCollection.Save(outputLocation + "bpm.xml");
// DebugInformationTable.Save(outputLocation + "debug.xml");
}
/// <summary>
/// Log to given position in Json format.
/// </summary>
/// <param name="outputLocation">Place to log</param>
public static void LogTracksInJson(string outputLocation)
{
StreamWriter sw = new StreamWriter(outputLocation + "index.json", false);
JsonSerializerOptions? JsonOptions = new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true,
};
sw.WriteLine(JsonSerializer.Serialize(new SortedDictionary<int, string>(CompiledTracks), JsonOptions));
sw.Close();
}
/// <summary>
/// Append Nodes to BPMCollection
/// </summary>
/// <param name="idValue">ID</param>
/// <param name="bpmValue">BPM</param>
public static void AppendBPM(string idValue, string bpmValue)
{
XmlElement node = BPMCollection.CreateElement("Node");
XmlElement id = BPMCollection.CreateElement("ID");
id.InnerText = idValue;
XmlElement bpm = BPMCollection.CreateElement("BPM");
bpm.InnerText = bpmValue;
node.AppendChild(id);
node.AppendChild(bpm);
XmlNode root = BPMCollection.ChildNodes[1] ?? throw new NullReferenceException();
root.AppendChild(node);
}
/// <summary>
/// Append debug information to save
/// </summary>
/// <param name="idValue">ID of the chart</param>
/// <param name="bpmTable">BPMTable</param>
/// <param name="firstNoteValue">First note of the Master Chart</param>
public static void AppendDebugInformation(string idValue, BPMChanges bpmTable, Note firstNoteValue)
{
XmlElement node = DebugInformationTable.CreateElement("Node");
XmlElement id = DebugInformationTable.CreateElement("ID");
id.InnerText = idValue;
XmlElement bpm = DebugInformationTable.CreateElement("BPM");
XmlElement firstNote = DebugInformationTable.CreateElement("FirstNote");
XmlElement firstNoteType = DebugInformationTable.CreateElement("Type");
firstNote.AppendChild(firstNoteType);
Console.WriteLine(firstNoteValue.ToString());
node.AppendChild(id);
node.AppendChild(bpm);
node.AppendChild(firstNote);
foreach (BPMChange note in bpmTable.ChangeNotes)
{
XmlElement changeNote = DebugInformationTable.CreateElement("Note");
XmlElement bar = DebugInformationTable.CreateElement("Bar");
bar.InnerText = note.Bar.ToString();
XmlElement tick = DebugInformationTable.CreateElement("Tick");
tick.InnerText = note.Tick.ToString();
XmlElement noteBPM = DebugInformationTable.CreateElement("BPM");
noteBPM.InnerText = note.BPM.ToString();
changeNote.AppendChild(bar);
changeNote.AppendChild(tick);
changeNote.AppendChild(noteBPM);
bpm.AppendChild(changeNote);
}
XmlNode root = DebugInformationTable.ChildNodes[1] ?? throw new NullReferenceException();
root.AppendChild(node);
}
}
}