示例#1
0
        public void OnBtActionBarClick(object sender, RoutedEventArgs e)
        {
#if DEBUG
            logger.Debug($"SuccessStory [Ignored] - OnBtActionBarClick()");
#endif
            PluginDatabase.IsViewOpen = true;
            dynamic ViewExtension = null;
            if (PluginDatabase.PluginSettings.EnableOneGameView)
            {
                ViewExtension = new SuccessStoryOneGameView(SuccessStoryDatabase.GameSelected);
            }
            else
            {
                if (PluginDatabase.PluginSettings.EnableRetroAchievementsView && PlayniteTools.IsGameEmulated(_PlayniteApi, SuccessStoryDatabase.GameSelected))
                {
                    ViewExtension = new SuccessView(_Plugin, _PlayniteApi, _Plugin.GetPluginUserDataPath(), true, SuccessStoryDatabase.GameSelected);
                }
                else
                {
                    ViewExtension = new SuccessView(_Plugin, _PlayniteApi, _Plugin.GetPluginUserDataPath(), false, SuccessStoryDatabase.GameSelected);
                }
            }
            Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(_PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
            windowExtension.ShowDialog();
            PluginDatabase.IsViewOpen = false;
        }
示例#2
0
        public DescriptionEditorView(TextBox TextDescription)
        {
            InitializeComponent();

            _TextDescription = TextDescription;
            Description      = TextDescription.Text;

            PlayniteTools.SetThemeInformation();
            string DescriptionViewFile = ThemeFile.GetFilePath("DescriptionView.html");

            Common.LogDebug(true, $"{DescriptionViewFile}");

            try
            {
                htmlTextView.Visibility   = Visibility.Visible;
                htmlTextView.TemplatePath = DescriptionViewFile;
                htmlTextView.HtmlText     = Description;

                htmlTextView.HtmlFontSize   = (double)resources.GetResource("FontSize");
                htmlTextView.HtmlFontFamily = (FontFamily)resources.GetResource("FontFamily");
                htmlTextView.HtmlForeground = (Color)resources.GetResource("TextColor");
                htmlTextView.LinkForeground = (Color)resources.GetResource("GlyphColor");

                PART_HtmlDescription.Children.Add(htmlTextView);
            }
            catch (Exception ex)
            {
                Common.LogError(ex, false, "Error on creation HtmlTextView");
            }

            DataContext = this;
        }
        // To add new main menu items override GetMainMenuItems
        public override List <MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args)
        {
            string MenuInExtensions = string.Empty;

            if (settings.MenuInExtensions)
            {
                MenuInExtensions = "@";
            }

            List <MainMenuItem> mainMenuItems = new List <MainMenuItem>
            {
                new MainMenuItem
                {
                    MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGames"),
                    Action      = (mainMenuItem) =>
                    {
                        var    ViewExtension   = new SuccessView(this, settings, PlayniteApi, this.GetPluginUserDataPath());
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                    }
                }
            };

            if (settings.EnableRetroAchievementsView && settings.EnableRetroAchievements)
            {
                mainMenuItems.Add(new MainMenuItem
                {
                    MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGames") + " - RetroAchievements",
                    Action      = (mainMenuItem) =>
                    {
                        SuccessView ViewExtension = null;
                        if (settings.EnableRetroAchievementsView && PlayniteTools.IsGameEmulated(PlayniteApi, GameSelected))
                        {
                            ViewExtension = new SuccessView(this, settings, PlayniteApi, this.GetPluginUserDataPath(), true, GameSelected);
                        }
                        else
                        {
                            ViewExtension = new SuccessView(this, settings, PlayniteApi, this.GetPluginUserDataPath(), false, GameSelected);
                        }
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                    }
                });
            }

#if DEBUG
            mainMenuItems.Add(new MainMenuItem
            {
                MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(mainMenuItems);
        }
        public void OnBtActionBarClick(object sender, RoutedEventArgs e)
        {
#if DEBUG
            logger.Debug($"SuccessStory - OnBtActionBarClick()");
#endif
            SuccessView ViewExtension = null;
            if (_Settings.EnableRetroAchievementsView && PlayniteTools.IsGameEmulated(_PlayniteApi, SuccessStory.GameSelected))
            {
                ViewExtension = new SuccessView(_Plugin, _Settings, _PlayniteApi, _Plugin.GetPluginUserDataPath(), true, SuccessStory.GameSelected);
            }
            else
            {
                ViewExtension = new SuccessView(_Plugin, _Settings, _PlayniteApi, _Plugin.GetPluginUserDataPath(), false, SuccessStory.GameSelected);
            }
            Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(_PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
            windowExtension.ShowDialog();
        }
        public GameRequierements GetFromWeb(Game game)
        {
            GameRequierements gameRequierements = GetDefault(game);

            string SourceName = string.Empty;

            try
            {
                SourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

                // Search datas
                logger.Info($"SystemChecker - Try find with PCGamingWikiRequierements for {game.Name}");
                gameRequierements = pCGamingWikiRequierements.GetRequirements(game);

                if (!pCGamingWikiRequierements.IsFind())
                {
                    logger.Info($"SystemChecker - Try find with SteamRequierements for {game.Name}");
                    switch (SourceName.ToLower())
                    {
                    case "steam":
                        gameRequierements      = steamRequierements.GetRequirements(game);
                        gameRequierements.Link = "https://store.steampowered.com/app/" + game.GameId;
                        break;

                    default:
                        SteamApi steamApi = new SteamApi(PluginUserDataPath);
                        int      SteamID  = steamApi.GetSteamId(game.Name);
                        if (SteamID != 0)
                        {
                            gameRequierements      = steamRequierements.GetRequirements(game, (uint)SteamID);
                            gameRequierements.Link = "https://store.steampowered.com/app/" + SteamID;
                        }
                        break;
                    }
                }

                gameRequierements = NormalizeRecommanded(gameRequierements);
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SystemChecker");
            }

            return(gameRequierements);
        }
        // Add RetroArch game automaticly
        private void PART_BtAddURetroArch_Click(object sender, RoutedEventArgs e)
        {
            TextboxSearch.Text = string.Empty;

            var tmpList = Serialization.GetClone(listGames).Where(x => PlayniteTools.GameUseRetroArch(PluginDatabase.PlayniteApi.Database.Games.Get(x.Id))).ToList();

            foreach (var game in tmpList)
            {
                int index = listGames.FindIndex(x => x.Id == game.Id);
                listGames.RemoveAt(index);

                string Icon = string.Empty;
                if (!game.Icon.IsNullOrEmpty())
                {
                    Icon = PluginDatabase.PlayniteApi.Database.GetFullFilePath(game.Icon);
                }

                List <FolderSettings> ScreenshotsFolders = new List <FolderSettings>();
                ScreenshotsFolders.Add(new FolderSettings
                {
                    ScreenshotsFolder = "{RetroArchScreenshotsDir}",
                    UsedFilePattern   = true,
                    FilePattern       = "{ImageNameNoExt}-{digit}-{digit}",
                });

                listGameScreenshots.Add(new ListGameScreenshot
                {
                    Id   = game.Id,
                    Icon = Icon,
                    Name = game.Name,
                    ScreenshotsFolders = ScreenshotsFolders,
                    SourceName         = game.SourceName,
                    SourceIcon         = TransformIcon.Get(game.SourceName)
                });
            }

            PART_ListGame.ItemsSource = null;
            PART_ListGame.ItemsSource = listGames;

            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
            PART_ListGameScreenshot.ItemsSource = null;
            PART_ListGameScreenshot.ItemsSource = listGameScreenshots;

            TextboxSearch_TextChanged(null, null);
        }
        private void ButtonRemove_Click(object sender, RoutedEventArgs e)
        {
            int index = int.Parse(((Button)sender).Tag.ToString());

            var item         = ((List <ListGameScreenshot>)PART_ListGameScreenshot.ItemsSource)[index];
            int ControlIndex = listGameScreenshots.FindIndex(x => x == item);

            PART_ListGameScreenshot.ItemsSource = null;
            listGameScreenshots.RemoveAt(ControlIndex);
            PART_ListGameScreenshot.ItemsSource = listGameScreenshots;
            TextboxSearch_TextChanged(null, null);

            var TaskView = Task.Run(() =>
            {
                var DbWithoutAlready = PluginDatabase.PlayniteApi.Database.Games.Where(x => !listGameScreenshots.Any(y => x.Id == y.Id));
                listGames            = new List <ListGame>();
                foreach (Game game in DbWithoutAlready)
                {
                    string Icon = string.Empty;
                    if (!game.Icon.IsNullOrEmpty())
                    {
                        Icon = PluginDatabase.PlayniteApi.Database.GetFullFilePath(game.Icon);
                    }

                    listGames.Add(new ListGame
                    {
                        Id         = game.Id,
                        Icon       = Icon,
                        Name       = game.Name,
                        SourceName = PlayniteTools.GetSourceName(game.Id)
                    });
                }

                this.Dispatcher.BeginInvoke((Action) delegate
                {
                    listGames.Sort((x, y) => x.Name.CompareTo(y.Name));
                    PART_ListGame.ItemsSource = null;
                    PART_ListGame.ItemsSource = listGames;

                    PART_ListGameScreenshot.ItemsSource = null;
                    PART_ListGameScreenshot.ItemsSource = listGameScreenshots;
                });
            });
        }
示例#8
0
        public void InitializeMultipleAdd(string GameSourceName = "all")
        {
            switch (GameSourceName.ToLower())
            {
            case "all":
                InitializeMultipleAdd("Steam");
                InitializeMultipleAdd("GOG");
                InitializeMultipleAdd("Origin");
                break;

            case "steam":
                break;

            case "gog":
                if (!PlayniteTools.IsDisabledPlaynitePlugins("GogLibrary", _PlayniteApi.Paths.ConfigurationPath) && PluginSettings.EnableGog && gogAPI == null)
                {
                    gogAPI = new GogAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                }
                break;

            case "origin":
                if (!PlayniteTools.IsDisabledPlaynitePlugins("OriginLibrary", _PlayniteApi.Paths.ConfigurationPath) && originAPI == null)
                {
                    originAPI = new OriginAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                }
                break;

            case "Xbox":
                if (!PlayniteTools.IsDisabledPlaynitePlugins("XboxLibrary", _PlayniteApi.Paths.ConfigurationPath) && xboxAPI == null)
                {
                    xboxAPI = new XboxAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                }
                break;

            case "playnite":
                break;
            }
        }
示例#9
0
        private void SetData(int index = -1)
        {
            PART_DataLoad.Visibility = Visibility.Visible;
            PART_Data.Visibility     = Visibility.Hidden;

            Task.Run(() =>
            {
                ObservableCollection <LveGame> LveGames = PluginDatabase.Database.Where(x => x.HasData)
                                                          .Select(x => new LveGame
                {
                    Id           = x.Id,
                    Icon         = PluginDatabase.PlayniteApi.Database.GetFullFilePath(x.Icon),
                    Name         = x.Name,
                    LastActivity = x.LastActivity,
                    SourceName   = PlayniteTools.GetSourceName(x.Id),

                    LastSsv = x.Items.Select(y => y.Modifed).Max(),
                    Total   = x.Items.Count
                }).ToObservable();
                return(LveGames);
            }).ContinueWith(antecedent =>
            {
                this.Dispatcher?.BeginInvoke(DispatcherPriority.Loaded, new ThreadStart(delegate
                {
                    ((SsvScreenshotsManagerData)DataContext).LveGames = antecedent.Result;

                    PART_LveGames.Sorting();
                    if (index != -1)
                    {
                        PART_LveGames.SelectedIndex = index;
                    }

                    PART_DataLoad.Visibility = Visibility.Hidden;
                    PART_Data.Visibility     = Visibility.Visible;
                }));
            });
        }
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="GameAdded"></param>
        public void Add(Game GameAdded, SuccessStorySettings settings)
        {
            GameAchievements GameAchievements = new GameAchievements();

            Guid   GameId                 = GameAdded.Id;
            Guid   GameSourceId           = GameAdded.SourceId;
            string GameSourceName         = PlayniteTools.GetSourceName(GameAdded, _PlayniteApi);
            string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json";

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(_plugin, _PlayniteApi, GameSourceName, settings, _PluginUserDataPath))
            {
                // Generate only not exist
                if (!File.Exists(PluginDatabaseGamePath))
                {
#if DEBUG
                    logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - OK");
#endif

                    // TODO one func
                    if (GameSourceName.ToLower() == "gog")
                    {
                        if (gogAPI == null)
                        {
                            gogAPI = new GogAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = gogAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "steam")
                    {
                        SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        GameAchievements = steamAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "origin")
                    {
                        if (originAPI == null)
                        {
                            originAPI = new OriginAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = originAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "xbox")
                    {
                        if (xboxAPI == null)
                        {
                            xboxAPI = new XboxAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = xboxAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "playnite")
                    {
                        SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        steamAPI.SetLocal();
                        GameAchievements = steamAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "retroachievements")
                    {
                        RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        GameAchievements = retroAchievementsAPI.GetAchievements(GameAdded);
                    }

#if DEBUG
                    logger.Debug($"SuccessStory - Achievements for {GameAdded.Name} - {GameSourceName} - {JsonConvert.SerializeObject(GameAchievements)}");
#endif

                    if (GameAchievements != null)
                    {
                        File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements));
                    }
                }
            }
            else
            {
#if DEBUG
                logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - KO");
#endif
            }
        }
        public override void RefreshElements(Game GameSelected, bool force = false)
        {
            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 = "Scheck_HasData", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Scheck_IsMinimumOK", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Scheck_IsRecommandedOK", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Scheck_IsAllOK", Value = false
                    });
                    ui.AddResources(resourcesLists);

                    if (!PlayniteTools.IsGameEmulated(_PlayniteApi, GameSelected))
                    {
                        // Load data
                        if (!PluginDatabase.IsLoaded)
                        {
                            return;
                        }
                        GameRequierements gameRequierements = PluginDatabase.Get(GameSelected);

                        SystemConfiguration systemConfiguration = PluginDatabase.Database.PC;


                        CheckMinimum     = new CheckSystem();
                        CheckRecommanded = new CheckSystem();
                        resourcesLists   = new List <ResourcesList>();
                        if (gameRequierements.GetMinimum().HasData)
                        {
                            CheckMinimum = SystemApi.CheckConfig(gameRequierements.GetMinimum(), systemConfiguration);
#if DEBUG
                            logger.Debug($"SystemChecker - CheckMinimum: {JsonConvert.SerializeObject(CheckMinimum)}");
#endif
                            resourcesLists.Add(new ResourcesList {
                                Key = "Scheck_HasData", Value = true
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Scheck_IsMinimumOK", Value = CheckMinimum.AllOk
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Scheck_IsAllOK", Value = CheckMinimum.AllOk
                            });
                        }
                        if (gameRequierements.GetRecommanded().HasData)
                        {
                            CheckRecommanded = SystemApi.CheckConfig(gameRequierements.GetRecommanded(), systemConfiguration);
#if DEBUG
                            logger.Debug($"SystemChecker - CheckRecommanded: {JsonConvert.SerializeObject(CheckRecommanded)}");
#endif
                            resourcesLists.Add(new ResourcesList {
                                Key = "Scheck_HasData", Value = true
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Scheck_IsRecommandedOK", Value = CheckRecommanded.AllOk
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Scheck_IsAllOK", Value = CheckRecommanded.AllOk
                            });
                        }

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

                            if (_PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
                            {
                                PluginDatabase.SetCurrent(gameRequierements);
                            }
                        }
                    }
                    else
                    {
                        logger.Info($"SystemChecker - No treatment for emulated game");
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SystemChecker", $"Error on TaskRefreshBtActionBar()");
                }
            }, ct);

            taskHelper.Add(TaskRefresh, tokenSource);
        }
        private void LoadData(IPlayniteAPI PlayniteApi)
        {
            listGameScreenshots = new List <ListGameScreenshot>();
            foreach (var item in ScreenshotsVisualizer.PluginDatabase.PluginSettings.Settings.gameSettings)
            {
                Game game = PlayniteApi.Database.Games.Get(item.Id);

                if (game != null)
                {
                    string Icon = string.Empty;
                    if (!game.Icon.IsNullOrEmpty())
                    {
                        Icon = PlayniteApi.Database.GetFullFilePath(game.Icon);
                    }

                    // TEMP
                    List <FolderSettings> ScreenshotsFolders = new List <FolderSettings>();
                    if (!item.ScreenshotsFolder.IsNullOrEmpty())
                    {
                        ScreenshotsFolders.Add(new FolderSettings
                        {
                            UsedFilePattern   = item.UsedFilePattern,
                            FilePattern       = item.FilePattern,
                            ScreenshotsFolder = item.ScreenshotsFolder,
                            ScanSubFolders    = item.ScanSubFolders
                        });
                    }
                    else
                    {
                        ScreenshotsFolders = item.ScreenshotsFolders;
                    }

                    listGameScreenshots.Add(new ListGameScreenshot
                    {
                        Id   = item.Id,
                        Icon = Icon,
                        Name = game.Name,
                        ScreenshotsFolders = ScreenshotsFolders,
                        UsedFilePattern    = item.UsedFilePattern,
                        ScanSubFolders     = item.ScanSubFolders,
                        FilePattern        = item.FilePattern,
                        SourceName         = PlayniteTools.GetSourceName(item.Id),
                        SourceIcon         = TransformIcon.Get(PlayniteTools.GetSourceName(item.Id))
                    });
                }
                else
                {
                    logger.Warn($"Game is deleted - {item.Id}");
                }
            }

            var DbWithoutAlready = PlayniteApi.Database.Games.Where(x => !listGameScreenshots.Any(y => x.Id == y.Id));

            listGames = new List <ListGame>();
            foreach (Game item in DbWithoutAlready)
            {
                string Icon = string.Empty;
                if (!item.Icon.IsNullOrEmpty())
                {
                    Icon = PlayniteApi.Database.GetFullFilePath(item.Icon);
                }

                listGames.Add(new ListGame
                {
                    Id         = item.Id,
                    Icon       = Icon,
                    Name       = item.Name,
                    SourceName = PlayniteTools.GetSourceName(item.Id),
                    SourceIcon = TransformIcon.Get(PlayniteTools.GetSourceName(item.Id))
                });
            }

            listGames.Sort((x, y) => x.Name.CompareTo(y.Name));
            listGameScreenshots.Sort((x, y) => x.Name.CompareTo(y.Name));
        }
示例#13
0
        public AchievementsGraphicsDataCountSources GetCountBySources()
        {
            List <string> tempSourcesLabels = new List <string>();

            if (PluginSettings.EnableRetroAchievementsView && PluginSettings.EnableRetroAchievements)
            {
                if (_isRetroachievements)
                {
                    if (PluginSettings.EnableRetroAchievements)
                    {
                        tempSourcesLabels.Add("RetroAchievements");
                    }
                }
                else
                {
                    if (PluginSettings.EnableGog)
                    {
                        tempSourcesLabels.Add("GOG");
                    }
                    if (PluginSettings.EnableSteam)
                    {
                        tempSourcesLabels.Add("Steam");
                    }
                    if (PluginSettings.EnableOrigin)
                    {
                        tempSourcesLabels.Add("Origin");
                    }
                    if (PluginSettings.EnableXbox)
                    {
                        tempSourcesLabels.Add("Xbox");
                    }
                    if (PluginSettings.EnableLocal)
                    {
                        tempSourcesLabels.Add("Playnite");
                        tempSourcesLabels.Add("Hacked");
                    }
                    if (PluginSettings.EnableRpcs3Achievements)
                    {
                        tempSourcesLabels.Add("RPCS3");
                    }
                }
            }
            else
            {
                if (PluginSettings.EnableGog)
                {
                    tempSourcesLabels.Add("GOG");
                }
                if (PluginSettings.EnableSteam)
                {
                    tempSourcesLabels.Add("Steam");
                }
                if (PluginSettings.EnableOrigin)
                {
                    tempSourcesLabels.Add("Origin");
                }
                if (PluginSettings.EnableXbox)
                {
                    tempSourcesLabels.Add("Xbox");
                }
                if (PluginSettings.EnableRetroAchievements)
                {
                    tempSourcesLabels.Add("RetroAchievements");
                }
                if (PluginSettings.EnableRpcs3Achievements)
                {
                    tempSourcesLabels.Add("RPCS3");
                }
                if (PluginSettings.EnableLocal)
                {
                    tempSourcesLabels.Add("Playnite");
                    tempSourcesLabels.Add("Hacked");
                }
            }

            tempSourcesLabels.Sort((x, y) => x.CompareTo(y));

            string[] GraphicsAchievementsLabels = new string[tempSourcesLabels.Count];
            List <AchievementsGraphicsDataSources> tempDataUnlocked = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataLocked   = new List <AchievementsGraphicsDataSources>();
            List <AchievementsGraphicsDataSources> tempDataTotal    = new List <AchievementsGraphicsDataSources>();

            for (int i = 0; i < tempSourcesLabels.Count; i++)
            {
                GraphicsAchievementsLabels[i] = TransformIcon.Get(tempSourcesLabels[i]);
                tempDataLocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataUnlocked.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
                tempDataTotal.Add(new AchievementsGraphicsDataSources {
                    source = tempSourcesLabels[i], value = 0
                });
            }


            foreach (var item in Database.Items)
            {
                if (!item.Value.HaveAchivements || item.Value.IsDeleted)
                {
                    continue;
                }

                try
                {
                    string SourceName = PlayniteTools.GetSourceName(_PlayniteApi, item.Key);

                    foreach (Achievements achievements in item.Value.Items)
                    {
                        for (int i = 0; i < tempDataUnlocked.Count; i++)
                        {
                            if (tempDataUnlocked[i].source == SourceName)
                            {
                                tempDataTotal[i].value += 1;
                                if (achievements.DateUnlocked != default(DateTime))
                                {
                                    tempDataUnlocked[i].value += 1;
                                }
                                if (achievements.DateUnlocked == default(DateTime))
                                {
                                    tempDataLocked[i].value += 1;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on GetCountBySources() for {item.Key}");
                }
            }

            ChartValues <CustomerForSingle> SourceAchievementsSeriesUnlocked = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesLocked   = new ChartValues <CustomerForSingle>();
            ChartValues <CustomerForSingle> SourceAchievementsSeriesTotal    = new ChartValues <CustomerForSingle>();

            for (int i = 0; i < tempDataUnlocked.Count; i++)
            {
                SourceAchievementsSeriesUnlocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataUnlocked[i].source),
                    Values = tempDataUnlocked[i].value
                });
                SourceAchievementsSeriesLocked.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataLocked[i].source),
                    Values = tempDataLocked[i].value
                });
                SourceAchievementsSeriesTotal.Add(new CustomerForSingle
                {
                    Name   = TransformIcon.Get(tempDataTotal[i].source),
                    Values = tempDataTotal[i].value
                });
            }


            return(new AchievementsGraphicsDataCountSources
            {
                Labels = GraphicsAchievementsLabels,
                SeriesLocked = SourceAchievementsSeriesLocked,
                SeriesUnlocked = SourceAchievementsSeriesUnlocked,
                SeriesTotal = SourceAchievementsSeriesTotal
            });
        }
