Esempio n. 1
0
        // Add code to be executed when game is preparing to be started.
        public override void OnGameStopped(Game game, long elapsedSeconds)
        {
            var TaskGameStopped = Task.Run(() =>
            {
                // Stop timer si HWiNFO log is enable.
                if (settings.EnableLogging)
                {
                    dataHWiNFO_stop();
                }

                // Infos
                GameActivitiesLog.GetLastSessionActivity().ElapsedSeconds = elapsedSeconds;
                PluginDatabase.Update(GameActivitiesLog);

                // Refresh integration interface
                var TaskIntegrationUI = Task.Run(() =>
                {
                    var dispatcherOp        = gameActivityUI.AddElements();
                    dispatcherOp.Completed += (s, e) => { gameActivityUI.RefreshElements(ActivityDatabase.GameSelected); };
                });
            });
        }
Esempio n. 2
0
        public override void RefreshElements(Game GameSelected, bool force = false)
        {
#if DEBUG
            logger.Debug($"GameActivity [Ignored] - RefreshElements({GameSelected.Name})");
#endif
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       ct          = tokenSource.Token;

            Task TaskRefresh = Task.Run(() =>
            {
                try
                {
                    Initial();

                    // Reset resources
                    List <ResourcesList> resourcesLists = new List <ResourcesList>();
                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_HasData", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_HasDataLog", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_LastDateSession", Value = string.Empty
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_LastDateTimeSession", Value = string.Empty
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_LastPlaytimeSession", Value = string.Empty
                    });

                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_IntegrationShowGraphic", Value = PluginDatabase.PluginSettings.IntegrationShowGraphic
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Ga_IntegrationShowGraphicLog", Value = PluginDatabase.PluginSettings.IntegrationShowGraphicLog
                    });
                    ui.AddResources(resourcesLists);


                    // Load data
                    if (!GameActivity.PluginDatabase.IsLoaded)
                    {
                        return;
                    }
                    GameActivities gameActivities = GameActivity.PluginDatabase.Get(GameSelected);

                    if (gameActivities.HasData)
                    {
                        resourcesLists = new List <ResourcesList>();
                        resourcesLists.Add(new ResourcesList {
                            Key = "Ga_IntegrationShowGraphic", Value = PluginDatabase.PluginSettings.IntegrationShowGraphic
                        });
                        resourcesLists.Add(new ResourcesList {
                            Key = "Ga_IntegrationShowGraphicLog", Value = PluginDatabase.PluginSettings.IntegrationShowGraphicLog
                        });

                        resourcesLists.Add(new ResourcesList {
                            Key = "Ga_HasData", Value = gameActivities.HasData
                        });

                        try
                        {
                            var data = gameActivities.GetSessionActivityDetails();
                            resourcesLists.Add(new ResourcesList {
                                Key = "Ga_HasDataLog", Value = gameActivities.HasDataDetails()
                            });
                        }
                        catch
                        {
                        }

                        try
                        {
                            resourcesLists.Add(new ResourcesList {
                                Key = "Ga_LastDateSession", Value = gameActivities.GetLastSession().ToLocalTime().ToString(Constants.DateUiFormat)
                            });
                            resourcesLists.Add(new ResourcesList
                            {
                                Key   = "Ga_LastDateTimeSession",
                                Value = gameActivities.GetLastSession().ToLocalTime().ToString(Constants.DateUiFormat)
                                        + " " + gameActivities.GetLastSession().ToLocalTime().ToString(Constants.TimeUiFormat)
                            });
                        }
                        catch
                        {
                        }

                        try
                        {
                            LongToTimePlayedConverter converter = new LongToTimePlayedConverter();
                            string playtime = (string)converter.Convert((long)gameActivities.GetLastSessionActivity().ElapsedSeconds, null, null, CultureInfo.CurrentCulture);
                            resourcesLists.Add(new ResourcesList {
                                Key = "Ga_LastPlaytimeSession", Value = playtime
                            });
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        logger.Warn($"GameActivity - No data for {GameSelected.Name}");
                    }

                    // If not cancel, show
                    if (!ct.IsCancellationRequested && GameSelected.Id == ActivityDatabase.GameSelected.Id)
                    {
                        ui.AddResources(resourcesLists);

                        if (_PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
                        {
                            PluginDatabase.SetCurrent(gameActivities);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "GameActivity");
                }
            }, ct);

            taskHelper.Add(TaskRefresh, tokenSource);
        }