From 5d6a3470dd6322ad2e33fded2efb4f1898bd1d55 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Wed, 11 Nov 2020 15:42:03 +0100 Subject: [PATCH] More NCNN GUI improvements/fixes --- Code/OS/ESRGAN.cs | 2 +- Code/OS/NcnnUtils.cs | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Code/OS/ESRGAN.cs b/Code/OS/ESRGAN.cs index 2f53a39..5b373a3 100644 --- a/Code/OS/ESRGAN.cs +++ b/Code/OS/ESRGAN.cs @@ -321,7 +321,7 @@ public static async Task RunNcnn(string inpath, string outpath, string modelPath await NcnnUtils.ConvertNcnnModel(modelPath); Logger.Log("[ESRGAN] NCNN Model is ready: " + currentNcnnModel); Program.mainForm.SetProgress(3f, "Loading ESRGAN-NCNN..."); - DialogForm dialog = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14); + //DialogForm dialog = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14); int scale = NcnnUtils.GetNcnnModelScale(currentNcnnModel); string opt = "/C"; diff --git a/Code/OS/NcnnUtils.cs b/Code/OS/NcnnUtils.cs index 7d0c7ea..6c5ac3a 100644 --- a/Code/OS/NcnnUtils.cs +++ b/Code/OS/NcnnUtils.cs @@ -44,28 +44,34 @@ public static async Task ConvertNcnnModel(string modelPath) static async Task RunConverter(string modelPath) { + bool showWindow = Config.GetInt("cmdDebugMode") > 0; + bool stayOpen = Config.GetInt("cmdDebugMode") == 2; + modelPath = modelPath.Wrap(); - string cmd2 = "/C cd /D " + Config.Get("esrganPath").Wrap() + " & pth2ncnn.exe " + modelPath; + string opt = "/C"; + if (stayOpen) opt = "/K"; + + string args = $"{opt} cd /D {Config.Get("esrganPath").Wrap()} & pth2ncnn.exe {modelPath}"; - Logger.Log("[CMD] " + cmd2); - Process converterProc = new Process(); - //converterProc.StartInfo.UseShellExecute = false; - //converterProc.StartInfo.RedirectStandardOutput = true; - //converterProc.StartInfo.RedirectStandardError = true; - //converterProc.StartInfo.CreateNoWindow = true; - converterProc.StartInfo.FileName = "cmd.exe"; - converterProc.StartInfo.Arguments = cmd2; - converterProc.OutputDataReceived += OutputHandler; - converterProc.ErrorDataReceived += OutputHandler; + Logger.Log("[CMD] " + args); + Process converterProc = OSUtils.NewProcess(!showWindow); + converterProc.StartInfo.Arguments = args; + if (!showWindow) + { + converterProc.OutputDataReceived += OutputHandler; + converterProc.ErrorDataReceived += OutputHandler; + } currentProcess = converterProc; converterProc.Start(); - //converterProc.BeginOutputReadLine(); - //converterProc.BeginErrorReadLine(); - while (!converterProc.HasExited) + if (!showWindow) { - await Task.Delay(100); + converterProc.BeginOutputReadLine(); + converterProc.BeginErrorReadLine(); } + while (!converterProc.HasExited) + await Task.Delay(100); + File.Delete(Paths.progressLogfile); } @@ -75,7 +81,7 @@ private static void OutputHandler(object sendingProcess, DataReceivedEventArgs o return; string data = output.Data; - Logger.Log("Model Converter Output: " + data); + Logger.Log("[NcnnUtils] Model Converter Output: " + data); } public static int GetNcnnModelScale(string modelDir)