From 8d313d9634bc9716001c8b2cb79c82cc4ef1337a Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 13 Jun 2024 01:20:17 +0200 Subject: [PATCH 1/5] Added a log message containing the executable's path --- src/Ryujinx/Program.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 4f68ca24f0..812e53d8cb 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -211,6 +211,16 @@ namespace Ryujinx.Ava private static void PrintSystemInfo() { + string executablePath = Environment.ProcessPath; + if (executablePath != null) + { + Logger.Notice.Print(LogClass.Application, $"Ryujinx Path: {executablePath}"); + } + else + { + Logger.Warning?.Print(LogClass.Application, "Can't determine executable path. It might have been renamed or deleted after launch."); + } + Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}"); SystemInfo.Gather().Print(); From 1e6c1f12367a0e654228c0cf2319afe761cc6ad6 Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 13 Jun 2024 01:26:50 +0200 Subject: [PATCH 2/5] Removed stray trailing space --- src/Ryujinx/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 812e53d8cb..e6555ee961 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -215,7 +215,7 @@ namespace Ryujinx.Ava if (executablePath != null) { Logger.Notice.Print(LogClass.Application, $"Ryujinx Path: {executablePath}"); - } + } else { Logger.Warning?.Print(LogClass.Application, "Can't determine executable path. It might have been renamed or deleted after launch."); From 3e3eb365f8cda6ce43b42960e17ce3b60329e985 Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 13 Jun 2024 02:40:50 +0200 Subject: [PATCH 3/5] Added log message to GTK version too --- src/Ryujinx.Gtk3/Program.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Ryujinx.Gtk3/Program.cs b/src/Ryujinx.Gtk3/Program.cs index 749cb69786..93238451bf 100644 --- a/src/Ryujinx.Gtk3/Program.cs +++ b/src/Ryujinx.Gtk3/Program.cs @@ -338,6 +338,16 @@ namespace Ryujinx private static void PrintSystemInfo() { + string executablePath = Environment.ProcessPath; + if (executablePath != null) + { + Logger.Notice.Print(LogClass.Application, $"Ryujinx Path: {executablePath}"); + } + else + { + Logger.Warning?.Print(LogClass.Application, "Can't determine executable path. It might have been renamed or deleted after launch."); + } + Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}"); SystemInfo.Gather().Print(); From db688793518f5ff4c7c33327702e6af07f9f8fcf Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 13 Jun 2024 04:36:25 +0200 Subject: [PATCH 4/5] Fixed the home dir redaction code to take 8.3 paths into account --- src/Ryujinx.Common/Logging/Logger.cs | 6 ++++ src/Ryujinx.Common/Utilities/WindowsNative.cs | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/Ryujinx.Common/Utilities/WindowsNative.cs diff --git a/src/Ryujinx.Common/Logging/Logger.cs b/src/Ryujinx.Common/Logging/Logger.cs index db46739ac3..2f1e842f5f 100644 --- a/src/Ryujinx.Common/Logging/Logger.cs +++ b/src/Ryujinx.Common/Logging/Logger.cs @@ -1,5 +1,6 @@ using Ryujinx.Common.Logging.Targets; using Ryujinx.Common.SystemInterop; +using Ryujinx.Common.Utilities; using System; using System.Collections.Generic; using System.Diagnostics; @@ -24,6 +25,7 @@ namespace Ryujinx.Common.Logging public readonly struct Log { private static readonly string _homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + private static readonly string _homeDirShort = WindowsNative.GetShortPathName(_homeDir); // empty string on non-windows platforms private static readonly string _homeDirRedacted = Path.Combine(Directory.GetParent(_homeDir).FullName, "[redacted]"); internal readonly LogLevel Level; @@ -106,6 +108,10 @@ namespace Ryujinx.Common.Logging [MethodImpl(MethodImplOptions.AggressiveInlining)] private static string FormatMessage(LogClass logClass, string caller, string message) { + if (_homeDirShort != "") + { + message = message.Replace(_homeDirShort, _homeDirRedacted); + } message = message.Replace(_homeDir, _homeDirRedacted); return $"{logClass} {caller}: {message}"; diff --git a/src/Ryujinx.Common/Utilities/WindowsNative.cs b/src/Ryujinx.Common/Utilities/WindowsNative.cs new file mode 100644 index 0000000000..98e6d04346 --- /dev/null +++ b/src/Ryujinx.Common/Utilities/WindowsNative.cs @@ -0,0 +1,35 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Text; + +namespace Ryujinx.Common.Utilities +{ + public static partial class WindowsNative + { + [SupportedOSPlatform("windows")] + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + static extern int GetShortPathName(string longPath, StringBuilder shortPath, int bufferSize); + + private const int ShortPathBufferLength = 256; + + public static string GetShortPathName(string longPath) + { + if (!OperatingSystem.IsWindows()) + { + return ""; + } + + StringBuilder shortPathBuffer = new StringBuilder(ShortPathBufferLength); + int result = GetShortPathName(longPath, shortPathBuffer, ShortPathBufferLength); + if (result == 0) + { + int errCode = Marshal.GetLastWin32Error(); + Logging.Logger.Debug?.Print(Logging.LogClass.Application, $"GetShortPathName failed for {longPath} (0x{errCode:X08})"); + return ""; + } + + return shortPathBuffer.ToString(); + } + } +} From 90de1e0fab685b13647dcab1b1ae6fea30e8c83f Mon Sep 17 00:00:00 2001 From: Emma Alyx Wunder Date: Thu, 27 Jun 2024 23:46:27 +0200 Subject: [PATCH 5/5] Fixed WindowsNative.GetShortPathName to use LibraryImport Changed comparison method in FormatMessage to use string.IsNullOrEmpty --- src/Ryujinx.Common/Logging/Logger.cs | 2 +- src/Ryujinx.Common/Utilities/WindowsNative.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Common/Logging/Logger.cs b/src/Ryujinx.Common/Logging/Logger.cs index 2f1e842f5f..166a572ab5 100644 --- a/src/Ryujinx.Common/Logging/Logger.cs +++ b/src/Ryujinx.Common/Logging/Logger.cs @@ -108,7 +108,7 @@ namespace Ryujinx.Common.Logging [MethodImpl(MethodImplOptions.AggressiveInlining)] private static string FormatMessage(LogClass logClass, string caller, string message) { - if (_homeDirShort != "") + if (!string.IsNullOrEmpty(_homeDirShort)) { message = message.Replace(_homeDirShort, _homeDirRedacted); } diff --git a/src/Ryujinx.Common/Utilities/WindowsNative.cs b/src/Ryujinx.Common/Utilities/WindowsNative.cs index 98e6d04346..125d5e2586 100644 --- a/src/Ryujinx.Common/Utilities/WindowsNative.cs +++ b/src/Ryujinx.Common/Utilities/WindowsNative.cs @@ -1,15 +1,14 @@ using System; using System.Runtime.InteropServices; using System.Runtime.Versioning; -using System.Text; namespace Ryujinx.Common.Utilities { public static partial class WindowsNative { [SupportedOSPlatform("windows")] - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - static extern int GetShortPathName(string longPath, StringBuilder shortPath, int bufferSize); + [LibraryImport("kernel32.dll", StringMarshalling = StringMarshalling.Utf16, SetLastError = true)] + internal static partial int GetShortPathNameW(string longPath, char[] shortPath, int bufferSize); private const int ShortPathBufferLength = 256; @@ -20,8 +19,8 @@ namespace Ryujinx.Common.Utilities return ""; } - StringBuilder shortPathBuffer = new StringBuilder(ShortPathBufferLength); - int result = GetShortPathName(longPath, shortPathBuffer, ShortPathBufferLength); + char[] shortPathBuffer = new char[ShortPathBufferLength]; + int result = GetShortPathNameW(longPath, shortPathBuffer, shortPathBuffer.Length); if (result == 0) { int errCode = Marshal.GetLastWin32Error(); @@ -29,7 +28,7 @@ namespace Ryujinx.Common.Utilities return ""; } - return shortPathBuffer.ToString(); + return new string(shortPathBuffer[..result]); } } }