@@ -12,8 +12,21 @@ namespace MaiChartManager.Controllers.Mod;
1212
1313[ ApiController ]
1414[ Route ( "MaiChartManagerServlet/[action]Api" ) ]
15- public class ConfigurationController ( StaticSettings settings , ILogger < ConfigurationController > logger ) : ControllerBase
15+ public class ConfigurationController : ControllerBase
1616{
17+ private readonly StaticSettings settings ;
18+ private readonly ILogger < ConfigurationController > logger ;
19+ private readonly MuModService muModService ;
20+ private static MuModService ? staticMuModService ;
21+
22+ public ConfigurationController ( StaticSettings settings , ILogger < ConfigurationController > logger , MuModService muModService )
23+ {
24+ this . settings = settings ;
25+ this . logger = logger ;
26+ this . muModService = muModService ;
27+ staticMuModService = muModService ;
28+ }
29+
1730 public class UnsupportedConfigApiVersionException ( ) : Exception ( Locale . UnsupportedConfigVersion ) ;
1831
1932 public class ConfigCorruptedException( ) : Exception ( Locale . AquaMaiConfigCorrupted ) ;
@@ -41,12 +54,17 @@ private static void CheckConfigApiVersion(HeadlessConfigInterface configInterfac
4154 [ NonAction ]
4255 public static IConfig GetCurrentAquaMaiConfig ( bool forceDefault = false , bool skipSignatureCheck = false )
4356 {
44- if ( ! System . IO . File . Exists ( ModPaths . AquaMaiDllInstalledPath ) )
57+ string dllPath ;
58+ try
59+ {
60+ dllPath = GetAquaMaiDllPath ( staticMuModService ) ;
61+ }
62+ catch ( AquaMaiNotInstalledException )
4563 {
46- throw new AquaMaiNotInstalledException ( ) ;
64+ throw ;
4765 }
4866
49- var binary = System . IO . File . ReadAllBytes ( ModPaths . AquaMaiDllInstalledPath ) ;
67+ var binary = System . IO . File . ReadAllBytes ( dllPath ) ;
5068 if ( ! skipSignatureCheck )
5169 {
5270 var sigResult = AquaMaiSignatureV2 . VerifySignature ( binary ) ;
@@ -92,11 +110,43 @@ public static IConfig GetCurrentAquaMaiConfig(bool forceDefault = false, bool sk
92110 return config ;
93111 }
94112
113+ [ NonAction ]
114+ private string GetAquaMaiDllPath ( )
115+ {
116+ return GetAquaMaiDllPath ( muModService ) ;
117+ }
118+
119+ [ NonAction ]
120+ private static string GetAquaMaiDllPath ( MuModService ? muModService )
121+ {
122+ var muModInstalled = muModService ? . IsMuModInstalled ( ) == true ;
123+ var aquaMaiInstalled = System . IO . File . Exists ( ModPaths . AquaMaiDllInstalledPath ) ;
124+
125+ if ( muModInstalled && ! aquaMaiInstalled )
126+ {
127+ var cachePath = muModService ! . GetResolvedCachePath ( ) ;
128+ if ( ! System . IO . File . Exists ( cachePath ) )
129+ {
130+ throw new AquaMaiNotInstalledException ( ) ;
131+ }
132+
133+ return cachePath ;
134+ }
135+
136+ if ( aquaMaiInstalled )
137+ {
138+ return ModPaths . AquaMaiDllInstalledPath ;
139+ }
140+
141+ throw new AquaMaiNotInstalledException ( ) ;
142+ }
143+
95144 [ HttpGet ]
96145 public AquaMaiConfigDto . ConfigDto GetAquaMaiConfig ( bool forceDefault = false , bool skipSignatureCheck = false )
97146 {
147+ var dllPath = GetAquaMaiDllPath ( ) ;
98148 Dictionary < string , string [ ] > ? configSort = null ;
99- using ( var stream = new FileStream ( ModPaths . AquaMaiDllInstalledPath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
149+ using ( var stream = new FileStream ( dllPath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
100150 {
101151 var asm = ModuleDefinition . ReadModule ( stream ) ;
102152 var configSortRes = asm . Resources . FirstOrDefault ( it => it is EmbeddedResource { Name : "configSort.yaml.compressed" } or EmbeddedResource { Name : "configSort.yaml" } ) ;
@@ -108,7 +158,8 @@ public AquaMaiConfigDto.ConfigDto GetAquaMaiConfig(bool forceDefault = false, bo
108158 configSort = deserializer . Deserialize < Dictionary < string , string [ ] > > ( yaml ) ;
109159 }
110160 }
111- var config = GetCurrentAquaMaiConfig ( forceDefault , skipSignatureCheck ) ;
161+ var shouldSkipSignatureCheck = skipSignatureCheck || ! string . Equals ( dllPath , ModPaths . AquaMaiDllInstalledPath , StringComparison . OrdinalIgnoreCase ) ;
162+ var config = GetCurrentAquaMaiConfig ( forceDefault , shouldSkipSignatureCheck ) ;
112163 return new AquaMaiConfigDto . ConfigDto (
113164 config . ReflectionManager . Sections . Select ( section =>
114165 {
@@ -124,10 +175,11 @@ public AquaMaiConfigDto.ConfigDto GetAquaMaiConfig(bool forceDefault = false, bo
124175 [ HttpPut ]
125176 public async Task SetAquaMaiConfig ( AquaMaiConfigDto . ConfigSaveDto config )
126177 {
178+ var dllPath = GetAquaMaiDllPath ( ) ;
127179 var jsonOptions = new JsonSerializerOptions ( ) ;
128180 jsonOptions . Converters . Add ( new JsonStringEnumConverter ( ) ) ;
129181
130- var configInterface = HeadlessConfigLoader . LoadFromPacked ( ModPaths . AquaMaiDllInstalledPath ) ;
182+ var configInterface = HeadlessConfigLoader . LoadFromPacked ( dllPath ) ;
131183 CheckConfigApiVersion ( configInterface ) ;
132184 var configEdit = configInterface . CreateConfig ( ) ;
133185
@@ -183,4 +235,4 @@ public async Task SetAquaMaiConfig(AquaMaiConfigDto.ConfigSaveDto config)
183235 // 可能修改了歌曲封面目录
184236 settings . ScanMusicList ( ) ;
185237 }
186- }
238+ }
0 commit comments