diff --git a/DockerForm/DatabaseManager.cs b/DockerForm/DatabaseManager.cs index 4495fbf..76574ae 100644 --- a/DockerForm/DatabaseManager.cs +++ b/DockerForm/DatabaseManager.cs @@ -204,7 +204,7 @@ public static bool Equality(byte[] a1, byte[] b1) return true; } - public static void SanityCheck() + public static bool SanityCheck() { string path_db = Form1.CurrentController.Name; @@ -262,11 +262,11 @@ public static void SanityCheck() } if (fileBytes == null || fileDBBytes == null) - return; + return true; if (path_db != crc_value) { - Form1.SendNotification("CRC missmatch detected for " + game.Name + ". Settings will be restored. (CRC: " + crc_value + ", Current: " + path_db + ")", true, true); + Form1.SendNotification("CRC missmatch detected for " + game.Name + ". Settings will be restored. (CRC: " + crc_value + ", Current: " + path_db + ")", true, true, true); // Overwrite current database and restore last known settings UpdateFilesAndRegistries(game, crc_value, path_db, true, true, false, path_db); @@ -275,7 +275,7 @@ public static void SanityCheck() } else if (!Equality(fileBytes,fileDBBytes)) { - Form1.SendNotification("Database sync conflict detected for " + game.Name, true, true); + Form1.SendNotification("Database sync conflict detected for " + game.Name, true, true, true); DialogBox dialogBox = new DialogBox(); dialogBox.UpdateDialogBox("Database Sync Conflict", game.Name, game.LastCheck, file.LastWriteTime); @@ -290,6 +290,7 @@ public static void SanityCheck() } Form1.IsFirstBoot = false; + return true; } public static List SearchMicrosoftStore() diff --git a/DockerForm/Form1.Designer.cs b/DockerForm/Form1.Designer.cs index c566a22..c327544 100644 --- a/DockerForm/Form1.Designer.cs +++ b/DockerForm/Form1.Designer.cs @@ -41,7 +41,6 @@ private void InitializeComponent() this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip2 = new System.Windows.Forms.MenuStrip(); this.undockedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.debugTextBox = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripStartItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); @@ -131,8 +130,7 @@ private void InitializeComponent() this.menuStrip2.Dock = System.Windows.Forms.DockStyle.Bottom; this.menuStrip2.ImageScalingSize = new System.Drawing.Size(24, 24); this.menuStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.undockedToolStripMenuItem, - this.debugTextBox}); + this.undockedToolStripMenuItem}); this.menuStrip2.Location = new System.Drawing.Point(0, 529); this.menuStrip2.Name = "menuStrip2"; this.menuStrip2.Size = new System.Drawing.Size(1008, 32); @@ -146,11 +144,6 @@ private void InitializeComponent() this.undockedToolStripMenuItem.Size = new System.Drawing.Size(95, 28); this.undockedToolStripMenuItem.Text = "Reading..."; // - // debugTextBox - // - this.debugTextBox.Name = "debugTextBox"; - this.debugTextBox.Size = new System.Drawing.Size(12, 28); - // // contextMenuStrip1 // this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); @@ -336,7 +329,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem toolStripStartItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; - private System.Windows.Forms.ToolStripMenuItem debugTextBox; } } diff --git a/DockerForm/Form1.cs b/DockerForm/Form1.cs index 919c0e3..7e4f93a 100644 --- a/DockerForm/Form1.cs +++ b/DockerForm/Form1.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Globalization; +using System.Threading.Tasks; namespace DockerForm { @@ -19,6 +20,7 @@ public partial class Form1 : Form public static bool DockStatus = false; public static bool IsFirstBoot = true; public static bool IsHardwareNew = false; + public static bool IsHardwarePending = false; public static VideoController CurrentController; // Configurable vars @@ -52,19 +54,22 @@ protected override void WndProc(ref Message m) { if (!DatabaseManager.IsUpdating()) { - ThreadGPU = new Thread(VideoControllerMonitor); - ThreadGPU.Start(); + if (!IsFirstBoot) + { + ThreadGPU = new Thread(VideoControllerMonitor); + ThreadGPU.Start(); + } + else if (!IsHardwarePending) + IsHardwarePending = true; } } base.WndProc(ref m); } - public static void SendNotification(string input, bool pushToast = false, bool pushLog = false) + public static void SendNotification(string input, bool pushToast = false, bool pushLog = false, bool IsError = false) { - _instance.BeginInvoke(new Action(() => _instance.debugTextBox.Text = input)); - if (pushLog) - LogManager.UpdateLog(input); + LogManager.UpdateLog(input, IsError); if (pushToast && ToastNotifications) { @@ -156,7 +161,7 @@ public static void VideoControllerMonitor(object data) CurrentController = DockStatus ? VideoControllers[Type.Discrete] : VideoControllers[Type.Internal]; // monitor hardware changes - IsHardwareNew = prevDockStatus != DockStatus; + IsHardwareNew = IsFirstBoot ? false : prevDockStatus != DockStatus; if (IsHardwareNew || IsFirstBoot) { @@ -165,10 +170,10 @@ public static void VideoControllerMonitor(object data) if (VideoControllers.ContainsKey(Type.Discrete)) LogManager.UpdateLog("eGPU: " + VideoControllers[Type.Discrete].Name); - _instance.BeginInvoke(new Action(() => UpdateFormIcons())); - if (IsFirstBoot) + { DatabaseManager.SanityCheck(); + } else { DatabaseManager.UpdateFilesAndRegistries(prevDockStatus, false, true); @@ -176,7 +181,15 @@ public static void VideoControllerMonitor(object data) } } + // update status prevDockStatus = DockStatus; + UpdateFormIcons(); + + if (IsHardwarePending) + { + IsHardwarePending = false; + VideoControllerMonitor(data); + } } catch (Exception ex) { LogManager.UpdateLog("VideoControllerMonitor: " + ex.Message, true); } } @@ -185,9 +198,6 @@ public static void UpdateFormIcons() { try { - // taskbar text - _instance.menuStrip2.Items[0].Text = CurrentController.Name; - // taskbar icon Image ConstructorLogo = Properties.Resources.intel; switch(CurrentController.Constructor) @@ -195,12 +205,17 @@ public static void UpdateFormIcons() case Constructor.AMD: ConstructorLogo = Properties.Resources.amd; break; case Constructor.Nvidia: ConstructorLogo = Properties.Resources.nvidia; break; } - _instance.undockedToolStripMenuItem.Image = ConstructorLogo; - // main application icon Icon myIcon = DockStatus ? Properties.Resources.tb3_on : Properties.Resources.tb3_off; - _instance.notifyIcon1.Icon = myIcon; - _instance.Icon = myIcon; + + // drawing + _instance.BeginInvoke((MethodInvoker)delegate () + { + _instance.menuStrip2.Items[0].Text = CurrentController.Name; + _instance.undockedToolStripMenuItem.Image = ConstructorLogo; + _instance.notifyIcon1.Icon = myIcon; + _instance.Icon = myIcon; + }); } catch (Exception ex) { LogManager.UpdateLog("UpdateFormIcons: " + ex.Message, true); } }