|
@ -37,7 +37,7 @@ namespace IPA.Logging |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void InitializeStreams() |
|
|
|
|
|
|
|
|
private static void InitializeStreams() |
|
|
{ |
|
|
{ |
|
|
InitializeOutStream(); |
|
|
InitializeOutStream(); |
|
|
InitializeInStream(); |
|
|
InitializeInStream(); |
|
@ -85,18 +85,11 @@ namespace IPA.Logging |
|
|
private static FileStream CreateFileStream(string name, uint win32DesiredAccess, uint win32ShareMode, |
|
|
private static FileStream CreateFileStream(string name, uint win32DesiredAccess, uint win32ShareMode, |
|
|
FileAccess dotNetFileAccess, out SafeFileHandle handle) |
|
|
FileAccess dotNetFileAccess, out SafeFileHandle handle) |
|
|
{ |
|
|
{ |
|
|
var file = new SafeFileHandle(CreateFileW(name, win32DesiredAccess, win32ShareMode, IntPtr.Zero, OpenExisting, FileAttributeNormal, IntPtr.Zero), true); |
|
|
|
|
|
|
|
|
var file = new SafeFileHandle(CreateFile(name, win32DesiredAccess, win32ShareMode, IntPtr.Zero, OpenExisting, FileAttributeNormal, IntPtr.Zero), true); |
|
|
if (!file.IsInvalid) |
|
|
if (!file.IsInvalid) |
|
|
{ |
|
|
{ |
|
|
handle = file; |
|
|
handle = file; |
|
|
#if NET4
|
|
|
|
|
|
var fs = new FileStream(file, dotNetFileAccess); |
|
|
var fs = new FileStream(file, dotNetFileAccess); |
|
|
#elif NET3
|
|
|
|
|
|
#pragma warning disable CS0618
|
|
|
|
|
|
// this is marked obsolete, and shouldn't need to be used, but the constructor used in .NET 4 doesn't exist in Unity's mscorlib.dll
|
|
|
|
|
|
var fs = new FileStream(file.DangerousGetHandle(), dotNetFileAccess); |
|
|
|
|
|
#pragma warning restore
|
|
|
|
|
|
#endif
|
|
|
|
|
|
return fs; |
|
|
return fs; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -106,47 +99,28 @@ namespace IPA.Logging |
|
|
|
|
|
|
|
|
#region Win API Functions and Constants
|
|
|
#region Win API Functions and Constants
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", |
|
|
|
|
|
EntryPoint = "AllocConsole", |
|
|
|
|
|
SetLastError = true, |
|
|
|
|
|
CharSet = CharSet.Auto, |
|
|
|
|
|
CallingConvention = CallingConvention.StdCall)] |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
private static extern bool AllocConsole(); |
|
|
private static extern bool AllocConsole(); |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", |
|
|
|
|
|
EntryPoint = "AttachConsole", |
|
|
|
|
|
SetLastError = true, |
|
|
|
|
|
CharSet = CharSet.Auto, |
|
|
|
|
|
CallingConvention = CallingConvention.StdCall)] |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
private static extern bool AttachConsole(int dwProcessId); |
|
|
private static extern bool AttachConsole(int dwProcessId); |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", |
|
|
|
|
|
EntryPoint = "CreateFileW", |
|
|
|
|
|
SetLastError = true, |
|
|
|
|
|
CharSet = CharSet.Unicode, |
|
|
|
|
|
CallingConvention = CallingConvention.StdCall)] |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
private static extern IntPtr CreateFileW( |
|
|
|
|
|
string lpFileName, |
|
|
|
|
|
uint dwDesiredAccess, |
|
|
|
|
|
uint dwShareMode, |
|
|
|
|
|
IntPtr lpSecurityAttributes, |
|
|
|
|
|
uint dwCreationDisposition, |
|
|
|
|
|
uint dwFlagsAndAttributes, |
|
|
|
|
|
IntPtr hTemplateFile |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] |
|
|
|
|
|
|
|
|
private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, |
|
|
|
|
|
IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); |
|
|
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
private static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); |
|
|
private static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
private static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); |
|
|
private static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] |
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
private static extern IntPtr GetStdHandle(int nStdHandle); |
|
|
private static extern IntPtr GetStdHandle(int nStdHandle); |
|
|
|
|
|
|
|
@ -158,7 +132,6 @@ namespace IPA.Logging |
|
|
private const uint FileShareWrite = 0x00000002; |
|
|
private const uint FileShareWrite = 0x00000002; |
|
|
private const uint OpenExisting = 0x00000003; |
|
|
private const uint OpenExisting = 0x00000003; |
|
|
private const uint FileAttributeNormal = 0x80; |
|
|
private const uint FileAttributeNormal = 0x80; |
|
|
private const uint ErrorAccessDenied = 5; |
|
|
|
|
|
|
|
|
|
|
|
internal const int AttachParent = -1; |
|
|
internal const int AttachParent = -1; |
|
|
|
|
|
|
|
|