Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
pvr: dropped the pvrenabled table in the addon db. users can upgrade …
Browse files Browse the repository at this point in the history
…to a pvr build without dropping the addon db now
  • Loading branch information
opdenkamp committed Feb 22, 2012
1 parent c731d12 commit deb2a03
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 65 deletions.
32 changes: 2 additions & 30 deletions xbmc/addons/AddonDatabase.cpp
Expand Up @@ -82,10 +82,6 @@ bool CAddonDatabase::CreateTables()
m_pDS->exec("CREATE TABLE disabled (id integer primary key, addonID text)\n");
m_pDS->exec("CREATE UNIQUE INDEX idxDisabled ON disabled(addonID)");

CLog::Log(LOGINFO, "create pvrenabled table");
m_pDS->exec("CREATE TABLE pvrenabled (id integer primary key, addonID text)\n");
m_pDS->exec("CREATE UNIQUE INDEX idxPVREnabled ON pvrenabled(addonID)");

CLog::Log(LOGINFO, "create broken table");
m_pDS->exec("CREATE TABLE broken (id integer primary key, addonID text, reason text)\n");
m_pDS->exec("CREATE UNIQUE INDEX idxBroken ON broken(addonID)");
Expand All @@ -109,17 +105,12 @@ bool CAddonDatabase::UpdateOldVersion(int version)

try
{
if (version < 13) // XXX this will have to get a different version when pvr is merged to master
{
m_pDS->exec("CREATE TABLE pvrenabled (id integer primary key, addonID text)\n");
m_pDS->exec("CREATE INDEX idxPVREnabled ON pvrenabled(addonID)");
}
if (version < 14)
if (version < 13)
{
m_pDS->exec("CREATE TABLE dependencies (id integer, addon text, version text, optional boolean)\n");
m_pDS->exec("CREATE INDEX idxDependencies ON dependencies(id)");
}
if (version < 15)
if (version < 14)
{
m_pDS->exec("ALTER TABLE addon add minversion text");
}
Expand Down Expand Up @@ -623,25 +614,6 @@ bool CAddonDatabase::DisableAddon(const CStdString &addonID, bool disable /* = t
return false;
}

bool CAddonDatabase::EnableSystemPVRAddon(const CStdString &addonID, bool bEnable)
{
if (bEnable)
{
if (!IsSystemPVRAddonEnabled(addonID))
{
CStdString strQuery = PrepareSQL("INSERT INTO pvrenabled(id, addonID) VALUES (NULL, '%s')", addonID.c_str());
return ExecuteQuery(strQuery);
}
}
else
{
CStdString strWhereClause = PrepareSQL("addonID = '%s'", addonID.c_str());
return DeleteValues("pvrenabled", strWhereClause);
}

return false;
}

bool CAddonDatabase::BreakAddon(const CStdString &addonID, const CStdString& reason)
{
try
Expand Down
14 changes: 2 additions & 12 deletions xbmc/addons/AddonDatabase.h
Expand Up @@ -81,18 +81,8 @@ class CAddonDatabase : public CDatabase
\sa DisableAddon, IsAddonDisabled */
bool HasDisabledAddons();

/*! \brief Enable an system PVR addon.
Sets a flag that this PVR addon has been enabled. If disabled, it is usually still available on disk.
\param addonID id of the addon to enable
\param disable whether to enable or disable. Defaults to false (disable)
\return true on success, false on failure
\sa IsSystemPVRAddonEnabled */
bool EnableSystemPVRAddon(const CStdString &addonID, bool enable = false);

/*! \brief Check whether an system PVR addon has been enabled via EnableSystemPVRAddon.
\param addonID id of the addon to check
\return true if the addon is disabled, false otherwise
\sa EnableSystemPVRAddon */
/*! @deprecated only here to allow clean upgrades from earlier pvr versions
*/
bool IsSystemPVRAddonEnabled(const CStdString &addonID);

/*! \brief Mark an addon as broken
Expand Down
20 changes: 5 additions & 15 deletions xbmc/addons/AddonManager.cpp
Expand Up @@ -298,14 +298,14 @@ bool CAddonMgr::HasAddons(const TYPE &type, bool enabled /*= true*/)
return GetAddons(type, addons, enabled);
}

bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/, bool allowRepos /* = false */)
bool CAddonMgr::GetAllAddons(VECADDONS &addons, bool enabled /*= true*/, bool allowRepos /* = false */, bool bGetDisabledPVRAddons /* = true */)
{
for (int i = ADDON_UNKNOWN+1; i < ADDON_VIZ_LIBRARY; ++i)
{
if (!allowRepos && ADDON_REPOSITORY == (TYPE)i)
continue;
VECADDONS temp;
if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabled))
if (CAddonMgr::Get().GetAddons((TYPE)i, temp, enabled, bGetDisabledPVRAddons))
addons.insert(addons.end(), temp.begin(), temp.end());
}
return !addons.empty();
Expand Down Expand Up @@ -384,7 +384,7 @@ bool CAddonMgr::HasOutdatedAddons(bool enabled /*= true*/)
return GetAllOutdatedAddons(dummy,enabled);
}

bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */)
bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* = true */, bool bGetDisabledPVRAddons /* = true */)
{
CStdString xbmcPath = _P("special://xbmc/addons");
CSingleLock lock(m_critSection);
Expand All @@ -396,12 +396,7 @@ bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* =
for(int i=0; i <num; i++)
{
AddonPtr addon(Factory(exts[i]));
if (addon && addon->Type() == ADDON_PVRDLL && addon->Path().Left(xbmcPath.size()).Equals(xbmcPath))
{
if (m_database.IsSystemPVRAddonEnabled(addon->ID()) != enabled)
addon->Disable();
}
if (addon && m_database.IsAddonDisabled(addon->ID()) != enabled)
if (addon && ((bGetDisabledPVRAddons && addon->Type() == ADDON_PVRDLL) || m_database.IsAddonDisabled(addon->ID()) != enabled))
addons.push_back(addon);
}
m_cpluff->release_info(m_cp_context, exts);
Expand All @@ -422,12 +417,7 @@ bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &typ

if (addon && addon.get() && enabledOnly)
{
if (addon->Type() == ADDON_PVRDLL && addon->Path().Left(xbmcPath.size()).Equals(xbmcPath))
{
if (!m_database.IsSystemPVRAddonEnabled(addon->ID()))
return false;
}
else if (m_database.IsAddonDisabled(addon->ID()))
if (m_database.IsAddonDisabled(addon->ID()))
return false;
}
return NULL != addon.get();
Expand Down
4 changes: 2 additions & 2 deletions xbmc/addons/AddonManager.h
Expand Up @@ -92,8 +92,8 @@ namespace ADDON
*/
bool GetAddon(const CStdString &id, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true);
bool HasAddons(const TYPE &type, bool enabled = true);
bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true);
bool GetAllAddons(VECADDONS &addons, bool enabled = true, bool allowRepos = false);
bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true, bool bGetDisabledPVRAddons = true);
bool GetAllAddons(VECADDONS &addons, bool enabled = true, bool allowRepos = false, bool bGetDisabledPVRAddons = true);
void AddToUpdateableAddons(AddonPtr &pAddon);
void RemoveFromUpdateableAddons(AddonPtr &pAddon);
bool ReloadSettings(const CStdString &id);
Expand Down
6 changes: 3 additions & 3 deletions xbmc/addons/GUIDialogAddonInfo.cpp
Expand Up @@ -214,9 +214,9 @@ void CGUIDialogAddonInfo::OnEnable(bool enable)
CStdString xbmcPath = _P("special://xbmc/addons");
CAddonDatabase database;
database.Open();
if (m_localAddon->Type() == ADDON_PVRDLL && m_localAddon->Path().Left(xbmcPath.size()).Equals(xbmcPath))
database.EnableSystemPVRAddon(m_localAddon->ID(), enable);
else
// if (m_localAddon->Type() == ADDON_PVRDLL && m_localAddon->Path().Left(xbmcPath.size()).Equals(xbmcPath))
// database.EnableSystemPVRAddon(m_localAddon->ID(), enable);
// else
database.DisableAddon(m_localAddon->ID(), !enable);

