Skip to content

Commit 9d3f186

Browse files
committed
v3.6.7.4
可设置关键日志高亮
1 parent 4f3da58 commit 9d3f186

File tree

8 files changed

+173
-19
lines changed

8 files changed

+173
-19
lines changed

MSL/MainWindow.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ await Task.Run(() =>
307307

308308
if (logColorConf["ERROR"] != null)
309309
ConfigStore.LogColor.ERROR = (SolidColorBrush)brushConverter.ConvertFromString(logColorConf["ERROR"].ToString());
310+
311+
if (logColorConf["HIGHLIGHT"] != null)
312+
ConfigStore.LogColor.HIGHLIGHT = (SolidColorBrush)brushConverter.ConvertFromString(logColorConf["HIGHLIGHT"].ToString());
310313
}
311314
//Logger.LogInfo("读取自动化功能配置成功(自动打开显示占用、记录玩家功能)!");
312315
}

MSL/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
5050
//通过使用 "*",如下所示:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("3.6.7.3")]
53-
[assembly: AssemblyFileVersion("3.6.7.3")]
52+
[assembly: AssemblyVersion("3.6.7.4")]
53+
[assembly: AssemblyFileVersion("3.6.7.4")]

MSL/forms/ServerRunner.xaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,9 @@
569569
<Grid Grid.Column="1">
570570
<Grid.ColumnDefinitions>
571571
<ColumnDefinition Width="Auto"/>
572-
<ColumnDefinition Width="100"/>
572+
<ColumnDefinition Width="75"/>
573+
<ColumnDefinition Width="Auto"/>
574+
<ColumnDefinition Width="35"/>
573575
<ColumnDefinition Width="Auto"/>
574576
<ColumnDefinition/>
575577
</Grid.ColumnDefinitions>
@@ -602,8 +604,7 @@
602604
<RowDefinition Height="Auto"/>
603605
</Grid.RowDefinitions>
604606
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top">
605-
<Label Content="屏蔽关键字日志:" Style="{StaticResource MagicLabel14}"/>
606-
<ToggleButton x:Name="shieldLogBtn" Style="{StaticResource ToggleButtonSwitch.Content}" Click="shieldLogBtn_Click"/>
607+
<ToggleButton x:Name="shieldLogBtn" Content="屏蔽关键字日志" Style="{StaticResource ToggleButtonSwitch.Content}" Click="shieldLogBtn_Click"/>
607608
</StackPanel>
608609
<ListBox x:Name="ShieldLogList" Grid.Row="1" Margin="0,5,0,5" MaxHeight="120"/>
609610
<Grid Grid.Row="2">
@@ -612,8 +613,28 @@
612613
<ColumnDefinition Width="5"/>
613614
<ColumnDefinition/>
614615
</Grid.ColumnDefinitions>
615-
<Button x:Name="LogShield_Add" Content="添加屏蔽词" Grid.Column="0" HorizontalAlignment="Stretch" Click="LogShield_Add_Click"/>
616-
<Button x:Name="LogShield_Del" Content="移除屏蔽词" Grid.Column="2" HorizontalAlignment="Stretch" Click="LogShield_Del_Click"/>
616+
<Button x:Name="LogShield_Add" Content="添加" Grid.Column="0" HorizontalAlignment="Stretch" Click="LogShield_Add_Click"/>
617+
<Button x:Name="LogShield_Del" Content="移除" Grid.Column="2" HorizontalAlignment="Stretch" Click="LogShield_Del_Click"/>
618+
</Grid>
619+
</Grid>
620+
<Grid Grid.Column="4">
621+
<Grid.RowDefinitions>
622+
<RowDefinition Height="Auto"/>
623+
<RowDefinition/>
624+
<RowDefinition Height="Auto"/>
625+
</Grid.RowDefinitions>
626+
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top">
627+
<ToggleButton x:Name="highLightLogBtn" Content="高亮关键字日志" Style="{StaticResource ToggleButtonSwitch.Content}" Click="highLightLogBtn_Click"/>
628+
</StackPanel>
629+
<ListBox x:Name="HighLightLogList" Grid.Row="1" Margin="0,5,0,5" MaxHeight="120"/>
630+
<Grid Grid.Row="2">
631+
<Grid.ColumnDefinitions>
632+
<ColumnDefinition/>
633+
<ColumnDefinition Width="5"/>
634+
<ColumnDefinition/>
635+
</Grid.ColumnDefinitions>
636+
<Button x:Name="LogHighLight_Add" Content="添加" Grid.Column="0" HorizontalAlignment="Stretch" Click="LogHighLight_Add_Click"/>
637+
<Button x:Name="LogHighLight_Del" Content="移除" Grid.Column="2" HorizontalAlignment="Stretch" Click="LogHighLight_Del_Click"/>
617638
</Grid>
618639
</Grid>
619640
</Grid>

