Browse Source

added open log button

Veloe 2 years ago
parent
commit
f5c0479c06

+ 21 - 0
VeloeMinecraftLauncher/MinecraftLauncher/CaptureFilePathHook .cs

@@ -0,0 +1,21 @@
+using Serilog.Sinks.File;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VeloeMinecraftLauncher.MinecraftLauncher
+{
+    internal class CaptureFilePathHook : FileLifecycleHooks
+    {
+        public string? Path { get; private set; }
+
+        public override Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding)
+        {
+            Path = path;
+            return base.OnFileOpened(path, underlyingStream, encoding);
+        }
+    }
+}

+ 2 - 0
VeloeMinecraftLauncher/MinecraftLauncher/Settings.cs

@@ -1,4 +1,5 @@
 using Serilog.Events;
+using Serilog.Sinks.File;
 using System;
 using System.IO;
 using System.Linq;
@@ -20,6 +21,7 @@ internal static class Settings
     public static string username;
     public static string lastChosenVersion;
     public static Serilog.ILogger logger;
+    public static CaptureFilePathHook logFilePath;
     public static Serilog.ILogger avaloniaLogger;
     public static bool setMaxLog = false;
     public static UInt32 maxLog = 1024;

+ 4 - 4
VeloeMinecraftLauncher/ViewModels/MainWindowViewModel.cs

@@ -41,14 +41,14 @@ public class MainWindowViewModel : ViewModelBase
                 //creating logger
                 EventSink eventSink = new(null);
                 eventSink.DataReceived += LogHandler;
-
+                var hook = new CaptureFilePathHook();
                 _logger = new LoggerConfiguration()
                     .MinimumLevel.Debug()
-                    .WriteTo.Sink(eventSink , Settings.consoleLogEventLevel)
-                    .WriteTo.File("launcher.log", Settings.fileLogEventLevel, fileSizeLimitBytes: Settings.maxLog * 1024, rollOnFileSizeLimit: true)// restricted... is Optional
+                    .WriteTo.Sink(eventSink, Settings.consoleLogEventLevel)
+                    .WriteTo.File("launcher.log", Settings.fileLogEventLevel, fileSizeLimitBytes: Settings.maxLog * 1024, rollOnFileSizeLimit: true, hooks: hook)// restricted... is Optional
                     .CreateLogger();
                 Settings.logger = _logger;
-
+                Settings.logFilePath = hook;
                 //loading settings
                 _logger.Debug("Loading settings.");
                 Settings.LoadSettings();

+ 8 - 0
VeloeMinecraftLauncher/ViewModels/SettingsWindowViewModel.cs

@@ -226,4 +226,12 @@ public class SettingsWindowViewModel : ViewModelBase
             JavaPath = result[0];
         });
     }
+
+    public void OpenLogFile()
+    {
+        if (Path.Exists(Settings.logFilePath.Path))
+        {
+            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = Settings.logFilePath.Path, UseShellExecute = true });
+        }
+    }
 }

+ 1 - 0
VeloeMinecraftLauncher/Views/SettingsWindow.axaml

@@ -91,6 +91,7 @@
 						<TextBox Grid.Row="3" Grid.Column="1" Margin="5" Name="MaxLog" Text="{Binding MaxLog}" IsEnabled="{Binding SetMaxLog}" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBox>
 
 						<CheckBox Grid.Row="4" Grid.ColumnSpan="2" IsChecked="{Binding GameLogToLauncher}">Show game log in launcher (performace issues)</CheckBox>
+						<Button Grid.Row="5" Grid.ColumnSpan="2" Content="Open log" Command="{Binding OpenLogFile}"></Button>
 					</Grid>
 				</TabItem>