/// <summary> /// Use the code page described by the file at the specified <paramref name="path"/> when en/decoding text messages sent to/from the server. /// </summary> /// <param name="path">The path to the code page file.</param> /// <returns>The updated game mode configuration builder.</returns> public GameModeBuilder UseEncoding(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } return(UseEncoding(CodePageEncoding.Load(path))); }
/// <summary> /// Uses the encoding code page. /// </summary> /// <param name="pageName">Name of the page.</param> /// <returns></returns> public GameModeBuilder UseEncodingCodePage(string pageName) { if (pageName == null) { throw new ArgumentNullException(nameof(pageName)); } var type = typeof(CodePageEncoding); var name = $"{type.Namespace}.data.{pageName.ToLowerInvariant()}.dat"; using (var stream = type.Assembly.GetManifestResourceStream(name)) { if (stream == null) { throw new GameModeBuilderException($"Code page with name {pageName} is not available."); } var encoding = CodePageEncoding.Deserialize(stream); return(UseEncoding(encoding)); } }
static Console() { // For console apps, the console handles are set to values like 3, 7, // and 11 OR if you've been created via CreateProcess, possibly -1 // or 0. -1 is definitely invalid, while 0 is probably invalid. // Also note each handle can independently be bad or good. // For Windows apps, the console handles are set to values like 3, 7, // and 11 but are invalid handles - you may not write to them. However, // you can still spawn a Windows app via CreateProcess and read stdout // and stderr. // So, we always need to check each handle independently for validity // by trying to write or read to it, unless it is -1. // Don't do any security check (from Security folks). At worst // case, all this really wastes is your time with console spew // instead of breaking your computer. For that reason, don't // bother with security checks here. // Delay initialize Console.In until someone uses it. // Set up Console.Out Encoding outEnc = null; Stream s = OpenStandardOutput(_DefaultConsoleBufferSize); if (s == Stream.Null) { #if _DEBUG if (CheckOutputDebug()) { _out = MakeDebugOutputTextWriter("Console.Out: "); } else #endif _out = TextWriter.Synchronized(StreamWriter.Null); } else { // To avoid loading about 7 classes, don't call Encoding.GetEncoding(int) outEnc = new CodePageEncoding(GetConsoleOutputCPNative()); StreamWriter stdout = new StreamWriter(s, outEnc, _DefaultConsoleBufferSize); stdout.AutoFlush = true; stdout.Closable = !IsStreamAConsole(Win32Native.STD_OUTPUT_HANDLE); _out = TextWriter.Synchronized(stdout); } // Set up Console.Error s = OpenStandardError(_DefaultConsoleBufferSize); if (s == Stream.Null) { #if _DEBUG if (CheckOutputDebug()) { _error = MakeDebugOutputTextWriter("Console.Error: "); } else #endif _error = TextWriter.Synchronized(StreamWriter.Null); } else { if (outEnc == null) { outEnc = new CodePageEncoding(GetConsoleOutputCPNative()); } StreamWriter stderr = new StreamWriter(s, outEnc, _DefaultConsoleBufferSize); stderr.AutoFlush = true; stderr.Closable = !IsStreamAConsole(Win32Native.STD_ERROR_HANDLE); _error = TextWriter.Synchronized(stderr); } }
/// <summary> /// Use the code page described by the specified <paramref name="stream"/> when en/decoding text messages sent to/from the server. /// </summary> /// <param name="stream">The stream containing the code page definition.</param> /// <returns>The updated game mode configuration builder.</returns> public GameModeBuilder UseEncoding(Stream stream) { return(UseEncoding(CodePageEncoding.Load(stream))); }