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

Commit

Permalink
alternate method of allowing install of plugins that are currently no…
Browse files Browse the repository at this point in the history
…t found
  • Loading branch information
Jonathan Marshall committed Jan 18, 2012
1 parent f7fc9eb commit a317756
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
21 changes: 21 additions & 0 deletions xbmc/addons/AddonInstaller.cpp
Expand Up @@ -156,6 +156,27 @@ bool CAddonInstaller::Cancel(const CStdString &addonID)
return false; return false;
} }


bool CAddonInstaller::PromptForInstall(const CStdString &addonID, AddonPtr &addon)
{
// we assume that addons that are enabled don't get to this routine (i.e. that GetAddon() has been called)
if (CAddonMgr::Get().GetAddon(addonID, addon, ADDON_UNKNOWN, false))
return false; // addon is installed but disabled, and the user has specifically activated something that needs
// the addon - should we enable it?

// check we have it available
CAddonDatabase database;
database.Open();
if (database.GetAddon(addonID, addon))
{ // yes - ask user if they want it installed
if (!CGUIDialogYesNo::ShowAndGetInput(g_localizeStrings.Get(24076), g_localizeStrings.Get(24100),
addon->Name().c_str(), g_localizeStrings.Get(24101)))
return false;
if (Install(addonID, true, "", false))
return CAddonMgr::Get().GetAddon(addonID, addon);
}
return false;
}

