mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-27 11:03:04 +00:00
Fixed WindowsNative.GetShortPathName to use LibraryImport
Changed comparison method in FormatMessage to use string.IsNullOrEmpty
This commit is contained in:
parent
db68879351
commit
90de1e0fab
2 changed files with 6 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue