-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1aeada
commit 8341fed
Showing
7 changed files
with
163 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace MinecraftLaunch.Classes.Enums; | ||
|
||
public enum LogType { | ||
Error = 1, | ||
Info, | ||
Debug, | ||
Fatal, | ||
Warning, | ||
Exception, | ||
StackTrace, | ||
Unknown | ||
} |
10 changes: 8 additions & 2 deletions
10
MinecraftLaunch/Classes/Models/Event/LogReceivedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
namespace MinecraftLaunch.Classes.Models.Event; | ||
using MinecraftLaunch.Classes.Enums; | ||
using MinecraftLaunch.Classes.Models.Game; | ||
|
||
public sealed class LogReceivedEventArgs(string log) : EventArgs { | ||
namespace MinecraftLaunch.Classes.Models.Event; | ||
|
||
public sealed class LogReceivedEventArgs(string log, string time, string source, LogType logType) : EventArgs { | ||
public string Text => log; | ||
public string Time => time; | ||
public string Source => source; | ||
public LogType LogType => logType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using MinecraftLaunch.Classes.Enums; | ||
|
||
namespace MinecraftLaunch.Classes.Models.Game; | ||
|
||
public sealed record GameLogEntry { | ||
public string Log { get; set; } | ||
|
||
public string Time { get; set; } | ||
|
||
public string Source { get; set; } | ||
|
||
public LogType LogType { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
using MinecraftLaunch.Classes.Interfaces; | ||
using MinecraftLaunch.Classes.Models.Game; | ||
|
||
namespace MinecraftLaunch.Components.Checker {//W.I.P | ||
internal class PreLaunchChecker(GameEntry entry) : IChecker { | ||
public bool IsCheckResource { get; set; } | ||
namespace MinecraftLaunch.Components.Checker; | ||
|
||
public bool IsCheckAccount { get; set; } | ||
public GameEntry Entry => entry; | ||
/// <summary> | ||
/// 预启动检查器 | ||
/// </summary> | ||
/// <param name="entry"></param> | ||
public sealed class PreLaunchChecker(GameEntry entry) : IChecker { | ||
public bool IsCheckResource { get; set; } | ||
|
||
public ValueTask<bool> CheckAsync() { | ||
/* | ||
* | ||
*/ | ||
throw new NotImplementedException(); | ||
} | ||
public bool IsCheckAccount { get; set; } | ||
public GameEntry Entry => entry; | ||
|
||
public ValueTask<bool> CheckAsync() { | ||
/* | ||
* | ||
*/ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using MinecraftLaunch.Classes.Enums; | ||
using System.Text.RegularExpressions; | ||
using MinecraftLaunch.Classes.Models.Game; | ||
|
||
namespace MinecraftLaunch.Components.Resolver; | ||
|
||
/// <summary> | ||
/// 游戏日志解析器 | ||
/// </summary> | ||
public sealed class GameLogResolver { | ||
public GameLogEntry Resolve(string log) { | ||
return new GameLogEntry { | ||
Log = GetLog(log), | ||
Source = GetSource(log), | ||
Time = Regex.IsMatch(log, "(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d", RegexOptions.Compiled) ? GetLogTime(log) : DateTime.Now.ToString(), | ||
LogType = GetLogType(log) switch { | ||
"FATAL" => LogType.Fatal, | ||
"ERROR" => LogType.Error, | ||
"WARN" => LogType.Warning, | ||
"INFO" => LogType.Info, | ||
"DEBUG" => LogType.Debug, | ||
"STACK" => LogType.StackTrace, | ||
"Exception" => LogType.Exception, | ||
_ => LogType.Unknown | ||
}, | ||
}; | ||
} | ||
|
||
public string GetLog(string log) { | ||
var res = GetTotalPrefix(log); | ||
var s = log.Split(res); | ||
return (s.Length >= 2 ? s[1] : log).Trim(); | ||
} | ||
|
||
/// <summary> | ||
/// 获取日志等级类型 | ||
/// </summary> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
public string GetLogType(string log) { | ||
//是否是堆栈信息 | ||
if (Regex.IsMatch(log, "(at .*)", RegexOptions.Compiled)) { | ||
return "STACK"; | ||
} | ||
|
||
//是否是异常信息 | ||
if (Regex.IsMatch(log, "(?m)^.*?Exception.*", RegexOptions.Compiled)) { | ||
return "Exception"; | ||
} | ||
|
||
return Regex.Match(log, "FATAL|ERROR|WARN|INFO|DEBUG", RegexOptions.Compiled).Value; | ||
} | ||
|
||
/// <summary> | ||
/// 获取日志源 | ||
/// </summary> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
public string GetSource(string log) { | ||
var content = Regex.Match(log, $"[\\w\\W\\s]{{2,}}/(FATAL|ERROR|WARN|INFO|DEBUG)", RegexOptions.Compiled) | ||
.Value.Split('/') | ||
.FirstOrDefault(); | ||
|
||
return content?.Replace($"{Regex.Match(log, | ||
$"\\[(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d\\]").Value} [", | ||
string.Empty)!; | ||
} | ||
|
||
/// <summary> | ||
/// 获取日志时间 | ||
/// </summary> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
public string GetLogTime(string log) { | ||
return Regex.Match(log, "(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d", | ||
RegexOptions.Compiled).Value; | ||
} | ||
|
||
/// <summary> | ||
/// 获取日志所有前缀 | ||
/// </summary> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
public string GetTotalPrefix(string log) { | ||
return Regex.Match(log, | ||
$"\\[(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d\\] \\[[\\w\\W\\s]{{2,}}/(FATAL|ERROR|WARN|INFO|DEBUG)\\]", | ||
RegexOptions.Compiled).Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters