public static void AddAllTag(IPlayniteAPI PlayniteApi, Game game, string PluginUserDataPath)
        {
            RemoveAllTag(PlayniteApi, game);

            if (HaveData(game.Id, PluginUserDataPath))
            {
                try {
                    HowLongToBeatData howLongToBeatData = new HowLongToBeatData(game, PluginUserDataPath, PlayniteApi, false);
                    HltbDataUser      data   = howLongToBeatData.GetData();
                    List <Guid>       tagIds = SetListHltbTag(PlayniteApi, data);

                    if (tagIds.Count > 0)
                    {
                        game.TagIds = tagIds;
                        PlayniteApi.Database.Games.Update(game);
                    }
                }
                catch (Exception ex)
                {
#if DEBUG
                    Common.LogError(ex, "HowLongToBeat", $"Error on AddAllTag()");
#endif
                    logger.Error($"HowLongToBeat - Tag insert error with {game.Name}");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "HowLongToBeat-Tag-Errors",
                                                      "HowLongToBeat\r\n" + resources.GetString("LOCCommonNotificationTagError"),
                                                      NotificationType.Error
                                                      ));
                }
            }
        }
Example #2
0
        public static void AddAllTag(IPlayniteAPI PlayniteApi, Game game, string PluginUserDataPath)
        {
            RemoveAllTag(PlayniteApi, game);

            if (HaveData(game.Id, PluginUserDataPath))
            {
                try {
                    HowLongToBeatData howLongToBeatData = new HowLongToBeatData(game, PluginUserDataPath, PlayniteApi, false);
                    HltbDataUser      data   = howLongToBeatData.GetData();
                    List <Guid>       tagIds = SetListHltbTag(PlayniteApi, data);

                    if (tagIds.Count > 0)
                    {
                        game.TagIds = tagIds;
                        PlayniteApi.Database.Games.Update(game);
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "HowLongToBeat", $"Tag insert error with {game.Name}");
                }
            }
        }
        public static void GetAllDataFromMain(IPlayniteAPI PlayniteApi, string PluginUserDataPath, HowLongToBeatSettings settings)
        {
            GlobalProgressOptions globalProgressOptions = new GlobalProgressOptions(
                resources.GetString("LOCCommonGettingAllDatas"),
                true
                );

            globalProgressOptions.IsIndeterminate = false;

            PlayniteApi.Dialogs.ActivateGlobalProgress((activateGlobalProgress) =>
            {
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                var db = PlayniteApi.Database.Games.Where(x => x.Hidden == false);
                activateGlobalProgress.ProgressMaxValue = (double)db.Count();

                string CancelText = string.Empty;

                foreach (Game game in db)
                {
                    if (activateGlobalProgress.CancelToken.IsCancellationRequested)
                    {
                        CancelText = " canceled";
                        break;
                    }

                    if (!HowLongToBeatData.HaveData(game.Id, PluginUserDataPath))
                    {
                        List <HltbData> dataSearch = new HowLongToBeatClient().Search(game.Name);

                        if (dataSearch.Count == 1 && settings.AutoAccept)
                        {
                            HowLongToBeatData.SaveData(game.Id, dataSearch[0], PluginUserDataPath);

                            if (settings.EnableTag)
                            {
                                HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath);
                            }
                        }
                        else
                        {
                            if (dataSearch.Count > 0 && settings.ShowWhenMismatch)
                            {
                                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                                {
                                    string FileGameData = PluginUserDataPath + "\\howlongtobeat\\" + game.Id.ToString() + ".json";

                                    var ViewExtension      = new HowLongToBeatSelect(dataSearch, FileGameData, game.Name);
                                    Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSelection"), ViewExtension);
                                    windowExtension.ShowDialog();

                                    if (settings.EnableTag)
                                    {
                                        HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath);
                                    }
                                }).Wait();
                            }
                        }
                    }
                    activateGlobalProgress.CurrentProgressValue++;
                }

                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;
                logger.Info($"HowLongToBeat - Task GetAllDataFromMain(){CancelText} - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
            }, globalProgressOptions);
        }