示例#14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="GameSourceName"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static bool VerifToAddOrShow(SuccessStory plugin, IPlayniteAPI PlayniteApi, SuccessStorySettings settings, string PluginUserDataPath, string GameSourceName)
        {
            if (settings.EnableSteam && GameSourceName.ToLower() == "steam")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("SteamLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - Steam is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Steam-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsSteamDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    SteamAchievements steamAchievements = new SteamAchievements(PlayniteApi, settings, PluginUserDataPath);
                    if (!steamAchievements.IsConfigured())
                    {
                        logger.Warn("SuccessStory - Bad Steam configuration");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Steam-NoConfig",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsSteamBadConfig")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableGog && GameSourceName.ToLower() == "gog")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("GogLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - GOG is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-GOG-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    GogAchievements gogAchievements = new GogAchievements(PlayniteApi, settings, PluginUserDataPath);

                    if (VerifToAddOrShowGog == null)
                    {
                        VerifToAddOrShowGog = gogAchievements.IsConnected();
                    }

                    if (!(bool)VerifToAddOrShowGog)
                    {
                        logger.Warn("SuccessStory - Gog user is not authenticate");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Gog-NoAuthenticated",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogNoAuthenticate")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableOrigin && GameSourceName.ToLower() == "origin")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("OriginLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - Origin is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Origin-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsOriginDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    OriginAchievements originAchievements = new OriginAchievements(PlayniteApi, settings, PluginUserDataPath);

                    if (VerifToAddOrShowOrigin == null)
                    {
                        VerifToAddOrShowOrigin = originAchievements.IsConnected();
                    }

                    if (!(bool)VerifToAddOrShowOrigin)
                    {
                        logger.Warn("SuccessStory - Origin user is not authenticated");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Origin-NoAuthenticate",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsOriginNoAuthenticate")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableXbox && GameSourceName.ToLower() == "xbox")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("XboxLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - Xbox is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Xbox-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsXboxDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    XboxAchievements xboxAchievements = new XboxAchievements(PlayniteApi, settings, PluginUserDataPath);

#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShowXbox: {VerifToAddOrShowXbox}");
#endif
                    if (VerifToAddOrShowXbox == null)
                    {
                        VerifToAddOrShowXbox = xboxAchievements.IsConnected();
                    }
#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShowXbox: {VerifToAddOrShowXbox}");
#endif

                    if (!(bool)VerifToAddOrShowXbox)
                    {
                        logger.Warn("SuccessStory - Xbox user is not authenticated");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Xbox-NoAuthenticate",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsXboxNotAuthenticate")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableLocal && (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked"))
            {
                return(true);
            }

            if (settings.EnableRetroAchievements && GameSourceName.ToLower() == "retroachievements")
            {
                RetroAchievements retroAchievements = new RetroAchievements(PlayniteApi, settings, PluginUserDataPath);
                if (!retroAchievements.IsConfigured())
                {
                    logger.Warn("SuccessStory - Bad RetroAchievements configuration");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-RetroAchievements-NoConfig",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsRetroAchievementsBadConfig")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                return(true);
            }

            if (settings.EnableRpcs3Achievements && GameSourceName.ToLower() == "rpcs3")
            {
                Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(PlayniteApi, settings, PluginUserDataPath);
                if (!rpcs3Achievements.IsConfigured())
                {
                    logger.Warn("SuccessStory - Bad RPCS3 configuration");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Rpcs3-NoConfig",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsRpcs3BadConfig")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                return(true);
            }

            logger.Warn($"SuccessStory - VerifToAddOrShow() find no action for {GameSourceName}");
            return(false);
        }
示例#15
0
        private void SetTotal()
        {
            SteamTotal             = 0;
            SteamTotalAchievements = 0;
            GogTotal                           = 0;
            GogTotalAchievements               = 0;
            OriginTotal                        = 0;
            OriginTotalAchievements            = 0;
            XboxTotal                          = 0;
            XboxTotalAchievements              = 0;
            RetroAchievementsTotal             = 0;
            RetroAchievementsTotalAchievements = 0;
            Rpcs3Total                         = 0;
            Rpcs3TotalAchievements             = 0;

            LocalTotal             = 0;
            LocalTotalAchievements = 0;

            try
            {
                foreach (var game in _PlayniteApi.Database.Games)
                {
                    string GameSourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

                    switch (GameSourceName.ToLower())
                    {
                    case "steam":
                        SteamTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            SteamTotalAchievements += 1;
                        }
                        break;

                    case "gog":
                        GogTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            GogTotalAchievements += 1;
                        }
                        break;

                    case "origin":
                        OriginTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            OriginTotalAchievements += 1;
                        }
                        break;

                    case "xbox":
                        XboxTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            XboxTotalAchievements += 1;
                        }
                        break;

                    case "retroachievements":
                        RetroAchievementsTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            RetroAchievementsTotalAchievements += 1;
                        }
                        break;

                    case "rpcs3":
                        Rpcs3Total += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            Rpcs3TotalAchievements += 1;
                        }
                        break;

                    case "playnite":
                        LocalTotal += 1;
                        if (PluginDatabase.VerifAchievementsLoad(game.Id))
                        {
                            LocalTotalAchievements += 1;
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", $"Error on SetTotal()");
            }

            SteamLoad.Content             = SteamTotalAchievements + "/" + SteamTotal;
            GogLoad.Content               = GogTotalAchievements + "/" + GogTotal;
            OriginLoad.Content            = OriginTotalAchievements + "/" + OriginTotal;
            XboxLoad.Content              = XboxTotalAchievements + "/" + XboxTotal;
            RetroAchievementsLoad.Content = RetroAchievementsTotalAchievements + "/" + RetroAchievementsTotal;
            LocalLoad.Content             = LocalTotalAchievements + "/" + LocalTotal;
            Rpcs3Load.Content             = Rpcs3TotalAchievements + "/" + Rpcs3Total;
        }
示例#16
0
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="game"></param>
        public GameAchievements GetFromWeb(Game game)
        {
            GameAchievements gameAchievements = GetDefault(game);

            Guid   GameId         = game.Id;
            Guid   GameSourceId   = game.SourceId;
            string GameSourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(_plugin, _PlayniteApi, PluginSettings, PluginUserDataPath, GameSourceName))
            {
#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - OK");
#endif

                // TODO one func
                if (GameSourceName.ToLower() == "gog")
                {
                    if (gogAPI == null)
                    {
                        gogAPI = new GogAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = gogAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "steam")
                {
                    SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = steamAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "origin")
                {
                    if (originAPI == null)
                    {
                        originAPI = new OriginAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = originAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "xbox")
                {
                    if (xboxAPI == null)
                    {
                        xboxAPI = new XboxAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = xboxAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked")
                {
                    SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    steamAPI.SetLocal();
                    gameAchievements = steamAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "retroachievements")
                {
                    RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = retroAchievementsAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "rpcs3")
                {
                    Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = rpcs3Achievements.GetAchievements(game);
                }

#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - Achievements for {game.Name} - {GameSourceName} - {JsonConvert.SerializeObject(gameAchievements)}");
#endif
            }
            else
            {
#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - KO");
#endif
            }

            return(gameAchievements);
        }
        public override void RefreshElements(Game GameSelected, bool Force = false)
        {
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken       ct          = tokenSource.Token;

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

                    // Reset resources
                    List <ResourcesList> resourcesLists = new List <ResourcesList>();
                    resourcesLists.Add(new ResourcesList {
                        Key = "Cl_HasData", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Cl_HasNativeSupport", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Cl_ListNativeSupport", Value = new List <Models.Localization>()
                    });
                    ui.AddResources(resourcesLists);

                    if (!PlayniteTools.IsGameEmulated(_PlayniteApi, GameSelected))
                    {
                        // Load data
                        if (!CheckLocalizations.PluginDatabase.IsLoaded)
                        {
                            return;
                        }
                        GameLocalizations gameLocalizations = CheckLocalizations.PluginDatabase.Get(GameSelected);

                        if (gameLocalizations.HasData)
                        {
                            resourcesLists = new List <ResourcesList>();
                            resourcesLists.Add(new ResourcesList {
                                Key = "Cl_HasData", Value = gameLocalizations.HasData
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Cl_HasNativeSupport", Value = gameLocalizations.HasNativeSupport()
                            });
                            resourcesLists.Add(new ResourcesList {
                                Key = "Cl_ListNativeSupport", Value = gameLocalizations.Items
                            });
                        }
                        else
                        {
                            logger.Warn($"CheckLocalizations - No data find for {GameSelected.Name}");
                        }

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

                            if (_PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
                            {
                                CheckLocalizations.PluginDatabase.SetCurrent(gameLocalizations);
                            }
                        }
                    }
                    else
                    {
                        logger.Info($"CheckLocalizations - No treatment for emulated game");
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "CheckLocalizations", $"Error on TaskRefreshBtActionBar()");
                }
            }, ct);

            taskHelper.Add(TaskRefreshBtActionBar, tokenSource);
        }
示例#18
0
        private void RefreshData(string SourceName, bool IsGet = false)
        {
            SuccessStoryDatabase.ListErrors = new CumulErrors();

#if DEBUG
            logger.Info($"SuccessStory [Ignored] - RefreshData() - Start");
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif

            SuccessStorySettings.IsEnabled = false;

            pbDataLoad.IsIndeterminate = false;
            pbDataLoad.Minimum         = 0;
            pbDataLoad.Value           = 0;

            DataLoad.Visibility   = Visibility.Visible;
            tcSettings.Visibility = Visibility.Hidden;

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

            bool IsFirstLoop = true;

            var taskSystem = Task.Run(() =>
            {
                try
                {
                    // filter games
                    IEnumerable <Game> FilterDatabaseGame = null;
                    switch (SourceName.ToLower())
                    {
                    case "all":
                        FilterDatabaseGame = _PlayniteApi.Database.Games;
                        break;

                    case "allrecent":
                        FilterDatabaseGame = _PlayniteApi.Database.Games.Where(
                            x => x.LastActivity > DateTime.Now.AddMonths(-2) || (x.Added != null && x.Added > DateTime.Now.AddMonths(-2))
                            );
                        break;

                    case "allinstalled":
                        FilterDatabaseGame = _PlayniteApi.Database.Games.Where(x => x.IsInstalled);
                        break;

                    default:
                        FilterDatabaseGame = _PlayniteApi.Database.Games.Where(
                            x => PlayniteTools.GetSourceName(_PlayniteApi, x).ToLower() == SourceName.ToLower()
                            );
                        break;
                    }

                    Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Maximum = FilterDatabaseGame.Count(); });
#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - FilterDatabaseGame: {FilterDatabaseGame.Count()}");
#endif
                    foreach (var game in FilterDatabaseGame)
                    {
                        try
                        {
                            if (SourceName.ToLower() == "steam" && IsFirstLoop)
                            {
#if DEBUG
                                logger.Debug($"SuccessStory [Ignored] - Check Steam profil with {game.GameId}");
#endif

                                SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginDatabase.PluginSettings, _PluginUserDataPath);
                                int AppId = 0;
                                int.TryParse(game.GameId, out AppId);
                                if (!steamAPI.CheckIsPublic(AppId))
                                {
                                    SuccessStoryDatabase.ListErrors.Add(resources.GetString("LOCSuccessStoryNotificationsSteamPrivate"));
                                    break;
                                }
                                IsFirstLoop = false;
                            }

                            // Respect API limitation
                            Thread.Sleep(1000);

                            if (IsGet)
                            {
                                // Add only it's not loaded
                                if (!PluginDatabase.VerifAchievementsLoad(game.Id))
                                {
                                    PluginDatabase.Get(game);
                                }
                            }
                            else
                            {
                                PluginDatabase.Remove(game);
                                PluginDatabase.Get(game);
                            }

                            Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Value += 1; });
                        }
                        catch (Exception ex)
                        {
                            Common.LogError(ex, "SuccessStory", $"Error on RefreshData({SourceName}, {IsGet}) for {game.Name}");
                        }

                        if (ct.IsCancellationRequested)
                        {
                            logger.Info($"IsCancellationRequested for RefreshData({ SourceName}, { IsGet})");
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on RefreshData({SourceName}, {IsGet})");
                }
            }, tokenSource.Token)
                             .ContinueWith(antecedent =>
            {
                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    DataLoad.Visibility   = Visibility.Collapsed;
                    tcSettings.Visibility = Visibility.Visible;

                    if (!WithoutMessage)
                    {
                        if (SuccessStoryDatabase.ListErrors.Get() != string.Empty)
                        {
                            _PlayniteApi.Dialogs.ShowErrorMessage(SuccessStoryDatabase.ListErrors.Get(), "SuccessStory errors");
                        }
                        else
                        {
                            _PlayniteApi.Dialogs.ShowMessage((string)ResourceProvider.GetResource("LOCSuccessStoryRefreshDataMessage"), "Success Story");
                        }
                    }

                    SetTotal();

                    SuccessStorySettings.IsEnabled = true;
#if DEBUG
                    stopwatch.Stop();
                    logger.Debug($"SuccessStory [Ignored] - RefreshData() - End - {stopwatch.Elapsed}");
#endif
                });
            });
        }
        public override void RefreshElements(Game GameSelected, bool force = false)
        {
#if DEBUG
            logger.Debug($"SuccessStory - RefreshElements({GameSelected.Name})");
#endif

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

            Task TaskRefresh = Task.Run(() =>
            {
#if DEBUG
                string IsCanceld = string.Empty;

                logger.Debug($"SuccessStory - TaskRefresh() - Start");
                Stopwatch stopwatch = new Stopwatch();
                TimeSpan ts;
                stopwatch.Start();
#endif
                try
                {
                    Initial();

                    // Reset resources
                    List <ResourcesList> resourcesLists = new List <ResourcesList>();
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_HasData", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Is100Percent", Value = false
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Total", Value = 0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalDouble", Value = (double)0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalString", Value = "0"
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Unlocked", Value = 0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedDouble", Value = (double)0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedString", Value = "0"
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Locked", Value = 0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedDouble", Value = (double)0
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedString", Value = "0"
                    });

                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_EnableIntegrationInCustomTheme", Value = _Settings.EnableIntegrationInCustomTheme
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowGraphic", Value = _Settings.IntegrationShowGraphic
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowAchievements", Value = _Settings.IntegrationShowAchievements
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowProgressBar", Value = _Settings.IntegrationShowProgressBar
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowAchievementsCompactLocked", Value = _Settings.IntegrationShowAchievementsCompactLocked
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_IntegrationShowAchievementsCompactUnlocked", Value = _Settings.IntegrationShowAchievementsCompactUnlocked
                    });
                    ui.AddResources(resourcesLists);


                    // Load data
                    SuccessStory.SelectedGameAchievements = null;
                    string GameSourceName = string.Empty;

                    try
                    {
                        SuccessStory.SelectedGameAchievements = SuccessStory.achievementsDatabase.Get(GameSelected.Id);
                        GameSourceName = PlayniteTools.GetSourceName(GameSelected, _PlayniteApi);
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex, "SuccessStory", "Error to load data");
                        _PlayniteApi.Dialogs.ShowErrorMessage(resources.GetString("LOCDatabaseErroTitle"), "SuccessStory");
                    }

                    // Download Achievements if not exist in database.
                    if (SuccessStory.SelectedGameAchievements == null)
                    {
                        logger.Info($"SuccessStory - Download achievements for {GameSelected.Name} - {GameSourceName}");
                        SuccessStory.achievementsDatabase.Add(GameSelected, _Settings);
                        SuccessStory.achievementsDatabase.Initialize();
                        SuccessStory.SelectedGameAchievements = SuccessStory.achievementsDatabase.Get(GameSelected.Id);
                    }

                    if (SuccessStory.SelectedGameAchievements == null)
                    {
                        logger.Warn("SuccessStory - No data for " + GameSelected.Name);
#if DEBUG
                        stopwatch.Stop();
                        ts = stopwatch.Elapsed;
                        logger.Debug($"SuccessStory - TaskRefresh(){IsCanceld} - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
                        return;
                    }

                    if (!SuccessStory.SelectedGameAchievements.HaveAchivements)
                    {
                        logger.Warn("SuccessStory - No achievements for " + GameSelected.Name);
#if DEBUG
                        stopwatch.Stop();
                        ts = stopwatch.Elapsed;
                        logger.Debug($"SuccessStory - TaskRefresh(){IsCanceld} - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
                        return;
                    }

#if DEBUG
                    logger.Debug($"SuccessStory - SuccessStory.SelectedGameAchievements: ({JsonConvert.SerializeObject(SuccessStory.SelectedGameAchievements)})");
#endif
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_HasData", Value = true
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Is100Percent", Value = SuccessStory.SelectedGameAchievements.Is100Percent
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Total", Value = SuccessStory.SelectedGameAchievements.Total
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalDouble", Value = double.Parse(SuccessStory.SelectedGameAchievements.Total.ToString())
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_TotalString", Value = SuccessStory.SelectedGameAchievements.Total.ToString()
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Unlocked", Value = SuccessStory.SelectedGameAchievements.Unlocked
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedDouble", Value = double.Parse(SuccessStory.SelectedGameAchievements.Unlocked.ToString())
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_UnlockedString", Value = SuccessStory.SelectedGameAchievements.Unlocked.ToString()
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_Locked", Value = SuccessStory.SelectedGameAchievements.Locked
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedDouble", Value = double.Parse(SuccessStory.SelectedGameAchievements.Locked.ToString())
                    });
                    resourcesLists.Add(new ResourcesList {
                        Key = "Sc_LockedString", Value = SuccessStory.SelectedGameAchievements.Locked.ToString()
                    });


                    // If not cancel, show
                    if (!ct.IsCancellationRequested && _PlayniteApi.ApplicationInfo.Mode == ApplicationMode.Desktop)
                    {
                        ui.AddResources(resourcesLists);

                        if (SuccessStory.SelectedGameAchievements != null && SuccessStory.SelectedGameAchievements.HaveAchivements)
                        {
                            Application.Current.Dispatcher.BeginInvoke((Action) delegate
                            {
                                if (_Settings.EnableIntegrationButton)
                                {
#if DEBUG
                                    logger.Debug($"SuccessStory - RefreshBtActionBar()");
#endif
                                    try
                                    {
                                        RefreshBtActionBar();
                                    }
                                    catch (Exception ex)
                                    {
                                        Common.LogError(ex, "SuccessStory", $"Error on RefreshBtActionBar()");
                                    }
                                }

                                if (_Settings.EnableIntegrationInDescription)
                                {
#if DEBUG
                                    logger.Debug($"SuccessStory - RefreshSpDescription()");
#endif
                                    try
                                    {
                                        RefreshSpDescription();
                                    }
                                    catch (Exception ex)
                                    {
                                        Common.LogError(ex, "SuccessStory", $"Error on RefreshSpDescription()");
                                    }
                                }

                                if (_Settings.EnableIntegrationInCustomTheme)
                                {
#if DEBUG
                                    logger.Debug($"SuccessStory - RefreshCustomElements()");
#endif
                                    try
                                    {
                                        RefreshCustomElements();
                                    }
                                    catch (Exception ex)
                                    {
                                        Common.LogError(ex, "SuccessStory", $"Error on RefreshCustomElements()");
                                    }
                                }
                            });
                        }
                        else
                        {
#if DEBUG
                            logger.Debug($"SuccessStory - No data for {SuccessStory.GameSelected.Name}");
#endif
                        }
                    }
                    else
                    {
#if DEBUG
                        IsCanceld = " canceled";
#endif
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on TaskRefreshBtActionBar()");
                }
