Skip to content

Commit fc19f87

Browse files
committed
StaticSettings.StartupErrorsList
1 parent 3ec2ff6 commit fc19f87

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace MaiChartManager.Controllers.App;
4+
5+
[ApiController]
6+
[Route("MaiChartManagerServlet/[action]Api")]
7+
public class AppStatusController(StaticSettings settings, ILogger<AppStatusController> logger) : ControllerBase
8+
{
9+
public IEnumerable<string> GetAppStartupErrors()
10+
{
11+
return StaticSettings.StartupErrorsList;
12+
}
13+
}

MaiChartManager/Controllers/App/AppVersionController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace MaiChartManager.Controllers.App;
55

66
[ApiController]
77
[Route("MaiChartManagerServlet/[action]Api")]
8-
public class AppVersionController(StaticSettings settings, ILogger<StaticSettings> logger) : ControllerBase
8+
public class AppVersionController(StaticSettings settings, ILogger<AppVersionController> logger) : ControllerBase
99
{
1010
public record AppVersionResult(string Version, int GameVersion, IapManager.LicenseStatus License, MovieConvertController.HardwareAccelerationStatus HardwareAcceleration, string H264Encoder);
1111

MaiChartManager/Controllers/VrcProcessController.cs renamed to MaiChartManager/Controllers/Music/VrcProcessController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.AspNetCore.Mvc;
33
using Xabe.FFmpeg;
44

5-
namespace MaiChartManager.Controllers;
5+
namespace MaiChartManager.Controllers.Music;
66

77
[ApiController]
88
[Route("MaiChartManagerServlet/[action]Api")]

MaiChartManager/StaticSettings.cs

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public partial class StaticSettings
1919
public static string ImageAssetsDir => Path.Combine(GamePath, _imageAssetsDir);
2020
public static string MovieAssetsDir => Path.Combine(GamePath, _movieAssetsDir);
2121
public static string SkinAssetsDir => Path.Combine(GamePath, _skinAssetsDir);
22+
public static List<string> StartupErrorsList { get; } = new();
2223

2324
public static Config Config { get; set; } = new();
2425

@@ -77,6 +78,7 @@ public List<MusicXmlWithABJacket> GetMusicList()
7778

7879
public void RescanAll()
7980
{
81+
StartupErrorsList.Clear();
8082
UpdateAssetPathsFromAquaMaiConfig();
8183
ScanMusicList();
8284
ScanGenre();
@@ -97,8 +99,17 @@ public void ScanMusicList()
9799
foreach (var subDir in Directory.EnumerateDirectories(musicDir))
98100
{
99101
if (!File.Exists(Path.Combine(subDir, "Music.xml"))) continue;
100-
var musicXml = new MusicXmlWithABJacket(Path.Combine(subDir, "Music.xml"), GamePath, a);
101-
_musicList.Add(musicXml);
102+
try
103+
{
104+
var musicXml = new MusicXmlWithABJacket(Path.Combine(subDir, "Music.xml"), GamePath, a);
105+
_musicList.Add(musicXml);
106+
}
107+
catch (Exception ex)
108+
{
109+
_logger.LogError(ex, "加载乐曲数据 {SubDir} 失败", subDir);
110+
SentrySdk.CaptureException(ex);
111+
StartupErrorsList.Add($"加载乐曲数据 {subDir} 失败: {ex.Message}");
112+
}
102113
}
103114
}
104115

@@ -116,16 +127,25 @@ public void ScanGenre()
116127
{
117128
if (!File.Exists(Path.Combine(genreDir, "MusicGenre.xml"))) continue;
118129
if (!Path.GetFileName(genreDir).StartsWith("musicgenre", StringComparison.InvariantCultureIgnoreCase)) continue;
119-
var id = int.Parse(Path.GetFileName(genreDir).Substring("musicgenre".Length));
120-
var genreXml = new GenreXml(id, a, GamePath);
130+
try
131+
{
132+
var id = int.Parse(Path.GetFileName(genreDir).Substring("musicgenre".Length));
133+
var genreXml = new GenreXml(id, a, GamePath);
134+
135+
var existed = GenreList.Find(it => it.Id == id);
136+
if (existed != null)
137+
{
138+
GenreList.Remove(existed);
139+
}
121140

122-
var existed = GenreList.Find(it => it.Id == id);
123-
if (existed != null)
141+
GenreList.Add(genreXml);
142+
}
143+
catch (Exception ex)
124144
{
125-
GenreList.Remove(existed);
145+
_logger.LogError(ex, "加载分类数据 {SubDir} 失败", genreDir);
146+
SentrySdk.CaptureException(ex);
147+
StartupErrorsList.Add($"加载分类数据 {genreDir} 失败: {ex.Message}");
126148
}
127-
128-
GenreList.Add(genreXml);
129149
}
130150
}
131151

@@ -142,20 +162,29 @@ public void ScanVersionList()
142162
{
143163
if (!File.Exists(Path.Combine(versionDir, "MusicVersion.xml"))) continue;
144164
if (!Path.GetFileName(versionDir).StartsWith("musicversion", StringComparison.InvariantCultureIgnoreCase)) continue;
145-
var id = int.Parse(Path.GetFileName(versionDir).Substring("musicversion".Length));
146-
var versionXml = new VersionXml(id, a, GamePath);
165+
try
166+
{
167+
var id = int.Parse(Path.GetFileName(versionDir).Substring("musicversion".Length));
168+
var versionXml = new VersionXml(id, a, GamePath);
147169

148-
var existed = VersionList.Find(it => it.Id == id);
149-
if (existed != null)
170+
var existed = VersionList.Find(it => it.Id == id);
171+
if (existed != null)
172+
{
173+
VersionList.Remove(existed);
174+
}
175+
176+
VersionList.Add(versionXml);
177+
}
178+
catch (Exception ex)
150179
{
151-
VersionList.Remove(existed);
180+
_logger.LogError(ex, "加载版本数据 {SubDir} 失败", versionDir);
181+
SentrySdk.CaptureException(ex);
182+
StartupErrorsList.Add($"加载版本数据 {versionDir} 失败: {ex.Message}");
152183
}
153-
154-
VersionList.Add(versionXml);
155184
}
156185
}
157186

158-
_logger.LogInformation($"Scan version list, found {VersionList.Count} version.");
187+
_logger.LogInformation("Scan version list, found {VersionListCount} version.", VersionList.Count);
159188
}
160189

161190
public void ScanAssetBundles()

0 commit comments

Comments
 (0)