Exemple #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;
        }
        // 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();
        }
        // 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);
        }
        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);
        }
        private bool IsEmulatedGame(KeyValuePair <Guid, GameAchievements> x)
        {
            Game game = _PlayniteApi.Database.Games.Get(x.Key);

            return(PlayniteTools.IsGameEmulated(_PlayniteApi, game));
        }
        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);
        }