#if DEBUG
                stopwatch.Stop();
                ts = stopwatch.Elapsed;
                logger.Debug($"SuccessStory - TaskRefresh(){IsCanceld} - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
            }, ct);

            taskHelper.Add(TaskRefresh, tokenSource);
        }
        // Add code to be executed when Playnite is initialized.
        public override void OnApplicationStarted()
        {
            successStoryUI.AddBtHeader();

            // Cache images
            if (settings.EnableImageCache)
            {
                CancellationToken ct = tokenSource.Token;
                var TaskCacheImage   = Task.Run(() =>
                {
                    // Wait Playnite & extension database are loaded
                    Thread.Sleep(50000);
#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - TaskCacheImage - {PlayniteApi.Database.Games.Count} - Start");
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
#endif
                    foreach (Game game in PlayniteApi.Database.Games)
                    {
                        try
                        {
                            Models.GameAchievements successStories = PluginDatabase.GetOnlyCache(game.Id);
                            if (successStories != null && successStories.HaveAchivements)
                            {
#if DEBUG
                                logger.Debug($"SuccessStory [Ignored] - TaskCacheImage - {game.Name} - {successStories.Items.Count}");
#endif
                                foreach (var achievement in successStories.Items)
                                {
                                    if (!achievement.UrlLocked.IsNullOrEmpty() && PlayniteTools.GetCacheFile(achievement.CacheLocked, "SuccessStory").IsNullOrEmpty())
                                    {
#if DEBUG
                                        logger.Debug($"SuccessStory [Ignored] - TaskCacheImage.DownloadFileImage - {game.Name} - GetCacheFile({achievement.Name}" + "_Locked)");
#endif
                                        Web.DownloadFileImage(achievement.CacheLocked, achievement.UrlLocked, PlaynitePaths.ImagesCachePath, "SuccessStory").GetAwaiter().GetResult();
                                    }

                                    if (ct.IsCancellationRequested)
                                    {
                                        logger.Info($"IsCancellationRequested for TaskCacheImage()");
                                        break;
                                    }

                                    if (PlayniteTools.GetCacheFile(achievement.CacheUnlocked, "SuccessStory").IsNullOrEmpty())
                                    {
#if DEBUG
                                        logger.Debug($"SuccessStory [Ignored] - TaskCacheImage.DownloadFileImage - {game.Name} - GetCacheFile({achievement.Name}" + "_Unlocked)");
#endif
                                        Web.DownloadFileImage(achievement.CacheUnlocked, achievement.UrlUnlocked, PlaynitePaths.ImagesCachePath, "SuccessStory").GetAwaiter().GetResult();
                                    }

                                    if (ct.IsCancellationRequested)
                                    {
                                        logger.Info($"IsCancellationRequested for TaskCacheImage()");
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
#if DEBUG
                            Common.LogError(ex, "SuccessStory [Ignored]", $"Error on TaskCacheImage");
#endif
                        }
                    }

#if DEBUG
                    stopwatch.Stop();
                    TimeSpan ts = stopwatch.Elapsed;
                    logger.Debug($"SuccessStory [Ignored] - TaskCacheImage() - End - {String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10)}");
#endif
                }, tokenSource.Token);
            }
        }
        // To add new game menu items override GetGameMenuItems
        public override List <GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs args)
        {
            Game             GameMenu          = args.Games.First();
            string           SourceName        = PlayniteTools.GetSourceName(PlayniteApi, GameMenu);
            bool             IsAddOrShowManual = SuccessStoryDatabase.IsAddOrShowManual(GameMenu, SourceName);
            GameAchievements gameAchievements  = PluginDatabase.Get(GameMenu, true);

            List <GameMenuItem> gameMenuItems = new List <GameMenuItem>();

            if (!settings.EnableOneGameView || (settings.EnableOneGameView && gameAchievements.HasData))
            {
                // Show list achievements for the selected game
                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGame"),
                    Action      = (gameMenuItem) =>
                    {
                        dynamic ViewExtension     = null;
                        PluginDatabase.IsViewOpen = true;
                        if (PluginDatabase.PluginSettings.EnableOneGameView)
                        {
                            ViewExtension = new SuccessStoryOneGameView(GameMenu);
                        }
                        else
                        {
                            ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), false, GameMenu);
                        }
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                        PluginDatabase.IsViewOpen = false;
                    }
                });
            }

            if (!IsAddOrShowManual)
            {
                gameMenuItems.Add(new GameMenuItem
                {
                    MenuSection = resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCCommonRefreshGameData"),
                    Action      = (gameMenuItem) =>
                    {
                        if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription)
                        {
                            PlayniteUiHelper.ResetToggle();
                        }

                        var TaskIntegrationUI = Task.Run(() =>
                        {
                            PluginDatabase.Remove(GameMenu);
                            var dispatcherOp        = successStoryUI.AddElements();
                            dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                        });
                    }
                });
            }

            if (settings.EnableManual && IsAddOrShowManual)
            {
                if (!gameAchievements.HasData)
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSuccessStory"),
                        Description = resources.GetString("LOCAddTitle"),
                        Action      = (mainMenuItem) =>
                        {
                            var TaskIntegrationUI = Task.Run(() =>
                            {
                                PluginDatabase.Remove(GameMenu);
                                PluginDatabase.GetManual(GameMenu);

                                var dispatcherOp        = successStoryUI.AddElements();
                                dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                            });
                        }
                    });
                }
                else
                {
                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSuccessStory"),
                        Description = resources.GetString("LOCEditGame"),
                        Action      = (mainMenuItem) =>
                        {
                            var ViewExtension      = new SuccessStoryEditManual(GameMenu);
                            Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                            windowExtension.ShowDialog();
                        }
                    });

                    gameMenuItems.Add(new GameMenuItem
                    {
                        MenuSection = resources.GetString("LOCSuccessStory"),
                        Description = resources.GetString("LOCRemoveTitle"),
                        Action      = (gameMenuItem) =>
                        {
                            if (settings.EnableIntegrationInCustomTheme || settings.EnableIntegrationInDescription)
                            {
                                PlayniteUiHelper.ResetToggle();
                            }

                            var TaskIntegrationUI = Task.Run(() =>
                            {
                                PluginDatabase.Remove(GameMenu);
                                var dispatcherOp        = successStoryUI.AddElements();
                                dispatcherOp.Completed += (s, e) => { successStoryUI.RefreshElements(GameMenu); };
                            });
                        }
                    });
                }
            }

