Skip to content

Commit c24dfd6

Browse files
committed
up not done
1 parent ead5800 commit c24dfd6

37 files changed

Lines changed: 1178 additions & 674 deletions

src/ColorMC.Core/CoreMain.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ internal static void OnGameLog(GameSettingObj obj, GameSystemLog type)
233233
}
234234
}
235235

236+
/// <summary>
237+
/// 添加系统日志
238+
/// </summary>
239+
/// <param name="obj">游戏实例</param>
240+
/// <param name="type">系统日志类型</param>
241+
internal static void OnGameLog(GameSettingObj obj, GameSystemLog type, string text1, string text2)
242+
{
243+
if (s_gameLogs.TryGetValue(obj.UUID, out var log))
244+
{
245+
var item = log.AddLog(type, text1, text2);
246+
GameLog?.Invoke(new GameLogEventArgs(obj, item));
247+
}
248+
}
249+
236250
/// <summary>
237251
/// 清理游戏实例日志
238252
/// </summary>

src/ColorMC.Core/Game/GameArg.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private static async Task<JvmArgRes> MakeJvmArgAsync(this GameSettingObj obj, Lo
510510
var res = await CoreHttpClient.GetStringAsync(login.Text1);
511511
if (!res.State)
512512
{
513-
throw new LaunchException(LaunchState.LoginCoreError);
513+
throw new LaunchException(LaunchError.LoginCoreError);
514514
}
515515
jvm.Add($"-javaagent:{AuthlibHelper.NowAuthlibInjector}={login.Text1}");
516516
jvm.Add($"-Dauthlibinjector.yggdrasil.prefetched={HashHelper.GenBase64(res.Data!)}");
@@ -520,7 +520,7 @@ private static async Task<JvmArgRes> MakeJvmArgAsync(this GameSettingObj obj, Lo
520520
res = await CoreHttpClient.GetStringAsync($"{UrlHelper.LittleSkin}api/yggdrasil");
521521
if (!res.State)
522522
{
523-
throw new LaunchException(LaunchState.LoginCoreError);
523+
throw new LaunchException(LaunchError.LoginCoreError);
524524
}
525525
jvm.Add($"-javaagent:{AuthlibHelper.NowAuthlibInjector}={UrlHelper.LittleSkin}api/yggdrasil");
526526
jvm.Add($"-Dauthlibinjector.yggdrasil.prefetched={HashHelper.GenBase64(res.Data!)}");
@@ -530,7 +530,7 @@ private static async Task<JvmArgRes> MakeJvmArgAsync(this GameSettingObj obj, Lo
530530
res = await CoreHttpClient.GetStringAsync($"{login.Text1}api/yggdrasil");
531531
if (!res.State)
532532
{
533-
throw new LaunchException(LaunchState.LoginCoreError);
533+
throw new LaunchException(LaunchError.LoginCoreError);
534534
}
535535
jvm.Add($"-javaagent:{AuthlibHelper.NowAuthlibInjector}={login.Text1}/api/yggdrasil");
536536
jvm.Add($"-Dauthlibinjector.yggdrasil.prefetched={HashHelper.GenBase64(res.Data!)}");
@@ -675,7 +675,7 @@ public static List<string> MakeRunArg(this GameSettingObj obj, GameLaunchArg lar
675675
private static string MakeMainClass(this GameSettingObj obj)
676676
{
677677
var version = VersionPath.GetVersion(obj.Version)
678-
?? throw new LaunchException(LaunchState.LostVersion);
678+
?? throw new LaunchException(LaunchError.LostVersionFile);
679679
var v2 = version.IsGameVersionV2();
680680
if (!string.IsNullOrWhiteSpace(obj.AdvanceJvm?.MainClass))
681681
{
@@ -776,7 +776,7 @@ await Task.Run(async () =>
776776
if (res2 == null)
777777
{
778778
res2 = await obj.BuildForgeAsync()
779-
?? throw new LaunchException(LaunchState.LostLoader);
779+
?? throw new LaunchException(LaunchError.LostLoaderFile);
780780
}
781781
loader = res2.Loaders;
782782
install = res2.Installs;
@@ -793,7 +793,7 @@ await Task.Run(async () =>
793793
return;
794794
}
795795
loader ??= await obj.BuildFabricAsync()
796-
?? throw new LaunchException(LaunchState.LostLoader);
796+
?? throw new LaunchException(LaunchError.LostLoaderFile);
797797
break;
798798
case Loaders.Quilt:
799799
loader = obj.GetQuiltLibs();
@@ -802,7 +802,7 @@ await Task.Run(async () =>
802802
return;
803803
}
804804
loader ??= await obj.BuildQuiltAsync()
805-
?? throw new LaunchException(LaunchState.LostLoader);
805+
?? throw new LaunchException(LaunchError.LostLoaderFile);
806806
break;
807807
case Loaders.OptiFine:
808808
loader = obj.GetOptifineLibs();
@@ -811,22 +811,22 @@ await Task.Run(async () =>
811811
return;
812812
}
813813
loader ??= await obj.BuildOptifineAsync()
814-
?? throw new LaunchException(LaunchState.LostLoader);
814+
?? throw new LaunchException(LaunchError.LostLoaderFile);
815815
GameHelper.ReadyOptifineWrapper();
816816
loader.Add(GameHelper.OptifineWrapper);
817817
break;
818818
case Loaders.Custom:
819819
if (obj.CustomLoader == null || !File.Exists(obj.GetGameLoaderFile()))
820820
{
821-
throw new LaunchException(LaunchState.LostLoader);
821+
throw new LaunchException(LaunchError.LostLoaderFile);
822822
}
823823

824824
if (cancel.IsCancellationRequested)
825825
{
826826
return;
827827
}
828828
var res1 = await GameDownloadHelper.DecodeLoaderJarAsync(obj, obj.GetGameLoaderFile(), cancel)
829-
?? throw new LaunchException(LaunchState.LostLoader);
829+
?? throw new LaunchException(LaunchError.LostLoaderFile);
830830
loader = res1.List?.ToList();
831831
break;
832832
}
@@ -892,7 +892,7 @@ await Task.Run(async () =>
892892
{
893893
//不存在json文件
894894
var res = await GameAPI.GetAssetsAsync(game.AssetIndex.Url)
895-
?? throw new LaunchException(LaunchState.AssetsError);
895+
?? throw new LaunchException(LaunchError.LostAssetsFile, data: game.AssetIndex.Id);
896896
assets = res.Assets;
897897
game.AddIndex(res.Text);
898898
}
@@ -946,7 +946,7 @@ await Task.Run(async () =>
946946
if (assets == null)
947947
{
948948
var res = await GameAPI.GetAssetsAsync(item.AssetIndex.Url)
949-
?? throw new LaunchException(LaunchState.AssetsError);
949+
?? throw new LaunchException(LaunchError.LostAssetsFile, data: item.AssetIndex.Id);
950950
assets = res.Assets;
951951
item.AddIndex(res.Text);
952952
}

src/ColorMC.Core/Game/GameAuth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private static async Task<LoginObj> RefreshLittleSkinAsync(LoginObj obj, Cancell
181181
/// </summary>
182182
/// <param name="obj">登录信息</param>
183183
/// <returns>登录结果</returns>
184-
public static async Task<LoginObj?> RefreshTokenAsync(this LoginObj obj, CancellationToken token)
184+
public static async Task<LoginObj> RefreshTokenAsync(this LoginObj obj, CancellationToken token)
185185
{
186186
return obj.AuthType switch
187187
{

src/ColorMC.Core/Game/GameHandel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Diagnostics;
22
using System.Text;
3-
using ColorMC.Core.Helpers;
43
using ColorMC.Core.LaunchPath;
54
using ColorMC.Core.Objs;
65
using ColorMC.Core.Utils;
@@ -73,7 +72,7 @@ public GameHandel(GameRunObj run)
7372
if (ProcessUtils.Launch(Process, run.Admin))
7473
{
7574
IsOutAdmin = true;
76-
ColorMCCore.OnGameLog(_game, LanguageHelper.Get("Core.Info21"));
75+
ColorMCCore.OnGameLog(_game, GameSystemLog.JavaRedirect);
7776
return;
7877
}
7978

src/ColorMC.Core/Game/GameLang.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static Dictionary<string, string> GetLangs(this AssetsObj? obj)
9494
}
9595
catch (Exception e)
9696
{
97-
Logs.Error($"error with read lang file: {item.Key}", e);
97+
ColorMCCore.OnError(new GameLangLoadErrorEventArgs(item.Key, e));
9898
}
9999
});
100100
}
@@ -144,7 +144,7 @@ public static Dictionary<string, string> GetLangs(this AssetsObj? obj)
144144
}
145145
catch (Exception e)
146146
{
147-
Logs.Error($"error with read lang key: {key}", e);
147+
ColorMCCore.OnError(new GameLangLoadErrorEventArgs(key, e));
148148
}
149149
}
150150
}

0 commit comments

Comments
 (0)