From 6842e252f3a4f5dcabdb5816d1844099006b7b22 Mon Sep 17 00:00:00 2001 From: Netch Date: Mon, 19 Jul 2021 05:18:15 +0800 Subject: [PATCH] Update aiodns --- .../Controllers/Other/DNS/AioDNSController.cs | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/Netch/Controllers/Other/DNS/AioDNSController.cs b/Netch/Controllers/Other/DNS/AioDNSController.cs index b5831226..661b734e 100644 --- a/Netch/Controllers/Other/DNS/AioDNSController.cs +++ b/Netch/Controllers/Other/DNS/AioDNSController.cs @@ -1,47 +1,45 @@ using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Runtime.InteropServices; namespace Netch.Controllers.Other.DNS { public class AioDNSController : Interface.IController { - private enum NameList : int + private Tools.Guard Guard = new() { - TYPE_REST, - TYPE_ADDR, - TYPE_LIST, - TYPE_CDNS, - TYPE_ODNS - } - - private static class Methods - { - [DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool aiodns_dial(NameList name, string value); - - [DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern bool aiodns_init(); - - [DllImport("aiodns.bin", CallingConvention = CallingConvention.Cdecl)] - public static extern void aiodns_free(); - } + StartInfo = new ProcessStartInfo() + { + FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\aiodns.exe"), + WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"), + CreateNoWindow = true, + UseShellExecute = false, + WindowStyle = ProcessWindowStyle.Hidden + }, + JudgmentStarted = new List() + { + "Started" + }, + JudgmentStopped = new List() + { + "[aiodns][main]" + }, + AutoRestart = true + }; public bool Create(Models.Server.Server s, Models.Mode.Mode m) { - Global.Logger.Info(String.Format("{0:x} aiodns.bin", Utils.FileHelper.Checksum("Bin\\aiodns.bin"))); + Global.Logger.Info(String.Format("{0:x} aiodns.exe", Utils.FileHelper.Checksum("bin\\aiodns.exe"))); - Methods.aiodns_dial(NameList.TYPE_REST, ""); - Methods.aiodns_dial(NameList.TYPE_ADDR, ":53"); - Methods.aiodns_dial(NameList.TYPE_LIST, "Bin\\aiodns.conf"); - Methods.aiodns_dial(NameList.TYPE_CDNS, Global.Config.AioDNS.ChinaDNS); - Methods.aiodns_dial(NameList.TYPE_ODNS, Global.Config.AioDNS.OtherDNS); - - return Methods.aiodns_init(); + this.Guard.StartInfo.Arguments = String.Format("-c {} -l {} -cdns {} -odns {}", ".\\aiodns.conf", ":53", Global.Config.AioDNS.ChinaDNS, Global.Config.AioDNS.OtherDNS); + return this.Guard.Create(); } public bool Delete() { - Methods.aiodns_free(); + this.Guard.Delete(); return true; }