Skip to content

Commit

Permalink
implemented HardwarePending check
Browse files Browse the repository at this point in the history
Usefull when hardware changes during CRC check and awaiting users commands.
  • Loading branch information
Lesueur Benjamin committed Nov 16, 2020
1 parent cf44ed5 commit 180806a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
9 changes: 5 additions & 4 deletions DockerForm/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -290,6 +290,7 @@ public static void SanityCheck()
}

Form1.IsFirstBoot = false;
return true;
}

public static List<DockerGame> SearchMicrosoftStore()
Expand Down
10 changes: 1 addition & 9 deletions DockerForm/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 31 additions & 16 deletions DockerForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Globalization;
using System.Threading.Tasks;

namespace DockerForm
{
Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -165,18 +170,26 @@ 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);
DatabaseManager.UpdateFilesAndRegistries(DockStatus, true, false);
}
}

// update status
prevDockStatus = DockStatus;
UpdateFormIcons();

if (IsHardwarePending)
{
IsHardwarePending = false;
VideoControllerMonitor(data);
}
}
catch (Exception ex) { LogManager.UpdateLog("VideoControllerMonitor: " + ex.Message, true); }
}
Expand All @@ -185,22 +198,24 @@ public static void UpdateFormIcons()
{
try
{
// taskbar text
_instance.menuStrip2.Items[0].Text = CurrentController.Name;

// taskbar icon
Image ConstructorLogo = Properties.Resources.intel;
switch(CurrentController.Constructor)
{
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); }
}
Expand Down

0 comments on commit 180806a

Please sign in to comment.