3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #include "dbwrappers/Database.h"
23 #include "addons/Addon.h"
24 #include "utils/StdString.h"
27 class CAddonDatabase : public CDatabase
31 virtual ~CAddonDatabase();
34 int AddAddon(const ADDON::AddonPtr& item, int idRepo);
35 bool GetAddon(const CStdString& addonID, ADDON::AddonPtr& addon);
36 bool GetAddons(ADDON::VECADDONS& addons);
38 /*! \brief grab the (largest) add-on version for an add-on */
39 ADDON::AddonVersion GetAddonVersion(const std::string &id);
41 /*! \brief Grab the repository from which a given addon came
42 \param addonID - the id of the addon in question
43 \param repo [out] - the id of the repository
44 \return true if a repo was found, false otherwise.
46 bool GetRepoForAddon(const CStdString& addonID, CStdString& repo);
47 int AddRepository(const CStdString& id, const ADDON::VECADDONS& addons, const CStdString& checksum);
48 void DeleteRepository(const CStdString& id);
49 void DeleteRepository(int id);
50 int GetRepoChecksum(const std::string& id, std::string& checksum);
51 bool GetRepository(const CStdString& id, ADDON::VECADDONS& addons);
52 bool GetRepository(int id, ADDON::VECADDONS& addons);
53 bool SetRepoTimestamp(const CStdString& id, const CStdString& timestamp);
55 /*! \brief Retrieve the time a repository was last checked
56 \param id id of the repo
57 \return last time the repo was checked, current time if not available
58 \sa SetRepoTimestamp */
59 CDateTime GetRepoTimestamp(const CStdString& id);
61 bool Search(const CStdString& search, ADDON::VECADDONS& items);
62 static void SetPropertiesFromAddon(const ADDON::AddonPtr& addon, CFileItemPtr& item);
64 /*! \brief Disable an addon.
65 Sets a flag that this addon has been disabled. If disabled, it is usually still available on disk.
66 \param addonID id of the addon to disable
67 \param disable whether to enable or disable. Defaults to true (disable)
68 \return true on success, false on failure
69 \sa IsAddonDisabled, HasDisabledAddons */
70 bool DisableAddon(const CStdString &addonID, bool disable = true);
72 /*! \brief Checks if an addon is in the database.
73 \param addonID id of the addon to be checked
74 \return true if addon is in database, false if addon is not in database yet */
75 bool HasAddon(const CStdString &addonID);
77 /*! \brief Check whether an addon has been disabled via DisableAddon.
78 \param addonID id of the addon to check
79 \return true if the addon is disabled, false otherwise
80 \sa DisableAddon, HasDisabledAddons */
81 bool IsAddonDisabled(const CStdString &addonID);
83 /*! \brief Check whether we have disabled addons.
84 \return true if we have disabled addons, false otherwise
85 \sa DisableAddon, IsAddonDisabled */
86 bool HasDisabledAddons();
88 /*! @deprecated only here to allow clean upgrades from earlier pvr versions
90 bool IsSystemPVRAddonEnabled(const CStdString &addonID);
92 /*! \brief Mark an addon as broken
93 Sets a flag that this addon has been marked as broken in the repository.
94 \param addonID id of the addon to mark as broken
95 \param reason why it is broken - if non empty we take it as broken. Defaults to empty
96 \return true on success, false on failure
98 bool BreakAddon(const CStdString &addonID, const CStdString& reason="");
100 /*! \brief Check whether an addon has been marked as broken via BreakAddon.
101 \param addonID id of the addon to check
102 \return reason if the addon is broken, blank otherwise
104 CStdString IsAddonBroken(const CStdString &addonID);
106 bool BlacklistAddon(const CStdString& addonID, const CStdString& version);
107 bool IsAddonBlacklisted(const CStdString& addonID, const CStdString& version);
108 bool RemoveAddonFromBlacklist(const CStdString& addonID,
109 const CStdString& version);
111 /*! \brief Store an addon's package filename and that file's hash for future verification
112 \param addonID id of the addon we're adding a package for
113 \param packageFileName filename of the package
114 \param hash MD5 checksum of the package
115 \return Whether or not the info successfully made it into the DB.
116 \sa GetPackageHash, RemovePackage
118 bool AddPackage(const CStdString& addonID,
119 const CStdString& packageFileName,
120 const CStdString& hash);
121 /*! \brief Query the MD5 checksum of the given given addon's given package
122 \param addonID id of the addon we're who's package we're querying
123 \param packageFileName filename of the package
124 \param hash return the MD5 checksum of the package
125 \return Whether or not we found a hash for the given addon's given package
126 \sa AddPackage, RemovePackage
128 bool GetPackageHash(const CStdString& addonID,
129 const CStdString& packageFileName,
131 /*! \brief Remove a package's info from the database
132 \param packageFileName filename of the package
133 \return Whether or not we succeeded in removing the package
134 \sa AddPackage, GetPackageHash
136 bool RemovePackage(const CStdString& packageFileName);
138 virtual bool CreateTables();
139 virtual bool UpdateOldVersion(int version);
140 virtual int GetMinVersion() const { return 16; }
141 const char *GetBaseDBName() const { return "Addons"; }
143 bool GetAddon(int id, ADDON::AddonPtr& addon);
145 /* keep in sync with the select in GetAddon */
167 dependencies_version,
168 dependencies_optional