private async void Application_Startup(object sender, StartupEventArgs e) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); notifyIcon = new(); notifyIcon.Visible = true; notifyIcon.Click += NotifyIcon_Click; InitWindow_ = new InitWindow(); InitWindow_.Show(); IMinecraft_QQ.ShowMessageCall = new IMinecraft_QQ.ShowMessage((string data) => { MessageBox.Show(data); }); IMinecraft_QQ.ServerConfigCall = new IMinecraft_QQ.ServerConfig((string key, string value) => { MainWindow_?.ServerConfig(key, value); }); IMinecraft_QQ.LogCall = new IMinecraft_QQ.Log((string data) => { MainWindow_?.AddLog(data); }); await IMinecraft_QQ.Start(); IMinecraft_QQ.GuiCall = new IMinecraft_QQ.Gui((GuiFun fun) => { Dispatcher.Invoke(() => { switch (fun) { case GuiFun.ServerList: MainWindow_?.InitServerList(); break; case GuiFun.PlayerList: MainWindow_?.InitPlayerList(); break; } }); }); }
static async Task Main() { Console.WriteLine("正在启动Minecraft_QQ"); IMinecraft_QQ.ShowMessageCall = Message; IMinecraft_QQ.LogCall = Message; IMinecraft_QQ.ConfigInitCall = ConfigInit; await IMinecraft_QQ.Start(); if (Environment.UserInteractive) { while (true) { string a = Console.ReadLine(); var arg = a.Split(' '); switch (arg[0]) { case "help": Console.WriteLine("帮助手册"); Console.WriteLine("reload 重读配置文件"); Console.WriteLine("stop 关闭"); break; case "reload": Console.WriteLine("正在读取配置文件"); var res = IMinecraft_QQ.Main.Reload(); if (res) { Console.WriteLine("已成功读取配置文件"); } else { Console.WriteLine("配置文件读取失败"); } break; case "stop": Console.WriteLine("正在关闭"); IMinecraft_QQ.Stop(); return; } } } }
public static void Stop() { MainWindow_ = null; notifyIcon.Dispose(); IMinecraft_QQ.Stop(); }