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