From 2676e97ca0510713273d486cb992c574f2252f27 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Sat, 29 Aug 2020 12:29:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=90=AF=E5=8A=A8Netch?= =?UTF-8?q?=E4=B8=8D=E6=B8=85=E9=99=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Netch.cs | 64 +++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/Netch/Netch.cs b/Netch/Netch.cs index 984252e3..bb4d5368 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -23,6 +23,32 @@ namespace Netch // 设置当前目录 Directory.SetCurrentDirectory(Global.NetchDir); + // 预创建目录 + var directories = new[] {"mode", "data", "i18n", "logging"}; + foreach (var item in directories) + { + if (!Directory.Exists(item)) + { + Directory.CreateDirectory(item); + } + } + + // 加载配置 + Configuration.Load(); + + // 加载语言 + i18N.Load(Global.Settings.Language); + + // 检查是否已经运行 + if (!mutex.WaitOne(0, false)) + { + OnlyInstance.Send(OnlyInstance.Commands.Show); + Logging.Info("唤起单实例"); + + // 退出进程 + Environment.Exit(1); + } + // 清理上一次的日志文件,防止淤积占用磁盘空间 if (Directory.Exists("logging")) { @@ -39,42 +65,10 @@ namespace Netch } } - // 预创建目录 - var directories = new[] {"mode", "data", "i18n", "logging"}; - foreach (var item in directories) - { - // 检查是否已经存在 - if (!Directory.Exists(item)) - { - // 创建目录 - Directory.CreateDirectory(item); - } - } - - // 加载配置 - Configuration.Load(); - - // 加载语言 - i18N.Load(Global.Settings.Language); - - Task.Run(() => - { - Logging.Info($"版本: {UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}"); - Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Application.ExecutablePath)}"); - }); - - // 检查是否已经运行 - if (!mutex.WaitOne(0, false)) - { - OnlyInstance.Send(OnlyInstance.Commands.Show); - Logging.Info("唤起单实例"); - - // 退出进程 - Environment.Exit(1); - } - - Task.Run(OnlyInstance.Server); + Logging.Info($"版本: {UpdateChecker.Owner}/{UpdateChecker.Repo}@{UpdateChecker.Version}"); + Task.Run(() => { Logging.Info($"主程序 SHA256: {Utils.Utils.SHA256CheckSum(Application.ExecutablePath)}"); }); Logging.Info("启动单实例"); + Task.Run(OnlyInstance.Server); // 绑定错误捕获 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);