public static void Kill() { currentStdout = IntPtr.Zero; FakeKill = true; #if !IsCore if (cWnd != null) { if (cWnd.InvokeRequired) { cWnd.Invoke(new Action(delegate { cWnd.Dispose(); })); } else { cWnd.Dispose(); } } #endif cWnd = null; }
public static void CreateConsole() { if (IsConsoleOk) { return; } #if IsCore currentStdout = (IntPtr)1; Console.Title = conTitle; PrintIntro(); return; #else #endif if (Variables.GetValue("useCustomConsole") == "1") { WaitingForForm = true; new Thread(delegate() { if (cWnd == null) { cWnd = new CustomConsoleWindow(); cWnd.ShowDialog(); cWnd.Activate(); } }).Start(); while (cWnd == null) { Thread.Sleep(10); } currentStdout = (IntPtr)1; WaitingForForm = false; } else { AllocConsole(); Console.CancelKeyPress += Console_CancelKeyPress; // stdout's handle seems to always be equal to 7 IntPtr defaultStdout = new IntPtr(7); currentStdout = GetStdHandle(StdOutputHandle); if (currentStdout != defaultStdout) { // reset stdout SetStdHandle(StdOutputHandle, defaultStdout); } try { // reopen stdout TextWriter writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }; Console.SetOut(writer); Console.OutputEncoding = System.Text.Encoding.UTF8; } catch (Exception ex) { EConsole.WriteLine("Can't set Console Output Encoding: " + ex.ToString(), true, ConsoleColor.Red); } try { TextReader reader = new StreamReader(Console.OpenStandardInput()); Console.SetIn(reader); Console.InputEncoding = System.Text.Encoding.Unicode; } catch (Exception ex) { EConsole.WriteLine("Can't set Console Input Encoding: " + ex.ToString(), true, ConsoleColor.Red); } } try { PrintIntro(); } catch (Exception ex) { Program.BachokMessage(ex); } Version cVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Title = String.Format("ESCRIPT {0}.{1}", cVer.Major, cVer.Minor); }