mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-15 07:00:32 +00:00
Fixed the home dir redaction code to take 8.3 paths into account
This commit is contained in:
parent
3e3eb365f8
commit
db68879351
2 changed files with 41 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
using Ryujinx.Common.Logging.Targets;
|
using Ryujinx.Common.Logging.Targets;
|
||||||
using Ryujinx.Common.SystemInterop;
|
using Ryujinx.Common.SystemInterop;
|
||||||
|
using Ryujinx.Common.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -24,6 +25,7 @@ namespace Ryujinx.Common.Logging
|
||||||
public readonly struct Log
|
public readonly struct Log
|
||||||
{
|
{
|
||||||
private static readonly string _homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
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]");
|
private static readonly string _homeDirRedacted = Path.Combine(Directory.GetParent(_homeDir).FullName, "[redacted]");
|
||||||
|
|
||||||
internal readonly LogLevel Level;
|
internal readonly LogLevel Level;
|
||||||
|
@ -106,6 +108,10 @@ namespace Ryujinx.Common.Logging
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static string FormatMessage(LogClass logClass, string caller, string message)
|
private static string FormatMessage(LogClass logClass, string caller, string message)
|
||||||
{
|
{
|
||||||
|
if (_homeDirShort != "")
|
||||||
|
{
|
||||||
|
message = message.Replace(_homeDirShort, _homeDirRedacted);
|
||||||
|
}
|
||||||
message = message.Replace(_homeDir, _homeDirRedacted);
|
message = message.Replace(_homeDir, _homeDirRedacted);
|
||||||
|
|
||||||
return $"{logClass} {caller}: {message}";
|
return $"{logClass} {caller}: {message}";
|
||||||
|
|
35
src/Ryujinx.Common/Utilities/WindowsNative.cs
Normal file
35
src/Ryujinx.Common/Utilities/WindowsNative.cs
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue