public void SearchData(Game game) { #if DEBUG logger.Debug($"HowLongToBeat - Search data for {game.Name}"); #endif var ViewExtension = new HowLongToBeatSelect(null, FileGameData, game.Name); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(_PlayniteApi, resources.GetString("LOCSelection"), ViewExtension); windowExtension.ShowDialog(); if (File.Exists(FileGameData)) { hltbDataUser = JsonConvert.DeserializeObject <HltbDataUser>(File.ReadAllText(FileGameData)); } else { hltbDataUser = null; } if (hltbDataUser != null && hltbDataUser.GameHltbData != null) { hasData = true; if (hltbDataUser.GameHltbData.MainStory != 0 || hltbDataUser.GameHltbData.MainExtra != 0 || hltbDataUser.GameHltbData.Completionist != 0 || hltbDataUser.GameHltbData.Solo != 0 || hltbDataUser.GameHltbData.CoOp != 0 || hltbDataUser.GameHltbData.Vs != 0) { isEmpty = false; HowLongToBeat.howLongToBeatUI.RefreshElements(HowLongToBeat.GameSelected); } } }
public GameHowLongToBeat SearchData(Game game) { #if DEBUG logger.Debug($"HowLongToBeat [Ignored] - Search data for {game.Name}"); #endif if (_PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop) { HowLongToBeatSelect ViewExtension = null; Application.Current.Dispatcher.BeginInvoke((Action) delegate { ViewExtension = new HowLongToBeatSelect(null, game); Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(_PlayniteApi, resources.GetString("LOCSelection"), ViewExtension); windowExtension.ShowDialog(); }).Wait(); if (ViewExtension.gameHowLongToBeat != null && ViewExtension.gameHowLongToBeat.Items.Count > 0) { return(ViewExtension.gameHowLongToBeat); } } return(null); }
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); }