Skip to content

Commit

Permalink
[Fixed] Some issues and optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarCC committed Nov 20, 2024
1 parent 702224f commit 3a96c2d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
76 changes: 49 additions & 27 deletions lib/dvb/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -2680,36 +2676,62 @@ 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;
}
ePtr<iDVBChannelList> db;
ePtr<eDVBResourceManager> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dvb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions lib/service/servicedvb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3a96c2d

Please sign in to comment.