#if DEBUG
            gameMenuItems.Add(new GameMenuItem
            {
                MenuSection = resources.GetString("LOCSuccessStory"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif
            return(gameMenuItems);
        }
        private bool IsEmulatedGame(KeyValuePair <Guid, GameAchievements> x)
        {
            Game game = _PlayniteApi.Database.Games.Get(x.Key);

            return(PlayniteTools.IsGameEmulated(_PlayniteApi, game));
        }
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            try
            {
                if (ListGames.Count == 0)
                {
                    var dataGameAchievements = PluginDatabase.Database.Where(x => x.HaveAchivements && x.IsDeleted == false);
                    foreach (GameAchievements item in dataGameAchievements)
                    {
                        string SourceName = PlayniteTools.GetSourceName(_PlayniteApi, item.Id);

                        string   GameId           = item.Id.ToString();
                        string   GameName         = item.Name;
                        string   GameIcon         = string.Empty;
                        string   Icon100          = string.Empty;
                        DateTime?GameLastActivity = null;

                        GameAchievements successStories = PluginDatabase.Get(item.Id);

                        if (item.LastActivity != null)
                        {
                            GameLastActivity = ((DateTime)item.LastActivity).ToLocalTime();
                        }

                        if (!item.Icon.IsNullOrEmpty())
                        {
                            GameIcon = _PlayniteApiDatabase.GetFullFilePath(item.Icon);
                        }

                        if (successStories.Is100Percent)
                        {
                            Icon100 = Path.Combine(pluginFolder, "Resources\\badge.png");
                        }

                        ListGames.Add(new ListViewGames()
                        {
                            Icon100Percent   = Icon100,
                            Id               = GameId,
                            Name             = GameName,
                            Icon             = GameIcon,
                            LastActivity     = GameLastActivity,
                            SourceName       = SourceName,
                            SourceIcon       = TransformIcon.Get(SourceName),
                            ProgressionValue = successStories.Progression,
                            Total            = successStories.Total,
                            TotalPercent     = successStories.Progression + "%",
                            Unlocked         = successStories.Unlocked,
                            IsManual         = successStories.IsManual
                        });
                    }

#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - ListGames: {JsonConvert.SerializeObject(ListGames)}");
#endif
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    ListviewGames.ItemsSource = ListGames;
                    Sorting();
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()");
            }
        }
        // To add new main menu items override GetMainMenuItems
        public override List <MainMenuItem> GetMainMenuItems(GetMainMenuItemsArgs args)
        {
            string MenuInExtensions = string.Empty;

            if (settings.MenuInExtensions)
            {
                MenuInExtensions = "@";
            }

            List <MainMenuItem> mainMenuItems = new List <MainMenuItem>
            {
                // Show list achievements for all games
                new MainMenuItem
                {
                    MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGames"),
                    Action      = (mainMenuItem) =>
                    {
                        PluginDatabase.IsViewOpen = true;
                        var    ViewExtension   = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath());
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                        PluginDatabase.IsViewOpen = false;
                    }
                }
            };

            if (settings.EnableRetroAchievementsView && settings.EnableRetroAchievements)
            {
                mainMenuItems.Add(new MainMenuItem
                {
                    MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                    Description = resources.GetString("LOCSuccessStoryViewGames") + " - RetroAchievements",
                    Action      = (mainMenuItem) =>
                    {
                        PluginDatabase.IsViewOpen = true;
                        SuccessView ViewExtension = null;
                        if (settings.EnableRetroAchievementsView && PlayniteTools.IsGameEmulated(PlayniteApi, SuccessStoryDatabase.GameSelected))
                        {
                            ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), true, SuccessStoryDatabase.GameSelected);
                        }
                        else
                        {
                            ViewExtension = new SuccessView(this, PlayniteApi, this.GetPluginUserDataPath(), false, SuccessStoryDatabase.GameSelected);
                        }
                        Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(PlayniteApi, resources.GetString("LOCSuccessStory"), ViewExtension);
                        windowExtension.ShowDialog();
                        PluginDatabase.IsViewOpen = false;
                    }
                });
            }

            // Download missing data for all game in database
            mainMenuItems.Add(
                new MainMenuItem
            {
                MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                Description = resources.GetString("LOCCommonGetAllDatas"),
                Action      = (mainMenuItem) =>
                {
                    PluginDatabase.GetAllDatas();
                }
            }
                );

