Skip to content

Commit c4b0647

Browse files
authored
fix: ModifyId,假如新ID和旧ID的NonDX相同(例如5003->15003),会导致源文件被误删除且发生报错。 (#66)
1 parent 7a3de3c commit c4b0647

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

MaiChartManager/Controllers/Music/MusicTransferController.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -513,21 +513,12 @@ private void DeleteAb(string abPath)
513513
FileSystem.DeleteFile(abPath + ".manifest", UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
514514
}
515515

516-
[HttpPost]
517-
public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
516+
private void MoveJacketSoundVideo(MusicXmlWithABJacket music, int newId, string assetDir)
518517
{
519-
if (IapManager.License != IapManager.LicenseStatus.Active) return;
520-
var music = settings.GetMusic(id, assetDir);
521-
if (music is null) return;
522-
var musicDir = Path.GetDirectoryName(music.FilePath);
523-
if (string.IsNullOrWhiteSpace(musicDir) || !Directory.Exists(musicDir))
524-
{
525-
var message = $"Invalid source directory for music {music.Id}: {music.FilePath}";
526-
logger.LogError("{message}", message);
527-
throw new DirectoryNotFoundException(message);
528-
}
529518
var newNonDxId = newId % 10000;
530-
519+
// 当新ID和旧ID的 NonDx部分相同时(例如 5003 -> 15003),封面、音频、视频文件的目标路径与源路径完全一致,因此既不需要也不应该删除/移动它们。
520+
if (newNonDxId == music.NonDxId) return;
521+
531522
var abiDir = Path.Combine(StaticSettings.StreamingAssets, assetDir, @"AssetBundleImages\jacket");
532523
var abiSDir = Path.Combine(StaticSettings.StreamingAssets, assetDir, @"AssetBundleImages\jacket_s");
533524
Directory.CreateDirectory(abiDir);
@@ -536,8 +527,7 @@ public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
536527
var abJacketSTarget = Path.Combine(abiSDir, $"ui_jacket_{newNonDxId:000000}_s.ab");
537528
var acbawbTarget = Path.Combine(StaticSettings.StreamingAssets, assetDir, "SoundData", $"music{newNonDxId:000000}");
538529
var movieTarget = Path.Combine(StaticSettings.StreamingAssets, assetDir, "MovieData", $"{newNonDxId:000000}");
539-
var newMusicDir = Path.Combine(StaticSettings.StreamingAssets, assetDir, "music", $"music{newId:000000}");
540-
DeleteIfExists(abJacketTarget, abJacketTarget + ".manifest", abJacketSTarget, abJacketSTarget + ".manifest", acbawbTarget + ".acb", acbawbTarget + ".awb", movieTarget + ".dat", movieTarget + ".mp4", newMusicDir);
530+
DeleteIfExists(abJacketTarget, abJacketTarget + ".manifest", abJacketSTarget, abJacketSTarget + ".manifest", acbawbTarget + ".acb", acbawbTarget + ".awb", movieTarget + ".dat", movieTarget + ".mp4");
541531

542532
#region 移动或重打包封面图
543533
var jacketSourcePath = music.JacketPath is not null ? music.JacketPath : music.PseudoAssetBundleJacket;
@@ -617,6 +607,27 @@ public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
617607
FileSystem.MoveFile(movie, movieTarget + Path.GetExtension(movie), UIOption.OnlyErrorDialogs);
618608
}
619609
#endregion
610+
}
611+
612+
[HttpPost]
613+
public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
614+
{
615+
if (IapManager.License != IapManager.LicenseStatus.Active) return;
616+
var music = settings.GetMusic(id, assetDir);
617+
if (music is null) return;
618+
var musicDir = Path.GetDirectoryName(music.FilePath);
619+
if (string.IsNullOrWhiteSpace(musicDir) || !Directory.Exists(musicDir))
620+
{
621+
var message = $"Invalid source directory for music {music.Id}: {music.FilePath}";
622+
logger.LogError("{message}", message);
623+
throw new DirectoryNotFoundException(message);
624+
}
625+
if (music.Id == newId) return;
626+
627+
var newMusicDir = Path.Combine(StaticSettings.StreamingAssets, assetDir, "music", $"music{newId:000000}");
628+
DeleteIfExists(newMusicDir);
629+
630+
MoveJacketSoundVideo(music, newId, assetDir); // 移动封面图、音频、视频
620631

621632
// 谱面
622633
var oldMusicDir = Path.GetDirectoryName(music.FilePath)!;

0 commit comments

Comments
 (0)