Skip to content

Commit

Permalink
NCNN GUI dialog improvements, video CopyBack() err handling
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Nov 11, 2020
1 parent 6ee4d2c commit 9c6f321
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 3 additions & 4 deletions Code/OS/ESRGAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public static async Task DoUpscale(string inpath, string outpath, ModelData mdl,
{
if (backend == Backend.NCNN)
{
Program.mainForm.SetProgress(1f, "Loading ESRGAN-NCNN...");
DialogForm dialogForm = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14);
Program.lastModelName = mdl.model1Name;
await RunNcnn(inpath, outpath, mdl.model1Path);
}
Expand Down Expand Up @@ -319,10 +317,11 @@ public static async Task RunNcnn(string inpath, string outpath, string modelPath
inpath = inpath.Wrap();
outpath = outpath.Wrap();

Program.mainForm.SetProgress(3f, "Converting NCNN model...");
Program.mainForm.SetProgress(1f, "Converting model...");
await NcnnUtils.ConvertNcnnModel(modelPath);
Logger.Log("[ESRGAN] NCNN Model is ready: " + currentNcnnModel);
Program.mainForm.SetProgress(4f, "Loading ESRGAN-NCNN...");
Program.mainForm.SetProgress(3f, "Loading ESRGAN-NCNN...");
DialogForm dialog = new DialogForm("Loading ESRGAN-NCNN...\nThis should take 10-25 seconds.", 14);
int scale = NcnnUtils.GetNcnnModelScale(currentNcnnModel);

string opt = "/C";
Expand Down
5 changes: 4 additions & 1 deletion Code/OS/NcnnUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cupscale.ImageUtils;
using Cupscale.Forms;
using Cupscale.ImageUtils;
using Cupscale.IO;
using Cupscale.UI;
using System;
Expand Down Expand Up @@ -26,11 +27,13 @@ public static async Task ConvertNcnnModel(string modelPath)
if (IOUtils.GetAmountOfFiles(outPath, false) < 2)
{
Logger.Log("Running model converter...");
DialogForm dialog = new DialogForm("Converting ESRGAN model to NCNN format...");
await RunConverter(modelPath);
string moveFrom = Path.Combine(Config.Get("esrganPath"), Path.ChangeExtension(modelName, null));
Logger.Log("Moving " + moveFrom + " to " + outPath);
IOUtils.Copy(moveFrom, outPath, "*", true);
Directory.Delete(moveFrom, true);
dialog.Close();
}
else
{
Expand Down
11 changes: 10 additions & 1 deletion Code/UI/VideoUpscaleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ static void CopyBack (string path)

outPath = Path.ChangeExtension(outPath, outputFormat.ToString().ToLower());
Print("Moving output video to " + outPath + "...");
File.Move(path, outPath);
try
{
if (File.Exists(outPath))
File.Delete(outPath);
File.Move(path, outPath);
}
catch (Exception e)
{
Logger.ErrorMessage("Failed to move video file to output folder.\nMake sure no other programs are accessing files in that folder.", e);
}
}

static void RenameOutFiles ()
Expand Down

0 comments on commit 9c6f321

Please sign in to comment.