[addondb] adds CAddonDatabase::GetAddonVersion() to speed up repository parsing
[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 (largest) add-on version for an add-on */
39   ADDON::AddonVersion GetAddonVersion(const std::string &id);
40
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.
45    */
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);
54
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);
60
61   bool Search(const CStdString& search, ADDON::VECADDONS& items);
62   static void SetPropertiesFromAddon(const ADDON::AddonPtr& addon, CFileItemPtr& item); 
63
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);
71
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);
76   
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);
82
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();
87
88   /*! @deprecated only here to allow clean upgrades from earlier pvr versions
89    */
90   bool IsSystemPVRAddonEnabled(const CStdString &addonID);
91
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
97    \sa IsAddonBroken */
98   bool BreakAddon(const CStdString &addonID, const CStdString& reason="");
99
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
103    \sa BreakAddon */
104   CStdString IsAddonBroken(const CStdString &addonID);
105
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);
110
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
117   */
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
127   */
128   bool GetPackageHash(const CStdString& addonID,
129                       const CStdString& packageFileName,
130                       CStdString&       hash);
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
135   */
136   bool RemovePackage(const CStdString& packageFileName);
137 protected:
138   virtual bool CreateTables();
139   virtual bool UpdateOldVersion(int version);
140   virtual int GetMinVersion() const { return 16; }
141   const char *GetBaseDBName() const { return "Addons"; }
142
143   bool GetAddon(int id, ADDON::AddonPtr& addon);
144
145   /* keep in sync with the select in GetAddon */
146   enum _AddonFields
147   {
148     addon_id=0,
149     addon_type,
150     addon_name,
151     addon_summary,
152     addon_description,
153     addon_stars,
154     addon_path,
155     addon_addonID,
156     addon_icon,
157     addon_version,
158     addon_changelog,
159     addon_fanart,
160     addon_author,
161     addon_disclaimer,
162     addon_minversion,
163     broken_reason,
164     addonextra_key,
165     addonextra_value,
166     dependencies_addon,
167     dependencies_version,
168     dependencies_optional
169   } AddonFields;
170 };
171