1- using Lagrange . Core ;
21using Lagrange . Core . Common ;
32using Lagrange . Core . Common . Interface ;
43using Lagrange . Milky . Api ;
@@ -32,95 +31,87 @@ public static HostApplicationBuilder ConfigureServices(this HostApplicationBuild
3231 }
3332
3433 public static HostApplicationBuilder ConfigureCore ( this HostApplicationBuilder builder ) => builder
34+ #pragma warning disable IL2026 , IL3050
35+ // https://github.com/dotnet/runtime/issues/94544
3536 . ConfigureServices ( services => services
36- . Configure < CoreConfiguration > ( builder . Configuration . GetSection ( "Core" ) )
37-
38- // Signer
39- . AddSingleton < Signer > ( )
40- // BotConfig
41- . AddSingleton ( services =>
42- {
43- var loggerConfiguration = services . GetRequiredService < IOptions < LoggerFilterOptions > > ( ) . Value ;
44- var coreConfiguration = services . GetRequiredService < IOptions < CoreConfiguration > > ( ) . Value ;
45- var signer = services . GetRequiredService < Signer > ( ) ;
46-
47- var platform = signer . GetAppInfo ( ) . Result switch
37+ . Configure < CoreConfiguration > ( builder . Configuration . GetSection ( "Core" ) )
38+ #pragma warning restore IL2026 , IL3050
39+ // Signer
40+ . AddSingleton < Signer > ( )
41+ // BotConfig
42+ . AddSingleton ( services =>
4843 {
49- { Os : "Linux" } => Protocols . Linux ,
50- { Os : "Mac" } => Protocols . MacOs ,
51- { Os : "Windows" } => Protocols . Windows ,
52- { Os : "Android" , PackageName : "com.tencent.mobileqq" } => Protocols . AndroidPhone ,
53- { Os : "Android" , PackageName : "com.tencent.qqlite" } => Protocols . AndroidWatch ,
54- _ => throw new NotSupportedException ( ) ,
55- } ;
56-
57- return new BotConfig
58- {
59- Protocol = platform ,
60- LogLevel = ( CoreLogLevel ) loggerConfiguration . GetDefaultLogLevel ( ) ,
61- AutoReconnect = coreConfiguration . Server . AutoReconnect ,
62- UseIPv6Network = coreConfiguration . Server . UseIPv6Network ,
63- GetOptimumServer = coreConfiguration . Server . GetOptimumServer ,
64- AutoReLogin = coreConfiguration . Login . AutoReLogin ,
65- SignProvider = signer ,
66- } ;
67- } )
68- // BotKeystore
69- . AddSingleton ( services =>
70- {
71- var configuration = services . GetRequiredService < IOptions < CoreConfiguration > > ( ) . Value ;
72-
73- if ( ! configuration . Login . Uin . HasValue ) throw new Exception ( "Core.Login.Uin cannot be null" ) ;
74- var path = $ "{ configuration . Login . Uin . Value } .keystore";
75-
76- BotKeystore keystore ;
77- if ( File . Exists ( path ) )
44+ var loggerConfiguration = services . GetRequiredService < IOptions < LoggerFilterOptions > > ( ) . Value ;
45+ var coreConfiguration = services . GetRequiredService < IOptions < CoreConfiguration > > ( ) . Value ;
46+ var signer = services . GetRequiredService < Signer > ( ) ;
47+
48+ return new BotConfig
49+ {
50+ Protocol = Protocols . Linux ,
51+ LogLevel = ( CoreLogLevel ) loggerConfiguration . GetDefaultLogLevel ( ) ,
52+ AutoReconnect = coreConfiguration . Server . AutoReconnect ,
53+ UseIPv6Network = coreConfiguration . Server . UseIPv6Network ,
54+ GetOptimumServer = coreConfiguration . Server . GetOptimumServer ,
55+ AutoReLogin = coreConfiguration . Login . AutoReLogin ,
56+ SignProvider = signer ,
57+ } ;
58+ } )
59+ // BotKeystore
60+ . AddSingleton ( services =>
7861 {
79- var keystoreNullable = JsonUtility . Deserialize < BotKeystore > ( File . ReadAllBytes ( path ) ) ;
80- keystore = keystoreNullable ?? throw new Exception (
81- $ "Invalid keystore detected. Please remove the '{ path } ' file and re-authenticate."
82- ) ;
83- }
84- else
62+ var configuration = services . GetRequiredService < IOptions < CoreConfiguration > > ( ) . Value ;
63+
64+ if ( ! configuration . Login . Uin . HasValue ) throw new Exception ( "Core.Login.Uin cannot be null" ) ;
65+ string path = $ "{ configuration . Login . Uin . Value } .keystore";
66+
67+ BotKeystore keystore ;
68+ if ( File . Exists ( path ) )
69+ {
70+ var keystoreNullable = JsonUtility . Deserialize < BotKeystore > ( File . ReadAllBytes ( path ) ) ;
71+ keystore = keystoreNullable ?? throw new Exception (
72+ $ "Invalid keystore detected. Please remove the '{ path } ' file and re-authenticate."
73+ ) ;
74+ }
75+ else
76+ {
77+ keystore = BotKeystore . CreateEmpty ( ) ;
78+ }
79+
80+ keystore . DeviceName = configuration . Login . DeviceName ;
81+ return keystore ;
82+ } )
83+ // BotContext
84+ . AddSingleton ( services =>
8585 {
86- keystore = BotKeystore . CreateEmpty ( ) ;
87- }
88-
89- keystore . DeviceName = configuration . Login . DeviceName ;
90- return keystore ;
91- } )
92- // BotAppInfo
93- . AddSingleton ( services => services . GetRequiredService < Signer > ( ) . GetAppInfo ( ) . Result )
94- // BotContext
95- . AddSingleton ( services =>
96- {
97- var config = services . GetRequiredService < BotConfig > ( ) ;
98- var keystore = services . GetRequiredService < BotKeystore > ( ) ;
99- var info = services . GetRequiredService < BotAppInfo > ( ) ;
86+ var config = services . GetRequiredService < BotConfig > ( ) ;
87+ var keystore = services . GetRequiredService < BotKeystore > ( ) ;
10088
101- return BotFactory . Create ( config , keystore , info ) ;
102- } )
89+ return BotFactory . Create ( config , keystore ) ;
90+ } )
10391
104- // CaptchaResolver
105- . AddSingleton < ICaptchaResolver > ( services =>
106- {
107- var configuration = services . GetRequiredService < IOptions < CoreConfiguration > > ( ) . Value ;
92+ // CaptchaResolver
93+ . AddSingleton < ICaptchaResolver > ( services =>
94+ {
95+ var configuration = services . GetRequiredService < IOptions < CoreConfiguration > > ( ) . Value ;
10896
109- return configuration . Login . UseOnlineCaptchaResolver
110- ? ActivatorUtilities . CreateInstance < OnlineCaptchaResolver > ( services )
111- : ActivatorUtilities . CreateInstance < ManualCaptchaResolver > ( services ) ;
112- } )
97+ return configuration . Login . UseOnlineCaptchaResolver
98+ ? ActivatorUtilities . CreateInstance < OnlineCaptchaResolver > ( services )
99+ : ActivatorUtilities . CreateInstance < ManualCaptchaResolver > ( services ) ;
100+ } )
113101
114- // Logger
115- . AddHostedService < CoreLoggerService > ( )
102+ // Logger
103+ . AddHostedService < CoreLoggerService > ( )
116104
117- // Login
118- . AddHostedService < CoreLoginService > ( )
119- ) ;
105+ // Login
106+ . AddHostedService < CoreLoginService > ( )
107+ ) ;
120108
121109 public static HostApplicationBuilder ConfigureMilky ( this HostApplicationBuilder builder ) => builder
110+ #pragma warning disable IL2026 , IL3050
111+ // https://github.com/dotnet/runtime/issues/94544
122112 . ConfigureServices ( services => services
123113 . Configure < MilkyConfiguration > ( builder . Configuration . GetSection ( "Milky" ) )
114+ #pragma warning restore IL2026 , IL3050
124115 // MessageCache
125116 . AddSingleton < MessageCache > ( )
126117 . AddHostedService ( ServiceProviderServiceExtensions . GetRequiredService < MessageCache > )
@@ -131,8 +122,11 @@ public static HostApplicationBuilder ConfigureMilky(this HostApplicationBuilder
131122 )
132123 . ConfigureServices ( services =>
133124 {
125+ #pragma warning disable IL2026 , IL3050
126+ // https://github.com/dotnet/runtime/issues/94544
134127 var configuration = builder . Configuration . GetSection ( "Milky" ) . Get < MilkyConfiguration > ( )
135128 ?? throw new Exception ( "Milky cannot be null" ) ;
129+ #pragma warning restore IL2026 , IL3050
136130
137131 // Api Handlers
138132 services . AddApiHandlers ( configuration . Debug ) ;
@@ -141,8 +135,11 @@ public static HostApplicationBuilder ConfigureMilky(this HostApplicationBuilder
141135 {
142136 services . AddHostedService < MilkyHttpApiService > ( ) ;
143137
138+ #pragma warning disable IL2026 , IL3050
139+ // https://github.com/dotnet/runtime/issues/94544
144140 var configuration = builder . Configuration . GetSection ( "Milky" ) . Get < MilkyConfiguration > ( )
145141 ?? throw new Exception ( "Milky cannot be null" ) ;
142+ #pragma warning restore IL2026 , IL3050
146143
147144 if ( configuration . EnabledWebSocket || configuration . WebHook != null )
148145 {
0 commit comments