Browse Source

Use the SafeHandle wrapper instead

pull/65/head
Meivyn 1 year ago
parent
commit
083181060e
No known key found for this signature in database GPG Key ID: 8BDD3E48158B2F71
1 changed files with 5 additions and 7 deletions
  1. +5
    -7
      IPA.Loader/Logging/StdoutInterceptorPipes.cs

+ 5
- 7
IPA.Loader/Logging/StdoutInterceptorPipes.cs View File

@ -1,7 +1,6 @@
using System;
using System.IO.Pipes;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
@ -36,7 +35,7 @@ namespace IPA.Logging
{
return new Thread(() =>
{
NamedPipeServerStream pipeServer = new(pipeName, PipeDirection.In);
var pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.In);
try
{
@ -67,14 +66,14 @@ namespace IPA.Logging
{
return new Thread(() =>
{
NamedPipeClientStream pipeClient = new(".", pipeName, PipeDirection.Out);
var pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.Out);
try
{
// If the client starts first, blocks the client thread.
manualResetEvent.Wait();
pipeClient.Connect();
SetStdHandle(stdHandle, pipeClient.SafePipeHandle.DangerousGetHandle());
SetStdHandle(stdHandle, pipeClient.SafePipeHandle);
while (pipeClient.IsConnected)
{
// Keeps the thread alive.
@ -96,10 +95,9 @@ namespace IPA.Logging
interceptor!.Write(Encoding.UTF8.GetString(buffer, 0, charsRead));
}
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
[DllImport("kernel32.dll", SetLastError = true)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[ResourceExposure(ResourceScope.Process)]
private static extern bool SetStdHandle(int nStdHandle, IntPtr hHandle);
private static extern bool SetStdHandle(int nStdHandle, SafeHandle hHandle);
private const int STD_OUTPUT_HANDLE = -11;
private const int STD_ERROR_HANDLE = -12;


Loading…
Cancel
Save