diff --git a/src/Ryujinx.Common/Logging/Logger.cs b/src/Ryujinx.Common/Logging/Logger.cs index db46739ac3..166a572ab5 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 (!string.IsNullOrEmpty(_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..125d5e2586 --- /dev/null +++ b/src/Ryujinx.Common/Utilities/WindowsNative.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +namespace Ryujinx.Common.Utilities +{ + public static partial class WindowsNative + { + [SupportedOSPlatform("windows")] + [LibraryImport("kernel32.dll", StringMarshalling = StringMarshalling.Utf16, SetLastError = true)] + internal static partial int GetShortPathNameW(string longPath, char[] shortPath, int bufferSize); + + private const int ShortPathBufferLength = 256; + + public static string GetShortPathName(string longPath) + { + if (!OperatingSystem.IsWindows()) + { + return ""; + } + + char[] shortPathBuffer = new char[ShortPathBufferLength]; + int result = GetShortPathNameW(longPath, shortPathBuffer, shortPathBuffer.Length); + if (result == 0) + { + int errCode = Marshal.GetLastWin32Error(); + Logging.Logger.Debug?.Print(Logging.LogClass.Application, $"GetShortPathName failed for {longPath} (0x{errCode:X08})"); + return ""; + } + + return new string(shortPathBuffer[..result]); + } + } +} 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(); diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index 4f68ca24f0..e6555ee961 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();