MSL/forms/ServerRunner.xaml.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ private void DisposeRes()
170170
conptyWindow = null;
171171
}
172172
}
173+
MCSLogHandler.Dispose();
174+
MCSLogHandler = null;
173175
getSystemInfo = false;
174176
ShieldLog = null;
175177
DownjavaName = null;
@@ -282,6 +284,20 @@ private async Task<bool> LoadingInfoEvent()
282284
LogShield_Add.IsEnabled = false;
283285
LogShield_Del.IsEnabled = false;
284286
}
287+
if (_json["highLightLogKeys"] != null)
288+
{
289+
var items = _json["highLightLogKeys"];
290+
List<string> tempList = new List<string>();
291+
foreach (var item in items)
292+
{
293+
tempList.Add(item.ToString());
294+
HighLightLogList.Items.Add(item.ToString());
295+
}
296+
MCSLogHandler.HighLightLog = [.. tempList];
297+
highLightLogBtn.IsChecked = true;
298+
LogHighLight_Add.IsEnabled = false;
299+
LogHighLight_Del.IsEnabled = false;
300+
}
285301
if (_json["shieldStackOut"] != null && _json["shieldStackOut"].ToString() == "False")
286302
{
287303
shieldStackOut.IsChecked = false;
@@ -4012,6 +4028,63 @@ private void LogShield_Del_Click(object sender, RoutedEventArgs e)
40124028
}
40134029
}
40144030

4031+
private void highLightLogBtn_Click(object sender, RoutedEventArgs e)
4032+
{
4033+
JObject jsonObject = JObject.Parse(File.ReadAllText(@"MSL\ServerList.json", Encoding.UTF8));
4034+
JObject _json = (JObject)jsonObject[RserverID.ToString()];
4035+
if (highLightLogBtn.IsChecked == true)
4036+
{
4037+
if (HighLightLogList.Items.Count > 0)
4038+
{
4039+
List<string> tempList = new List<string>();
4040+
4041+
JArray jArray = new JArray();
4042+
foreach (var item in HighLightLogList.Items)
4043+
{
4044+
tempList.Add(item.ToString());
4045+
jArray.Add(item.ToString());
4046+
}
4047+
4048+
MCSLogHandler.HighLightLog = [.. tempList];
4049+
_json["highLightLogKeys"] = jArray;
4050+
4051+
LogHighLight_Add.IsEnabled = false;
4052+
LogHighLight_Del.IsEnabled = false;
4053+
}
4054+
else
4055+
{
4056+
MagicFlowMsg.ShowMessage("请先进行添加!", 2);
4057+
highLightLogBtn.IsChecked = false;
4058+
}
4059+
}
4060+
else
4061+
{
4062+
MCSLogHandler.HighLightLog = null;
4063+
_json.Remove("highLightLogKeys");
4064+
LogHighLight_Add.IsEnabled = true;
4065+
LogHighLight_Del.IsEnabled = true;
4066+
}
4067+
jsonObject[RserverID.ToString()] = _json;
4068+
File.WriteAllText("MSL\\ServerList.json", Convert.ToString(jsonObject), Encoding.UTF8);
4069+
}
4070+
4071+
private async void LogHighLight_Add_Click(object sender, RoutedEventArgs e)
4072+
{
4073+
string text = await MagicShow.ShowInput(this, "输入你想高亮日志的关键字");
4074+
if ((!string.IsNullOrEmpty(text)) && (!HighLightLogList.Items.Contains(text)))
4075+
{
4076+
HighLightLogList.Items.Add(text);
4077+
}
4078+
}
4079+
4080+
private void LogHighLight_Del_Click(object sender, RoutedEventArgs e)
4081+
{
4082+
if (HighLightLogList.SelectedIndex != -1)
4083+
{
4084+
HighLightLogList.Items.Remove(HighLightLogList.SelectedItem);
4085+
}
4086+
}
4087+
40154088
private void shieldStackOut_Click(object sender, RoutedEventArgs e)
40164089
{
40174090
JObject jsonObject = JObject.Parse(File.ReadAllText(@"MSL\ServerList.json", Encoding.UTF8));

MSL/pages/SettingsPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<ComboBoxItem Content="INFO" IsSelected="True"/>
165165
<ComboBoxItem Content="WARN"/>
166166
<ComboBoxItem Content="ERROR"/>
167+
<ComboBoxItem Content="HIGHLIGHT"/>
167168
</ComboBox>
168169
<Button x:Name="ChangeLogForeColor" Content="点击选色" Click="ChangeLogForeColor_Click"/>
169170
<Button x:Name="RestoreLogForeColor" Content="重置" Click="RestoreLogForeColor_Click"/>

MSL/pages/SettingsPage.xaml.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ private void ChangeLogForeColor_Click(object sender, RoutedEventArgs e)
662662
case 2:
663663
picker.SelectedBrush = ConfigStore.LogColor.ERROR;
664664
break;
665+
case 3:
666+
picker.SelectedBrush = ConfigStore.LogColor.HIGHLIGHT;
667+
break;
665668
}
666669
var window = new PopupWindow
667670
{
@@ -686,12 +689,16 @@ private void ChangeLogForeColor_Click(object sender, RoutedEventArgs e)
686689
case 2:
687690
ConfigStore.LogColor.ERROR = picker.SelectedBrush;
688691
break;
692+
case 3:
693+
ConfigStore.LogColor.HIGHLIGHT = picker.SelectedBrush;
694+
break;
689695
}
690696
var config = new
691697
{
692698
ConfigStore.LogColor.INFO,
693699
ConfigStore.LogColor.WARN,
694-
ConfigStore.LogColor.ERROR
700+
ConfigStore.LogColor.ERROR,
701+
ConfigStore.LogColor.HIGHLIGHT
695702
};
696703
string json = JsonConvert.SerializeObject(config, Formatting.Indented);
697704
Config.Write("LogColor", JObject.Parse(json));
@@ -704,6 +711,7 @@ private void RestoreLogForeColor_Click(object sender, RoutedEventArgs e)
704711
ConfigStore.LogColor.INFO = Brushes.Green;
705712
ConfigStore.LogColor.WARN = Brushes.Orange;
706713
ConfigStore.LogColor.ERROR = Brushes.Red;
714+
ConfigStore.LogColor.HIGHLIGHT = Brushes.Blue;
707715
MagicFlowMsg.ShowMessage("已恢复默认日志颜色!重新打开服务器运行窗口以使其生效!", 1);
708716
}
709717

