- add: Log
This commit is contained in:
1
.idea/.idea.Nebula/.idea/avalonia.xml
generated
1
.idea/.idea.Nebula/.idea/avalonia.xml
generated
@@ -16,6 +16,7 @@
|
||||
<entry key="Nebula.Launcher/Views/Pages/ServerListPage.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Pages/ServerListView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/InfoPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/LogPopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/Popup/MessagePopupView.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ServerContainer.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
<entry key="Nebula.Launcher/Views/ServerList.axaml" value="Nebula.Launcher/Nebula.Launcher.csproj" />
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewHelper;
|
||||
using Nebula.Launcher.Views.Popup;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
@@ -14,14 +19,21 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
private readonly ContentService _contentService = default!;
|
||||
private readonly CancellationService _cancellationService = default!;
|
||||
private readonly DebugService _debugService = default!;
|
||||
private readonly RunnerService _runnerService;
|
||||
private readonly RunnerService _runnerService = default!;
|
||||
private readonly PopupMessageService _popupMessageService;
|
||||
|
||||
[ObservableProperty] private bool _runVisible = true;
|
||||
|
||||
public ServerHubInfo ServerHubInfo { get; set; } = default!;
|
||||
|
||||
|
||||
private Process? _process;
|
||||
|
||||
public LogPopupModelView CurrLog;
|
||||
|
||||
public ServerEntryModelView() : base()
|
||||
{
|
||||
CurrLog = GetViewModel<LogPopupModelView>();
|
||||
}
|
||||
|
||||
public ServerEntryModelView(
|
||||
@@ -30,7 +42,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
ContentService contentService,
|
||||
CancellationService cancellationService,
|
||||
DebugService debugService,
|
||||
RunnerService runnerService
|
||||
RunnerService runnerService, PopupMessageService popupMessageService
|
||||
) : base(serviceProvider)
|
||||
{
|
||||
_authService = authService;
|
||||
@@ -38,9 +50,10 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
_cancellationService = cancellationService;
|
||||
_debugService = debugService;
|
||||
_runnerService = runnerService;
|
||||
}
|
||||
_popupMessageService = popupMessageService;
|
||||
|
||||
private Process? _process;
|
||||
CurrLog = GetViewModel<LogPopupModelView>();
|
||||
}
|
||||
|
||||
public async void RunInstance()
|
||||
{
|
||||
@@ -62,14 +75,23 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
{ "GAME_URL", ServerHubInfo.Address } ,
|
||||
{ "AUTH_LOGIN", authProv?.AuthLoginPassword.Login } ,
|
||||
},
|
||||
CreateNoWindow = true, UseShellExecute = false
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true, StandardOutputEncoding = Encoding.UTF8
|
||||
});
|
||||
|
||||
|
||||
if (_process is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_process.BeginOutputReadLine();
|
||||
_process.BeginErrorReadLine();
|
||||
|
||||
RunVisible = false;
|
||||
|
||||
_process.OutputDataReceived += OnOutputDataReceived;
|
||||
_process.ErrorDataReceived += OnErrorDataReceived;
|
||||
|
||||
@@ -91,22 +113,31 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
RunVisible = true;
|
||||
}
|
||||
|
||||
private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data != null) _debugService.Error(e.Data);
|
||||
if (e.Data != null)
|
||||
{
|
||||
_debugService.Error(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
if (e.Data != null) _debugService.Log(e.Data);
|
||||
if (e.Data != null)
|
||||
{
|
||||
_debugService.Log(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ReadLog()
|
||||
{
|
||||
|
||||
_popupMessageService.Popup(CurrLog);
|
||||
}
|
||||
|
||||
public void StopInstance()
|
||||
@@ -132,4 +163,73 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
throw new Exception("Dotnet not found!");
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class LogInfo
|
||||
{
|
||||
public string Category { get; set; } = "LOG";
|
||||
public IBrush CategoryColor { get; set; } = Brush.Parse("#424242");
|
||||
public string Message { get; set; } = "";
|
||||
|
||||
public static LogInfo FromString(string input)
|
||||
{
|
||||
var matches = Regex.Matches(input, @"(\[(?<c>.*)\] (?<m>.*))|(?<m>.*)");
|
||||
string category = "All";
|
||||
|
||||
if( matches[0].Groups.TryGetValue("c", out var c))
|
||||
{
|
||||
category = c.Value;
|
||||
}
|
||||
|
||||
var color = Brush.Parse("#444444");
|
||||
|
||||
switch (category)
|
||||
{
|
||||
case "DEBG":
|
||||
color = Brush.Parse("#2436d4");
|
||||
break;
|
||||
case "ERRO":
|
||||
color = Brush.Parse("#d42436");
|
||||
break;
|
||||
case "INFO":
|
||||
color = Brush.Parse("#0ab3c9");
|
||||
break;
|
||||
}
|
||||
|
||||
var message = matches[0].Groups["m"].Value;
|
||||
return new LogInfo()
|
||||
{
|
||||
Category = category, Message = message, CategoryColor = color
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[ViewModelRegister(typeof(LogPopupView), false)]
|
||||
public sealed class LogPopupModelView : PopupViewModelBase
|
||||
{
|
||||
public LogPopupModelView() : base()
|
||||
{
|
||||
Logs.Add(new LogInfo()
|
||||
{
|
||||
Category = "DEBG", Message = "MEOW MEOW TEST"
|
||||
});
|
||||
|
||||
Logs.Add(new LogInfo()
|
||||
{
|
||||
Category = "ERRO", Message = "MEOW MEOW TEST 11\naaaaa"
|
||||
});
|
||||
}
|
||||
|
||||
public LogPopupModelView(IServiceProvider serviceProvider) : base(serviceProvider)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Title => "LOG";
|
||||
|
||||
public ObservableCollection<LogInfo> Logs { get; } = new();
|
||||
|
||||
public void Append(string str)
|
||||
{
|
||||
Logs.Add(LogInfo.FromString(str));
|
||||
}
|
||||
}
|
||||
@@ -98,8 +98,7 @@
|
||||
<Border Background="#111" Opacity="50" />
|
||||
<Border
|
||||
CornerRadius="10"
|
||||
Height="320"
|
||||
Width="520">
|
||||
Margin="40">
|
||||
<Grid RowDefinitions="35,*,20">
|
||||
<Border
|
||||
BorderThickness="0,0,0,2"
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
<Label HorizontalAlignment="Center">Profiles:</Label>
|
||||
</Border>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||
<ListBox
|
||||
<ItemsControl
|
||||
Background="#00000000"
|
||||
Classes="AccountSelector"
|
||||
ItemsSource="{Binding Accounts}"
|
||||
Padding="0">
|
||||
<ListBox.ItemTemplate>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:AuthLoginPasswordModel}">
|
||||
<Border
|
||||
CornerRadius="0,10,0,10"
|
||||
@@ -64,8 +63,8 @@
|
||||
</Panel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
<Grid ColumnDefinitions="*" RowDefinitions="*,40">
|
||||
<ScrollViewer Margin="0,0,0,10" Padding="0,0,8,0">
|
||||
<ListBox
|
||||
<ItemsControl
|
||||
Background="#00000000"
|
||||
ItemsSource="{Binding ServerInfos}"
|
||||
Padding="0">
|
||||
<ListBox.ItemTemplate>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:ServerEntryModelView}">
|
||||
<Grid
|
||||
ColumnDefinitions="*,120"
|
||||
@@ -153,8 +153,8 @@
|
||||
</Panel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
|
||||
<Border
|
||||
|
||||
39
Nebula.Launcher/Views/Popup/LogPopupView.axaml
Normal file
39
Nebula.Launcher/Views/Popup/LogPopupView.axaml
Normal file
@@ -0,0 +1,39 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="clr-namespace:Nebula.Launcher.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Nebula.Launcher.Views.Popup.LogPopupView"
|
||||
x:DataType="viewModels:LogPopupModelView">
|
||||
<Design.DataContext>
|
||||
<viewModels:LogPopupModelView />
|
||||
</Design.DataContext>
|
||||
|
||||
<ScrollViewer Margin="10" Padding="0,0,8,0">
|
||||
<ItemsControl
|
||||
Background="#00000000"
|
||||
ItemsSource="{Binding Logs}"
|
||||
Padding="0">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:LogInfo}">
|
||||
<Border CornerRadius="5" Margin="0,0,0,5">
|
||||
<StackPanel Orientation="Horizontal" Spacing="5" Margin="0">
|
||||
<Border MinWidth="100"
|
||||
Background="{Binding CategoryColor}"
|
||||
CornerRadius="5,0,0,5"
|
||||
Padding="10,0,12,0" BorderThickness="2,0,2,0">
|
||||
<Label FontSize="15" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Category }"></TextBlock>
|
||||
</Label>
|
||||
</Border>
|
||||
<Label FontSize="12" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Message }"></TextBlock>
|
||||
</Label>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
19
Nebula.Launcher/Views/Popup/LogPopupView.axaml.cs
Normal file
19
Nebula.Launcher/Views/Popup/LogPopupView.axaml.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Nebula.Launcher.ViewModels;
|
||||
|
||||
namespace Nebula.Launcher.Views.Popup;
|
||||
|
||||
public partial class LogPopupView : UserControl
|
||||
{
|
||||
public LogPopupView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public LogPopupView(LogPopupModelView viewModel) : this()
|
||||
{
|
||||
DataContext = viewModel;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.5-beta1"/>
|
||||
<PackageReference Include="SharpZstd.Interop" Version="1.5.6"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user