int CPVRClients::RegisterClient(AddonPtr client) { int iClientId(-1); if (!client->Enabled()) return -1; CLog::Log(LOGDEBUG, "%s - registering add-on '%s'", __FUNCTION__, client->Name().c_str()); CPVRDatabase *database = GetPVRDatabase(); if (!database) return -1; // check whether we already know this client iClientId = database->GetClientId(client->ID()); // try to register the new client in the db if (iClientId < 0 && (iClientId = database->Persist(client)) < 0) { CLog::Log(LOGERROR, "PVR - %s - can't add client '%s' to the database", __FUNCTION__, client->Name().c_str()); return -1; } PVR_CLIENT addon; // load and initialise the client libraries { CSingleLock lock(m_critSection); PVR_CLIENTMAP_ITR existingClient = m_clientMap.find(iClientId); if (existingClient != m_clientMap.end()) { // return existing client addon = existingClient->second; } else { // create a new client instance addon = boost::dynamic_pointer_cast<CPVRClient>(client); m_clientMap.insert(std::make_pair(iClientId, addon)); } } if (iClientId < 0) CLog::Log(LOGERROR, "PVR - %s - can't register add-on '%s'", __FUNCTION__, client->Name().c_str()); return iClientId; }
int CActiveAEDSP::RegisterAudioDSPAddon(AddonPtr addon, bool* newRegistration/*=NULL*/) { int iAddonId(-1); if (newRegistration) *newRegistration = false; if (!addon->Enabled()) return -1; CLog::Log(LOGDEBUG, "ActiveAE DSP - %s - registering add-on '%s'", __FUNCTION__, addon->Name().c_str()); if (!m_databaseDSP.IsOpen()) { CLog::Log(LOGERROR, "ActiveAE DSP - %s - failed to get the database", __FUNCTION__); return -1; } /* check whether we already know this dsp addon */ iAddonId = m_databaseDSP.GetAudioDSPAddonId(addon->ID()); /* try to register the new dsp addon in the db */ if (iAddonId < 0) { if ((iAddonId = m_databaseDSP.Persist(addon)) < 0) { CLog::Log(LOGERROR, "ActiveAE DSP - %s - can't add dsp addon '%s' to the database", __FUNCTION__, addon->Name().c_str()); return -1; } else if (newRegistration) *newRegistration = true; } AE_DSP_ADDON dspAddon; /* load and initialise the dsp addon libraries */ { CSingleLock lock(m_critSection); AE_DSP_ADDONMAP_CITR existingAddon = m_addonMap.find(iAddonId); if (existingAddon != m_addonMap.end()) { /* return existing addon */ dspAddon = existingAddon->second; } else { /* create a new addon instance */ dspAddon = std::dynamic_pointer_cast<CActiveAEDSPAddon> (addon); m_addonMap.insert(std::make_pair(iAddonId, dspAddon)); } } if (iAddonId < 0) CLog::Log(LOGERROR, "ActiveAE DSP - %s - can't register dsp add-on '%s'", __FUNCTION__, addon->Name().c_str()); return iAddonId; }
int CPVRDatabase::Persist(const AddonPtr client) { int iReturn(-1); /* invalid client uid or name */ if (client->Name().empty() || client->ID().empty()) { CLog::Log(LOGERROR, "PVR - %s - invalid client uid or name", __FUNCTION__); return iReturn; } CStdString strQuery = PrepareSQL("REPLACE INTO clients (sName, sUid) VALUES ('%s', '%s');", client->Name().c_str(), client->ID().c_str()); if (ExecuteQuery(strQuery)) iReturn = (int) m_pDS->lastinsertid(); return iReturn; }
int CActiveAEDSPDatabase::Persist(const AddonPtr addon) { int iReturn(-1); /* invalid addon uid or name */ if (addon->Name().empty() || addon->ID().empty()) { CLog::Log(LOGERROR, "Audio DSP - %s - invalid add-on uid or name", __FUNCTION__); return iReturn; } string strQuery = PrepareSQL("REPLACE INTO addons (sName, sUid) VALUES ('%s', '%s');", addon->Name().c_str(), addon->ID().c_str()); if (ExecuteQuery(strQuery)) iReturn = (int) m_pDS->lastinsertid(); return iReturn; }
int CPVRClients::RegisterClient(AddonPtr client) { int iClientId(-1); CAddonDatabase database; PVR_CLIENT addon; if (CAddonMgr::GetInstance().IsAddonDisabled(client->ID()) || !database.Open()) return -1; CLog::Log(LOGDEBUG, "%s - registering add-on '%s'", __FUNCTION__, client->Name().c_str()); // check whether we already know this client iClientId = database.GetAddonId(client); //database->GetClientId(client->ID()); // try to register the new client in the db if (iClientId <= 0) iClientId = database.AddAddon(client, 0); if (iClientId > 0) // load and initialise the client libraries { CSingleLock lock(m_critSection); PVR_CLIENTMAP_CITR existingClient = m_clientMap.find(iClientId); if (existingClient != m_clientMap.end()) { // return existing client addon = existingClient->second; } else { // create a new client instance addon = std::dynamic_pointer_cast<CPVRClient>(client); m_clientMap.insert(std::make_pair(iClientId, addon)); m_addonNameIds.insert(make_pair(addon->ID(), iClientId)); } } if (iClientId <= 0) CLog::Log(LOGERROR, "PVR - %s - can't register add-on '%s'", __FUNCTION__, client->Name().c_str()); return iClientId; }
bool CPluginDirectory::RunScriptWithParams(const CStdString& strPath) { CURL url(strPath); if (url.GetHostName().IsEmpty()) // called with no script - should never happen return false; AddonPtr addon; 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()); return false; } // options CStdString options = url.GetOptions(); URIUtils::RemoveSlashAtEnd(options); // This MAY kill some scripts (eg though with a URL ending with a slash), but // is needed for all others, as XBMC adds slashes to "folders" url.SetOptions(""); // do this because we can then use the url to generate the basepath // which is passed to the plugin (and represents the share) CStdString basePath(url.Get()); // setup our parameters to send the script CStdString strHandle; strHandle.Format("%i", -1); vector<CStdString> argv; argv.push_back(basePath); argv.push_back(strHandle); argv.push_back(options); // run the script #ifdef HAS_PYTHON CLog::Log(LOGDEBUG, "%s - calling plugin %s('%s','%s','%s')", __FUNCTION__, addon->Name().c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str()); if (g_pythonParser.evalFile(addon->LibPath(), argv,addon) >= 0) return true; else #endif CLog::Log(LOGERROR, "Unable to run plugin %s", addon->Name().c_str()); return false; }
int CAddonDatabase::AddAddon(const AddonPtr& addon, int idRepo) { try { if (NULL == m_pDB.get()) return -1; if (NULL == m_pDS.get()) return -1; CStdString sql = PrepareSQL("insert into addon (id, type, name, summary," "description, stars, path, icon, changelog, " "fanart, addonID, version, author, disclaimer)" " values(NULL, '%s', '%s', '%s', '%s', %i," "'%s', '%s', '%s', '%s', '%s','%s','%s','%s')", TranslateType(addon->Type(),false).c_str(), addon->Name().c_str(), addon->Summary().c_str(), addon->Description().c_str(),addon->Stars(), addon->Path().c_str(), addon->Props().icon.c_str(), addon->ChangeLog().c_str(),addon->FanArt().c_str(), addon->ID().c_str(), addon->Version().str.c_str(), addon->Author().c_str(),addon->Disclaimer().c_str()); m_pDS->exec(sql.c_str()); int idAddon = (int)m_pDS->lastinsertid(); sql = PrepareSQL("insert into addonlinkrepo (idRepo, idAddon) values (%i,%i)",idRepo,idAddon); m_pDS->exec(sql.c_str()); const InfoMap &info = addon->ExtraInfo(); for (InfoMap::const_iterator i = info.begin(); i != info.end(); ++i) { sql = PrepareSQL("insert into addonextra(id, key, value) values (%i, '%s', '%s')", idAddon, i->first.c_str(), i->second.c_str()); m_pDS->exec(sql.c_str()); } return idAddon; } catch (...) { CLog::Log(LOGERROR, "%s failed on addon '%s'", __FUNCTION__, addon->Name().c_str()); } return -1; }
int CPVRClients::AddClientToDb(const AddonPtr client) { /* add this client to the database if it's not in there yet */ CPVRDatabase *database = GetPVRDatabase(); int iClientDbId = database ? database->Persist(client) : -1; if (iClientDbId == -1) { CLog::Log(LOGERROR, "PVR - %s - can't add client '%s' to the database", __FUNCTION__, client->Name().c_str()); } return iClientDbId; }
bool CLanguageResource::FindLegacyLanguage(const std::string &locale, std::string &legacyLanguage) { if (locale.empty()) return false; std::string addonId = GetAddonId(locale); AddonPtr addon; if (!CServiceBroker::GetAddonMgr().GetAddon(addonId, addon, ADDON_RESOURCE_LANGUAGE, true)) return false; legacyLanguage = addon->Name(); return true; }
bool CPVRClients::InitialiseClient(AddonPtr client) { bool bReturn(false); if (!client->Enabled()) return bReturn; CLog::Log(LOGDEBUG, "%s - initialising add-on '%s'", __FUNCTION__, client->Name().c_str()); /* register this client in the db */ int iClientId = AddClientToDb(client); if (iClientId == -1) return bReturn; /* load and initialise the client libraries */ boost::shared_ptr<CPVRClient> addon; { CSingleLock lock(m_critSection); CLIENTMAPITR existingClient = m_clientMap.find(iClientId); if (existingClient != m_clientMap.end()) { addon = existingClient->second; } else { addon = boost::dynamic_pointer_cast<CPVRClient>(client); m_clientMap.insert(std::make_pair(iClientId, addon)); } } if (addon) bReturn = addon->Create(iClientId); if (!bReturn) CLog::Log(LOGERROR, "PVR - %s - can't initialise add-on '%s'", __FUNCTION__, client->Name().c_str()); return bReturn; }
int CPVRDatabase::Persist(const AddonPtr client) { int iReturn(-1); /* invalid client uid or name */ if (client->Name().IsEmpty() || client->ID().IsEmpty()) { CLog::Log(LOGERROR, "PVR - %s - invalid client uid or name", __FUNCTION__); return iReturn; } /* only add this client if it's not already in the database */ iReturn = GetClientId(client->ID()); if (iReturn <= 0) { CStdString strQuery = FormatSQL("INSERT INTO clients (sName, sUid) VALUES ('%s', '%s');", client->Name().c_str(), client->ID().c_str()); if (ExecuteQuery(strQuery)) iReturn = (int) m_pDS->lastinsertid(); } return iReturn; }
bool CPluginDirectory::RunScriptWithParams(const std::string& strPath) { CURL url(strPath); if (url.GetHostName().empty()) // called with no script - should never happen return false; AddonPtr addon; 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()); return false; } // options std::string options = url.GetOptions(); url.SetOptions(""); // do this because we can then use the url to generate the basepath // which is passed to the plugin (and represents the share) std::string basePath(url.Get()); // setup our parameters to send the script std::string strHandle = StringUtils::Format("%i", -1); vector<string> argv; argv.push_back(basePath); argv.push_back(strHandle); argv.push_back(options); // run the script CLog::Log(LOGDEBUG, "%s - calling plugin %s('%s','%s','%s')", __FUNCTION__, addon->Name().c_str(), argv[0].c_str(), argv[1].c_str(), argv[2].c_str()); if (CScriptInvocationManager::Get().Execute(addon->LibPath(), addon, argv) >= 0) return true; else CLog::Log(LOGERROR, "Unable to run plugin %s", addon->Name().c_str()); return false; }
std::string CGUIDialogAddonSettings::GetAddonNames(const std::string& addonIDslist) const { std::string retVal; vector<string> addons = StringUtils::Split(addonIDslist, ','); for (vector<string>::const_iterator it = addons.begin(); it != addons.end() ; ++it) { if (!retVal.empty()) retVal += ", "; AddonPtr addon; if (CAddonMgr::Get().GetAddon(*it ,addon)) retVal += addon->Name(); else retVal += *it; } return retVal; }
void CAddonDatabase::SetPropertiesFromAddon(const AddonPtr& addon, CFileItemPtr& pItem) { pItem->SetProperty("Addon.ID", addon->ID()); pItem->SetProperty("Addon.Type", TranslateType(addon->Type(),true)); pItem->SetProperty("Addon.intType", TranslateType(addon->Type())); pItem->SetProperty("Addon.Name", addon->Name()); pItem->SetProperty("Addon.Version", addon->Version().c_str()); pItem->SetProperty("Addon.Summary", addon->Summary()); pItem->SetProperty("Addon.Description", addon->Description()); pItem->SetProperty("Addon.Creator", addon->Author()); pItem->SetProperty("Addon.Disclaimer", addon->Disclaimer()); pItem->SetProperty("Addon.Rating", addon->Stars()); CStdString starrating; starrating.Format("rating%d.png", addon->Stars()); pItem->SetProperty("Addon.StarRating",starrating); pItem->SetProperty("Addon.Path", addon->Path()); pItem->SetProperty("Addon.Broken", addon->Props().broken); }
static CVariant Serialize(const AddonPtr& addon) { CVariant variant; variant["addonid"] = addon->ID(); variant["type"] = CAddonInfo::TranslateType(addon->Type(), false); variant["name"] = addon->Name(); variant["version"] = addon->Version().asString(); variant["summary"] = addon->Summary(); variant["description"] = addon->Description(); variant["path"] = addon->Path(); variant["author"] = addon->Author(); variant["thumbnail"] = addon->Icon(); variant["disclaimer"] = addon->Disclaimer(); variant["fanart"] = addon->FanArt(); variant["dependencies"] = CVariant(CVariant::VariantTypeArray); for (const auto& dep : addon->GetDependencies()) { CVariant info(CVariant::VariantTypeObject); info["addonid"] = dep.id; info["version"] = dep.requiredVersion.asString(); info["optional"] = dep.optional; variant["dependencies"].push_back(std::move(info)); } if (addon->Broken().empty()) variant["broken"] = false; else variant["broken"] = addon->Broken(); variant["extrainfo"] = CVariant(CVariant::VariantTypeArray); for (const auto& kv : addon->ExtraInfo()) { CVariant info(CVariant::VariantTypeObject); info["key"] = kv.first; info["value"] = kv.second; variant["extrainfo"].push_back(std::move(info)); } variant["rating"] = -1; return variant; }
void CAddonDatabase::SetPropertiesFromAddon(const AddonPtr& addon, CFileItemPtr& pItem) { pItem->SetProperty("Addon.ID", addon->ID()); pItem->SetProperty("Addon.Type", TranslateType(addon->Type(),true)); pItem->SetProperty("Addon.intType", TranslateType(addon->Type())); pItem->SetProperty("Addon.Name", addon->Name()); pItem->SetProperty("Addon.Version", addon->Version().c_str()); pItem->SetProperty("Addon.Summary", addon->Summary()); pItem->SetProperty("Addon.Description", addon->Description()); pItem->SetProperty("Addon.Creator", addon->Author()); pItem->SetProperty("Addon.Disclaimer", addon->Disclaimer()); pItem->SetProperty("Addon.Rating", addon->Stars()); CStdString starrating; starrating.Format("rating%d.png", addon->Stars()); pItem->SetProperty("Addon.StarRating",starrating); pItem->SetProperty("Addon.Path", addon->Path()); pItem->SetProperty("Addon.Broken", addon->Props().broken); std::map<CStdString,CStdString>::iterator it = addon->Props().extrainfo.find("language"); if (it != addon->Props().extrainfo.end()) pItem->SetProperty("Addon.Language", it->second); }
bool CAddonInstaller::DoInstall(const AddonPtr &addon, const CStdString &hash, bool update, const CStdString &referer, bool background) { // check whether we already have the addon installing CSingleLock lock(m_critSection); if (m_downloadJobs.find(addon->ID()) != m_downloadJobs.end()) return false; // check whether all the dependencies are available or not // TODO: we currently assume that dependencies will install correctly (and each of their dependencies and so on). // it may be better to install the dependencies first to minimise the chance of an addon becoming orphaned due to // missing deps. if (!CheckDependencies(addon)) { CGUIDialogKaiToast::QueueNotification(addon->Icon(), addon->Name(), g_localizeStrings.Get(24044), TOAST_DISPLAY_TIME, false); return false; } if (background) { unsigned int jobID = CJobManager::GetInstance().AddJob(new CAddonInstallJob(addon, hash, update, referer), this); m_downloadJobs.insert(make_pair(addon->ID(), CDownloadJob(jobID))); } else { m_downloadJobs.insert(make_pair(addon->ID(), CDownloadJob(0))); lock.Leave(); CAddonInstallJob job(addon, hash, update, referer); if (!job.DoWork()) { // TODO: dump something to debug log? return false; } lock.Enter(); JobMap::iterator i = m_downloadJobs.find(addon->ID()); m_downloadJobs.erase(i); } return true; }
void CAddonInstallJob::ReportInstallError(const CStdString& addonID, const CStdString& fileName) { AddonPtr addon; CAddonDatabase database; database.Open(); database.GetAddon(addonID, addon); if (addon) { AddonPtr addon2; CAddonMgr::Get().GetAddon(addonID, addon2); CGUIDialogKaiToast::QueueNotification(addon->Icon(), addon->Name(), g_localizeStrings.Get(addon2 ? 113 : 114), TOAST_DISPLAY_TIME, false); } else { CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, fileName, g_localizeStrings.Get(114), TOAST_DISPLAY_TIME, false); } }
void CGUIDialogAddonInfo::OnUpdate() { if (!m_localAddon) return; CAddonDatabase database; if (!database.Open()) return; std::vector<std::pair<AddonVersion, std::string>> versions; if (!database.GetAvailableVersions(m_localAddon->ID(), versions)) return; CFileItemList items; if (XFILE::CDirectory::GetDirectory("special://home/addons/packages/", items, ".zip", DIR_FLAG_NO_FILE_DIRS)) { for (int i = 0; i < items.Size(); ++i) { std::string packageId; std::string versionString; if (AddonVersion::SplitFileName(packageId, versionString, items[i]->GetLabel())) { if (packageId == m_localAddon->ID()) { std::string hash; std::string path(items[i]->GetPath()); if (database.GetPackageHash(m_localAddon->ID(), items[i]->GetPath(), hash)) { std::string md5 = CUtil::GetFileMD5(path); if (md5 == hash) versions.push_back(std::make_pair(AddonVersion(versionString), LOCAL_CACHE)); } } } } } if (versions.empty()) { CGUIDialogOK::ShowAndGetInput(CVariant{21341}, CVariant{21342}); return; } auto* dialog = static_cast<CGUIDialogSelect*>(g_windowManager.GetWindow(WINDOW_DIALOG_SELECT)); dialog->Reset(); dialog->SetHeading(CVariant{21338}); dialog->SetUseDetails(true); std::stable_sort(versions.begin(), versions.end(), CompareVersion); for (const auto& versionInfo : versions) { CFileItem item(StringUtils::Format(g_localizeStrings.Get(21339).c_str(), versionInfo.first.asString().c_str())); if (versionInfo.first == m_localAddon->Version()) item.Select(true); AddonPtr repo; if (versionInfo.second == LOCAL_CACHE) { item.SetProperty("Addon.Summary", g_localizeStrings.Get(24095)); item.SetIconImage("DefaultAddonRepository.png"); dialog->Add(item); } else if (CAddonMgr::GetInstance().GetAddon(versionInfo.second, repo, ADDON_REPOSITORY)) { item.SetProperty("Addon.Summary", repo->Name()); item.SetIconImage(repo->Icon()); dialog->Add(item); } } dialog->Open(); if (dialog->IsConfirmed()) { Close(); auto selected = versions.at(dialog->GetSelectedLabel()); //turn auto updating off if downgrading if (selected.first < m_localAddon->Version()) CAddonMgr::GetInstance().AddToUpdateBlacklist(m_localAddon->ID()); if (selected.second == LOCAL_CACHE) CAddonInstaller::GetInstance().InstallFromZip(StringUtils::Format("special://home/addons/packages/%s-%s.zip", m_localAddon->ID().c_str(), selected.first.asString().c_str())); else CAddonInstaller::GetInstance().Install(m_addon->ID(), selected.first, selected.second); } }
bool CPVRClients::UpdateAndInitialiseClients(bool bInitialiseAllClients /* = false */) { bool bReturn(true); ADDON::VECADDONS map; ADDON::VECADDONS disableAddons; { CSingleLock lock(m_critSection); map = m_addons; } if (map.size() == 0) return false; for (unsigned iClientPtr = 0; iClientPtr < map.size(); iClientPtr++) { const AddonPtr clientAddon = map.at(iClientPtr); bool bEnabled = clientAddon->Enabled() && !m_addonDb.IsAddonDisabled(clientAddon->ID()); if (!bEnabled && IsKnownClient(clientAddon)) { CSingleLock lock(m_critSection); /* stop the client and remove it from the db */ StopClient(clientAddon, false); ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), clientAddon); if (addonPtr != m_addons.end()) m_addons.erase(addonPtr); } else if (bEnabled && (bInitialiseAllClients || !IsKnownClient(clientAddon) || !IsConnectedClient(clientAddon))) { bool bDisabled(false); // register the add-on in the pvr db, and create the CPVRClient instance int iClientId = RegisterClient(clientAddon); if (iClientId < 0) { // failed to register or create the add-on, disable it CLog::Log(LOGWARNING, "%s - failed to register add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str()); disableAddons.push_back(clientAddon); bDisabled = true; } else { PVR_CLIENT addon; if (!GetClient(iClientId, addon)) { CLog::Log(LOGWARNING, "%s - failed to find add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str()); disableAddons.push_back(clientAddon); bDisabled = true; } // re-check the enabled status. newly installed clients get disabled when they're added to the db else if (addon->Enabled() && !addon->Create(iClientId)) { CLog::Log(LOGWARNING, "%s - failed to create add-on %s", __FUNCTION__, clientAddon->Name().c_str()); if (!addon.get() || !addon->DllLoaded()) { // failed to load the dll of this add-on, disable it CLog::Log(LOGWARNING, "%s - failed to load the dll for add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str()); disableAddons.push_back(clientAddon); bDisabled = true; } } } if (bDisabled && (g_PVRManager.GetState() == ManagerStateStarted || g_PVRManager.GetState() == ManagerStateStarting)) CGUIDialogOK::ShowAndGetInput(24070, 24071, 16029, 0); } } // disable add-ons that failed to initialise if (disableAddons.size() > 0) { CSingleLock lock(m_critSection); for (ADDON::VECADDONS::iterator it = disableAddons.begin(); it != disableAddons.end(); it++) { // disable in the add-on db m_addonDb.DisableAddon((*it)->ID(), true); // remove from the pvr add-on list ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), *it); if (addonPtr != m_addons.end()) m_addons.erase(addonPtr); } } return bReturn; }
bool CAddonsDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString path1(strPath); URIUtils::RemoveSlashAtEnd(path1); CURL path(path1); items.ClearProperties(); items.SetContent("addons"); VECADDONS addons; // get info from repository bool reposAsFolders = true; if (path.GetHostName().Equals("enabled")) { CAddonMgr::Get().GetAllAddons(addons, true); items.SetProperty("reponame",g_localizeStrings.Get(24062)); items.SetLabel(g_localizeStrings.Get(24062)); } else if (path.GetHostName().Equals("disabled")) { // grab all disabled addons, including disabled repositories reposAsFolders = false; CAddonMgr::Get().GetAllAddons(addons, false, true); items.SetProperty("reponame",g_localizeStrings.Get(24039)); items.SetLabel(g_localizeStrings.Get(24039)); } else if (path.GetHostName().Equals("outdated")) { reposAsFolders = false; CAddonMgr::Get().GetAllOutdatedAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24043)); items.SetLabel(g_localizeStrings.Get(24043)); } else if (path.GetHostName().Equals("repos")) { CAddonMgr::Get().GetAddons(ADDON_REPOSITORY,addons,true); items.SetLabel(g_localizeStrings.Get(24033)); // Get Add-ons } else if (path.GetHostName().Equals("sources")) { return GetScriptsAndPlugins(path.GetFileName(), items); } else if (path.GetHostName().Equals("all")) { CAddonDatabase database; database.Open(); database.GetAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24032)); items.SetLabel(g_localizeStrings.Get(24032)); } else if (path.GetHostName().Equals("search")) { CStdString search(path.GetFileName()); if (search.IsEmpty() && !GetKeyboardInput(16017, search)) return false; items.SetProperty("reponame",g_localizeStrings.Get(283)); items.SetLabel(g_localizeStrings.Get(283)); CAddonDatabase database; database.Open(); database.Search(search, addons); GenerateListing(path, addons, items, true); path.SetFileName(search); items.SetPath(path.Get()); return true; } else { reposAsFolders = false; AddonPtr addon; CAddonMgr::Get().GetAddon(path.GetHostName(),addon); if (!addon) return false; // ensure our repos are up to date CAddonInstaller::Get().UpdateRepos(false, true); CAddonDatabase database; database.Open(); database.GetRepository(addon->ID(),addons); items.SetProperty("reponame",addon->Name()); items.SetLabel(addon->Name()); } if (path.GetFileName().IsEmpty()) { if (!path.GetHostName().Equals("repos")) { for (int i=ADDON_UNKNOWN+1;i<ADDON_VIZ_LIBRARY;++i) { for (unsigned int j=0;j<addons.size();++j) { if (addons[j]->IsType((TYPE)i)) { CFileItemPtr item(new CFileItem(TranslateType((TYPE)i,true))); item->SetPath(URIUtils::AddFileToFolder(strPath,TranslateType((TYPE)i,false))); item->m_bIsFolder = true; CStdString thumb = GetIcon((TYPE)i); if (!thumb.IsEmpty() && g_TextureManager.HasTexture(thumb)) item->SetArt("thumb", thumb); items.Add(item); break; } } } items.SetPath(strPath); return true; } } else { TYPE type = TranslateType(path.GetFileName()); items.SetProperty("addoncategory",TranslateType(type, true)); items.SetLabel(TranslateType(type, true)); items.SetPath(strPath); // FIXME: Categorisation of addons needs adding here for (unsigned int j=0;j<addons.size();++j) { if (!addons[j]->IsType(type)) addons.erase(addons.begin()+j--); } } items.SetPath(strPath); GenerateListing(path, addons, items, reposAsFolders); // check for available updates if (path.GetHostName().Equals("enabled")) { CAddonDatabase database; database.Open(); for (int i=0;i<items.Size();++i) { AddonPtr addon2; database.GetAddon(items[i]->GetProperty("Addon.ID").asString(),addon2); if (addon2 && addon2->Version() > AddonVersion(items[i]->GetProperty("Addon.Version").asString()) && !database.IsAddonBlacklisted(addon2->ID(),addon2->Version().c_str())) { items[i]->SetProperty("Addon.Status",g_localizeStrings.Get(24068)); items[i]->SetProperty("Addon.UpdateAvail", true); } } } if (path.GetHostName().Equals("repos") && items.Size() > 1) { CFileItemPtr item(new CFileItem("addons://all/",true)); item->SetLabel(g_localizeStrings.Get(24032)); items.Add(item); } return true; }
bool CActiveAEDSP::UpdateAndInitialiseAudioDSPAddons(bool bInitialiseAllAudioDSPAddons /* = false */) { bool bReturn(true); VECADDONS map; VECADDONS disableAddons; { CSingleLock lock(m_critUpdateSection); map = m_addons; } if (map.empty()) return false; for (unsigned iAddonPtr = 0; iAddonPtr < map.size(); ++iAddonPtr) { const AddonPtr dspAddon = map.at(iAddonPtr); bool bEnabled = !CAddonMgr::GetInstance().IsAddonDisabled(dspAddon->ID()); if (!bEnabled && IsKnownAudioDSPAddon(dspAddon)) { CSingleLock lock(m_critUpdateSection); /* stop the dsp addon and remove it from the db */ StopAudioDSPAddon(dspAddon, false); VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), dspAddon); if (addonPtr != m_addons.end()) m_addons.erase(addonPtr); } else if (bEnabled && (bInitialiseAllAudioDSPAddons || !IsKnownAudioDSPAddon(dspAddon) || !IsReadyAudioDSPAddon(dspAddon))) { bool bDisabled(false); /* register the add-on in the audio dsp db, and create the CActiveAEDSPAddon instance */ int iAddonId = RegisterAudioDSPAddon(dspAddon); if (iAddonId < 0) { /* failed to register or create the add-on, disable it */ CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to register add-on %s, disabling it", __FUNCTION__, dspAddon->Name().c_str()); disableAddons.push_back(dspAddon); bDisabled = true; } else { ADDON_STATUS status(ADDON_STATUS_UNKNOWN); AE_DSP_ADDON addon; { CSingleLock lock(m_critUpdateSection); if (!GetAudioDSPAddon(iAddonId, addon)) { CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to find add-on %s, disabling it", __FUNCTION__, dspAddon->Name().c_str()); disableAddons.push_back(dspAddon); bDisabled = true; } } /* re-check the enabled status. newly installed dsps get disabled when they're added to the db */ if (!bDisabled && !CAddonMgr::GetInstance().IsAddonDisabled(addon->ID()) && (status = addon->Create(iAddonId)) != ADDON_STATUS_OK) { CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to create add-on %s, status = %d", __FUNCTION__, dspAddon->Name().c_str(), status); if (!addon.get() || !addon->DllLoaded() || status == ADDON_STATUS_PERMANENT_FAILURE) { /* failed to load the dll of this add-on, disable it */ CLog::Log(LOGWARNING, "ActiveAE DSP - %s - failed to load the dll for add-on %s, disabling it", __FUNCTION__, dspAddon->Name().c_str()); disableAddons.push_back(dspAddon); bDisabled = true; } } } if (bDisabled && IsActivated()) CGUIDialogOK::ShowAndGetInput(24070, 24071, 16029, 0); } } /* disable add-ons that failed to initialise */ if (!disableAddons.empty()) { CSingleLock lock(m_critUpdateSection); for (VECADDONS::iterator itr = disableAddons.begin(); itr != disableAddons.end(); ++itr) { /* disable in the add-on db */ CAddonMgr::GetInstance().DisableAddon((*itr)->ID()); /* remove from the audio dsp add-on list */ VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), *itr); if (addonPtr != m_addons.end()) m_addons.erase(addonPtr); } } return bReturn; }
bool CPVRClients::UpdateAndInitialiseClients(bool bInitialiseAllClients /* = false */) { bool bReturn(true); ADDON::VECADDONS map; ADDON::VECADDONS disableAddons; { CSingleLock lock(m_critSection); map = m_addons; } if (map.size() == 0) return false; for (unsigned iClientPtr = 0; iClientPtr < map.size(); iClientPtr++) { const AddonPtr clientAddon = map.at(iClientPtr); bool bEnabled = clientAddon->Enabled() && !m_addonDb.IsAddonDisabled(clientAddon->ID()); if (!bEnabled && IsKnownClient(clientAddon)) { CSingleLock lock(m_critSection); /* stop the client and remove it from the db */ StopClient(clientAddon, false); ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), clientAddon); if (addonPtr != m_addons.end()) m_addons.erase(addonPtr); } else if (bEnabled && (bInitialiseAllClients || !IsKnownClient(clientAddon) || !IsConnectedClient(clientAddon))) { bool bDisabled(false); // register the add-on in the pvr db, and create the CPVRClient instance int iClientId = RegisterClient(clientAddon); if (iClientId < 0) { // failed to register or create the add-on, disable it CLog::Log(LOGWARNING, "%s - failed to register add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str()); disableAddons.push_back(clientAddon); bDisabled = true; } else { ADDON_STATUS status(ADDON_STATUS_UNKNOWN); PVR_CLIENT addon; { CSingleLock lock(m_critSection); if (!GetClient(iClientId, addon)) { CLog::Log(LOGWARNING, "%s - failed to find add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str()); disableAddons.push_back(clientAddon); bDisabled = true; } } // throttle connection attempts, no more than 1 attempt per 5 seconds if (!bDisabled && addon->Enabled()) { time_t now; CDateTime::GetCurrentDateTime().GetAsTime(now); std::map<int, time_t>::iterator it = m_connectionAttempts.find(iClientId); if (it != m_connectionAttempts.end() && now < it->second) continue; m_connectionAttempts[iClientId] = now + 5; } // re-check the enabled status. newly installed clients get disabled when they're added to the db if (!bDisabled && addon->Enabled() && (status = addon->Create(iClientId)) != ADDON_STATUS_OK) { CLog::Log(LOGWARNING, "%s - failed to create add-on %s, status = %d", __FUNCTION__, clientAddon->Name().c_str(), status); if (!addon.get() || !addon->DllLoaded() || status == ADDON_STATUS_PERMANENT_FAILURE) { // failed to load the dll of this add-on, disable it CLog::Log(LOGWARNING, "%s - failed to load the dll for add-on %s, disabling it", __FUNCTION__, clientAddon->Name().c_str()); disableAddons.push_back(clientAddon); bDisabled = true; } } } if (bDisabled && (g_PVRManager.GetState() == ManagerStateStarted || g_PVRManager.GetState() == ManagerStateStarting)) CGUIDialogOK::ShowAndGetInput(24070, 24071, 16029, 0); } } // disable add-ons that failed to initialise if (disableAddons.size() > 0) { CSingleLock lock(m_critSection); for (ADDON::VECADDONS::iterator it = disableAddons.begin(); it != disableAddons.end(); it++) { // disable in the add-on db m_addonDb.DisableAddon((*it)->ID(), true); // remove from the pvr add-on list ADDON::VECADDONS::iterator addonPtr = std::find(m_addons.begin(), m_addons.end(), *it); if (addonPtr != m_addons.end()) m_addons.erase(addonPtr); } } return bReturn; }
bool CPVRClients::LoadClients(void) { if (m_bAllClientsLoaded) return !m_clientMap.empty(); CAddonMgr::Get().RegisterAddonMgrCallback(ADDON_PVRDLL, this); /* get all PVR addons */ VECADDONS addons; if (!CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true)) return false; /* load and initialise the clients */ CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) { CLog::Log(LOGERROR, "PVR - %s - cannot open the database", __FUNCTION__); return false; } m_bAllClientsLoaded = true; for (unsigned iClientPtr = 0; iClientPtr < addons.size(); iClientPtr++) { const AddonPtr clientAddon = addons.at(iClientPtr); if (!clientAddon->Enabled()) continue; int iClientId = AddClientToDb(clientAddon->ID(), clientAddon->Name()); if (iClientId == -1) continue; // don't set "m_bAllClientsLoaded = false;" here because this will enter a neverending loop /* check if this client isn't active already */ if (ClientLoaded(clientAddon->ID())) continue; /* load and initialise the client libraries */ boost::shared_ptr<CPVRClient> addon = boost::dynamic_pointer_cast<CPVRClient>(clientAddon); if (addon && addon->Create(iClientId, this)) { /* get the client's properties */ PVR_SERVERPROPS props; if (addon->GetProperties(&props) == PVR_ERROR_NO_ERROR) { m_clientMap.insert(std::make_pair(iClientId, addon)); m_clientsProps.insert(std::make_pair(iClientId, props)); } else { CLog::Log(LOGERROR, "PVR - %s - can't get client properties from addon '%s'", __FUNCTION__, clientAddon->Name().c_str()); m_bAllClientsLoaded = false; } } else { CLog::Log(LOGERROR, "PVR - %s - can't initialise client '%s'", __FUNCTION__, clientAddon->Name().c_str()); m_bAllClientsLoaded = false; } } database->Close(); return !m_clientMap.empty(); }
bool CAddonsDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CStdString path1(strPath); CUtil::RemoveSlashAtEnd(path1); CURL path(path1); items.ClearProperties(); items.SetContent("addons"); VECADDONS addons; // get info from repository bool reposAsFolders = true; if (path.GetHostName().Equals("enabled")) { CAddonMgr::Get().GetAllAddons(addons, true); items.SetProperty("reponame",g_localizeStrings.Get(24062)); } else if (path.GetHostName().Equals("disabled")) { // grab all disabled addons, including disabled repositories reposAsFolders = false; CAddonMgr::Get().GetAllAddons(addons, false, true); items.SetProperty("reponame",g_localizeStrings.Get(24039)); } else if (path.GetHostName().Equals("outdated")) { reposAsFolders = false; CAddonMgr::Get().GetAllOutdatedAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24043)); } else if (path.GetHostName().Equals("repos")) { CAddonMgr::Get().GetAddons(ADDON_REPOSITORY,addons,true); } else if (path.GetHostName().Equals("sources")) { return GetScriptsAndPlugins(path.GetFileName(), items); } else if (path.GetHostName().Equals("all")) { CAddonDatabase database; database.Open(); database.GetAddons(addons); items.SetProperty("reponame",g_localizeStrings.Get(24032)); } else { AddonPtr addon; CAddonMgr::Get().GetAddon(path.GetHostName(),addon); if (!addon) return false; CAddonDatabase database; database.Open(); if (!database.GetRepository(addon->ID(),addons)) { RepositoryPtr repo = boost::dynamic_pointer_cast<CRepository>(addon); addons = CRepositoryUpdateJob::GrabAddons(repo,false); } items.SetProperty("reponame",addon->Name()); } if (path.GetFileName().IsEmpty()) { if (!path.GetHostName().Equals("repos")) { for (int i=ADDON_UNKNOWN+1;i<ADDON_VIZ_LIBRARY;++i) { for (unsigned int j=0;j<addons.size();++j) { if (addons[j]->IsType((TYPE)i)) { CFileItemPtr item(new CFileItem(TranslateType((TYPE)i,true))); item->m_strPath = CUtil::AddFileToFolder(strPath,TranslateType((TYPE)i,false)); item->m_bIsFolder = true; CStdString thumb = GetIcon((TYPE)i); if (!thumb.IsEmpty() && g_TextureManager.HasTexture(thumb)) item->SetThumbnailImage(thumb); items.Add(item); break; } } } items.m_strPath = strPath; return true; } } else { TYPE type = TranslateType(path.GetFileName()); items.SetProperty("addoncategory",TranslateType(type, true)); items.m_strPath = strPath; // FIXME: Categorisation of addons needs adding here for (unsigned int j=0;j<addons.size();++j) { if (!addons[j]->IsType(type)) addons.erase(addons.begin()+j--); } } items.m_strPath = strPath; GenerateListing(path, addons, items, reposAsFolders); // check for available updates if (path.GetHostName().Equals("enabled")) { CAddonDatabase database; database.Open(); for (int i=0;i<items.Size();++i) { AddonPtr addon2; database.GetAddon(items[i]->GetProperty("Addon.ID"),addon2); if (addon2 && addon2->Version() > AddonVersion(items[i]->GetProperty("Addon.Version"))) { items[i]->SetProperty("Addon.Status",g_localizeStrings.Get(24068)); items[i]->SetProperty("Addon.UpdateAvail","true"); } } } if (path.GetHostName().Equals("repos") && items.Size() > 1) { CFileItemPtr item(new CFileItem("addons://all/",true)); item->SetLabel(g_localizeStrings.Get(24032)); items.Add(item); } return true; }