Skip to content

Commit

Permalink
implemented GetCurrentState(), GetCurrentPower()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lesueur Benjamin committed Feb 3, 2021
1 parent fdf9661 commit 80553b1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
Binary file modified .vs/DockerForm/v16/.suo
Binary file not shown.
42 changes: 8 additions & 34 deletions DockerForm/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,9 @@ public static void UpdateFilesAndRegistries(DockerGame game, string path_dest, s
continue;
}

// use opposite status if current powerstatus is missing
if (setting.data.ContainsKey((updateDB ? path_game : path_dest) + Form1.PowerStatus))
{
if (updateDB)
path_game += Form1.PowerStatus;
else
path_dest += Form1.PowerStatus;

crc_value = (updateDB ? path_game : path_dest);
}
else if (setting.data.ContainsKey((updateDB ? path_game : path_dest) + !Form1.PowerStatus))
{
if (updateDB)
path_game += Form1.PowerStatus;
else
path_dest += Form1.PowerStatus;

crc_value = (updateDB ? path_game : path_dest);
}
else if (!setting.data.ContainsKey((updateDB ? path_game : path_dest)))
continue;
// check if we have opposite plugged status
if (updateFILE && !setting.data.ContainsKey(path_dest))
path_dest = path_dest.Replace(":False", "");

if (setting.Type == SettingsType.File)
{
Expand All @@ -132,7 +114,7 @@ public static void UpdateFilesAndRegistries(DockerGame game, string path_dest, s
}
else
{
LogManager.UpdateLog("[" + game.Name + "]" + " " + path_dest + " database update skipped for file [" + file + "] - no data available");
LogManager.UpdateLog("[" + game.Name + "]" + " " + path_dest + " settings restoration skipped for file [" + file + "] - no data available");
}
}
}
Expand Down Expand Up @@ -163,7 +145,7 @@ public static void UpdateFilesAndRegistries(DockerGame game, string path_dest, s
}
else
{
LogManager.UpdateLog("[" + game.Name + "]" + " " + path_dest + " database update skipped for registry entry [" + file + "] - no data available");
LogManager.UpdateLog("[" + game.Name + "]" + " " + path_dest + " settings restoration skipped for registry entry [" + file + "] - no data available");
}
}

Expand All @@ -175,12 +157,12 @@ public static void UpdateFilesAndRegistries(DockerGame game, string path_dest, s
game.SetCrc(crc_value);
game.Serialize();

Form1.SendNotification(game.Name + " settings have been updated for (" + path_dest + ")", pushToast);
Form1.SendNotification(game.Name + " settings have been updated", pushToast);
}

public static void UpdateFilesAndRegistries(bool updateFILE, bool updateDB)
{
string path_db = Form1.CurrentController.Name;
string path_db = Form1.GetCurrentState();

foreach (DockerGame game in GameDB.Values)
UpdateFilesAndRegistries(game, path_db, game.GetCrc(), updateDB, updateFILE, false, path_db);
Expand Down Expand Up @@ -218,7 +200,7 @@ public static bool Equality(byte[] a1, byte[] b1)

public static bool SanityCheck()
{
string path_db = Form1.CurrentController.Name;
string path_db = Form1.GetCurrentState();

foreach (DockerGame game in GameDB.Values)
{
Expand Down Expand Up @@ -250,14 +232,6 @@ public static bool SanityCheck()
continue;
}

// use opposite status if current powerstatus is missing
if (setting.data.ContainsKey(path_db + Form1.PowerStatus))
path_db += Form1.PowerStatus;
else if (setting.data.ContainsKey(path_db + !Form1.PowerStatus))
path_db += !Form1.PowerStatus;
else if (!setting.data.ContainsKey(path_db))
continue;

if (setting.Type == SettingsType.File)
{
file = new FileInfo(filename);
Expand Down
45 changes: 36 additions & 9 deletions DockerForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ protected override void WndProc(ref Message m)
base.WndProc(ref m);
}

private static void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
IsHardwarePending = true;
}

public static void SendNotification(string input, bool pushToast = false, bool pushLog = false, bool IsError = false)
{
if (pushLog)
Expand Down Expand Up @@ -127,12 +132,32 @@ static void stopWatch_EventArrived(object sender, EventArrivedEventArgs e)

// Update current title
if (game_exe == info_exe || game_uri == info_uri)
DatabaseManager.UpdateFilesAndRegistries(game, CurrentController.Name, CurrentController.Name, true, false, true, CurrentController.Name);
DatabaseManager.UpdateFilesAndRegistries(game, GetCurrentState(), GetCurrentState(), true, false, true, GetCurrentState());
}
}
catch (Exception ex) { }
}

public static string GetCurrentState()
{
string state = CurrentController.Name;

/*
* NVIDIA GeForce RTX 2070
* Intel(R) Iris(R) Plus Graphics
* Intel(R) Iris(R) Plus Graphics:False
*/
if (!DockStatus && !PowerStatus)
state += ":" + PowerStatus;

return state;
}

public static string GetCurrentPower()
{
return PowerStatus ? "plugged in" : "on battery";
}

public static void VideoControllerMonitor(object data)
{
while(IsRunning)
Expand Down Expand Up @@ -178,15 +203,14 @@ public static void VideoControllerMonitor(object data)
{
if (IsHardwareNew)
{
if (VideoControllers.ContainsKey(Type.Internal))
LogManager.UpdateLog("iGPU: " + VideoControllers[Type.Internal].Name);
if (VideoControllers.ContainsKey(Type.Discrete))
LogManager.UpdateLog("eGPU: " + VideoControllers[Type.Discrete].Name);
else if (VideoControllers.ContainsKey(Type.Internal))
LogManager.UpdateLog("iGPU: " + VideoControllers[Type.Internal].Name);
}
else if (IsPowerNew)
{
LogManager.UpdateLog("Power: " + PowerStatus);
}

if (IsPowerNew)
LogManager.UpdateLog("Power Status: " + GetCurrentPower());

if (IsFirstBoot)
{
Expand Down Expand Up @@ -230,7 +254,7 @@ public static void UpdateFormIcons()
// drawing
_instance.BeginInvoke((MethodInvoker)delegate ()
{
_instance.menuStrip2.Items[0].Text = CurrentController.Name + " (" + (PowerStatus ? "plugged in" : "on battery") + ")";
_instance.menuStrip2.Items[0].Text = CurrentController.Name + " (" + GetCurrentPower() + ")";
_instance.undockedToolStripMenuItem.Image = ConstructorLogo;
_instance.notifyIcon1.Icon = myIcon;
_instance.Icon = myIcon;
Expand Down Expand Up @@ -266,7 +290,7 @@ public void InsertOrUpdateGameItem(DockerGame game, bool Update = true)

// Update current title
DockerGame output = DatabaseManager.GameDB[game.GUID];
DatabaseManager.UpdateFilesAndRegistries(output, CurrentController.Name, CurrentController.Name, true, false, true, CurrentController.Name);
DatabaseManager.UpdateFilesAndRegistries(output, GetCurrentState(), GetCurrentState(), true, false, true, GetCurrentState());

GameList.Sort();
}
Expand Down Expand Up @@ -369,6 +393,9 @@ private void Form1_Shown(object sender, System.EventArgs e)

LogManager.UpdateLog("Process monitor has started");
}

// Monitor Power Status
SystemEvents.PowerModeChanged += OnPowerModeChanged;
}

private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
Expand Down

0 comments on commit 80553b1

Please sign in to comment.