Skip to content

Commit 7813fbc

Browse files
committed
fix: 读取游戏版本号失败导致可能的崩溃
1 parent 06682ff commit 7813fbc

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

MaiChartManager/Controllers/MusicController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public async Task<ActionResult> GetMusicWav(int id)
194194
hash = (await xxHash64.ComputeHashAsync(readStream)).ToString();
195195
}
196196

197-
var cachePath = Path.Combine(settings.tempPath, hash + ".wav");
197+
var cachePath = Path.Combine(StaticSettings.tempPath, hash + ".wav");
198198

199199
if (System.IO.File.Exists(cachePath))
200200
// 这里 enableRangeProcessing 不开的话,对着两首歌打交会卡死,硬控十五秒

MaiChartManager/Front/vite.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ export default defineConfig(({command}) => ({
1111
UnoCSS(),
1212
ViteYaml(),
1313
sentryVitePlugin({
14-
org: "maichartmanager",
15-
project: "front",
14+
org: "sentry",
15+
project: "maichartmanager-front",
1616
disable: command === 'serve',
17+
url: "https://sentry.c5y.moe",
1718
})],
1819
resolve: {
1920
alias: {

MaiChartManager/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static void Main()
2525
ApplicationConfiguration.Initialize();
2626

2727
Directory.CreateDirectory(StaticSettings.appData);
28+
Directory.CreateDirectory(StaticSettings.tempPath);
2829
if (File.Exists(Path.Combine(StaticSettings.appData, "config.json")))
2930
StaticSettings.Config = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
3031

MaiChartManager/StaticSettings.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace MaiChartManager;
77

88
public partial class StaticSettings
99
{
10-
public readonly string tempPath = Path.Combine(Path.GetTempPath(), "MaiChartManager");
10+
public static readonly string tempPath = Path.Combine(Path.GetTempPath(), "MaiChartManager");
1111
public static readonly string appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MaiChartManager");
1212

1313
public static Config Config { get; set; } = new();
@@ -18,8 +18,11 @@ public partial class StaticSettings
1818
public StaticSettings(ILogger<StaticSettings> logger)
1919
{
2020
_logger = logger;
21-
Directory.CreateDirectory(tempPath);
22-
if (string.IsNullOrEmpty(GamePath)) return;
21+
if (string.IsNullOrEmpty(GamePath))
22+
{
23+
throw new ArgumentException("未指定游戏目录");
24+
}
25+
2326
AssetDir = "A500";
2427
ScanMusicList();
2528
ScanGenre();
@@ -165,8 +168,20 @@ public void ScanSoundData()
165168

166169
private void GetGameVersion()
167170
{
168-
var xmlDoc = new XmlDocument();
169-
xmlDoc.Load(Path.Combine(StreamingAssets, @"A000/DataConfig.xml"));
170-
int.TryParse(xmlDoc.SelectSingleNode("/DataConfig/version/minor")?.InnerText, out gameVersion);
171+
try
172+
{
173+
var xmlDoc = new XmlDocument();
174+
xmlDoc.Load(Path.Combine(StreamingAssets, @"A000/DataConfig.xml"));
175+
if (!int.TryParse(xmlDoc.SelectSingleNode("/DataConfig/version/minor")?.InnerText, out gameVersion))
176+
{
177+
MessageBox.Show("无法获取游戏版本号,解析数据失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
178+
}
179+
}
180+
catch (Exception e)
181+
{
182+
_logger.LogError(e, "Get game version failed.");
183+
SentrySdk.CaptureEvent(new SentryEvent(e) { Message = @"无法获取游戏版本号,可能是因为 A000\DataConfig.xml 找不到或者有错误" });
184+
MessageBox.Show(@"无法获取游戏版本号,可能是因为 A000\DataConfig.xml 找不到或者有错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
185+
}
171186
}
172187
}

0 commit comments

Comments
 (0)