12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.IO;
- using System.Text;
- using BepInEx.ConsoleUtil;
- using UnityInjector.ConsoleUtil;
- namespace BepInEx
- {
- internal class WindowsConsoleDriver : IConsoleDriver
- {
- public TextWriter StandardOut { get; private set; }
- public TextWriter ConsoleOut { get; private set; }
- public bool ConsoleActive { get; private set; }
- public bool ConsoleIsExternal => true;
- public void Initialize(bool alreadyActive)
- {
- ConsoleActive = alreadyActive;
- StandardOut = Console.Out;
- }
- public void CreateConsole(uint codepage)
- {
-
-
- #pragma warning disable 618
- ConsoleWindow.Attach();
-
-
-
- ConsoleEncoding.ConsoleCodePage = codepage;
-
-
-
- var stdout = ConsoleWindow.OriginalStdoutHandle != IntPtr.Zero ? ConsoleWindow.OriginalStdoutHandle : ConsoleWindow.ConsoleOutHandle;
- var originalOutStream = new FileStream(stdout, FileAccess.Write);
- StandardOut = new StreamWriter(originalOutStream, new UTF8Encoding(false))
- {
- AutoFlush = true
- };
- var consoleOutStream = new FileStream(ConsoleWindow.ConsoleOutHandle, FileAccess.Write);
-
- ConsoleOut = new StreamWriter(consoleOutStream, ConsoleEncoding.OutputEncoding)
- {
- AutoFlush = true
- };
- ConsoleActive = true;
- #pragma warning restore 618
- }
- public void DetachConsole()
- {
- ConsoleWindow.Detach();
- ConsoleOut.Close();
- ConsoleOut = null;
- ConsoleActive = false;
- }
- public void SetConsoleColor(ConsoleColor color)
- {
- SafeConsole.ForegroundColor = color;
- Kon.ForegroundColor = color;
- }
- public void SetConsoleTitle(string title)
- {
- ConsoleWindow.Title = title;
- }
- }
- }
|