8ae85ee78170bf1184979a806f819809b6f06d26
[vuplus_xbmc] / xbmc / addons / AddonDatabase.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21
22 #include "dbwrappers/Database.h"
23 #include "addons/Addon.h"
24 #include "utils/StdString.h"
25 #include "FileItem.h"
26
27 class CAddonDatabase : public CDatabase
28 {
29 public:
30   CAddonDatabase();
31   virtual ~CAddonDatabase();
32   virtual bool Open();
33
34   int AddAddon(const ADDON::AddonPtr& item, int idRepo);
35   bool GetAddon(const CStdString& addonID, ADDON::AddonPtr& addon);
36   bool GetAddons(ADDON::VECADDONS& addons);
37
38   /*! \brief Grab the repository from which a given addon came
39    \param addonID - the id of the addon in question
40    \param repo [out] - the id of the repository
41    \return true if a repo was found, false otherwise.
42    */
43   bool GetRepoForAddon(const CStdString& addonID, CStdString& repo);
44   int AddRepository(const CStdString& id, const ADDON::VECADDONS& addons, const CStdString& checksum);
45   void DeleteRepository(const CStdString& id);
46   void DeleteRepository(int id);
47   int GetRepoChecksum(const std::string& id, std::string& checksum);
48   bool GetRepository(const CStdString& id, ADDON::VECADDONS& addons);
49   bool GetRepository(int id, ADDON::VECADDONS& addons);
50   bool SetRepoTimestamp(const CStdString& id, const CStdString& timestamp);
51
52   /*! \brief Retrieve the time a repository was last checked
53    \param id id of the repo
54    \return last time the repo was checked, current time if not available
55    \sa SetRepoTimestamp */
56   CDateTime GetRepoTimestamp(const CStdString& id);
57
58   bool Search(const CStdString& search, ADDON::VECADDONS& items);
59   static void SetPropertiesFromAddon(const ADDON::AddonPtr& addon, CFileItemPtr& item); 
60
61   /*! \brief Disable an addon.
62    Sets a flag that this addon has been disabled.  If disabled, it is usually still available on disk.
63    \param addonID id of the addon to disable
64    \param disable whether to enable or disable.  Defaults to true (disable)
65    \return true on success, false on failure
66    \sa IsAddonDisabled, HasDisabledAddons */
67   bool DisableAddon(const CStdString &addonID, bool disable = true);
68
69   /*! \brief Checks if an addon is in the database.
70    \param addonID id of the addon to be checked
71    \return true if addon is in database, false if addon is not in database yet */
72   bool HasAddon(const CStdString &addonID);
73   
74   /*! \brief Check whether an addon has been disabled via DisableAddon.
75    \param addonID id of the addon to check
76    \return true if the addon is disabled, false otherwise
77    \sa DisableAddon, HasDisabledAddons */
78   bool IsAddonDisabled(const CStdString &addonID);
79
80   /*! \brief Check whether we have disabled addons.
81    \return true if we have disabled addons, false otherwise
82    \sa DisableAddon, IsAddonDisabled */
83   bool HasDisabledAddons();
84
85   /*! @deprecated only here to allow clean upgrades from earlier pvr versions
86    */
87   bool IsSystemPVRAddonEnabled(const CStdString &addonID);
88
89   /*! \brief Mark an addon as broken
90    Sets a flag that this addon has been marked as broken in the repository.
91    \param addonID id of the addon to mark as broken
92    \param reason why it is broken - if non empty we take it as broken.  Defaults to empty
93    \return true on success, false on failure
94    \sa IsAddonBroken */
95   bool BreakAddon(const CStdString &addonID, const CStdString& reason="");
96
97   /*! \brief Check whether an addon has been marked as broken via BreakAddon.
98    \param addonID id of the addon to check
99    \return reason if the addon is broken, blank otherwise
100    \sa BreakAddon */
101   CStdString IsAddonBroken(const CStdString &addonID);
102
103   bool BlacklistAddon(const CStdString& addonID, const CStdString& version);
104   bool IsAddonBlacklisted(const CStdString& addonID, const CStdString& version);
105   bool RemoveAddonFromBlacklist(const CStdString& addonID,
106                                 const CStdString& version);
107
108   /*! \brief Store an addon's package filename and that file's hash for future verification
109       \param  addonID         id of the addon we're adding a package for
110       \param  packageFileName filename of the package
111       \param  hash            MD5 checksum of the package
112       \return Whether or not the info successfully made it into the DB.
113       \sa GetPackageHash, RemovePackage
114   */
115   bool AddPackage(const CStdString& addonID,
116                   const CStdString& packageFileName,
117                   const CStdString& hash);
118   /*! \brief Query the MD5 checksum of the given given addon's given package
119       \param  addonID         id of the addon we're who's package we're querying
120       \param  packageFileName filename of the package
121       \param  hash            return the MD5 checksum of the package
122       \return Whether or not we found a hash for the given addon's given package
123       \sa AddPackage, RemovePackage
124   */
125   bool GetPackageHash(const CStdString& addonID,
126                       const CStdString& packageFileName,
127                       CStdString&       hash);
128   /*! \brief Remove a package's info from the database
129       \param  packageFileName filename of the package
130       \return Whether or not we succeeded in removing the package
131       \sa AddPackage, GetPackageHash
132   */
133   bool RemovePackage(const CStdString& packageFileName);
134 protected:
135   virtual bool CreateTables();
136   virtual bool UpdateOldVersion(int version);
137   virtual int GetMinVersion() const { return 16; }
138   const char *GetBaseDBName() const { return "Addons"; }
139
140   bool GetAddon(int id, ADDON::AddonPtr& addon);
141 };
142