From 4505a7f162b2e7920d64ddfe2a70c4da6d8f9118 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Tue, 30 Jan 2024 17:52:45 +0100 Subject: [PATCH] Fix opening the wrong log directory (#6220) --- src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs | 4 ++-- src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs | 2 +- src/Ryujinx.Headless.SDL2/Program.cs | 4 ++-- src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs | 11 +++++++++-- src/Ryujinx/Ui/MainWindow.cs | 4 ++-- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs index dff5b59b..2caee16c 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/MainWindowViewModel.cs @@ -1352,9 +1352,9 @@ namespace Ryujinx.Ava.UI.ViewModels { string logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"); - if (ReleaseInformation.IsValid) + if (LoggerModule.LogDirectoryPath != null) { - logPath = Path.Combine(AppDataManager.BaseDirPath, "Logs"); + logPath = LoggerModule.LogDirectoryPath; } new DirectoryInfo(logPath).Create(); diff --git a/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs b/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs index c40c3abe..a4e8f714 100644 --- a/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs +++ b/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Common.Logging.Targets public static FileStream PrepareLogFile(string path) { // Ensure directory is present - DirectoryInfo logDir = new(Path.Combine(path, "Logs")); + DirectoryInfo logDir = new(path); try { logDir.Create(); diff --git a/src/Ryujinx.Headless.SDL2/Program.cs b/src/Ryujinx.Headless.SDL2/Program.cs index 6eaa1b86..c2300275 100644 --- a/src/Ryujinx.Headless.SDL2/Program.cs +++ b/src/Ryujinx.Headless.SDL2/Program.cs @@ -427,11 +427,11 @@ namespace Ryujinx.Headless.SDL2 if (!option.DisableFileLog) { - FileStream logFile = FileLogTarget.PrepareLogFile(AppDomain.CurrentDomain.BaseDirectory); + FileStream logFile = FileLogTarget.PrepareLogFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs")); if (logFile == null) { - logFile = FileLogTarget.PrepareLogFile(AppDataManager.BaseDirPath); + logFile = FileLogTarget.PrepareLogFile(Path.Combine(AppDataManager.BaseDirPath, "Logs")); if (logFile == null) { diff --git a/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs b/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs index 6cd63272..f22ee83a 100644 --- a/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs +++ b/src/Ryujinx.Ui.Common/Configuration/LoggerModule.cs @@ -9,6 +9,8 @@ namespace Ryujinx.Ui.Common.Configuration { public static class LoggerModule { + public static string LogDirectoryPath { get; private set; } + public static void Initialize() { ConfigurationState.Instance.Logger.EnableDebug.Event += ReloadEnableDebug; @@ -82,21 +84,26 @@ namespace Ryujinx.Ui.Common.Configuration { if (e.NewValue) { - FileStream logFile = FileLogTarget.PrepareLogFile(AppDomain.CurrentDomain.BaseDirectory); + string logDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"); + FileStream logFile = FileLogTarget.PrepareLogFile(logDir); if (logFile == null) { - logFile = FileLogTarget.PrepareLogFile(AppDataManager.BaseDirPath); + logDir = Path.Combine(AppDataManager.BaseDirPath, "Logs"); + logFile = FileLogTarget.PrepareLogFile(logDir); if (logFile == null) { Logger.Error?.Print(LogClass.Application, "No writable log directory available. Make sure either the application directory or the Ryujinx directory is writable."); + LogDirectoryPath = null; Logger.RemoveTarget("file"); return; } } + LogDirectoryPath = logDir; + Logger.AddTarget(new AsyncLogTargetWrapper( new FileLogTarget("file", logFile), 1000, diff --git a/src/Ryujinx/Ui/MainWindow.cs b/src/Ryujinx/Ui/MainWindow.cs index 3cd2b0eb..1ecbb9ea 100644 --- a/src/Ryujinx/Ui/MainWindow.cs +++ b/src/Ryujinx/Ui/MainWindow.cs @@ -1378,9 +1378,9 @@ namespace Ryujinx.Ui { string logPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"); - if (ReleaseInformation.IsValid) + if (LoggerModule.LogDirectoryPath != null) { - logPath = System.IO.Path.Combine(AppDataManager.BaseDirPath, "Logs"); + logPath = LoggerModule.LogDirectoryPath; } new DirectoryInfo(logPath).Create();