| 1 |
/* |
| 2 |
* Copyright (C) 2012-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "GameTypes.h" |
| 12 |
|
| 13 |
#include <mutex> |
| 14 |
#include <set> |
| 15 |
#include <string> |
| 16 |
|
| 17 |
class CFileItem; |
| 18 |
class CURL; |
| 19 |
|
| 20 |
namespace ADDON |
| 21 |
{ |
| 22 |
class IAddon; |
| 23 |
using AddonPtr = std::shared_ptr<IAddon>; |
| 24 |
using VECADDONS = std::vector<AddonPtr>; |
| 25 |
} // namespace ADDON |
| 26 |
|
| 27 |
namespace KODI |
| 28 |
{ |
| 29 |
namespace GAME |
| 30 |
{ |
| 31 |
/*! |
| 32 |
* \ingroup games |
| 33 |
* |
| 34 |
* \brief Game related utilities. |
| 35 |
*/ |
| 36 |
class CGameUtils |
| 37 |
{ |
| 38 |
public: |
| 39 |
/*! |
| 40 |
* \brief Set the game client property, prompt the user for a savestate if there are any |
| 41 |
* (savestates store the information of which game client created it). |
| 42 |
* If there are no savestates or the user wants a new savestate, prompt the user |
| 43 |
* for a game client. |
| 44 |
* |
| 45 |
* \param item The item with or without a game client in its info tag |
| 46 |
* \param savestatePath Output. The path to the savestate selected. Empty if new savestate was |
| 47 |
* selected |
| 48 |
* |
| 49 |
* \return True if the item has a valid game client ID in its info tag |
| 50 |
*/ |
| 51 |
static bool FillInGameClient(CFileItem& item, std::string& savestatePath); |
| 52 |
|
| 53 |
/*! |
| 54 |
* \brief Check if the file extension is supported by an add-on in |
| 55 |
* a local or remote repository |
| 56 |
* |
| 57 |
* \param path The path of the game file |
| 58 |
* |
| 59 |
* \return true if the path's extension is supported by a known game client |
| 60 |
*/ |
| 61 |
static bool HasGameExtension(const std::string& path); |
| 62 |
|
| 63 |
/*! |
| 64 |
* \brief Get all game extensions |
| 65 |
*/ |
| 66 |
static std::set<std::string> GetGameExtensions(); |
| 67 |
|
| 68 |
/*! |
| 69 |
* \brief Check if game script or game add-on can be launched directly |
| 70 |
* |
| 71 |
* \return true if the add-on can be launched, false otherwise |
| 72 |
*/ |
| 73 |
static bool IsStandaloneGame(const ADDON::AddonPtr& addon); |
| 74 |
|
| 75 |
/*! |
| 76 |
* \brief Called when the cache of installable game add-ons should be |
| 77 |
* refreshed, such as when a new add-on repo is installed |
| 78 |
*/ |
| 79 |
static void UpdateInstallableAddons(); |
| 80 |
|
| 81 |
private: |
| 82 |
static void GetGameClients(const CFileItem& file, |
| 83 |
GameClientVector& candidates, |
| 84 |
GameClientVector& installable, |
| 85 |
bool& bHasVfsGameClient); |
| 86 |
static void GetGameClients(const ADDON::VECADDONS& addons, |
| 87 |
const CURL& translatedUrl, |
| 88 |
GameClientVector& candidates, |
| 89 |
bool& bHasVfsGameClient); |
| 90 |
|
| 91 |
/*! |
| 92 |
* \brief Install the specified game client |
| 93 |
* |
| 94 |
* If the game client is not installed, a model dialog is shown installing |
| 95 |
* the game client. If the installation fails, an error dialog is shown. |
| 96 |
* |
| 97 |
* \param gameClient The game client to install |
| 98 |
* |
| 99 |
* \return True if the game client is installed, false otherwise |
| 100 |
*/ |
| 101 |
static bool Install(const std::string& gameClient); |
| 102 |
|
| 103 |
/*! |
| 104 |
* \brief Enable the specified game client |
| 105 |
* |
| 106 |
* \param gameClient the game client to enable |
| 107 |
* |
| 108 |
* \return True if the game client is enabled, false otherwise |
| 109 |
*/ |
| 110 |
static bool Enable(const std::string& gameClient); |
| 111 |
|
| 112 |
/*! |
| 113 |
* \brief Load and cache installable game add-ons |
| 114 |
*/ |
| 115 |
static void LoadInstallableAddons(); |
| 116 |
|
| 117 |
/*! |
| 118 |
* \brief Cache of installable game add-ons used to compute the list of |
| 119 |
* known game file extensions |
| 120 |
*/ |
| 121 |
static ADDON::VECADDONS m_installableGameAddons; |
| 122 |
|
| 123 |
/*! |
| 124 |
* \brief Set to true to update cache of installable game add-ons |
| 125 |
*/ |
| 126 |
static bool m_checkInstallable; |
| 127 |
|
| 128 |
/*! |
| 129 |
* \brief Mutex to guard list of installable game add-ons |
| 130 |
*/ |
| 131 |
static std::mutex m_installableMutex; |
| 132 |
}; |
| 133 |
} // namespace GAME |
| 134 |
} // namespace KODI |