From 3a96c2db3b4f5cf3746a0bdb5f5250eb71ade0c9 Mon Sep 17 00:00:00 2001 From: Dimitar Tsenev Date: Wed, 20 Nov 2024 13:57:51 +0200 Subject: [PATCH] [Fixed] Some issues and optimized code --- lib/dvb/db.cpp | 76 ++++++++++++++++++++++++-------------- lib/dvb/db.h | 2 +- lib/service/servicedvb.cpp | 4 -- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 6ae262e67d9..bc761cb6a48 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -220,15 +220,6 @@ RESULT eDVBService::getName(const eServiceReference &ref, std::string &name) else name = "(...)"; - std::string res_name = ""; - std::string res_provider = ""; - eServiceReference::parseNameAndProviderFromName(name, res_name, res_provider); - name = res_name; - - if (!res_provider.empty() && m_provider_name.empty()) { - m_provider_name = res_provider; - } - return 0; } @@ -1390,7 +1381,12 @@ void eDVBDB::loadBouquet(const char *path) else if (read_descr && !strncmp(line, "#DESCRIPTION", 12)) { int offs = line[12] == ':' ? 14 : 13; - e->name = line+offs; + std::string name_temp = line+offs; + std::string res_name = ""; + std::string res_provider = ""; + eServiceReference::parseNameAndProviderFromName(name_temp, res_name, res_provider); + e->name = res_name; + e->prov = res_provider; read_descr=false; } else if (!strncmp(line, "#NAME ", 6)) @@ -2680,11 +2676,11 @@ RESULT eDVBDB::appendServicesToBouquet(const std::string &filename, ePyObject se return 0; } -RESULT eDVBDB::removeBouquet(const std::string &filename) +RESULT eDVBDB::removeBouquet(const std::string &filename_regex) { std::string ext = ".tv"; int type = 1; - if (filename.find(".radio") != std::string::npos) { + if (filename_regex.find(".radio") != std::string::npos) { ext = ".radio"; type = 2; } @@ -2692,24 +2688,50 @@ RESULT eDVBDB::removeBouquet(const std::string &filename) ePtr res; eDVBResourceManager::getInstance(res); res->getChannelList(db); - std::string bouquetquery = "FROM BOUQUET \"" + filename + "\" ORDER BY bouquet"; - eServiceReference bouquetref(eServiceReference::idDVB, eServiceReference::flagDirectory, bouquetquery); - bouquetref.setData(0, type); - eBouquet *bouquet = NULL; - eServiceReference rootref(eServiceReference::idDVB, eServiceReference::flagDirectory, "FROM BOUQUET \"bouquets" + ext + "\" ORDER BY bouquet"); - if (!db->getBouquet(bouquetref, bouquet) && bouquet) - { - if (!db->getBouquet(rootref, bouquet) && bouquet) - { - bouquet->m_services.remove(bouquetref); - bouquet->flushChanges(); - deleteBouquet(filename); - } - } - else + std::string p = eEnv::resolve("${sysconfdir}/enigma2/"); + DIR *dir = opendir(p.c_str()); + if (!dir) { + eDebug("[eDVBDB] Cannot open directory where the userbouquets should be expected.."); return -1; } + dirent *entry; + while((entry = readdir(dir)) != NULL) + if (entry->d_type == DT_REG) + { + std::string path = entry->d_name; + if (std::regex_search(path, std::regex(filename_regex))) + { + std::string bouquetquery = "FROM BOUQUET \"" + path + "\" ORDER BY bouquet"; + eServiceReference bouquetref(eServiceReference::idDVB, eServiceReference::flagDirectory, bouquetquery); + bouquetref.setData(0, type); + eBouquet *bouquet = NULL; + eServiceReference rootref(eServiceReference::idDVB, eServiceReference::flagDirectory, "FROM BOUQUET \"bouquets" + ext + "\" ORDER BY bouquet"); + if (!db->getBouquet(bouquetref, bouquet) && bouquet) + { + if (!db->getBouquet(rootref, bouquet) && bouquet) + { + int status = std::remove((p+path).c_str()); + if (status != 0) { + eDebug("[eDVBDB] ERROR DELETING FILE %s", path.c_str()); + } + m_bouquets.erase(path); + bouquet->m_services.remove(bouquetref); + bouquet->flushChanges(); + } + else + { + return -1; + } + } + else + { + return -1; + } + } + } + closedir(dir); + return 0; } diff --git a/lib/dvb/db.h b/lib/dvb/db.h index 1f0ccfc55e3..5cb2819288d 100644 --- a/lib/dvb/db.h +++ b/lib/dvb/db.h @@ -150,7 +150,7 @@ class eDVBDB: public iDVBChannelList RESULT addOrUpdateBouquet(const std::string &name, const std::string &filename, SWIG_PYOBJECT(ePyObject) services, bool isAddedFirst = false); RESULT addOrUpdateBouquet(const std::string &name, SWIG_PYOBJECT(ePyObject) services, const int type, bool isAddedFirst = false); RESULT appendServicesToBouquet(const std::string &filename, SWIG_PYOBJECT(ePyObject) services); - RESULT removeBouquet(const std::string &filename); + RESULT removeBouquet(const std::string &filename_regex); RESULT addChannelToDB(const eServiceReference &service, const eDVBFrontendParameters &feparam, SWIG_PYOBJECT(ePyObject) cachedPids, SWIG_PYOBJECT(ePyObject) caPids, const int serviceFlags); void removeServicesFlag(unsigned int flagmask); PyObject *readSatellites(SWIG_PYOBJECT(ePyObject) sat_list, SWIG_PYOBJECT(ePyObject) sat_dict, SWIG_PYOBJECT(ePyObject) tp_dict); diff --git a/lib/service/servicedvb.cpp b/lib/service/servicedvb.cpp index cf6be4ca6e9..5070f3592f7 100644 --- a/lib/service/servicedvb.cpp +++ b/lib/service/servicedvb.cpp @@ -383,10 +383,6 @@ RESULT eStaticServiceDVBPVRInformation::getName(const eServiceReference &ref, st m_parser.m_name = name; } - std::string res_name = ""; - std::string res_provider = ""; - eServiceReference::parseNameAndProviderFromName(name, res_name, res_provider); - name = res_name; m_parser.m_name = name; if (m_parser.m_prov.empty() && !ref.prov.empty()) m_parser.m_prov = ref.prov;