示例#1
0
        private void ButtonAddTag_Click(object sender, RoutedEventArgs e)
        {
            tbDataLoad.Text            = resources.GetString("LOCHowLongToBeatProgressBarTag");
            pbDataLoad.IsIndeterminate = true;

            DataLoad.Visibility   = Visibility.Visible;
            spSettings.Visibility = Visibility.Hidden;

            tokenSource = new CancellationTokenSource();
            ct          = tokenSource.Token;

            var taskSystem = Task.Run(() =>
            {
                ct.ThrowIfCancellationRequested();

                foreach (Game game in PlayniteApi.Database.Games)
                {
                    HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath);

                    if (ct.IsCancellationRequested)
                    {
                        ct.ThrowIfCancellationRequested();
                    }
                }
            }, tokenSource.Token)
                             .ContinueWith(antecedent =>
            {
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    DataLoad.Visibility   = Visibility.Collapsed;
                    spSettings.Visibility = Visibility.Visible;
                }));
            });
        }
示例#2
0
        private void BtAddData_Click(object sender, RoutedEventArgs e)
        {
            bool AutoAccept       = (bool)cbAutoAccept.IsChecked;
            bool ShowWhenMismatch = (bool)cbShowWhenMismatch.IsChecked;
            bool EnableTag        = (bool)cbEnableTag.IsChecked;

            pbDataLoad.IsIndeterminate = false;
            pbDataLoad.Minimum         = 0;
            pbDataLoad.Value           = 0;
            pbDataLoad.Maximum         = PlayniteApi.Database.Games.Count;

            DataLoad.Visibility   = Visibility.Visible;
            spSettings.Visibility = Visibility.Hidden;

            tokenSource = new CancellationTokenSource();
            ct          = tokenSource.Token;

            int TotalAdded     = 0;
            int TotalAlready   = 0;
            int TotalMultiFind = 0;
            int TotlaNotFind   = 0;

            var taskSystem = Task.Run(() =>
            {
                ct.ThrowIfCancellationRequested();

                foreach (Game game in PlayniteApi.Database.Games)
                {
                    try
                    {
                        if (!HowLongToBeatData.HaveData(game.Id, PluginUserDataPath))
                        {
                            List <HltbData> dataSearch = new HowLongToBeatClient().Search(game.Name);

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

                                if (EnableTag)
                                {
                                    HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath);
                                }

                                TotalAdded += 1;
                            }
                            else
                            {
                                TotalMultiFind += 1;
                                if (dataSearch.Count > 0 && ShowWhenMismatch)
                                {
                                    Application.Current.Dispatcher.Invoke(new Action(() =>
                                    {
                                        string FileGameData = PluginUserDataPath + "\\howlongtobeat\\" + game.Id.ToString() + ".json";
                                        new HowLongToBeatSelect(dataSearch, FileGameData, game.Name).ShowDialog();

                                        if (EnableTag)
                                        {
                                            HowLongToBeatData.AddAllTag(PlayniteApi, game, PluginUserDataPath);
                                        }
                                    }));
                                }
                                else
                                {
                                    TotlaNotFind += 1;
                                }
                            }
                        }
                        else
                        {
                            TotalAlready += 1;
                            logger.Debug($"HowLongToBeat - {game.Name}");
                        }
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            tbDataLoad.Text   = string.Format(resources.GetString("LOCHowLongToBeatProgressBar"), TotalAdded, TotalAlready, TotlaNotFind);
                            pbDataLoad.Value += 1;
                        }));
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex, "HowLongToBeat", $"Error on BtAddData_Click()");
                    }

                    if (ct.IsCancellationRequested)
                    {
                        ct.ThrowIfCancellationRequested();
                    }
                }
            }, tokenSource.Token)
                             .ContinueWith(antecedent =>
            {
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    DataLoad.Visibility   = Visibility.Collapsed;
                    spSettings.Visibility = Visibility.Visible;
                }));
            });
        }