- rework: Logging logic and file logging
This commit is contained in:
@@ -7,6 +7,7 @@ using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Nebula.Launcher.MessageBox;
|
||||
using Nebula.Launcher.ViewModels.ContentView;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared;
|
||||
@@ -22,6 +23,25 @@ public class App : Application
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (!Program.IsNewInstance)
|
||||
{
|
||||
IMessageContainerProvider? provider = null;
|
||||
switch (ApplicationLifetime)
|
||||
{
|
||||
case IClassicDesktopStyleApplicationLifetime desktop:
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
desktop.MainWindow = new MessageWindow(out provider);
|
||||
break;
|
||||
case ISingleViewApplicationLifetime singleViewPlatform:
|
||||
singleViewPlatform.MainView = new MessageView(out provider);
|
||||
break;
|
||||
}
|
||||
|
||||
provider?.ShowMessage("Launcher is already running.","hey shithead!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Design.IsDesignMode)
|
||||
{
|
||||
switch (ApplicationLifetime)
|
||||
|
||||
17
Nebula.Launcher/MessageBox/MessageView.axaml
Normal file
17
Nebula.Launcher/MessageBox/MessageView.axaml
Normal file
@@ -0,0 +1,17 @@
|
||||
<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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
Width="600"
|
||||
Height="400"
|
||||
x:Class="Nebula.Launcher.MessageBox.MessageView">
|
||||
<Grid RowDefinitions="50,*" ColumnDefinitions="*">
|
||||
<Border Grid.Column="0" Background="#222222" Padding="10" BorderBrush="#444444" BorderThickness="0,0,0,3">
|
||||
<Label VerticalAlignment="Center" x:Name="Title">Text</Label>
|
||||
</Border>
|
||||
<Panel Margin="5" Grid.Row="1">
|
||||
<Label x:Name="Message">Message</Label>
|
||||
</Panel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
25
Nebula.Launcher/MessageBox/MessageView.axaml.cs
Normal file
25
Nebula.Launcher/MessageBox/MessageView.axaml.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Nebula.Launcher.MessageBox;
|
||||
|
||||
public partial class MessageView : UserControl, IMessageContainerProvider
|
||||
{
|
||||
public MessageView(out IMessageContainerProvider provider)
|
||||
{
|
||||
InitializeComponent();
|
||||
provider = this;
|
||||
}
|
||||
|
||||
public void ShowMessage(string message, string title)
|
||||
{
|
||||
Title.Content = title;
|
||||
Message.Content = message;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMessageContainerProvider
|
||||
{
|
||||
public void ShowMessage(string message, string title);
|
||||
}
|
||||
12
Nebula.Launcher/MessageBox/MessageWindow.axaml
Normal file
12
Nebula.Launcher/MessageBox/MessageWindow.axaml
Normal file
@@ -0,0 +1,12 @@
|
||||
<Window 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:messageBox="clr-namespace:Nebula.Launcher.MessageBox"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
Width="600"
|
||||
Height="400"
|
||||
x:Class="Nebula.Launcher.MessageBox.MessageWindow"
|
||||
Title="MessageWindow">
|
||||
|
||||
</Window>
|
||||
12
Nebula.Launcher/MessageBox/MessageWindow.axaml.cs
Normal file
12
Nebula.Launcher/MessageBox/MessageWindow.axaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace Nebula.Launcher.MessageBox;
|
||||
|
||||
public partial class MessageWindow : Window
|
||||
{
|
||||
public MessageWindow(out IMessageContainerProvider provider)
|
||||
{
|
||||
InitializeComponent();
|
||||
Content = new MessageView(out provider);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
using Avalonia;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Avalonia;
|
||||
|
||||
namespace Nebula.Launcher;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
private static Mutex? _mutex;
|
||||
public static bool IsNewInstance;
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
_mutex = new Mutex(true, $"Global\\Nebula.Launcher", out IsNewInstance);
|
||||
BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
if (IsNewInstance)
|
||||
_mutex.ReleaseMutex();
|
||||
}
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
@@ -18,4 +27,5 @@ public static class Program
|
||||
.WithInterFont()
|
||||
.LogToTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.FileApis.Interfaces;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
|
||||
namespace Nebula.Launcher.Services;
|
||||
|
||||
@@ -25,10 +26,11 @@ public sealed partial class DecompilerService
|
||||
[GenerateProperty] private ContentService ContentService {get;}
|
||||
[GenerateProperty] private FileService FileService {get;}
|
||||
[GenerateProperty] private CancellationService CancellationService {get;}
|
||||
[GenerateProperty] private EngineService engineService {get;}
|
||||
[GenerateProperty] private DebugService debugService {get;}
|
||||
[GenerateProperty] private EngineService EngineService {get;}
|
||||
[GenerateProperty] private DebugService DebugService {get;}
|
||||
|
||||
private HttpClient _httpClient = new HttpClient();
|
||||
private ILogger _logger;
|
||||
|
||||
private static string fullPath = Path.Join(FileService.RootPath,"ILSpy");
|
||||
private static string executePath = Path.Join(fullPath, "ILSpy.exe");
|
||||
@@ -50,7 +52,7 @@ public sealed partial class DecompilerService
|
||||
|
||||
var buildInfo =
|
||||
await ContentService.GetBuildInfo(url, CancellationService.Token);
|
||||
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
|
||||
var engine = await EngineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion);
|
||||
|
||||
if (engine is null)
|
||||
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
|
||||
@@ -73,12 +75,15 @@ public sealed partial class DecompilerService
|
||||
|
||||
((IDisposable)loadingHandler).Dispose();
|
||||
|
||||
debugService.Log("File extracted. " + tmpDir);
|
||||
_logger.Log("File extracted. " + tmpDir);
|
||||
|
||||
OpenDecompiler(string.Join(' ', myTempDir.AllFiles.Select(f=>Path.Join(tmpDir, f))) + " --newinstance");
|
||||
}
|
||||
|
||||
private void Initialise(){}
|
||||
private void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
}
|
||||
private void InitialiseInDesignMode(){}
|
||||
|
||||
private async Task EnsureILSpy(){
|
||||
|
||||
@@ -10,6 +10,7 @@ using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
@@ -43,6 +44,8 @@ public partial class MainViewModel : ViewModelBase
|
||||
[GenerateProperty, DesignConstruct] private ViewHelperService ViewHelperService { get; } = default!;
|
||||
[GenerateProperty] private FileService FileService { get; } = default!;
|
||||
|
||||
private ILogger _logger;
|
||||
|
||||
public ObservableCollection<ListItemTemplate> Items { get; private set; }
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
@@ -53,6 +56,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
InitialiseInDesignMode();
|
||||
|
||||
PopupMessageService.OnPopupRequired += OnPopupRequired;
|
||||
@@ -160,7 +164,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
break;
|
||||
case Exception error:
|
||||
var err = ViewHelperService.GetViewModel<ExceptionListViewModel>();
|
||||
DebugService.Error(error);
|
||||
_logger.Error(error);
|
||||
err.AppendError(error);
|
||||
PopupMessage(err);
|
||||
break;
|
||||
|
||||
@@ -15,6 +15,7 @@ using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels.Pages;
|
||||
@@ -31,6 +32,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
[ObservableProperty] private string _searchText = "";
|
||||
|
||||
private ContentEntry? _selectedEntry;
|
||||
private ILogger _logger;
|
||||
[ObservableProperty] private string _serverText = "";
|
||||
[ObservableProperty] private ContentViewBase? _contentView;
|
||||
public bool IsCustomContenView => ContentView != null;
|
||||
@@ -69,7 +71,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
var myTempFile = Path.Combine(Path.GetTempPath(), "tempie" + ext);
|
||||
|
||||
if(TryGetContentViewer(ext, out var contentViewBase)){
|
||||
DebugService.Debug($"Opening custom context:{item.Value.Path}");
|
||||
_logger.Debug($"Opening custom context:{item.Value.Path}");
|
||||
contentViewBase.InitialiseWithData(value.GetPath(), stream, value);
|
||||
stream.Dispose();
|
||||
ContentView = contentViewBase;
|
||||
@@ -88,7 +90,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
};
|
||||
|
||||
|
||||
DebugService.Log("Opening " + myTempFile);
|
||||
_logger.Log("Opening " + myTempFile);
|
||||
Process.Start(startInfo);
|
||||
|
||||
return;
|
||||
@@ -122,6 +124,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
FillRoot(HubService.ServerList);
|
||||
|
||||
HubService.HubServerChangedEventArgs += HubServerChangedEventArgs;
|
||||
@@ -173,7 +176,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
|
||||
if (ServerText != SelectedEntry?.ServerName) SelectedEntry = await CreateEntry(ServerText);
|
||||
|
||||
DebugService.Debug("Going to:" + path.Path);
|
||||
_logger.Debug("Going to:" + path.Path);
|
||||
|
||||
var oriPath = path.Clone();
|
||||
try
|
||||
@@ -214,7 +217,7 @@ public sealed partial class ContentBrowserViewModel : ViewModelBase , IViewModel
|
||||
FileName = "explorer.exe",
|
||||
Arguments = tmpDir,
|
||||
};
|
||||
DebugService.Log("Opening " + tmpDir);
|
||||
_logger.Log("Opening " + tmpDir);
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Nebula.Launcher.ViewModels.Pages;
|
||||
using Nebula.Launcher.Views.Pages;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
using AddFavoriteView = Nebula.Launcher.Views.Popup.AddFavoriteView;
|
||||
|
||||
@@ -12,12 +13,15 @@ namespace Nebula.Launcher.ViewModels.Popup;
|
||||
[ConstructGenerator]
|
||||
public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
protected override void InitialiseInDesignMode()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
}
|
||||
|
||||
[GenerateProperty]
|
||||
@@ -41,7 +45,7 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
|
||||
catch (Exception e)
|
||||
{
|
||||
Error = e.Message;
|
||||
DebugService.Error(e);
|
||||
_logger.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ using Nebula.Launcher.ViewModels.Popup;
|
||||
using Nebula.Launcher.Views;
|
||||
using Nebula.Shared.Models;
|
||||
using Nebula.Shared.Services;
|
||||
using Nebula.Shared.Services.Logging;
|
||||
using Nebula.Shared.Utils;
|
||||
|
||||
namespace Nebula.Launcher.ViewModels;
|
||||
@@ -31,6 +32,8 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
private string _lastError = "";
|
||||
private Process? _p;
|
||||
private ILogger _logger;
|
||||
private ILogger? _processLogger;
|
||||
|
||||
private ServerInfo? _serverInfo;
|
||||
[ObservableProperty] private bool _tagDataVisible;
|
||||
@@ -89,7 +92,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
catch (Exception e)
|
||||
{
|
||||
Description = e.Message;
|
||||
DebugService.Error(e);
|
||||
_logger.Error(e);
|
||||
}
|
||||
|
||||
return _serverInfo;
|
||||
@@ -109,6 +112,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
|
||||
protected override void Initialise()
|
||||
{
|
||||
_logger = DebugService.GetLogger(this);
|
||||
CurrLog = ViewHelperService.GetViewModel<LogPopupModelView>();
|
||||
}
|
||||
|
||||
@@ -144,7 +148,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugService.Error(e);
|
||||
_logger.Error(e);
|
||||
Status = new ServerStatus("ErrorLand", $"ERROR: {e.Message}", [], "", -1, -1, -1, false,
|
||||
DateTime.Now,
|
||||
-1);
|
||||
@@ -211,6 +215,8 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
}
|
||||
|
||||
if (Process is null) return;
|
||||
|
||||
_processLogger = DebugService.GetLogger(buildInfo.BuildInfo.Build.Hash);
|
||||
|
||||
Process.EnableRaisingEvents = true;
|
||||
|
||||
@@ -240,11 +246,13 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
Process.ErrorDataReceived -= OnErrorDataReceived;
|
||||
Process.Exited -= OnExited;
|
||||
|
||||
DebugService.Log("PROCESS EXIT WITH CODE " + Process.ExitCode);
|
||||
_processLogger?.Log("PROCESS EXIT WITH CODE " + Process.ExitCode);
|
||||
|
||||
if (Process.ExitCode != 0)
|
||||
PopupMessageService.Popup($"Game exit with code {Process.ExitCode}.\nReason: {_lastError}");
|
||||
|
||||
_processLogger?.Dispose();
|
||||
|
||||
Process.Dispose();
|
||||
Process = null;
|
||||
}
|
||||
@@ -254,7 +262,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
if (e.Data != null)
|
||||
{
|
||||
_lastError = e.Data;
|
||||
DebugService.Error(e.Data);
|
||||
_processLogger?.Error(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +271,7 @@ public partial class ServerEntryModelView : ViewModelBase
|
||||
{
|
||||
if (e.Data != null)
|
||||
{
|
||||
DebugService.Log(e.Data);
|
||||
_processLogger?.Log(e.Data);
|
||||
CurrLog.Append(e.Data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user