-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
68 lines (59 loc) · 1.86 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
using System.CommandLine;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;
using Sitreamai;
var musicId = new Option<int>(
name: "--id",
description: "歌曲 ID",
getDefaultValue: () => 0);
var fromDir = new Option<string>(
name: "--from",
description: "谱面目录",
getDefaultValue: () => "."
);
var assetsDir = new Option<string>(
name: "--assets",
description: "A500 目录"
) { IsRequired = true };
var rootCommand = new RootCommand("Simai 谱面上机工具")
{
musicId, fromDir, assetsDir
};
using var factory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = factory.CreateLogger($"Main");
rootCommand.SetHandler((musicId, from, assetsDir) =>
{
if (musicId == 0)
{
var musicDir = Path.Join(assetsDir, "music");
var musicEntities = Directory.EnumerateDirectories(musicDir);
musicId = 5000;
if (musicEntities.Any())
{
musicId = musicEntities.Select(it => int.Parse(it[^4..])).Max() + 1;
}
}
if (!File.Exists(Path.Join(from, "maidata.txt")))
{
logger.LogInformation("批量模式");
var fromDirs = Directory.EnumerateDirectories(from);
foreach (var fromDir in fromDirs)
{
var localMusicId = musicId++;
if (int.TryParse(Path.GetFileName(fromDir), out var dirId))
{
localMusicId = dirId;
}
var converter = new Converter(localMusicId, fromDir, assetsDir);
converter.Convert();
}
}
else
{
var converter = new Converter(musicId, from, assetsDir);
converter.Convert();
}
},
musicId, fromDir, assetsDir);
await rootCommand.InvokeAsync(args);