Skip to content

Commit

Permalink
code optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacro59 committed May 18, 2022
1 parent d8b7b8b commit b420779
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions source/GameActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public GameActivity(IPlayniteAPI api) : base(api)
Title = resources.GetString("LOCGameActivityViewGamesActivities"),
Activated = () =>
{
var windowOptions = new WindowOptions
WindowOptions windowOptions = new WindowOptions
{
ShowMinimizeButton = false,
ShowMaximizeButton = true,
Expand All @@ -136,7 +136,7 @@ public GameActivity(IPlayniteAPI api) : base(api)
Height = 740
};

var ViewExtension = new GameActivityView();
GameActivityView ViewExtension = new GameActivityView();
Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCGamesActivitiesTitle"), ViewExtension, windowOptions);
windowExtension.ResizeMode = ResizeMode.CanResize;
windowExtension.ShowDialog();
Expand Down Expand Up @@ -271,8 +271,7 @@ private bool CheckGoodForLogging(bool WithNotification = false)
/// </summary>
public void DataLogging_start(Guid Id)
{
logger.Info($"DataLogging_start - {Id}");

logger.Info($"DataLogging_start - {Id}");
RunningActivity runningActivity = runningActivities.Find(x => x.Id == Id);

runningActivity.timer = new System.Timers.Timer(PluginSettings.Settings.TimeIntervalLogging * 60000);
Expand All @@ -287,15 +286,14 @@ public void DataLogging_start(Guid Id)
public void DataLogging_stop(Guid Id)
{
logger.Info($"DataLogging_stop - {Id}");

RunningActivity runningActivity = runningActivities.Find(x => x.Id == Id);
if (runningActivity.WarningsMessage.Count != 0 && PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
{
try
{
Application.Current.Dispatcher.BeginInvoke((Action)delegate
{
var ViewExtension = new WarningsDialogs(runningActivity.WarningsMessage);
WarningsDialogs ViewExtension = new WarningsDialogs(runningActivity.WarningsMessage);
Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCGameActivityWarningCaption"), ViewExtension);
windowExtension.ShowDialog();
});
Expand Down Expand Up @@ -434,7 +432,7 @@ private async void OnTimedEvent(Object source, ElapsedEventArgs e, Guid Id)
{
try
{
foreach (var sensorItems in dataHWinfo)
foreach (HWiNFODumper.JsonObj sensorItems in dataHWinfo)
{
dynamic sensorItemsOBJ = Serialization.FromJson<dynamic>(Serialization.ToJson(sensorItems));

Expand All @@ -444,7 +442,7 @@ private async void OnTimedEvent(Object source, ElapsedEventArgs e, Guid Id)
if (sensorsID.ToLower() == PluginSettings.Settings.HWiNFO_fps_sensorsID.ToLower())
{
// Find data fps
foreach (var items in sensorItemsOBJ["sensors"])
foreach (dynamic items in sensorItemsOBJ["sensors"])
{
dynamic itemOBJ = Serialization.FromJson<dynamic>(Serialization.ToJson(items));
string dataID = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");
Expand All @@ -460,7 +458,7 @@ private async void OnTimedEvent(Object source, ElapsedEventArgs e, Guid Id)
if (sensorsID.ToLower() == PluginSettings.Settings.HWiNFO_gpu_sensorsID.ToLower())
{
// Find data gpu
foreach (var items in sensorItemsOBJ["sensors"])
foreach (dynamic items in sensorItemsOBJ["sensors"])
{
dynamic itemOBJ = Serialization.FromJson<dynamic>(Serialization.ToJson(items));
string dataID = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");
Expand All @@ -476,7 +474,7 @@ private async void OnTimedEvent(Object source, ElapsedEventArgs e, Guid Id)
if (sensorsID.ToLower() == PluginSettings.Settings.HWiNFO_gpuT_sensorsID.ToLower())
{
// Find data gpu
foreach (var items in sensorItemsOBJ["sensors"])
foreach (dynamic items in sensorItemsOBJ["sensors"])
{
dynamic itemOBJ = Serialization.FromJson<dynamic>(Serialization.ToJson(items));
string dataID = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");
Expand All @@ -492,7 +490,7 @@ private async void OnTimedEvent(Object source, ElapsedEventArgs e, Guid Id)
if (sensorsID.ToLower() == PluginSettings.Settings.HWiNFO_cpuT_sensorsID.ToLower())
{
// Find data gpu
foreach (var items in sensorItemsOBJ["sensors"])
foreach (dynamic items in sensorItemsOBJ["sensors"])
{
dynamic itemOBJ = Serialization.FromJson<dynamic>(Serialization.ToJson(items));
string dataID = "0x" + ((uint)itemOBJ["dwSensorID"]).ToString("X");
Expand Down Expand Up @@ -596,8 +594,13 @@ private async void OnTimedEvent(Object source, ElapsedEventArgs e, Guid Id)
public void DataBackup_start(Guid Id)
{
RunningActivity runningActivity = runningActivities.Find(x => x.Id == Id);
if (runningActivity == null)
{
logger.Warn($"No runningActivity find for {Id}");
return;
}

runningActivity.timerBackup = new System.Timers.Timer(60000);
runningActivity.timerBackup = new System.Timers.Timer(PluginSettings.Settings.TimeIntervalLogging * 60000);
runningActivity.timerBackup.AutoReset = true;
runningActivity.timerBackup.Elapsed += (sender, e) => OnTimedBackupEvent(sender, e, Id);
runningActivity.timerBackup.Start();
Expand All @@ -606,6 +609,11 @@ public void DataBackup_start(Guid Id)
public void DataBackup_stop(Guid Id)
{
RunningActivity runningActivity = runningActivities.Find(x => x.Id == Id);
if (runningActivity == null)
{
logger.Warn($"No runningActivity find for {Id}");
return;
}

runningActivity.timerBackup.AutoReset = false;
runningActivity.timerBackup.Stop();
Expand Down Expand Up @@ -1091,7 +1099,7 @@ public override void OnGameStarted(OnGameStartedEventArgs args)
// Add code to be executed when game is preparing to be started.
public override void OnGameStopped(OnGameStoppedEventArgs args)
{
var TaskGameStopped = Task.Run(() =>
Task.Run(() =>
{
try
{
Expand Down

0 comments on commit b420779

Please sign in to comment.