mirror of
https://github.com/sp-tarkov/launcher.git
synced 2025-02-12 17:10:44 -05:00
add copy logs command
This commit is contained in:
parent
e58c76892b
commit
7a3079a4c8
@ -300,7 +300,6 @@ namespace SPT.Launcher
|
|||||||
foreach (var value in key.GetValueNames())
|
foreach (var value in key.GetValueNames())
|
||||||
{
|
{
|
||||||
key.DeleteValue(value);
|
key.DeleteValue(value);
|
||||||
LogManager.Instance.Debug($"Removing reg key: {key.Name}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -352,7 +351,6 @@ namespace SPT.Launcher
|
|||||||
{
|
{
|
||||||
file.IsReadOnly = false;
|
file.IsReadOnly = false;
|
||||||
file.Delete();
|
file.Delete();
|
||||||
LogManager.Instance.Debug($" -> del file: {file.FullName}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove directory
|
// remove directory
|
||||||
|
@ -20,16 +20,16 @@ namespace SPT.Launcher.Controllers
|
|||||||
private static LogManager _instance;
|
private static LogManager _instance;
|
||||||
public static LogManager Instance => _instance ??= new LogManager();
|
public static LogManager Instance => _instance ??= new LogManager();
|
||||||
private readonly string _filePath;
|
private readonly string _filePath;
|
||||||
private readonly string _logFile;
|
public readonly string LogFile;
|
||||||
|
|
||||||
private LogManager()
|
private LogManager()
|
||||||
{
|
{
|
||||||
_filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "user", "logs");
|
_filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "user", "logs");
|
||||||
_logFile = Path.Combine(_filePath, "launcher.log");
|
LogFile = Path.Combine(_filePath, "launcher.log");
|
||||||
|
|
||||||
if (File.Exists(_logFile))
|
if (File.Exists(LogFile))
|
||||||
{
|
{
|
||||||
File.Delete(_logFile);
|
File.Delete(LogFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
Write($" ==== Launcher Started ====");
|
Write($" ==== Launcher Started ====");
|
||||||
@ -52,7 +52,7 @@ namespace SPT.Launcher.Controllers
|
|||||||
Directory.CreateDirectory(_filePath);
|
Directory.CreateDirectory(_filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
File.AppendAllLines(_logFile, new[] { $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]{GetDevModeTag()}{text}" });
|
File.AppendAllLines(LogFile, new[] { $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]{GetDevModeTag()}{text}" });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Debug(string text) => Write($"[Debug] {text}");
|
public void Debug(string text) => Write($"[Debug] {text}");
|
||||||
|
@ -7,12 +7,14 @@ using Avalonia;
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Controls.Notifications;
|
using Avalonia.Controls.Notifications;
|
||||||
|
using Avalonia.Input;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
|
||||||
namespace SPT.Launcher.ViewModels
|
namespace SPT.Launcher.ViewModels
|
||||||
@ -36,6 +38,64 @@ namespace SPT.Launcher.ViewModels
|
|||||||
LauncherSettingsProvider.Instance.SaveSettings();
|
LauncherSettingsProvider.Instance.SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task CopyLogsToClipboard()
|
||||||
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Copying logs to clipboard ...");
|
||||||
|
|
||||||
|
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
{
|
||||||
|
if (desktop.MainWindow?.Clipboard == null)
|
||||||
|
{
|
||||||
|
LogManager.Instance.Error("[Settings] Failed to get clipboard");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var traceLogs = Directory.GetFiles(Path.Join(LauncherSettingsProvider.Instance.GamePath, "Logs"), $"{DateTime.Now:yyyy.MM.dd}_* traces.log", SearchOption.AllDirectories);
|
||||||
|
|
||||||
|
var traceLog = traceLogs.Length > 0 ? traceLogs[0] : "";
|
||||||
|
|
||||||
|
var filesToCopy = new string[]
|
||||||
|
{
|
||||||
|
Path.Join(LauncherSettingsProvider.Instance.GamePath, @"\user\logs", $"server-{DateTime.Now:yyyy-MM-dd}.log"),
|
||||||
|
traceLog,
|
||||||
|
Path.Join(LauncherSettingsProvider.Instance.GamePath, @"BepInEx\LogOutput.log"),
|
||||||
|
Path.Join(LauncherSettingsProvider.Instance.GamePath, @"\user\profiles", $"{AccountManager.SelectedAccount.id}.json"),
|
||||||
|
LogManager.Instance.LogFile,
|
||||||
|
};
|
||||||
|
|
||||||
|
List<IStorageFile> files = new List<IStorageFile>();
|
||||||
|
|
||||||
|
foreach (var logPath in filesToCopy)
|
||||||
|
{
|
||||||
|
var file = await desktop.MainWindow.StorageProvider.TryGetFileFromPathAsync(logPath);
|
||||||
|
|
||||||
|
if (file != null)
|
||||||
|
{
|
||||||
|
LogManager.Instance.Debug($"file to copy :: {logPath}");
|
||||||
|
files.Add(file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager.Instance.Warning($"failed to get file to copy :: {logPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.Count == 0)
|
||||||
|
{
|
||||||
|
LogManager.Instance.Warning("[Settings] Failed to copy log files");
|
||||||
|
SendNotification("", LocalizationProvider.Instance.copy_failed);
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = new DataObject();
|
||||||
|
|
||||||
|
data.Set(DataFormats.Files, files.ToArray());
|
||||||
|
|
||||||
|
await desktop.MainWindow.Clipboard.SetDataObjectAsync(data);
|
||||||
|
|
||||||
|
LogManager.Instance.Info($"[Settings] {files.Count} log/s copied to clipboard");
|
||||||
|
SendNotification("", $"{files.Count} {LocalizationProvider.Instance.copied}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void GoBackCommand()
|
public void GoBackCommand()
|
||||||
{
|
{
|
||||||
if (Application.Current?.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
if (Application.Current?.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
@ -55,40 +115,47 @@ namespace SPT.Launcher.ViewModels
|
|||||||
|
|
||||||
public void CleanTempFilesCommand()
|
public void CleanTempFilesCommand()
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Clearing temp files ...");
|
||||||
bool filesCleared = gameStarter.CleanTempFiles();
|
bool filesCleared = gameStarter.CleanTempFiles();
|
||||||
|
|
||||||
if (filesCleared)
|
if (filesCleared)
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Temp files cleared");
|
||||||
SendNotification("", LocalizationProvider.Instance.clean_temp_files_succeeded, NotificationType.Success);
|
SendNotification("", LocalizationProvider.Instance.clean_temp_files_succeeded, NotificationType.Success);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Temp files failed to clear");
|
||||||
SendNotification("", LocalizationProvider.Instance.clean_temp_files_failed, NotificationType.Error);
|
SendNotification("", LocalizationProvider.Instance.clean_temp_files_failed, NotificationType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRegistryKeysCommand()
|
public void RemoveRegistryKeysCommand()
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Removing registry keys ...");
|
||||||
bool regKeysRemoved = gameStarter.RemoveRegistryKeys();
|
bool regKeysRemoved = gameStarter.RemoveRegistryKeys();
|
||||||
|
|
||||||
if (regKeysRemoved)
|
if (regKeysRemoved)
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Registry keys removed");
|
||||||
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Registry keys failed to remove");
|
||||||
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ResetGameSettingsCommand()
|
public async Task ResetGameSettingsCommand()
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Reseting game settings ...");
|
||||||
string EFTSettingsFolder = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Battlestate Games", "Escape from Tarkov", "Settings");
|
string EFTSettingsFolder = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Battlestate Games", "Escape from Tarkov", "Settings");
|
||||||
string SPTSettingsFolder = Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings");
|
string SPTSettingsFolder = Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings");
|
||||||
|
|
||||||
if (!Directory.Exists(EFTSettingsFolder))
|
if (!Directory.Exists(EFTSettingsFolder))
|
||||||
{
|
{
|
||||||
LogManager.Instance.Warning($"EFT settings folder not found, can't reset :: Path: {EFTSettingsFolder}");
|
LogManager.Instance.Warning($"[Settings] EFT settings folder not found, can't reset :: Path: {EFTSettingsFolder}");
|
||||||
SendNotification("", LocalizationProvider.Instance.load_live_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
SendNotification("", LocalizationProvider.Instance.load_live_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -114,12 +181,14 @@ namespace SPT.Launcher.ViewModels
|
|||||||
SendNotification("", LocalizationProvider.Instance.load_live_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
SendNotification("", LocalizationProvider.Instance.load_live_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogManager.Instance.Info("[Settings] Game settings reset to live settings");
|
||||||
SendNotification("", LocalizationProvider.Instance.load_live_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
SendNotification("", LocalizationProvider.Instance.load_live_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ClearGameSettingsCommand()
|
public async Task ClearGameSettingsCommand()
|
||||||
{
|
{
|
||||||
|
LogManager.Instance.Info("[Settings] Clearing game settings ...");
|
||||||
var SPTSettingsDir = new DirectoryInfo(Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings"));
|
var SPTSettingsDir = new DirectoryInfo(Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings"));
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -134,7 +203,8 @@ namespace SPT.Launcher.ViewModels
|
|||||||
SendNotification("", LocalizationProvider.Instance.clear_game_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
SendNotification("", LocalizationProvider.Instance.clear_game_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogManager.Instance.Info("[Settings] Game settings cleared");
|
||||||
SendNotification("", LocalizationProvider.Instance.clear_game_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
SendNotification("", LocalizationProvider.Instance.clear_game_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,29 +12,29 @@
|
|||||||
|
|
||||||
<!-- Backdrop -->
|
<!-- Backdrop -->
|
||||||
<Rectangle Fill="{DynamicResource BackgroundBrush}"
|
<Rectangle Fill="{DynamicResource BackgroundBrush}"
|
||||||
Grid.RowSpan="7" Grid.ColumnSpan="5"
|
Grid.RowSpan="8" Grid.ColumnSpan="5"
|
||||||
Opacity=".7"
|
Opacity=".7"
|
||||||
/>
|
/>
|
||||||
<WrapPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal">
|
<WrapPanel Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal">
|
||||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=remove_registry_keys}"
|
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=remove_registry_keys}"
|
||||||
Command="{Binding RemoveRegistryKeysCommand}"
|
Command="{Binding RemoveRegistryKeysCommand}"
|
||||||
Classes="outlined"
|
Classes="outlined" Margin="0 0 10 5"
|
||||||
Margin="0 0 10 5"
|
|
||||||
/>
|
/>
|
||||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=load_live_settings}"
|
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=load_live_settings}"
|
||||||
Command="{Binding ResetGameSettingsCommand}"
|
Command="{Binding ResetGameSettingsCommand}"
|
||||||
Classes="outlined"
|
Classes="outlined" Margin="0 0 10 5"
|
||||||
Margin="0 0 10 5"
|
|
||||||
/>
|
/>
|
||||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=clear_game_settings}"
|
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=clear_game_settings}"
|
||||||
Command="{Binding ClearGameSettingsCommand}"
|
Command="{Binding ClearGameSettingsCommand}"
|
||||||
Classes="outlined"
|
Classes="outlined" Margin="0 0 10 5"
|
||||||
Margin="0 0 10 5"
|
|
||||||
/>
|
/>
|
||||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=clean_temp_files}"
|
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=clean_temp_files}"
|
||||||
Command="{Binding CleanTempFilesCommand}"
|
Command="{Binding CleanTempFilesCommand}"
|
||||||
Classes="outlined"
|
Classes="outlined" Margin="0 0 10 5"
|
||||||
Margin="0 0 10 5"
|
/>
|
||||||
|
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=copy_logs_to_clipboard}"
|
||||||
|
Command="{Binding CopyLogsToClipboard}"
|
||||||
|
Classes="outlined" Margin="0 0 10 5"
|
||||||
/>
|
/>
|
||||||
</WrapPanel>
|
</WrapPanel>
|
||||||
|
|
||||||
@ -68,9 +68,11 @@
|
|||||||
|
|
||||||
<!-- Game Path -->
|
<!-- Game Path -->
|
||||||
<StackPanel Grid.Row="5" Grid.Column="1" Margin="0 10 10 10" IsEnabled="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=IsDevMode}">
|
<StackPanel Grid.Row="5" Grid.Column="1" Margin="0 10 10 10" IsEnabled="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=IsDevMode}">
|
||||||
<Label Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=game_path}"/>
|
<Label Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=game_path}"
|
||||||
|
/>
|
||||||
<TextBox Watermark="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=game_path}"
|
<TextBox Watermark="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=game_path}"
|
||||||
Text="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=GamePath}"
|
Text="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=GamePath}"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
/>
|
/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
@ -101,6 +103,7 @@
|
|||||||
<Label Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=url}"/>
|
<Label Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=url}"/>
|
||||||
<TextBox Watermark="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=url}"
|
<TextBox Watermark="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=url}"
|
||||||
Text="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=Server.Url}"
|
Text="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=Server.Url}"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
/>
|
/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user