bool CAddonInstaller::Install(const CStdString &addonID, bool force, const CStdString &referer, bool background) bool CAddonInstaller::Install(const CStdString &addonID, bool force, const CStdString &referer, bool background)
{ {
AddonPtr addon; AddonPtr addon;
Expand Down
8 changes: 8 additions & 0 deletions xbmc/addons/AddonInstaller.h
Expand Up @@ -35,6 +35,14 @@ class CAddonInstaller : public IJobCallback
bool GetProgress(const CStdString &addonID, unsigned int &percent) const; bool GetProgress(const CStdString &addonID, unsigned int &percent) const;
bool Cancel(const CStdString &addonID); bool Cancel(const CStdString &addonID);


/*! \brief Prompt the user as to whether they wish to install an addon.
\param addonID the addon ID of the item to install.
\param addon [out] the installed addon for later use.
\return true on successful install, false otherwise.
\sa Install
*/
bool PromptForInstall(const CStdString &addonID, ADDON::AddonPtr &addon);

/*! \brief Install an addon if it is available in a repository /*! \brief Install an addon if it is available in a repository
\param addonID the addon ID of the item to install \param addonID the addon ID of the item to install
\param force whether to force the install even if the addon is already installed (eg for updating). Defaults to false. \param force whether to force the install even if the addon is already installed (eg for updating). Defaults to false.
Expand Down
23 changes: 1 addition & 22 deletions xbmc/addons/AddonManager.cpp
Expand Up @@ -20,7 +20,6 @@
*/ */
#include "AddonManager.h" #include "AddonManager.h"
#include "Addon.h" #include "Addon.h"
#include "AddonInstaller.h"
#include "DllLibCPluff.h" #include "DllLibCPluff.h"
#include "utils/StringUtils.h" #include "utils/StringUtils.h"
#include "utils/JobManager.h" #include "utils/JobManager.h"
Expand All @@ -32,7 +31,6 @@
#include "settings/AdvancedSettings.h" #include "settings/AdvancedSettings.h"
#include "utils/log.h" #include "utils/log.h"
#include "tinyXML/tinyxml.h" #include "tinyXML/tinyxml.h"
#include "dialogs/GUIDialogYesNo.h"




#ifdef HAS_VISUALISATION #ifdef HAS_VISUALISATION
Expand Down Expand Up @@ -392,7 +390,7 @@ bool CAddonMgr::GetAddons(const TYPE &type, VECADDONS &addons, bool enabled /* =
return addons.size() > 0; return addons.size() > 0;
} }


bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabledOnly /*= true*/, bool install /*= false*/) bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &type/*=ADDON_UNKNOWN*/, bool enabledOnly /*= true*/)
{ {
CSingleLock lock(m_critSection); CSingleLock lock(m_critSection);


Expand All @@ -406,25 +404,6 @@ bool CAddonMgr::GetAddon(const CStdString &str, AddonPtr &addon, const TYPE &typ
return false; return false;
return NULL != addon.get(); return NULL != addon.get();
} }
else
{
if (install)
{
if (!CGUIDialogYesNo::ShowAndGetInput(g_localizeStrings.Get(24076), g_localizeStrings.Get(24100),
str.c_str(), g_localizeStrings.Get(24101)))
return false;

if (CAddonInstaller::Get().Install(str.c_str(), true, "", false))
{
cp_plugin_info_t *cpaddon = m_cpluff->get_plugin_info(m_cp_context, str.c_str(), &status);
addon = GetAddonFromDescriptor(cpaddon);
m_cpluff->release_info(m_cp_context, cpaddon);
if (status == CP_OK && cpaddon)
return NULL != addon.get();
}
}
}

if (cpaddon) if (cpaddon)
m_cpluff->release_info(m_cp_context, cpaddon); m_cpluff->release_info(m_cp_context, cpaddon);


Expand Down
3 changes: 1 addition & 2 deletions xbmc/addons/AddonManager.h
Expand Up @@ -86,10 +86,9 @@ namespace ADDON
\param addon [out] the retrieved addon pointer - only use if the function returns true. \param addon [out] the retrieved addon pointer - only use if the function returns true.
\param type type of addon to retrieve - defaults to any type. \param type type of addon to retrieve - defaults to any type.
\param enabledOnly whether we only want enabled addons - set to false to allow both enabled and disabled addons - defaults to true. \param enabledOnly whether we only want enabled addons - set to false to allow both enabled and disabled addons - defaults to true.
\param install whether to install the requested addon in case it's not yet installed - defaults to false.
\return true if an addon matching the id of the given type is available and is enabled (if enabledOnly is true). \return true if an addon matching the id of the given type is available and is enabled (if enabledOnly is true).
*/ */
bool GetAddon(const CStdString &id, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true, bool install = false); bool GetAddon(const CStdString &id, AddonPtr &addon, const TYPE &type = ADDON_UNKNOWN, bool enabledOnly = true);
bool HasAddons(const TYPE &type, bool enabled = true); bool HasAddons(const TYPE &type, bool enabled = true);
bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true); bool GetAddons(const TYPE &type, VECADDONS &addons, bool enabled = true);
bool GetAllAddons(VECADDONS &addons, bool enabled = true, bool allowRepos = false); bool GetAllAddons(VECADDONS &addons, bool enabled = true, bool allowRepos = false);
Expand Down
5 changes: 3 additions & 2 deletions xbmc/filesystem/PluginDirectory.cpp
Expand Up @@ -25,6 +25,7 @@
#include "PluginDirectory.h" #include "PluginDirectory.h"
#include "utils/URIUtils.h" #include "utils/URIUtils.h"
#include "addons/AddonManager.h" #include "addons/AddonManager.h"
#include "addons/AddonInstaller.h"
#include "addons/IAddon.h" #include "addons/IAddon.h"
#ifdef HAS_PYTHON #ifdef HAS_PYTHON
#include "interfaces/python/XBPython.h" #include "interfaces/python/XBPython.h"
Expand Down Expand Up @@ -77,7 +78,7 @@ bool CPluginDirectory::StartScript(const CStdString& strPath, bool retrievingDir
{ {
CURL url(strPath); CURL url(strPath);


if (!CAddonMgr::Get().GetAddon(url.GetHostName(), m_addon, ADDON_PLUGIN, true, true)) if (!CAddonMgr::Get().GetAddon(url.GetHostName(), m_addon, ADDON_PLUGIN) && !CAddonInstaller::Get().PromptForInstall(url.GetHostName(), m_addon))
{ {
CLog::Log(LOGERROR, "Unable to find plugin %s", url.GetHostName().c_str()); CLog::Log(LOGERROR, "Unable to find plugin %s", url.GetHostName().c_str());
return false; return false;
Expand Down Expand Up @@ -408,7 +409,7 @@ bool CPluginDirectory::RunScriptWithParams(const CStdString& strPath)
return false; return false;


AddonPtr addon; AddonPtr addon;
if (!CAddonMgr::Get().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN, true , true)) if (!CAddonMgr::Get().GetAddon(url.GetHostName(), addon, ADDON_PLUGIN) && !CAddonInstaller::Get().PromptForInstall(url.GetHostName(), addon))
{ {
CLog::Log(LOGERROR, "Unable to find plugin %s", url.GetHostName().c_str()); CLog::Log(LOGERROR, "Unable to find plugin %s", url.GetHostName().c_str());
return false; return false;
Expand Down

0 comments on commit a317756

Please sign in to comment.