コード例 #1
0
        public HowLongToBeatDatabase(HowLongToBeat plugin, IPlayniteAPI PlayniteApi, HowLongToBeatSettings PluginSettings, string PluginUserDataPath) : base(PlayniteApi, PluginSettings, PluginUserDataPath)
        {
            PluginName = "HowLongToBeat";

            ControlAndCreateDirectory(PluginUserDataPath, "HowLongToBeat");

            howLongToBeatClient = new HowLongToBeatClient(plugin, PlayniteApi);
        }
コード例 #2
0
        public HowLongToBeatData(Game game, string PluginUserDataPath, IPlayniteAPI PlayniteApi, bool mustFind = true)
        {
            _PlayniteApi = PlayniteApi;
            _game        = game;

            string PluginDatabasePath = PluginUserDataPath + "\\howlongtobeat";

            if (!Directory.Exists(PluginDatabasePath))
            {
                Directory.CreateDirectory(PluginDatabasePath);
            }

            FileGameData = PluginDatabasePath + "\\" + game.Id.ToString() + ".json";

            if (File.Exists(FileGameData))
            {
                // Load data
                logger.Info($"HowLongToBeat - Load data for {game.Name}");

                data = JsonConvert.DeserializeObject <HltbDataUser>(File.ReadAllText(FileGameData));
            }
            else
            {
                if (mustFind)
                {
                    // Search data
                    logger.Info($"HowLongToBeat - Search data for {game.Name}");

                    List <HltbData> dataSearch = new HowLongToBeatClient().Search(game.Name);
                    new HowLongToBeatSelect(dataSearch, FileGameData, game.Name).ShowDialog();

                    if (File.Exists(FileGameData))
                    {
                        data = JsonConvert.DeserializeObject <HltbDataUser>(File.ReadAllText(FileGameData));
                    }
                    else
                    {
                    }
                }
            }

            if (data != null && data != new HltbDataUser())
            {
                hasData = true;
            }
        }
コード例 #3
0
        public HowLongToBeatData(Game game, string PluginUserDataPath, bool mustFind = true)
        {
            string PluginDatabasePath = PluginUserDataPath + "\\howlongtobeat";

            if (!Directory.Exists(PluginDatabasePath))
            {
                Directory.CreateDirectory(PluginDatabasePath);
            }

            FileGameData = PluginDatabasePath + "\\" + game.Id.ToString() + ".json";

            if (File.Exists(FileGameData))
            {
                // Load data
                logger.Info("HowLongToBeat - Load data");

                data = JsonConvert.DeserializeObject <HltbDataUser>(File.ReadAllText(FileGameData));
            }
            else
            {
                if (mustFind)
                {
                    // Create data
                    logger.Debug("HowLongToBeat - Create data");

                    List <HltbData> dataSearch = new HowLongToBeatClient().Search(game.Name);
                    new HowLongToBeatSelect(dataSearch, FileGameData).ShowDialog();

                    if (File.Exists(FileGameData))
                    {
                        data = JsonConvert.DeserializeObject <HltbDataUser>(File.ReadAllText(FileGameData));
                    }
                    else
                    {
                    }
                }
            }
        }
        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);
        }