1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- using System.IO;
- using System.Text;
- using BepInEx.Configuration;
- using UnityInjector.ConsoleUtil;
- namespace BepInEx
- {
- public static class ConsoleManager
- {
- public static bool ConsoleActive { get; private set; }
- public static TextWriter StandardOut => ConsoleWindow.StandardOut;
- public static void CreateConsole()
- {
- if (ConsoleActive)
- return;
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.Win32NT:
- {
- ConsoleWindow.Attach();
- break;
- }
- default:
- throw new PlatformNotSupportedException("Spawning a console is not currently supported on this platform");
- }
- ConsoleActive = true;
- }
- public static void DetachConsole()
- {
- if (!ConsoleActive)
- return;
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.Win32NT:
- {
- ConsoleWindow.Detach();
- break;
- }
- default:
- throw new PlatformNotSupportedException("Spawning a console is not currently supported on this platform");
- }
- ConsoleActive = false;
- }
- public static void SetConsoleEncoding(uint encodingCodePage)
- {
- if (!ConsoleActive)
- throw new InvalidOperationException("Console is not currently active");
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.Win32NT:
- {
- ConsoleEncoding.ConsoleCodePage = encodingCodePage;
- Console.OutputEncoding = Encoding.GetEncoding((int)encodingCodePage);
- break;
- }
- default:
- throw new PlatformNotSupportedException("Spawning a console is not currently supported on this platform");
- }
- }
- public static void SetConsoleTitle(string title)
- {
- if (!ConsoleActive)
- throw new InvalidOperationException("Console is not currently active");
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.Win32NT:
- {
- ConsoleWindow.Title = title;
- break;
- }
- default:
- throw new PlatformNotSupportedException("Spawning a console is not currently supported on this platform");
- }
- }
- public static readonly ConfigEntry<bool> ConfigConsoleEnabled = ConfigFile.CoreConfig.Bind(
- "Logging.Console", "Enabled",
- false,
- "Enables showing a console for log output.");
- public static readonly ConfigEntry<bool> ConfigConsoleShiftJis = ConfigFile.CoreConfig.Bind(
- "Logging.Console", "ShiftJisEncoding",
- false,
- "If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding.");
- }
- }
|