diff --git a/Code/IO/Installer.cs b/Code/IO/Installer.cs index 40abd96..3e135e8 100644 --- a/Code/IO/Installer.cs +++ b/Code/IO/Installer.cs @@ -188,7 +188,7 @@ public static void Uninstall (bool full) } catch (Exception e) { - Logger.Log("Failed to uninstall.\nClose Cupscale and try deleting %APPDATA%/Cupscale manually. " + e.Message); + Logger.Log("Failed to uninstall.\nClose Cupscale and try deleting CupscaleData manually. " + e.Message); } } } diff --git a/Code/Main/Logger.cs b/Code/Main/Logger.cs index 7132bce..853efcf 100644 --- a/Code/Main/Logger.cs +++ b/Code/Main/Logger.cs @@ -81,7 +81,7 @@ public static string GetSessionLog () public static MsgBox ErrorMessage (string msg, Exception e) { - string text = $"{msg}\n{e.Message}\n\nStack Trace:\n{e.StackTrace}"; + string text = $"{msg}\n\n{e.Message}\n\nStack Trace:\n{e.StackTrace}"; Clipboard.SetText(text); Log(text); return Program.ShowMessage(text + "\n\nThe error message was copied to the clipboard.", "Error"); diff --git a/Code/OS/NcnnUtils.cs b/Code/OS/NcnnUtils.cs index 6dd9c91..99322a0 100644 --- a/Code/OS/NcnnUtils.cs +++ b/Code/OS/NcnnUtils.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Drawing; using System.IO; +using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -15,6 +16,7 @@ namespace Cupscale.OS class NcnnUtils { static Process currentProcess; + public static string lastNcnnOutput; static string ncnnDir = ""; public static async Task ConvertNcnnModel(string modelPath) @@ -31,7 +33,11 @@ public static async Task ConvertNcnnModel(string modelPath) Logger.Log("Running model converter..."); DialogForm dialog = new DialogForm("Converting ESRGAN model to NCNN format..."); await RunConverter(modelPath); - string moveFrom = Path.Combine(Paths.esrganPath, Path.ChangeExtension(modelName, null)); + + if (lastNcnnOutput.Contains("Error:")) + throw new Exception(lastNcnnOutput.SplitIntoLines().Where(x => x.Contains("Error:")).First()); + + string moveFrom = Path.Combine(Paths.esrganPath, Path.ChangeExtension(modelName, null)); Logger.Log("Moving " + moveFrom + " to " + outPath); await IOUtils.CopyDir(moveFrom, outPath, "*", true); Directory.Delete(moveFrom, true); @@ -46,12 +52,13 @@ public static async Task ConvertNcnnModel(string modelPath) } catch (Exception e) { - Logger.ErrorMessage("Failed to convert Pytorch model to NCNN format!", e); + Logger.ErrorMessage("Failed to convert Pytorch model to NCNN format! It might be incompatible.", e); } } static async Task RunConverter(string modelPath) - { + { + lastNcnnOutput = ""; bool showWindow = Config.GetInt("cmdDebugMode") > 0; bool stayOpen = Config.GetInt("cmdDebugMode") == 2; @@ -90,7 +97,8 @@ private static void OutputHandler(object sendingProcess, DataReceivedEventArgs o string data = output.Data; Logger.Log("[NcnnUtils] Model Converter Output: " + data); - } + lastNcnnOutput += $"{data}\n"; + } public static int GetNcnnModelScale(string modelDir) { diff --git a/Code/UI/ExtensionMethods.cs b/Code/UI/ExtensionMethods.cs index 9a59530..0a670be 100644 --- a/Code/UI/ExtensionMethods.cs +++ b/Code/UI/ExtensionMethods.cs @@ -133,5 +133,10 @@ public static string TrimWhitespaces(this string str) } return newString.ToString(); } + + public static string[] SplitIntoLines(this string str) + { + return Regex.Split(str, "\r\n|\r|\n"); + } } }