diff --git a/src/Common.cs b/src/Common.cs index 03b2f85..ba2a135 100644 --- a/src/Common.cs +++ b/src/Common.cs @@ -134,6 +134,8 @@ class Common public static List GPUList = new(); public static List GPURAMList = new(); + public static Exception GlobalException = null; + #endregion /// diff --git a/src/Forms/FormMain.cs b/src/Forms/FormMain.cs index 233b242..767d904 100644 --- a/src/Forms/FormMain.cs +++ b/src/Forms/FormMain.cs @@ -61,258 +61,277 @@ private void FormMain_Load(object sender, EventArgs e) lockobj = new object(); - lock (lockobj) + try { - ThreadStart ts = new(StartThread); - Thread thread = new(ts) + lock (lockobj) { - Name = "Splash", - IsBackground = true - }; - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); + ThreadStart ts = new(StartThread); + Thread thread = new(ts) + { + Name = "Splash", + IsBackground = true + }; + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); - DlgMsg d = new(ShowMessage); + DlgMsg d = new(ShowMessage); - //fs?.Invoke(d, "Initializing..."); - fs?.Dispatcher.Invoke(d, "Initializing..."); - label1.Text = Strings.DragDropCaption; - Thread.Sleep(200); + //fs?.Invoke(d, "Initializing..."); + fs?.Dispatcher.Invoke(d, "Initializing..."); + label1.Text = Strings.DragDropCaption; + Thread.Sleep(200); - foreach (var files in Directory.GetFiles(Directory.GetCurrentDirectory() + @"\res", "*", SearchOption.AllDirectories)) - { - FileInfo fi = new(files); - if (fs != null) + foreach (var files in Directory.GetFiles(Directory.GetCurrentDirectory() + @"\res", "*", SearchOption.AllDirectories)) { - fs.Dispatcher.Invoke(d, string.Format(Strings.SplashFormFileCaption, fi.Name)); - Thread.Sleep(10); + FileInfo fi = new(files); + if (fs != null) + { + fs.Dispatcher.Invoke(d, string.Format(Strings.SplashFormFileCaption, fi.Name)); + Thread.Sleep(10); + } } - } - //fs?.Invoke(d, Strings.SplashFormConfigCaption); - if (fs != null) - { - fs.Dispatcher.Invoke(d, Strings.SplashFormConfigCaption); - } - - - Config.Load(Common.xmlpath); + //fs?.Invoke(d, Strings.SplashFormConfigCaption); + if (fs != null) + { + fs.Dispatcher.Invoke(d, Strings.SplashFormConfigCaption); + } - Common.FFmpegPath = Config.Entry["FFmpegLocation"].Value; - Common.ImageParam = Config.Entry["Param"].Value; - Common.VideoParam = Config.Entry["VideoParam"].Value; - Common.AudioParam = Config.Entry["AudioParam"].Value; - Common.MergeParam = Config.Entry["MergeParam"].Value; - if (Directory.Exists(Directory.GetCurrentDirectory() + @"\_temp-project\")) - { - Common.DeleteDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\"); - } - if (Config.Entry["VideoLocation"].Value != "") - { - Directory.CreateDirectory(Config.Entry["VideoLocation"].Value + @"\image-frames"); - Directory.CreateDirectory(Config.Entry["VideoLocation"].Value + @"\image-frames2x"); - Common.DeletePathFrames = Config.Entry["VideoLocation"].Value + @"\image-frames"; - Common.DeletePathFrames2x = Config.Entry["VideoLocation"].Value + @"\image-frames2x"; - } - else - { - Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\image-frames"); - Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\image-frames2x"); - Common.DeletePathFrames = Directory.GetCurrentDirectory() + @"\_temp-project\image-frames"; - Common.DeletePathFrames2x = Directory.GetCurrentDirectory() + @"\_temp-project\image-frames2x"; - } - if (Config.Entry["AudioLocation"].Value != "") - { - Directory.CreateDirectory(Config.Entry["AudioLocation"].Value + @"\audio"); - Common.DeletePathAudio = Config.Entry["AudioLocation"].Value + @"\audio"; - } - else - { - Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\audio"); - Common.DeletePathAudio = Directory.GetCurrentDirectory() + @"\_temp-project\audio"; - } + Config.Load(Common.xmlpath); - Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\images"); - Thread.Sleep(200); + Common.FFmpegPath = Config.Entry["FFmpegLocation"].Value; + Common.ImageParam = Config.Entry["Param"].Value; + Common.VideoParam = Config.Entry["VideoParam"].Value; + Common.AudioParam = Config.Entry["AudioParam"].Value; + Common.MergeParam = Config.Entry["MergeParam"].Value; - if (fs != null) - { - fs.Dispatcher.Invoke(d, Strings.SplashFormSystemCaption); - } - string[] OSInfo = new string[17]; - string[] CPUInfo = new string[3]; - string[] GPUInfo = new string[3]; - SystemInfo.GetSystemInformation(OSInfo); - SystemInfo.GetProcessorsInformation(CPUInfo); - SystemInfo.GetVideoControllerInformation(GPUInfo); - - List GPUList = new(); - List GPURAMList = new(); - string[] vn = null; - long[] vr = null; - - VRAM v = new(); - VRAMInfo vram = new(vn, vr); - vram = v.GetdGPUInfo(); - GPUList = new(vram.Name);//SystemInfo.GetGraphicsCardsInformation(); - GPURAMList = new(vram.VRAM);//SystemInfo.GetGraphicsCardNamesInformation(); - if (GPUList.Count == 0) - { - MessageBox.Show(Strings.GPUInfomationFailedCaption, Strings.MSGError, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - if (GPURAMList.Count == 0) - { - MessageBox.Show(Strings.GPUInfomationFailedCaption, Strings.MSGError, MessageBoxButtons.OK, MessageBoxIcon.Error); - } - - ResetLabels(); - //label_OS.Text = OSInfo[1] + " - " + OSInfo[3] + " [ build: " + OSInfo[4] + " ]"; - //label_Processor.Text = CPUInfo[0] + " [ " + CPUInfo[1] + " Core / " + CPUInfo[2] + " Threads ]"; - toolStripStatusLabel_Status.ForeColor = Color.FromArgb(0, 255, 0, 0); + if (Directory.Exists(Directory.GetCurrentDirectory() + @"\_temp-project\")) + { + Common.DeleteDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\"); + } + if (Config.Entry["VideoLocation"].Value != "") + { + Directory.CreateDirectory(Config.Entry["VideoLocation"].Value + @"\image-frames"); + Directory.CreateDirectory(Config.Entry["VideoLocation"].Value + @"\image-frames2x"); + Common.DeletePathFrames = Config.Entry["VideoLocation"].Value + @"\image-frames"; + Common.DeletePathFrames2x = Config.Entry["VideoLocation"].Value + @"\image-frames2x"; + } + else + { + Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\image-frames"); + Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\image-frames2x"); + Common.DeletePathFrames = Directory.GetCurrentDirectory() + @"\_temp-project\image-frames"; + Common.DeletePathFrames2x = Directory.GetCurrentDirectory() + @"\_temp-project\image-frames2x"; + } + if (Config.Entry["AudioLocation"].Value != "") + { + Directory.CreateDirectory(Config.Entry["AudioLocation"].Value + @"\audio"); + Common.DeletePathAudio = Config.Entry["AudioLocation"].Value + @"\audio"; + } + else + { + Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\audio"); + Common.DeletePathAudio = Directory.GetCurrentDirectory() + @"\_temp-project\audio"; + } - if (fs != null) - { - fs.Dispatcher.Invoke(d, "Detected OS: " + OSInfo[1]); - } - Thread.Sleep(10); - if (fs != null) - { - fs.Dispatcher.Invoke(d, "Detected CPU: " + CPUInfo[0]); - } - Thread.Sleep(10); + Directory.CreateDirectory(Directory.GetCurrentDirectory() + @"\_temp-project\images"); + Thread.Sleep(200); - int gpucount = 0; - foreach (var gpu in GPUList) - { - if (gpu != null && GPURAMList[gpucount] != 0 && !Common.GPUList.Contains(gpu)) + if (fs != null) { - fs?.Dispatcher.Invoke(d, "Detected GPU: " + gpu); - Thread.Sleep(10); - //comboBox_GPU.Items.Add(gpu); - Common.GPUList.Add(gpu); - Common.GPURAMList.Add(GPURAMList[gpucount]); + fs.Dispatcher.Invoke(d, Strings.SplashFormSystemCaption); } - else if (gpu != null && GPURAMList[gpucount] == 0) + string[] OSInfo = new string[17]; + string[] CPUInfo = new string[3]; + string[] GPUInfo = new string[3]; + SystemInfo.GetSystemInformation(OSInfo); + SystemInfo.GetProcessorsInformation(CPUInfo); + SystemInfo.GetVideoControllerInformation(GPUInfo); + + List GPUList = new(); + List GPURAMList = new(); + string[] vn = null; + long[] vr = null; + + VRAM v = new(); + VRAMInfo vram = new(vn, vr); + vram = v.GetdGPUInfo(); + GPUList = new(vram.Name);//SystemInfo.GetGraphicsCardsInformation(); + GPURAMList = new(vram.VRAM);//SystemInfo.GetGraphicsCardNamesInformation(); + if (GPUList.Count == 0) { - fs?.Dispatcher.Invoke(d, "Detected Discrate iGPU: " + gpu); - Thread.Sleep(10); - //comboBox_GPU.Items.Add(gpu); - Common.GPUList.Add(gpu); - Common.GPURAMList.Add(GPURAMList[gpucount]); + MessageBox.Show(Strings.GPUInfomationFailedCaption, Strings.MSGError, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + if (GPURAMList.Count == 0) + { + MessageBox.Show(Strings.GPUInfomationFailedCaption, Strings.MSGError, MessageBoxButtons.OK, MessageBoxIcon.Error); } - gpucount++; - } - /*comboBox_GPU.SelectedIndex = 0; - if (Common.GPUList.Count == 1) - { - comboBox_GPU.Enabled = false; - } - else - { - comboBox_GPU.Enabled = true; - } - - label_Graphic.Text = Common.GPUList[0] + " [ " + Common.GPURAMList[0] + " MiB RAM ]";*/ + ResetLabels(); + //label_OS.Text = OSInfo[1] + " - " + OSInfo[3] + " [ build: " + OSInfo[4] + " ]"; + //label_Processor.Text = CPUInfo[0] + " [ " + CPUInfo[1] + " Core / " + CPUInfo[2] + " Threads ]"; + toolStripStatusLabel_Status.ForeColor = Color.FromArgb(0, 255, 0, 0); - /*if (GPUList.Count == 1) - { if (fs != null) { - fs.Dispatcher.Invoke(d, "Detected GPU: " + GPUNList); + fs.Dispatcher.Invoke(d, "Detected OS: " + OSInfo[1]); } Thread.Sleep(10); - comboBox_GPU.Items.Add(GPUNList[0]); - comboBox_GPU.SelectedIndex = 0; - comboBox_GPU.Enabled = false; - label_Graphic.Text = GPUList[0]; - } - else - { - foreach (var GPU in GPUNList) + if (fs != null) + { + fs.Dispatcher.Invoke(d, "Detected CPU: " + CPUInfo[0]); + } + Thread.Sleep(10); + + int gpucount = 0; + foreach (var gpu in GPUList) + { + if (gpu != null && GPURAMList[gpucount] != 0 && !Common.GPUList.Contains(gpu)) + { + fs?.Dispatcher.Invoke(d, "Detected GPU: " + gpu); + Thread.Sleep(10); + //comboBox_GPU.Items.Add(gpu); + Common.GPUList.Add(gpu); + Common.GPURAMList.Add(GPURAMList[gpucount]); + } + else if (gpu != null && GPURAMList[gpucount] == 0) + { + fs?.Dispatcher.Invoke(d, "Detected Discrate iGPU: " + gpu); + Thread.Sleep(10); + //comboBox_GPU.Items.Add(gpu); + Common.GPUList.Add(gpu); + Common.GPURAMList.Add(GPURAMList[gpucount]); + } + gpucount++; + } + + /*comboBox_GPU.SelectedIndex = 0; + if (Common.GPUList.Count == 1) + { + comboBox_GPU.Enabled = false; + } + else + { + comboBox_GPU.Enabled = true; + } + + label_Graphic.Text = Common.GPUList[0] + " [ " + Common.GPURAMList[0] + " MiB RAM ]";*/ + + /*if (GPUList.Count == 1) { if (fs != null) { - fs.Dispatcher.Invoke(d, "Detected GPU: " + GPU); + fs.Dispatcher.Invoke(d, "Detected GPU: " + GPUNList); } Thread.Sleep(10); - comboBox_GPU.Items.Add(GPU); + comboBox_GPU.Items.Add(GPUNList[0]); + comboBox_GPU.SelectedIndex = 0; + comboBox_GPU.Enabled = false; + label_Graphic.Text = GPUList[0]; } - comboBox_GPU.SelectedIndex = 0; - comboBox_GPU.Enabled = true; - label_Graphic.Text = GPUList[0]; - }*/ + else + { + foreach (var GPU in GPUNList) + { + if (fs != null) + { + fs.Dispatcher.Invoke(d, "Detected GPU: " + GPU); + } + Thread.Sleep(10); + comboBox_GPU.Items.Add(GPU); + } + comboBox_GPU.SelectedIndex = 0; + comboBox_GPU.Enabled = true; + label_Graphic.Text = GPUList[0]; + }*/ - ResetLabels(); - toolStripStatusLabel_Status.ForeColor = Color.FromArgb(0, 255, 0, 0); + ResetLabels(); + toolStripStatusLabel_Status.ForeColor = Color.FromArgb(0, 255, 0, 0); - if (fs != null) - { - fs.Dispatcher.Invoke(d, Strings.SplashFormUpdateCaption); - } - Thread.Sleep(200); - if (File.Exists(Directory.GetCurrentDirectory() + @"\updated.dat")) - { if (fs != null) { - fs.Dispatcher.Invoke(d, Strings.SplashFormUpdatingCaption); + fs.Dispatcher.Invoke(d, Strings.SplashFormUpdateCaption); } - File.Delete(Directory.GetCurrentDirectory() + @"\updated.dat"); - string updpath = Directory.GetCurrentDirectory()[..Directory.GetCurrentDirectory().LastIndexOf('\\')]; - File.Delete(updpath + @"\updater.exe"); - File.Delete(updpath + @"\waifu2x-nvger.zip"); - Common.DeleteDirectory(updpath + @"\updater-temp"); Thread.Sleep(200); + if (File.Exists(Directory.GetCurrentDirectory() + @"\updated.dat")) + { + if (fs != null) + { + fs.Dispatcher.Invoke(d, Strings.SplashFormUpdatingCaption); + } + File.Delete(Directory.GetCurrentDirectory() + @"\updated.dat"); + string updpath = Directory.GetCurrentDirectory()[..Directory.GetCurrentDirectory().LastIndexOf('\\')]; + File.Delete(updpath + @"\updater.exe"); + File.Delete(updpath + @"\waifu2x-nvger.zip"); + Common.DeleteDirectory(updpath + @"\updater-temp"); + Thread.Sleep(200); - if (fs != null) + if (fs != null) + { + fs.Dispatcher.Invoke(d, Strings.SplashFormUpdatedCaption); + } + Thread.Sleep(200); + + using Form dummy = new(); + dummy.TopMost = true; + MessageBox.Show(dummy, Strings.UpdateCompletedCaption, Strings.MSGInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); + dummy.TopMost = false; + } + else { - fs.Dispatcher.Invoke(d, Strings.SplashFormUpdatedCaption); + if (bool.Parse(Config.Entry["CheckUpdateWithStartup"].Value) == true) + { + UpdateTask = Task.Run(CheckForUpdatesForInit); + UpdateTask.Wait(); + + if (RunUpdate == true) + { + CloseSplash(); + Activate(); + Close(); + return; + } + } } - Thread.Sleep(200); - using Form dummy = new(); - dummy.TopMost = true; - MessageBox.Show(dummy, Strings.UpdateCompletedCaption, Strings.MSGInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); - dummy.TopMost = false; - } - else - { - if (bool.Parse(Config.Entry["CheckUpdateWithStartup"].Value) == true) + if (fs != null) { - UpdateTask = Task.Run(CheckForUpdatesForInit); - UpdateTask.Wait(); + fs.Dispatcher.Invoke(d, Strings.SplashFormFFCaption); + } - if (RunUpdate == true) - { - CloseSplash(); - Activate(); - Close(); - return; - } + if (bool.Parse(Config.Entry["CheckUpdateFFWithStartup"].Value) == true) + { + var ffupdate = Task.Run(() => CheckForFFmpeg()); + ffupdate.Wait(); } - } - if (fs != null) - { - fs.Dispatcher.Invoke(d, Strings.SplashFormFFCaption); + if (fs != null) + { + fs.Dispatcher.Invoke(d, Strings.SplashFormFinalCaption); + } + Thread.Sleep(200); } - if (bool.Parse(Config.Entry["CheckUpdateFFWithStartup"].Value) == true) + if (Common.GlobalException is not null) { - var ffupdate = Task.Run(() => CheckForFFmpeg()); - ffupdate.Wait(); + MessageBox.Show(this, string.Format(Strings.UnExpectedError, Common.GlobalException), Strings.MSGError, MessageBoxButtons.OK, MessageBoxIcon.Warning); } - if (fs != null) - { - fs.Dispatcher.Invoke(d, Strings.SplashFormFinalCaption); - } - Thread.Sleep(200); + CloseSplash(); + Activate(); } + catch (Exception ex) + { + using Form dummy = new(); + dummy.TopMost = true; + MessageBox.Show(dummy, "An unexpected error has occurred.\n\n" + ex, Strings.MSGError, MessageBoxButtons.OK, MessageBoxIcon.Error); + dummy.TopMost = false; - CloseSplash(); - Activate(); + CloseSplash(); + Activate(); + } + } private void OpenImegeIToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/src/Forms/FormSplashWPF.xaml.cs b/src/Forms/FormSplashWPF.xaml.cs index 07c99ab..deed1b9 100644 --- a/src/Forms/FormSplashWPF.xaml.cs +++ b/src/Forms/FormSplashWPF.xaml.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Net.Http; @@ -31,35 +32,44 @@ private void Grid_Loaded(object sender, RoutedEventArgs e) { Config.Load(Common.xmlpath); - switch (bool.Parse(Config.Entry["CustomSplashImage"].Value)) + try { - case true: - { - Bitmap bimg = new(Properties.Resources.waifu2x_splash); - Bitmap cimg = new(Config.Entry["SplashImagePath"].Value); - Graphics g = Graphics.FromImage(cimg); - g.DrawImage(bimg, 0, 0, bimg.Width, bimg.Height); - - image.Source = BIMG.ToBitmapImage(cimg); - break; - } - case false: - { - if (NetworkInterface.GetIsNetworkAvailable()) + switch (bool.Parse(Config.Entry["CustomSplashImage"].Value)) + { + case true: { - string url = "https://github.com/XyLe-GBP/waifu2x-ncnn-vulkan-GUI-Edition-Reloaded/raw/master/Properties/waifu2x-splash.png"; - Task st = stream.GetStreamAsync(url); - Bitmap bitmap = new(st.Result); + Bitmap bimg = new(Properties.Resources.waifu2x_splash); + Bitmap cimg = new(Config.Entry["SplashImagePath"].Value); + Graphics g = Graphics.FromImage(cimg); + g.DrawImage(bimg, 0, 0, bimg.Width, bimg.Height); - image.Source = BIMG.ToBitmapImage(bitmap); + image.Source = BIMG.ToBitmapImage(cimg); + break; } - else + case false: { - image.Source = BIMG.ToBitmapImage(Properties.Resources.waifu2x_splash); + if (NetworkInterface.GetIsNetworkAvailable()) + { + string url = "https://github.com/XyLe-GBP/waifu2x-ncnn-vulkan-GUI-Edition-Reloaded/raw/master/Properties/waifu2x-splash.png"; + Task st = stream.GetStreamAsync(url); + Bitmap bitmap = new(st.Result); + + image.Source = BIMG.ToBitmapImage(bitmap); + } + else + { + image.Source = BIMG.ToBitmapImage(Properties.Resources.waifu2x_splash); + } + break; } - break; - } + } + } + catch (Exception ex) + { + Common.GlobalException = ex; + image.Source = BIMG.ToBitmapImage(Properties.Resources.waifu2x_splash); } + } public string ProgressMsg