22using ColorMC . Core . Config ;
33using ColorMC . Core . Downloader ;
44using ColorMC . Core . Game ;
5- using ColorMC . Core . Helpers ;
65using ColorMC . Core . LaunchPath ;
76using ColorMC . Core . Net ;
87using ColorMC . Core . Objs ;
@@ -91,22 +90,6 @@ public static class ColorMCCore
9190 /// <param name="now">目前进度</param>
9291 public delegate void PackUpdate ( int size , int now ) ;
9392 /// <summary>
94- /// 下载器状态更新
95- /// </summary>
96- /// <param name="state">状态</param>
97- public delegate void DownloadUpdate ( int thread , bool state , int count ) ;
98- /// <summary>
99- /// 下载任务状态更新
100- /// </summary>
101- /// <param name="type">更新类型</param>
102- /// <param name="type">更新数据</param>
103- public delegate void DownloadTaskUpdate ( UpdateType type , int data ) ;
104- /// <summary>
105- /// 下载项目状态更新
106- /// </summary>
107- /// <param name="obj">项目</param>
108- public delegate void DownloadItemUpdate ( int thread , FileItemObj obj ) ;
109- /// <summary>
11093 /// 压缩包导入状态改变
11194 /// </summary>
11295 /// <param name="state">状态</param>
@@ -128,53 +111,45 @@ public static class ColorMCCore
128111 /// <summary>
129112 /// 显示下载窗口
130113 /// </summary>
131- public static Func < DownloadArg > ? OnDownload { get ; set ; }
132-
114+ public static event Action < DownloadEventArgs > ? Download ;
133115 /// <summary>
134116 /// 错误显示回调
135- /// 标题 错误 关闭程序
136117 /// </summary>
137- public static event Action < string ? , Exception ? , bool > ? Error ;
118+ public static event Action < CoreErrorEventArgs > ? Error ;
138119 /// <summary>
139120 /// 游戏日志回调
140121 /// </summary>
141- public static event Action < GameSettingObj , GameLogItemObj ? > ? GameLog ;
142- /// <summary>
143- /// 语言重载
144- /// </summary>
145- public static event Action < LanguageType > ? LanguageReload ;
122+ public static event Action < GameLogEventArgs > ? GameLog ;
146123 /// <summary>
147124 /// 游戏退出事件
148125 /// </summary>
149- public static event Action < GameSettingObj , LoginObj , int > GameExit ;
150- /// <summary>
151- /// 游戏实例数量修改事件
152- /// </summary>
153- public static event Action ? InstanceChange ;
126+ public static event Action < GameExitEventArgs > GameExit ;
154127 /// <summary>
155- /// 游戏实例图标修改事件
128+ /// 游戏实例事件
156129 /// </summary>
157- public static event Action < GameSettingObj > ? InstanceIconChange ;
130+ public static event Action < InstanceChangeEventArgs > ? InstanceChange ;
158131 /// <summary>
159132 /// 是否为新运行
160133 /// </summary>
161134 public static bool NewStart { get ; internal set ; }
135+
162136 /// <summary>
163137 /// 停止事件
164138 /// </summary>
165139 internal static event Action ? Stop ;
166140 /// <summary>
167- /// 游戏窗口句柄
168- /// </summary>
169- internal static readonly ConcurrentDictionary < string , GameHandel > Games = [ ] ;
170- /// <summary>
171141 /// 启动器核心参数
172142 /// </summary>
173143 internal static CoreInitArg CoreArg ;
144+
145+ /// <summary>
146+ /// 游戏窗口句柄
147+ /// </summary>
148+ private static readonly ConcurrentDictionary < string , GameHandel > s_games = [ ] ;
174149 /// <summary>
175150 /// 游戏日志
176151 /// </summary>
177- internal static readonly ConcurrentDictionary < string , GameRuntimeLog > GameLogs = [ ] ;
152+ private static readonly ConcurrentDictionary < string , GameRuntimeLog > s_gameLogs = [ ] ;
178153
179154 /// <summary>
180155 /// 初始化阶段1
@@ -184,21 +159,15 @@ public static void Init(CoreInitArg arg)
184159 {
185160 if ( string . IsNullOrWhiteSpace ( arg . Local ) )
186161 {
187- throw new Exception ( " Local is empty" ) ;
162+ throw new ArgumentNullException ( nameof ( arg . Local ) ) ;
188163 }
189164 CoreArg = arg ;
190165
191166 BaseDir = arg . Local ;
192167 Directory . CreateDirectory ( BaseDir ) ;
193168
194- LanguageHelper . Load ( LanguageType . zh_cn ) ;
195- Logs . Init ( ) ;
196- ConfigUtils . Init ( ) ;
169+ ConfigLoad . Init ( ) ;
197170 CoreHttpClient . Init ( ) ;
198-
199- Logs . Info ( LanguageHelper . Get ( "Core.Info1" ) ) ;
200- Logs . Info ( SystemInfo . SystemName ) ;
201- Logs . Info ( SystemInfo . System ) ;
202171 }
203172
204173 /// <summary>
@@ -212,8 +181,6 @@ public static void Init1()
212181 AuthDatabase . Init ( ) ;
213182 JvmPath . Init ( ) ;
214183 MinecraftPath . Init ( BaseDir ) ;
215-
216- Logs . Info ( LanguageHelper . Get ( "Core.Info3" ) ) ;
217184 }
218185
219186 /// <summary>
@@ -230,7 +197,7 @@ public static void Close()
230197 /// <param name="uuid"></param>
231198 public static void KillGame ( string uuid )
232199 {
233- if ( Games . TryGetValue ( uuid , out var handel ) )
200+ if ( s_games . TryGetValue ( uuid , out var handel ) )
234201 {
235202 handel . Kill ( ) ;
236203 }
@@ -239,13 +206,13 @@ public static void KillGame(string uuid)
239206 /// <summary>
240207 /// 启动器产生错误,并打开窗口显示
241208 /// </summary>
242- /// <param name="text "></param>
209+ /// <param name="type "></param>
243210 /// <param name="e"></param>
244211 /// <param name="close"></param>
245- internal static void OnError ( string text , Exception ? e , bool close )
212+ /// <param name="show"></param>
213+ internal static void OnError ( CoreErrorEventArgs args )
246214 {
247- Error ? . Invoke ( text , e , close ) ;
248- Logs . Error ( text , e ) ;
215+ Error ? . Invoke ( args ) ;
249216 }
250217
251218 /// <summary>
@@ -255,10 +222,10 @@ internal static void OnError(string text, Exception? e, bool close)
255222 /// <param name="text"></param>
256223 internal static void OnGameLog ( GameSettingObj obj , string ? text )
257224 {
258- if ( GameLogs . TryGetValue ( obj . UUID , out var log ) )
225+ if ( s_gameLogs . TryGetValue ( obj . UUID , out var log ) )
259226 {
260227 var item = log . AddLog ( text ) ;
261- GameLog ? . Invoke ( obj , item ) ;
228+ GameLog ? . Invoke ( new GameLogEventArgs ( obj , item ) ) ;
262229 }
263230 }
264231
@@ -268,25 +235,16 @@ internal static void OnGameLog(GameSettingObj obj, string? text)
268235 /// <param name="obj"></param>
269236 internal static void GameLogClear ( GameSettingObj obj )
270237 {
271- if ( GameLogs . TryGetValue ( obj . UUID , out var log ) )
238+ if ( s_gameLogs . TryGetValue ( obj . UUID , out var log ) )
272239 {
273240 log . Clear ( ) ;
274241 }
275242 else
276243 {
277- GameLogs . TryAdd ( obj . UUID , new ( ) ) ;
244+ s_gameLogs . TryAdd ( obj . UUID , new ( ) ) ;
278245 }
279246 }
280247
281- /// <summary>
282- /// 语言重载
283- /// </summary>
284- /// <param name="type"></param>
285- internal static void OnLanguageReload ( LanguageType type )
286- {
287- LanguageReload ? . Invoke ( type ) ;
288- }
289-
290248 /// <summary>
291249 /// 游戏退出
292250 /// </summary>
@@ -295,8 +253,8 @@ internal static void OnLanguageReload(LanguageType type)
295253 /// <param name="code"></param>
296254 public static void OnGameExit ( GameSettingObj obj , LoginObj obj1 , int code )
297255 {
298- Games . TryRemove ( obj . UUID , out _ ) ;
299- GameExit ? . Invoke ( obj , obj1 , code ) ;
256+ s_games . TryRemove ( obj . UUID , out _ ) ;
257+ GameExit ? . Invoke ( new GameExitEventArgs ( obj , obj1 , code ) ) ;
300258 }
301259
302260 /// <summary>
@@ -306,7 +264,7 @@ public static void OnGameExit(GameSettingObj obj, LoginObj obj1, int code)
306264 /// <returns>实例日志</returns>
307265 public static GameRuntimeLog ? GetGameRuntimeLog ( GameSettingObj obj )
308266 {
309- if ( GameLogs . TryGetValue ( obj . UUID , out var log ) )
267+ if ( s_gameLogs . TryGetValue ( obj . UUID , out var log ) )
310268 {
311269 return log ;
312270 }
@@ -321,9 +279,9 @@ public static void OnGameExit(GameSettingObj obj, LoginObj obj1, int code)
321279 /// <param name="handel"></param>
322280 internal static void AddGameHandel ( string uuid , GameHandel handel )
323281 {
324- if ( ! Games . TryAdd ( uuid , handel ) )
282+ if ( ! s_games . TryAdd ( uuid , handel ) )
325283 {
326- Games [ uuid ] = handel ;
284+ s_games [ uuid ] = handel ;
327285 }
328286 }
329287
@@ -332,7 +290,7 @@ internal static void AddGameHandel(string uuid, GameHandel handel)
332290 /// </summary>
333291 internal static void OnInstanceChange ( )
334292 {
335- InstanceChange ? . Invoke ( ) ;
293+ InstanceChange ? . Invoke ( new InstanceChangeEventArgs ( InstanceChangeType . NumberChange ) ) ;
336294 }
337295
338296 /// <summary>
@@ -341,6 +299,17 @@ internal static void OnInstanceChange()
341299 /// <param name="obj"></param>
342300 internal static void OnInstanceIconChange ( GameSettingObj obj )
343301 {
344- InstanceIconChange ? . Invoke ( obj ) ;
302+ InstanceChange ? . Invoke ( new InstanceChangeEventArgs ( InstanceChangeType . IconChange , obj ) ) ;
303+ }
304+
305+ /// <summary>
306+ /// 获取下载窗口句柄
307+ /// </summary>
308+ /// <returns></returns>
309+ internal static DownloadEventArgs OnDownloadGui ( )
310+ {
311+ var arg = new DownloadEventArgs ( ) ;
312+ Download ? . Invoke ( arg ) ;
313+ return arg ;
345314 }
346315}
0 commit comments