MSL/utils/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class LogColor
2424
public static SolidColorBrush INFO { get; set; } = Brushes.Green;
2525
public static SolidColorBrush WARN { get; set; } = Brushes.Orange;
2626
public static SolidColorBrush ERROR { get; set; } = Brushes.Red;
27+
public static SolidColorBrush HIGHLIGHT { get; set; } = Brushes.Blue;
2728
}
2829
}
2930

MSL/utils/MCServerService.cs

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4-
using System.Text;
4+
using System.Linq;
55
using System.Windows.Media;
66
using System.Windows.Threading;
77

@@ -68,13 +68,20 @@ internal class MCServerService
6868

6969
}
7070

71-
internal class MCSLogHandler
71+
internal class MCSLogHandler : IDisposable
7272
{
73+
public void Dispose()
74+
{
75+
CleanupResources();
76+
HighLightLog = null;
77+
}
78+
7379
private readonly Action<string, SolidColorBrush> _logAction;
7480
private readonly Action<List<string>> _logBatch;
7581
private readonly Action<string> _infoHandler;
7682
private readonly Action<string> _warnHandler;
7783
private readonly Action _encodingIssueHandler;
84+
public string[] HighLightLog;
7885

7986
public class LogConfig
8087
{
@@ -266,20 +273,60 @@ public void ProcessLogGroup(List<string> group)
266273
{
267274
// 单条日志直接处理
268275
ProcessLogMessage(group[0]);
276+
return;
269277
}
270-
else
278+
279+
// 检查是否有需要高亮的日志
280+
bool hasHighlight = HighLightLog != null && HighLightLog.Any() &&
281+
group.Any(msg => HighLightLog.Any(s => msg.Contains(s)));
282+
283+
if (!hasHighlight)
271284
{
272-
// 多条相同类型的日志,合并处理
273-
// 构建合并后的日志文本
274-
var sb = new StringBuilder();
275-
foreach (var msg in group)
285+
// 没有高亮日志,直接合并输出
286+
string combinedMessage = string.Join(Environment.NewLine, group);
287+
ProcessLogMessage(combinedMessage);
288+
return;
289+
}
290+
291+
// 有高亮日志,分段处理
292+
var beforeHighlight = new List<string>();
293+
var highlightLogs = new List<string>();
294+
var afterHighlight = new List<string>();
295+
bool foundHighlight = false;
296+
297+
foreach (var msg in group)
298+
{
299+
bool isHighlight = HighLightLog.Any(s => msg.Contains(s));
300+
301+
if (!foundHighlight && !isHighlight)
276302
{
277-
sb.AppendLine(msg);
303+
beforeHighlight.Add(msg);
278304
}
305+
else if (isHighlight)
306+
{
307+
highlightLogs.Add(msg);
308+
foundHighlight = true;
309+
}
310+
else
311+
{
312+
afterHighlight.Add(msg);
313+
}
314+
}
279315

280-
// 一次性输出
281-
string combinedMessage = sb.ToString().TrimEnd();
282-
ProcessLogMessage(combinedMessage);
316+
// 输出三部分内容
317+
if (beforeHighlight.Count > 0)
318+
{
319+
ProcessLogMessage(string.Join(Environment.NewLine, beforeHighlight));
320+
}
321+
322+
foreach (var highlight in highlightLogs)
323+
{
324+
PrintLog(highlight, ConfigStore.LogColor.HIGHLIGHT);
325+
}
326+
327+
if (afterHighlight.Count > 0)
328+
{
329+
ProcessLogMessage(string.Join(Environment.NewLine, afterHighlight));
283330
}
284331
}
285332

0 commit comments

Comments
 (0)