From fe179ad726c70925153f102fb526880abe882541 Mon Sep 17 00:00:00 2001 From: Meivyn <793322+Meivyn@users.noreply.github.com> Date: Mon, 20 Feb 2023 00:41:42 -0500 Subject: [PATCH] Revert "Use the SafeHandle wrapper instead" This reverts commit 083181060ef03892a32d98fec5ab5fee394a4ae8. --- IPA.Loader/Logging/StdoutInterceptorPipes.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/IPA.Loader/Logging/StdoutInterceptorPipes.cs b/IPA.Loader/Logging/StdoutInterceptorPipes.cs index 4409c5dd..3d484a98 100644 --- a/IPA.Loader/Logging/StdoutInterceptorPipes.cs +++ b/IPA.Loader/Logging/StdoutInterceptorPipes.cs @@ -1,6 +1,7 @@ using System; using System.IO.Pipes; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Text; using System.Threading; @@ -35,7 +36,7 @@ namespace IPA.Logging { return new Thread(() => { - var pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.In); + NamedPipeServerStream pipeServer = new(pipeName, PipeDirection.In); try { @@ -67,14 +68,14 @@ namespace IPA.Logging { return new Thread(() => { - var pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.Out); + NamedPipeClientStream pipeClient = new(".", pipeName, PipeDirection.Out); try { // If the client starts first, blocks the client thread. manualResetEvent.Wait(); pipeClient.Connect(); - SetStdHandle(stdHandle, pipeClient.SafePipeHandle); + SetStdHandle(stdHandle, pipeClient.SafePipeHandle.DangerousGetHandle()); while (pipeClient.IsConnected) { // Keeps the thread alive. @@ -97,9 +98,10 @@ namespace IPA.Logging interceptor!.Write(Encoding.UTF8.GetString(buffer, 0, charsRead)); } - [DllImport("kernel32.dll", SetLastError = true)] + [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] - private static extern bool SetStdHandle(int nStdHandle, SafeHandle hHandle); + [ResourceExposure(ResourceScope.Process)] + private static extern bool SetStdHandle(int nStdHandle, IntPtr hHandle); private const int STD_OUTPUT_HANDLE = -11; private const int STD_ERROR_HANDLE = -12;