#if DEBUG
            mainMenuItems.Add(new MainMenuItem
            {
                MenuSection = MenuInExtensions + resources.GetString("LOCSuccessStory"),
                Description = "Test",
                Action      = (mainMenuItem) => { }
            });
#endif

            return(mainMenuItems);
        }
示例#25
0
        // Override additional methods based on supported metadata fields.
        public override string GetDescription()
        {
            // Get type source, data and description
            string Data;
            string Description = string.Empty;

            if (AvailableFields.Contains(MetadataField.Description))
            {
                // Get Playnite language
                PlayniteLanguage = _plugin.PlayniteApi.ApplicationSettings.Language;

                string GameId    = string.Empty;
                string GameName  = string.Empty;
                string StoreName = string.Empty;

                try
                {
                    GameId   = _options.GameData.GameId;
                    GameName = _options.GameData.Name;

                    if (_options.GameData.SourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
                    {
                        StoreName = _options.GameData.Source.Name;
                    }
                    else
                    {
                        logger.Warn("No source name");
                    }


                    // Selectable Store metadata
                    if (!_options.IsBackgroundDownload && _settings.EnableSelectStore)
                    {
                        MetadataLocalStoreSelection ViewExtension = null;
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            ViewExtension          = new MetadataLocalStoreSelection(_plugin.PlayniteApi, StoreName, GameName, _plugin.GetPluginUserDataPath());
                            Window windowExtension = PlayniteUiHelper.CreateExtensionWindow(_plugin.PlayniteApi, resources.GetString("LOCMetadataLocalStoreSelection"), ViewExtension);
                            windowExtension.ShowDialog();
                        }));

                        if (!ViewExtension.StoreResult.StoreName.IsNullOrEmpty())
                        {
                            GameId    = ViewExtension.StoreResult.StoreId;
                            GameName  = ViewExtension.StoreResult.Name;
                            StoreName = ViewExtension.StoreResult.StoreName;
                        }
                        else
                        {
                            GameId    = string.Empty;
                            GameName  = string.Empty;
                            StoreName = string.Empty;
                        }
                    }


                    switch (StoreName.ToLower())
                    {
                    case "steam":
                        uint appId = uint.Parse(GameId);
                        Data = GetSteamData(appId, PlayniteLanguage);
                        var parsedData = JsonConvert.DeserializeObject <Dictionary <string, StoreAppDetailsResult> >(Data);
                        Description = parsedData[appId.ToString()].data.detailed_description;
                        break;

                    case "origin":
                        Description = GetOriginData(GameId, PlayniteLanguage);
                        break;

                    case "epic":
                        Description = GetEpicData(GameName);
                        break;

                    case "xbox":
                        if (!PlayniteTools.IsDisabledPlaynitePlugins("XboxLibrary", _PlayniteConfigurationPath))
                        {
                            Description = GetXboxData(GameId, PlayniteLanguage, _plugin.GetPluginUserDataPath(), _plugin).GetAwaiter().GetResult();
                        }
                        else
                        {
                            logger.Warn("XboxLibrary is used then disabled");
                            _plugin.PlayniteApi.Notifications.Add(new NotificationMessage(
                                                                      $"metadataLocal-xbox-disabled",
                                                                      "XboxLibrary is used then disabled",
                                                                      NotificationType.Error,
                                                                      () => _plugin.OpenSettingsView()
                                                                      ));
                        }
                        break;

                    case "ubisoft":
                    case "uplay":
                    case "ubisoft connect":
                        Description = GetUbisoftData(GameName, PlayniteLanguage, GameId);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, false, $"Error with {GameName} - {GameId} - {StoreName}");
                }
            }

            if (Description.IsNullOrEmpty())
            {
                return(base.GetDescription());
            }
            else
            {
                return(Description);
            }
        }
示例#26
0
 public List <string> GetScreenshotsFolders(IPlayniteAPI PlayniteApi)
 {
     return(ScreenshotsFolders.Select(x => PlayniteTools.StringExpandWithStores(PlayniteApi.Database.Games.Get(Id), x.ScreenshotsFolder)).ToList());
 }
示例#27
0
        /// <summary>
        /// Show list game with achievement.
        /// </summary>
        public void GetListGame()
        {
            string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            try
            {
                if (ListGames.Count == 0)
                {
                    var dataGameAchievements = AchievementsDb.gameAchievements.Where(x => x.Value.HaveAchivements);
                    foreach (var item in dataGameAchievements)
                    {
                        Game   game       = _PlayniteApiDatabase.Games.Get(item.Key);
                        string SourceName = PlayniteTools.GetSourceName(game, _PlayniteApi);

                        if (AchievementsDatabase.VerifToAddOrShow(plugin, _PlayniteApi, SourceName, settings, PluginUserDataPath))
                        {
                            string   GameId           = game.Id.ToString();
                            string   GameName         = game.Name;
                            string   GameIcon         = string.Empty;
                            string   Icon100          = string.Empty;
                            DateTime?GameLastActivity = null;

                            GameAchievements GameAchievements = AchievementsDb.Get(game.Id);

                            if (game.LastActivity != null)
                            {
                                GameLastActivity = ((DateTime)game.LastActivity).ToLocalTime();
                            }

                            if (!game.Icon.IsNullOrEmpty())
                            {
                                GameIcon = _PlayniteApiDatabase.GetFullFilePath(game.Icon);
                            }

                            if (GameAchievements.Is100Percent)
                            {
                                Icon100 = Path.Combine(pluginFolder, "Resources\\badge.png");
                            }

                            ListGames.Add(new ListViewGames()
                            {
                                Icon100Percent   = Icon100,
                                Id               = GameId,
                                Name             = GameName,
                                Icon             = GameIcon,
                                LastActivity     = GameLastActivity,
                                SourceName       = SourceName,
                                SourceIcon       = TransformIcon.Get(SourceName),
                                ProgressionValue = GameAchievements.Progression,
                                Total            = GameAchievements.Total,
                                TotalPercent     = GameAchievements.Progression + "%",
                                Unlocked         = GameAchievements.Unlocked
                            });
                        }
                    }
                }

                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    ListviewGames.ItemsSource = ListGames;
                    Sorting();
                });
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "SuccessStory", "Errorn on GetListGames()");
            }
        }