-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4102 from DimitarCC/fixes-1
[Fixed] Some issues and optimized code
- Loading branch information
Showing
3 changed files
with
51 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include <fstream> | ||
#include <stdexcept> | ||
#include <exception> | ||
#include <regex> | ||
|
||
/* | ||
* Copyright (C) 2017 Marcus Metzler <[email protected]> | ||
|
@@ -220,15 +221,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 +1382,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,36 +2677,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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters