write debug log to seperate file
This commit is contained in:
parent
b2b64dcae0
commit
c2c1670ab2
@ -9,13 +9,16 @@ using SPTInstaller.ViewModels;
|
||||
using SPTInstaller.Views;
|
||||
using System.Reactive;
|
||||
using System.Text;
|
||||
using DynamicData;
|
||||
using SPTInstaller.Helpers;
|
||||
using SPTInstaller.Models;
|
||||
|
||||
namespace SPTInstaller;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public static string LogPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "spt-installer", "spt-installer.log");
|
||||
public static string LogDebugPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"spt-installer", "spt-isntaller-debug.log");
|
||||
|
||||
public static void ReLaunch(bool debug, string installPath = "")
|
||||
{
|
||||
@ -56,34 +59,38 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var debug = false;
|
||||
var data = ServiceHelper.Get<InternalData>() ?? throw new Exception("failed to get internal data");
|
||||
|
||||
data.DebugMode = false;
|
||||
var providedPath = "";
|
||||
|
||||
if (desktop.Args != null)
|
||||
{
|
||||
debug = desktop.Args.Any(x => x.ToLower() == "debug");
|
||||
data.DebugMode = desktop.Args.Any(x => x.ToLower() == "debug");
|
||||
var installPath = desktop.Args.FirstOrDefault(x => x.StartsWith("installPath=", StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
providedPath = installPath != null && installPath.Contains('=') ? installPath?.Split('=')[1] ?? "" : "";
|
||||
}
|
||||
|
||||
if (debug)
|
||||
if (data.DebugMode)
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo
|
||||
.File(path: LogPath,
|
||||
.File(path: LogDebugPath,
|
||||
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug)
|
||||
.CreateLogger();
|
||||
|
||||
System.Diagnostics.Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener());
|
||||
Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener());
|
||||
|
||||
Log.Debug("TraceListener is registered");
|
||||
}
|
||||
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel(providedPath, debug),
|
||||
DataContext = new MainWindowViewModel(providedPath),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ namespace SPTInstaller.Models;
|
||||
|
||||
public class InternalData
|
||||
{
|
||||
public bool DebugMode { get; set; } = false;
|
||||
/// <summary>
|
||||
/// The folder to install SPT into
|
||||
/// </summary>
|
||||
|
@ -10,8 +10,8 @@
|
||||
<PackageIcon>icon.ico</PackageIcon>
|
||||
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
|
||||
<Configurations>Debug;Release;TEST</Configurations>
|
||||
<AssemblyVersion>2.87</AssemblyVersion>
|
||||
<FileVersion>2.87</FileVersion>
|
||||
<AssemblyVersion>2.88</AssemblyVersion>
|
||||
<FileVersion>2.88</FileVersion>
|
||||
<Company>SPT</Company>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -13,7 +13,6 @@ namespace SPTInstaller.ViewModels;
|
||||
|
||||
public class InstallPathSelectionViewModel : ViewModelBase
|
||||
{
|
||||
private bool _debugging = false;
|
||||
private InternalData _data;
|
||||
|
||||
private string _selectedPath;
|
||||
@ -39,9 +38,8 @@ public class InstallPathSelectionViewModel : ViewModelBase
|
||||
set => this.RaiseAndSetIfChanged(ref _errorMessage, value);
|
||||
}
|
||||
|
||||
public InstallPathSelectionViewModel(IScreen host, string installPath, bool debugging) : base(host)
|
||||
public InstallPathSelectionViewModel(IScreen host, string installPath) : base(host)
|
||||
{
|
||||
_debugging = debugging;
|
||||
_data = ServiceHelper.Get<InternalData?>() ?? throw new Exception("Failed to get internal data");
|
||||
SelectedPath = Environment.CurrentDirectory;
|
||||
ValidPath = false;
|
||||
@ -154,6 +152,6 @@ public class InstallPathSelectionViewModel : ViewModelBase
|
||||
|
||||
_data.TargetInstallPath = SelectedPath;
|
||||
|
||||
NavigateTo(new PreChecksViewModel(HostScreen, _debugging));
|
||||
NavigateTo(new PreChecksViewModel(HostScreen));
|
||||
}
|
||||
}
|
@ -12,11 +12,9 @@ public class InstallerUpdateViewModel : ViewModelBase
|
||||
public InstallerUpdateInfo UpdateInfo { get; set; } = new();
|
||||
private InternalData _data;
|
||||
|
||||
private bool _debugging;
|
||||
private string _installPath;
|
||||
public InstallerUpdateViewModel(IScreen Host, string installPath, bool debugging) : base(Host)
|
||||
public InstallerUpdateViewModel(IScreen Host, string installPath) : base(Host)
|
||||
{
|
||||
_debugging = debugging;
|
||||
_installPath = installPath;
|
||||
|
||||
_data = ServiceHelper.Get<InternalData>() ?? throw new Exception("Failed to get internal data");
|
||||
@ -27,14 +25,14 @@ public class InstallerUpdateViewModel : ViewModelBase
|
||||
|
||||
if (!UpdateInfo.UpdateAvailable)
|
||||
{
|
||||
NavigateTo(new OverviewViewModel(HostScreen, _installPath, _debugging));
|
||||
NavigateTo(new OverviewViewModel(HostScreen, _installPath));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void NotNowCommand()
|
||||
{
|
||||
NavigateTo(new OverviewViewModel(HostScreen, _installPath, _debugging));
|
||||
NavigateTo(new OverviewViewModel(HostScreen, _installPath));
|
||||
}
|
||||
|
||||
public async Task UpdateInstallCommand()
|
||||
|
@ -3,6 +3,8 @@ using ReactiveUI;
|
||||
using Serilog;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using SPTInstaller.Helpers;
|
||||
using SPTInstaller.Models;
|
||||
|
||||
namespace SPTInstaller.ViewModels;
|
||||
|
||||
@ -19,10 +21,12 @@ public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScree
|
||||
set => this.RaiseAndSetIfChanged(ref _title, value);
|
||||
}
|
||||
|
||||
public MainWindowViewModel(string installPath, bool debugging)
|
||||
public MainWindowViewModel(string installPath)
|
||||
{
|
||||
var data = ServiceHelper.Get<InternalData>() ?? throw new Exception("failed to get interanl data");
|
||||
|
||||
Title =
|
||||
$"{(debugging ? "-debug-" : "")} SPT Installer {"v" + Assembly.GetExecutingAssembly().GetName()?.Version?.ToString() ?? "--unknown version--"}";
|
||||
$"{(data.DebugMode ? "-debug-" : "")} SPT Installer {"v" + Assembly.GetExecutingAssembly().GetName()?.Version?.ToString() ?? "--unknown version--"}";
|
||||
|
||||
Log.Information($"========= {Title} Started =========");
|
||||
Log.Information(Environment.OSVersion.VersionString);
|
||||
@ -31,7 +35,7 @@ public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScree
|
||||
|
||||
Log.Information("System Language: {iso} - {name}", uiCulture.TwoLetterISOLanguageName, uiCulture.DisplayName);
|
||||
|
||||
Router.Navigate.Execute(new InstallerUpdateViewModel(this, installPath, debugging));
|
||||
Router.Navigate.Execute(new InstallerUpdateViewModel(this, installPath));
|
||||
}
|
||||
|
||||
public void CloseCommand()
|
||||
|
@ -80,6 +80,8 @@ public class MessageViewModel : ViewModelBase
|
||||
|
||||
public ICommand CopyLogFileToClipboard => ReactiveCommand.CreateFromTask(async () =>
|
||||
{
|
||||
var data = ServiceHelper.Get<InternalData>();
|
||||
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
try
|
||||
@ -91,7 +93,7 @@ public class MessageViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
var dataObject = new DataObject();
|
||||
var logFile = await desktop.MainWindow.StorageProvider.TryGetFileFromPathAsync(App.LogPath);
|
||||
var logFile = await desktop.MainWindow.StorageProvider.TryGetFileFromPathAsync(data.DebugMode ? App.LogDebugPath : App.LogPath);
|
||||
|
||||
if (logFile == null)
|
||||
{
|
||||
|
@ -6,11 +6,9 @@ namespace SPTInstaller.ViewModels;
|
||||
public class OverviewViewModel : ViewModelBase
|
||||
{
|
||||
private string _providedPath;
|
||||
private bool _debugging;
|
||||
public OverviewViewModel(IScreen Host, string providedPath, bool debugging) : base(Host)
|
||||
public OverviewViewModel(IScreen Host, string providedPath) : base(Host)
|
||||
{
|
||||
_providedPath = providedPath;
|
||||
_debugging = debugging;
|
||||
|
||||
if (!string.IsNullOrEmpty(_providedPath))
|
||||
{
|
||||
@ -20,6 +18,6 @@ public class OverviewViewModel : ViewModelBase
|
||||
|
||||
public void NextCommand()
|
||||
{
|
||||
NavigateTo(new InstallPathSelectionViewModel(HostScreen, _providedPath, _debugging));
|
||||
NavigateTo(new InstallPathSelectionViewModel(HostScreen, _providedPath));
|
||||
}
|
||||
}
|
@ -109,12 +109,13 @@ public class PreChecksViewModel : ViewModelBase
|
||||
});
|
||||
}
|
||||
|
||||
public PreChecksViewModel(IScreen host, bool debugging) : base(host)
|
||||
public PreChecksViewModel(IScreen host) : base(host)
|
||||
{
|
||||
Debugging = debugging;
|
||||
var data = ServiceHelper.Get<InternalData?>();
|
||||
var installer = ServiceHelper.Get<InstallController?>();
|
||||
|
||||
Debugging = data.DebugMode;
|
||||
|
||||
installer.RecheckRequested += ReCheckRequested;
|
||||
|
||||
InstallButtonText = "Please wait ...";
|
||||
|
Loading…
x
Reference in New Issue
Block a user