diff --git a/linker.service/LinkerService.cs b/linker.service/LinkerService.cs index 748aef17..c7a557aa 100644 --- a/linker.service/LinkerService.cs +++ b/linker.service/LinkerService.cs @@ -17,8 +17,9 @@ namespace linker.service protected override void OnStart(string[] _args) { + OpenExe(); + OpenExeTray(); CheckMainProcess(); - } protected override void OnStop() { @@ -28,8 +29,10 @@ namespace linker.service } private Process proc; + private Process procTray; private void CheckMainProcess() { + Task.Run(async () => { while (cancellationTokenSource.IsCancellationRequested == false) @@ -38,8 +41,7 @@ namespace linker.service { if (Process.GetProcessesByName(mainExeName).Any() == false) { - KillExe(); - OpenExe(); + RestartService(); } } catch (Exception) @@ -55,20 +57,17 @@ namespace linker.service { string filename = Process.GetCurrentProcess().MainModule.FileName; string dir = Path.GetDirectoryName(filename); - string file = Path.Combine(dir, $"{mainExeName}.exe"); - ProcessStartInfo processStartInfo = new ProcessStartInfo() + proc = Process.Start(new ProcessStartInfo() { WorkingDirectory = dir, - FileName = file, + FileName = Path.Combine(dir, $"{mainExeName}.exe"), CreateNoWindow = false, ErrorDialog = false, UseShellExecute = true, WindowStyle = ProcessWindowStyle.Hidden, //Arguments = string.Join(" ", this.args), Verb = "runas", - }; - proc = Process.Start(processStartInfo); - + }); return true; } catch (Exception) @@ -105,5 +104,75 @@ namespace linker.service proc = null; } } + + private bool OpenExeTray() + { + try + { + string filename = Process.GetCurrentProcess().MainModule.FileName; + string dir = Path.GetDirectoryName(filename); + procTray = Process.Start(new ProcessStartInfo() + { + WorkingDirectory = dir, + FileName = Path.Combine(dir, $"{mainExeName}.tray.win.exe"), + CreateNoWindow = false, + ErrorDialog = false, + UseShellExecute = true, + WindowStyle = ProcessWindowStyle.Hidden, + Arguments = "--task=1", + Verb = "runas", + }); + + return true; + } + catch (Exception) + { + try + { + procTray.Kill(); + procTray.Dispose(); + } + catch (Exception) + { + } + procTray = null; + } + return false; + } + private void KillExeTray() + { + try + { + procTray?.Close(); + procTray?.Dispose(); + + foreach (var item in Process.GetProcessesByName($"{mainExeName}.tray.win")) + { + item.Kill(); + } + } + catch (Exception) + { + } + finally + { + procTray = null; + } + } + + + public void RestartService() + { + try + { + KillExe(); + KillExeTray(); + + Environment.Exit(1); + } + catch (Exception) + { + } + } } } diff --git a/linker.tray.win/default.aproj b/linker.tray.win/default.aproj index 817e5bab..ff295aaf 100644 --- a/linker.tray.win/default.aproj +++ b/linker.tray.win/default.aproj @@ -1,5 +1,5 @@  - + diff --git a/linker.tray.win/dist/linker.tray.win.exe b/linker.tray.win/dist/linker.tray.win.exe index 39bc99ba..9f1e6b63 100644 Binary files a/linker.tray.win/dist/linker.tray.win.exe and b/linker.tray.win/dist/linker.tray.win.exe differ diff --git a/linker.tray.win/main.aardio b/linker.tray.win/main.aardio index 464a4681..470fa4c8 100644 --- a/linker.tray.win/main.aardio +++ b/linker.tray.win/main.aardio @@ -78,12 +78,23 @@ mainForm.showPopmenu = function(){ }); } + + +mainForm.failureService = function() +{ + import process.popen; + var prcs = process.popen.cmd("sc failure " + mainForm.serviceName +" reset= 0 actions= restart/3000/restart/3000/restart/3000") + prcs.readAll(); +} + mainForm.checkService = function(){ import service; mainForm.btnInstall.text = service.isExist(mainForm.serviceName) ? "卸载服务" : "安装服务"; mainForm.btnRun.text = service.isRunning(mainForm.serviceName) ? "停止服务" : "运行服务"; mainForm.showPopmenu(); mainForm.runAsTaskCheck(); + + mainForm.failureService(); } mainForm.btnCheck.oncommand = function(id,event){ mainForm.checkService(); diff --git a/linker/plugins/updater/UpdaterTransfer.cs b/linker/plugins/updater/UpdaterTransfer.cs index b2fb6ebb..15cd1558 100644 --- a/linker/plugins/updater/UpdaterTransfer.cs +++ b/linker/plugins/updater/UpdaterTransfer.cs @@ -188,6 +188,7 @@ namespace linker.plugins.updater } catch (Exception) { + continue; } } @@ -272,25 +273,7 @@ namespace linker.plugins.updater private void StartClearTempFile() { - if (OperatingSystem.IsWindows()) - { - Process[] trays = Process.GetProcessesByName("linker.tray.win"); - if (trays.Length > 0) - { - foreach (var tray in trays) - { - tray.Kill(); - } - CommandHelper.Windows(string.Empty, new string[] { "start linker.tray.win.exe --task=1" }); - } - } - ClearTempFile(); - - if (File.Exists("linker.service.exe.temp")) - { - CommandHelper.Windows(string.Empty, new string[] { "sc stop linker.service & sc start linker.service" }); - } } private void ClearTempFile(string path = "./") {