if (m_localAddon->Type() == ADDON_PVRDLL && enable)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/filesystem/AddonsDirectory.cpp
Expand Up @@ -69,7 +69,7 @@ bool CAddonsDirectory::GetDirectory(const CStdString& strPath, CFileItemList &it
else if (path.GetHostName().Equals("disabled"))
{ // grab all disabled addons, including disabled repositories
reposAsFolders = false;
CAddonMgr::Get().GetAllAddons(addons, false, true);
CAddonMgr::Get().GetAllAddons(addons, false, true, false);
items.SetProperty("reponame",g_localizeStrings.Get(24039));
items.SetLabel(g_localizeStrings.Get(24039));
}
Expand Down
32 changes: 32 additions & 0 deletions xbmc/pvr/PVRDatabase.cpp
Expand Up @@ -32,6 +32,7 @@
using namespace std;
using namespace dbiplus;
using namespace PVR;
using namespace ADDON;

CPVRDatabase::CPVRDatabase(void)
{
Expand Down Expand Up @@ -167,6 +168,19 @@ bool CPVRDatabase::CreateTables()
bReturn = false;
}

// disable all PVR add-on when started the first time
ADDON::VECADDONS addons;
if ((bReturn = CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true, false)) == false)
CLog::Log(LOGERROR, "%s - failed to get add-ons from the add-on manager", __FUNCTION__);
else
{
CAddonDatabase database;
database.Open();
for (IVECADDONS it = addons.begin(); it != addons.end(); it++)
database.DisableAddon(it->get()->ID());
database.Close();
}

return bReturn;
}

Expand Down Expand Up @@ -223,6 +237,24 @@ bool CPVRDatabase::UpdateOldVersion(int iVersion)
m_pDS->exec("CREATE UNIQUE INDEX idx_channels_iClientId_iUniqueId on channels(iClientId, iUniqueId);");
m_pDS->exec("CREATE UNIQUE INDEX idx_idGroup_idChannel on map_channelgroups_channels(idGroup, idChannel);");
}
if (iVersion < 19)
{
// bit of a hack, but we need to keep the version/contents of the non-pvr databases the same to allow clean upgrades
ADDON::VECADDONS addons;
if ((bReturn = CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true, false)) == false)
CLog::Log(LOGERROR, "%s - failed to get add-ons from the add-on manager", __FUNCTION__);
else
{
CAddonDatabase database;
database.Open();
for (IVECADDONS it = addons.begin(); it != addons.end(); it++)
{
if (!database.IsSystemPVRAddonEnabled(it->get()->ID()))
database.DisableAddon(it->get()->ID());
}
database.Close();
}
}
}
}
catch (...)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/PVRDatabase.h
Expand Up @@ -57,7 +57,7 @@ namespace PVR
* @brief Get the minimal database version that is required to operate correctly.
* @return The minimal database version.
*/
virtual int GetMinVersion() const { return 18; };
virtual int GetMinVersion() const { return 19; };

/*!
* @brief Get the default sqlite database filename.
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/addons/PVRClients.cpp
Expand Up @@ -1365,7 +1365,7 @@ bool CPVRClients::UpdateAddons(void)
bool bReturn(false);
CSingleLock lock(m_critSection);

if ((bReturn = CAddonMgr::Get().GetAddons(ADDON_PVRDLL, m_addons, true)) == false)
if ((bReturn = CAddonMgr::Get().GetAddons(ADDON_PVRDLL, m_addons, true, false)) == false)
CLog::Log(LOGERROR, "%s - failed to get add-ons from the add-on manager", __FUNCTION__);

return bReturn;
Expand Down

0 comments on commit deb2a03

Please sign in to comment.