@@ -506,6 +506,13 @@ private void DeleteIfExists(params string[] path)
506506 }
507507 }
508508
509+ private void DeleteAb ( string abPath )
510+ {
511+ FileSystem . DeleteFile ( abPath , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin ) ;
512+ if ( System . IO . File . Exists ( abPath + ".manifest" ) )
513+ FileSystem . DeleteFile ( abPath + ".manifest" , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin ) ;
514+ }
515+
509516 [ HttpPost ]
510517 public async Task ModifyId ( int id , [ FromBody ] int newId , string assetDir )
511518 {
@@ -521,16 +528,18 @@ public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
521528 }
522529 var newNonDxId = newId % 10000 ;
523530
524- var abJacketTarget = Path . Combine ( StaticSettings . StreamingAssets , assetDir , "AssetBundleImages" , "jacket" , $ "ui_jacket_{ newNonDxId : 000000} .ab") ;
525- var abJacketSTarget = Path . Combine ( StaticSettings . StreamingAssets , assetDir , "AssetBundleImages" , "jacket_s" , $ "ui_jacket_{ newNonDxId : 000000} _s.ab") ;
531+ var abiDir = Path . Combine ( StaticSettings . StreamingAssets , assetDir , @"AssetBundleImages\jacket" ) ;
532+ var abiSDir = Path . Combine ( StaticSettings . StreamingAssets , assetDir , @"AssetBundleImages\jacket_s" ) ;
533+ Directory . CreateDirectory ( abiDir ) ;
534+ Directory . CreateDirectory ( abiSDir ) ;
535+ var abJacketTarget = Path . Combine ( abiDir , $ "ui_jacket_{ newNonDxId : 000000} .ab") ;
536+ var abJacketSTarget = Path . Combine ( abiSDir , $ "ui_jacket_{ newNonDxId : 000000} _s.ab") ;
526537 var acbawbTarget = Path . Combine ( StaticSettings . StreamingAssets , assetDir , "SoundData" , $ "music{ newNonDxId : 000000} ") ;
527538 var movieTarget = Path . Combine ( StaticSettings . StreamingAssets , assetDir , "MovieData" , $ "{ newNonDxId : 000000} ") ;
528539 var newMusicDir = Path . Combine ( StaticSettings . StreamingAssets , assetDir , "music" , $ "music{ newId : 000000} ") ;
529540 DeleteIfExists ( abJacketTarget , abJacketTarget + ".manifest" , abJacketSTarget , abJacketSTarget + ".manifest" , acbawbTarget + ".acb" , acbawbTarget + ".awb" , movieTarget + ".dat" , movieTarget + ".mp4" , newMusicDir ) ;
530- var abiDir = Path . Combine ( StaticSettings . StreamingAssets , assetDir , @"AssetBundleImages\jacket" ) ;
531- Directory . CreateDirectory ( abiDir ) ;
532541
533- // jacket
542+ #region 移动或重打包封面图
534543 var jacketSourcePath = music . JacketPath is not null ? music . JacketPath : music . PseudoAssetBundleJacket ;
535544 if ( jacketSourcePath is not null )
536545 {
@@ -542,29 +551,51 @@ public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
542551 }
543552 else if ( music . AssetBundleJacket is not null )
544553 {
545- // 否则需要执行转换逻辑
546- var localJacketTarget = Path . Combine ( abiDir , $ "ui_jacket_{ newNonDxId : 000000} .png") ;
547- logger . LogInformation ( "Convert jacket: {music.AssetBundleJacket} -> {abJacketTarget}" , music . AssetBundleJacket , abJacketTarget ) ;
548- System . IO . File . WriteAllBytes ( localJacketTarget , music . GetMusicJacketPngData ( ) ! ) ;
549- FileSystem . DeleteFile ( music . AssetBundleJacket , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin ) ;
550- // AB→PNG: the old .ab.manifest no longer has a matching .ab at the new ID, so just delete it instead of moving
551- if ( System . IO . File . Exists ( music . AssetBundleJacket + ".manifest" ) )
554+ var oldAb = music . AssetBundleJacket ! ;
555+ var oldSmallAb = GetAssetBundleJacketSmallPath ( oldAb ) ;
556+ var idPad = $ "{ newNonDxId : 000000} ";
557+ logger . LogInformation ( "Repack jacket AB: {oldMainAb} -> {abJacketTarget}" , oldAb , abJacketTarget ) ;
558+
559+ // 重打包大jacket
560+ AssetBundleCreator . RepackTextureAssetBundle (
561+ oldAb ,
562+ abJacketTarget ,
563+ $ "UI_Jacket_{ idPad } ",
564+ $ "assets/assetbundle/jacket/ui_jacket_{ idPad } .png",
565+ $ "jacket/ui_jacket_{ idPad } .ab") ;
566+
567+ // 对小jacket:如果存在,重打包;如果不存在,则从png重新缩放,重新CreateTextureAssetBundle
568+ if ( oldSmallAb is not null && System . IO . File . Exists ( oldSmallAb ) )
552569 {
553- FileSystem . DeleteFile ( music . AssetBundleJacket + ".manifest" , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin ) ;
570+ AssetBundleCreator . RepackTextureAssetBundle (
571+ oldSmallAb ,
572+ abJacketSTarget ,
573+ $ "UI_Jacket_{ idPad } _s",
574+ $ "assets/assetbundle/jacket_s/ui_jacket_{ idPad } _s.png",
575+ $ "jacket_s/ui_jacket_{ idPad } _s.ab") ;
554576 }
555-
556- // Issue #42: also clean up the companion jacket_s AB so it doesn't stay orphaned under the old ID
557- var oldJacketSPath = GetAssetBundleJacketSmallPath ( music . AssetBundleJacket ) ;
558- if ( oldJacketSPath is not null && System . IO . File . Exists ( oldJacketSPath ) )
577+ else
559578 {
560- FileSystem . DeleteFile ( oldJacketSPath , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin ) ;
561- if ( System . IO . File . Exists ( oldJacketSPath + ".manifest" ) )
562- {
563- FileSystem . DeleteFile ( oldJacketSPath + ".manifest" , UIOption . OnlyErrorDialogs , RecycleOption . SendToRecycleBin ) ;
564- }
579+ var pngBytes = music . GetMusicJacketPngData ( ) ;
580+ AssetBundleCreator . CreateTextureAssetBundle (
581+ pngBytes ,
582+ abJacketSTarget ,
583+ $ "UI_Jacket_{ idPad } _s",
584+ $ "assets/assetbundle/jacket_s/ui_jacket_{ idPad } _s.png",
585+ $ "jacket_s/ui_jacket_{ idPad } _s.ab",
586+ resizeWidth : 200 ,
587+ resizeHeight : 200 ) ;
565588 }
589+
590+ DeleteAb ( oldAb ) ;
591+ if ( oldSmallAb is not null ) DeleteAb ( oldSmallAb ) ;
592+
593+ StaticSettings . AssetBundleJacketMap . Remove ( music . NonDxId ) ;
594+ StaticSettings . AssetBundleJacketMap [ newNonDxId ] = abJacketTarget ;
566595 }
596+ #endregion
567597
598+ #region 移动音频和视频
568599 // 我也不知道它需不需要重新保存,先直接移动试试
569600 // 是可以的
570601 if ( StaticSettings . AcbAwb . TryGetValue ( $ "music{ music . NonDxId : 000000} .acb", out var acb ) )
@@ -585,6 +616,7 @@ public async Task ModifyId(int id, [FromBody] int newId, string assetDir)
585616 logger . LogInformation ( "Move movie: {movie} -> {movieTarget}" , movie , movieTarget ) ;
586617 FileSystem . MoveFile ( movie , movieTarget + Path . GetExtension ( movie ) , UIOption . OnlyErrorDialogs ) ;
587618 }
619+ #endregion
588620
589621 // 谱面
590622 var oldMusicDir = Path . GetDirectoryName ( music . FilePath ) ! ;
0 commit comments