Skip to content

Commit 2eb02f7

Browse files
committed
up not done
1 parent f7e0f16 commit 2eb02f7

76 files changed

Lines changed: 997 additions & 1102 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ csharp_space_around_binary_operators = before_and_after
8181
csharp_indent_labels = one_less_than_current
8282
csharp_prefer_system_threading_lock = true:suggestion
8383
csharp_prefer_static_anonymous_function = true:suggestion
84+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
8485

8586
[*.vb]
8687
#### 命名样式 ####
@@ -147,4 +148,5 @@ dotnet_style_allow_multiple_blank_lines_experimental = true:silent
147148
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
148149
tab_width = 4
149150
indent_size = 4
150-
dotnet_style_operator_placement_when_wrapping = beginning_of_line
151+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
152+
dotnet_diagnostic.CA2208.severity = none

src/ColorMC.Core/ColorMC.Core.csproj

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@
1414
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
1515
<DebugType>embedded</DebugType>
1616
</PropertyGroup>
17-
18-
<ItemGroup>
19-
<None Remove="Resources\Language\core_en-us.json" />
20-
<None Remove="Resources\Language\core_zh-cn.json" />
21-
<None Remove="Resources\Language\en-us" />
22-
<None Remove="Resources\Language\zh-cn" />
23-
</ItemGroup>
24-
2517
<ItemGroup>
26-
<EmbeddedResource Include="Resources\Language\core_zh-cn.json" />
27-
<EmbeddedResource Include="Resources\Language\core_en-us.json" />
18+
<Compile Remove="Resources\Language\**" />
19+
<EmbeddedResource Remove="Resources\Language\**" />
20+
<None Remove="Resources\Language\**" />
2821
</ItemGroup>
2922

3023
<ItemGroup>
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ColorMC.Core.Config;
77
/// <summary>
88
/// 配置文件
99
/// </summary>
10-
public static class ConfigUtils
10+
public static class ConfigLoad
1111
{
1212
/// <summary>
1313
/// 配置文件
@@ -36,8 +36,6 @@ internal static void Init()
3636
/// <returns>是否加载成功</returns>
3737
public static bool Load(string local, bool quit = false)
3838
{
39-
Logs.Info(LanguageHelper.Get("Core.Info4"));
40-
4139
using var data = PathHelper.OpenRead(local);
4240
ConfigObj? obj = null;
4341
if (data == null)
@@ -60,7 +58,7 @@ public static bool Load(string local, bool quit = false)
6058
}
6159
catch (Exception e)
6260
{
63-
ColorMCCore.OnError(LanguageHelper.Get("Core.Error1"), e, true);
61+
ColorMCCore.OnError(new ConfigLoadErrorEventArgs(e));
6462
}
6563
}
6664

@@ -71,7 +69,6 @@ public static bool Load(string local, bool quit = false)
7169
{
7270
return false;
7371
}
74-
Logs.Warn(LanguageHelper.Get("Core.Info6"));
7572

7673
Config = MakeDefaultConfig();
7774
}
@@ -95,8 +92,6 @@ public static bool Load(string local, bool quit = false)
9592
Config.Version = ColorMCCore.Version;
9693
}
9794

98-
LanguageHelper.Change(Config.Language);
99-
10095
Save();
10196

10297
return true;
@@ -107,7 +102,6 @@ public static bool Load(string local, bool quit = false)
107102
/// </summary>
108103
public static void Save()
109104
{
110-
Logs.Info(LanguageHelper.Get("Core.Info5"));
111105
ConfigSave.AddItem(ConfigSaveObj.Build(Names.NameConfigFile, s_local, Config, JsonType.ConfigObj));
112106
}
113107

@@ -116,7 +110,6 @@ public static void Save()
116110
/// </summary>
117111
public static void SaveNow()
118112
{
119-
Logs.Info(LanguageHelper.Get("Core.Info5"));
120113
File.WriteAllText(s_local, JsonUtils.ToString(Config, JsonType.ConfigObj));
121114
}
122115

src/ColorMC.Core/Config/ConfigSave.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static void Save()
9696
}
9797
catch (Exception e)
9898
{
99-
Logs.Error(LanguageHelper.Get("Core.Error2"), e);
99+
ColorMCCore.OnError(new ConfigSaveErrorEventArgs(e));
100100
}
101101
}
102102
}

src/ColorMC.Core/CoreMain.cs

Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using ColorMC.Core.Config;
33
using ColorMC.Core.Downloader;
44
using ColorMC.Core.Game;
5-
using ColorMC.Core.Helpers;
65
using ColorMC.Core.LaunchPath;
76
using ColorMC.Core.Net;
87
using 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
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using ColorMC.Core.Objs;
2+
3+
namespace ColorMC.Core.Downloader;
4+
5+
/// <summary>
6+
/// 下载项目
7+
/// </summary>
8+
internal record DownloadItem
9+
{
10+
/// <summary>
11+
/// 下载任务
12+
/// </summary>
13+
public DownloadTask Task;
14+
/// <summary>
15+
/// 下载项目
16+
/// </summary>
17+
public FileItemObj File;
18+
}

0 commit comments

Comments
 (0)