mirror of
https://github.com/sp-tarkov/launcher.git
synced 2025-02-12 14: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())
|
||||
{
|
||||
key.DeleteValue(value);
|
||||
LogManager.Instance.Debug($"Removing reg key: {key.Name}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -352,7 +351,6 @@ namespace SPT.Launcher
|
||||
{
|
||||
file.IsReadOnly = false;
|
||||
file.Delete();
|
||||
LogManager.Instance.Debug($" -> del file: {file.FullName}");
|
||||
}
|
||||
|
||||
// remove directory
|
||||
|
@ -20,16 +20,16 @@ namespace SPT.Launcher.Controllers
|
||||
private static LogManager _instance;
|
||||
public static LogManager Instance => _instance ??= new LogManager();
|
||||
private readonly string _filePath;
|
||||
private readonly string _logFile;
|
||||
public readonly string LogFile;
|
||||
|
||||
private LogManager()
|
||||
{
|
||||
_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 ====");
|
||||
@ -52,7 +52,7 @@ namespace SPT.Launcher.Controllers
|
||||
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}");
|
||||
|
@ -7,12 +7,14 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace SPT.Launcher.ViewModels
|
||||
@ -36,6 +38,64 @@ namespace SPT.Launcher.ViewModels
|
||||
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()
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktop)
|
||||
@ -55,40 +115,47 @@ namespace SPT.Launcher.ViewModels
|
||||
|
||||
public void CleanTempFilesCommand()
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Clearing temp files ...");
|
||||
bool filesCleared = gameStarter.CleanTempFiles();
|
||||
|
||||
if (filesCleared)
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Temp files cleared");
|
||||
SendNotification("", LocalizationProvider.Instance.clean_temp_files_succeeded, NotificationType.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Temp files failed to clear");
|
||||
SendNotification("", LocalizationProvider.Instance.clean_temp_files_failed, NotificationType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveRegistryKeysCommand()
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Removing registry keys ...");
|
||||
bool regKeysRemoved = gameStarter.RemoveRegistryKeys();
|
||||
|
||||
if (regKeysRemoved)
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Registry keys removed");
|
||||
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Registry keys failed to remove");
|
||||
SendNotification("", LocalizationProvider.Instance.remove_registry_keys_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
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 SPTSettingsFolder = Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings");
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -114,12 +181,14 @@ namespace SPT.Launcher.ViewModels
|
||||
SendNotification("", LocalizationProvider.Instance.load_live_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LogManager.Instance.Info("[Settings] Game settings reset to live settings");
|
||||
SendNotification("", LocalizationProvider.Instance.load_live_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
||||
}
|
||||
|
||||
public async Task ClearGameSettingsCommand()
|
||||
{
|
||||
LogManager.Instance.Info("[Settings] Clearing game settings ...");
|
||||
var SPTSettingsDir = new DirectoryInfo(Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings"));
|
||||
|
||||
try
|
||||
@ -134,7 +203,8 @@ namespace SPT.Launcher.ViewModels
|
||||
SendNotification("", LocalizationProvider.Instance.clear_game_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LogManager.Instance.Info("[Settings] Game settings cleared");
|
||||
SendNotification("", LocalizationProvider.Instance.clear_game_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);
|
||||
}
|
||||
|
||||
|
@ -12,29 +12,29 @@
|
||||
|
||||
<!-- Backdrop -->
|
||||
<Rectangle Fill="{DynamicResource BackgroundBrush}"
|
||||
Grid.RowSpan="7" Grid.ColumnSpan="5"
|
||||
Grid.RowSpan="8" Grid.ColumnSpan="5"
|
||||
Opacity=".7"
|
||||
/>
|
||||
<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}"
|
||||
Command="{Binding RemoveRegistryKeysCommand}"
|
||||
Classes="outlined"
|
||||
Margin="0 0 10 5"
|
||||
Classes="outlined" Margin="0 0 10 5"
|
||||
/>
|
||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=load_live_settings}"
|
||||
Command="{Binding ResetGameSettingsCommand}"
|
||||
Classes="outlined"
|
||||
Margin="0 0 10 5"
|
||||
Classes="outlined" Margin="0 0 10 5"
|
||||
/>
|
||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=clear_game_settings}"
|
||||
Command="{Binding ClearGameSettingsCommand}"
|
||||
Classes="outlined"
|
||||
Margin="0 0 10 5"
|
||||
Classes="outlined" Margin="0 0 10 5"
|
||||
/>
|
||||
<Button Content="{Binding Source={x:Static helpers:LocalizationProvider.Instance}, Path=clean_temp_files}"
|
||||
Command="{Binding CleanTempFilesCommand}"
|
||||
Classes="outlined"
|
||||
Margin="0 0 10 5"
|
||||
Classes="outlined" 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>
|
||||
|
||||
@ -68,9 +68,11 @@
|
||||
|
||||
<!-- Game Path -->
|
||||
<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}"
|
||||
Text="{Binding Source={x:Static helpers:LauncherSettingsProvider.Instance}, Path=GamePath}"
|
||||
VerticalContentAlignment="Center"
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
@ -101,6 +103,7 @@
|
||||
<Label Content="{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}"
|
||||
VerticalContentAlignment="Center"
|
||||
/>
|
||||
</StackPanel>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user