Skip to content

Commit

Permalink
More NCNN GUI improvements/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Nov 11, 2020
1 parent 9c6f321 commit 5d6a347
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Code/OS/ESRGAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
38 changes: 22 additions & 16 deletions Code/OS/NcnnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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)
Expand Down

0 comments on commit 5d6a347

Please sign in to comment.