diff --git a/Mime/HttpMimeServier.cs b/Mime/HttpMimeServier.cs index 87bbeb3..31e4960 100644 --- a/Mime/HttpMimeServier.cs +++ b/Mime/HttpMimeServier.cs @@ -456,7 +456,7 @@ namespace UMC.Host { var key = UMC.Data.Utility.Parse36Encode(UMC.Data.Utility.IntParse(new Guid(UMC.Data.Utility.MD5(UMC.Data.Utility.MapPath("~"))))); ; using (NamedPipeServerStream pipeServer = - new NamedPipeServerStream($"UMC.{key}", PipeDirection.InOut)) + new NamedPipeServerStream($"APIUMC", PipeDirection.InOut)) // new NamedPipeServerStream($"APIUMC", PipeDirection.InOut)) { do @@ -628,6 +628,15 @@ namespace UMC.Host } break; + case "check": + if (str.Length > 1) + { + if (String.Equals(key, str[1]) == false) + { + pipeServer.Write(System.Text.Encoding.UTF8.GetBytes($"主程序目录:{UMC.Data.Utility.MapPath("~")}")); + } + } + break; case "http": case "start": if (str.Length > 1) diff --git a/Program.cs b/Program.cs index acad8bb..f199418 100644 --- a/Program.cs +++ b/Program.cs @@ -21,7 +21,7 @@ namespace UMC.Host { public static void Main(string[] args) { - + AppDomain.CurrentDomain.UnhandledException += UnhandledException; var variable = System.Environment.GetEnvironmentVariable("UMC"); @@ -92,28 +92,33 @@ namespace UMC.Host public static bool IsRun() { - var ls = Utility.Reader(UMC.Data.Utility.MapPath(".lock")); - if (String.IsNullOrEmpty(ls) == false) + using (var pipeClient = new NamedPipeClientStream(".", $"APIUMC", PipeDirection.InOut)) { - var hs = JSON.Deserialize(ls); - if (hs != null) + try { - var id = hs["Id"] as string; - try - { - var prc = System.Diagnostics.Process.GetProcessById(Convert.ToInt32(id)); - if (prc != null) - { - return true; - } - } - catch + var key = UMC.Data.Utility.Parse36Encode(UMC.Data.Utility.IntParse(new Guid(UMC.Data.Utility.MD5(UMC.Data.Utility.MapPath("~"))))); ; + + pipeClient.Connect(10); + pipeClient.Write(System.Text.Encoding.UTF8.GetBytes($"check {key}")); + var ls = new byte[0x200]; + var l = pipeClient.Read(ls, 0, ls.Length); + if (l > 0) { - return false; + Console.ForegroundColor = ConsoleColor.DarkRed; + Console.WriteLine(System.Text.Encoding.UTF8.GetString(ls, 0, l)); + Console.WriteLine(); + Console.ResetColor(); + } + pipeClient.Close(); + return true; + } + catch + { + return false; } } - return false; + } static void Write(params string[] args) @@ -121,7 +126,7 @@ namespace UMC.Host try { var key = UMC.Data.Utility.Parse36Encode(UMC.Data.Utility.IntParse(new Guid(UMC.Data.Utility.MD5(UMC.Data.Utility.MapPath("~"))))); ; - using (var pipeClient = new NamedPipeClientStream(".", $"UMC.{key}", PipeDirection.InOut)) + using (var pipeClient = new NamedPipeClientStream(".", $"APIUMC", PipeDirection.InOut)) { @@ -387,17 +392,22 @@ namespace UMC.Host stream.Flush(); stream.Close(); stream.Dispose(); - - System.IO.Compression.ZipFile.ExtractToDirectory(downloadFile, UMC.Data.Utility.MapPath("/"), true); - if (native.EndsWith("exe")) + try { - Utility.Move(UMC.Data.Utility.MapPath("/cavif.exe"), file); + System.IO.Compression.ZipFile.ExtractToDirectory(downloadFile, UMC.Data.Utility.MapPath("/"), true); + if (native.EndsWith("exe")) + { + Utility.Move(UMC.Data.Utility.MapPath("/cavif.exe"), file); + } + else + { + Utility.Move(UMC.Data.Utility.MapPath("/cavif"), file); + } } - else + catch { - Utility.Move(UMC.Data.Utility.MapPath("/cavif"), file); + Console.WriteLine($"图片组件下载失败,影响图片功能"); } - File.Delete(downloadFile); mre.Set(); } diff --git a/UMC.Host.csproj b/UMC.Host.csproj index fb67234..8aa16c1 100644 --- a/UMC.Host.csproj +++ b/UMC.Host.csproj @@ -43,6 +43,10 @@ - + + + + \ No newline at end of file