Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed Sep 4, 2019
1 parent 225d50d commit 6dad75f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 48 deletions.
13 changes: 0 additions & 13 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ using namespace iptvsimple;
using namespace iptvsimple::data;
using namespace iptvsimple::utilities;

#ifdef TARGET_WINDOWS
#define snprintf _snprintf
#ifdef CreateDirectory
#undef CreateDirectory
#endif
#ifdef DeleteFile
#undef DeleteFile
#endif
#endif

bool m_created = false;
ADDON_STATUS m_currentStatus = ADDON_STATUS_UNKNOWN;
PVRIptvData* m_data = nullptr;
Expand Down Expand Up @@ -118,9 +108,6 @@ ADDON_STATUS ADDON_Create(void* hdl, void* props)
const std::string userPath = pvrprops->strUserPath;
const std::string clientPath = pvrprops->strClientPath;

if (!XBMC->DirectoryExists(settings.GetUserPath().c_str()))
XBMC->CreateDirectory(settings.GetUserPath().c_str());

settings.ReadFromAddon(userPath, clientPath);

m_data = new PVRIptvData;
Expand Down
13 changes: 3 additions & 10 deletions src/iptvsimple/Epg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ using namespace iptvsimple::data;
using namespace iptvsimple::utilities;
using namespace rapidxml;

#ifdef TARGET_WINDOWS
#ifdef DeleteFile
#undef DeleteFile
#endif
#endif

Epg::Epg(Channels& channels)
: m_channels(channels), m_xmltvLocation(Settings::GetInstance().GetEpgLocation()), m_epgTimeShift(Settings::GetInstance().GetEpgTimeshiftSecs()),
m_tsOverride(Settings::GetInstance().GetTsOverride()), m_lastStart(0), m_lastEnd(0)
Expand Down Expand Up @@ -216,8 +210,7 @@ bool Epg::LoadChannelEpgs(xml_node<>* rootElement)

m_channelEpgs.clear();

xml_node<>* channelNode = nullptr;
for (channelNode = rootElement->first_node("channel"); channelNode; channelNode = channelNode->next_sibling("channel"))
for (xml_node<>* channelNode = rootElement->first_node("channel"); channelNode; channelNode = channelNode->next_sibling("channel"))
{
ChannelEpg channelEpg;

Expand Down Expand Up @@ -473,6 +466,6 @@ void Epg::MoveOldGenresXMLFileToNewLocation()
else
FileUtils::CopyFile(FileUtils::GetResourceDataPath() + "/" + GENRES_MAP_FILENAME, DEFAULT_GENRE_TEXT_MAP_FILE);

XBMC->DeleteFile((ADDON_DATA_BASE_DIR + "/" + GENRES_MAP_FILENAME).c_str());
XBMC->DeleteFile((FileUtils::GetSystemAddonPath() + "/" + GENRES_MAP_FILENAME).c_str());
FileUtils::DeleteFile(ADDON_DATA_BASE_DIR + "/" + GENRES_MAP_FILENAME.c_str());
FileUtils::DeleteFile(FileUtils::GetSystemAddonPath() + "/" + GENRES_MAP_FILENAME.c_str());
}
14 changes: 4 additions & 10 deletions src/iptvsimple/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ using namespace ADDON;
using namespace iptvsimple;
using namespace iptvsimple::utilities;

#ifdef TARGET_WINDOWS
#ifdef DeleteFile
#undef DeleteFile
#endif
#endif

/***************************************************************************
* PVR settings
**************************************************************************/
Expand Down Expand Up @@ -99,12 +93,12 @@ ADDON_STATUS Settings::SetValue(const std::string& settingName, const void* sett
// reset cache and restart addon

std::string strFile = FileUtils::GetUserDataAddonFilePath(M3U_CACHE_FILENAME);
if (XBMC->FileExists(strFile.c_str(), false))
XBMC->DeleteFile(strFile.c_str());
if (FileUtils::FileExists(strFile.c_str()))
FileUtils::DeleteFile(strFile);

strFile = FileUtils::GetUserDataAddonFilePath(XMLTV_CACHE_FILENAME);
if (XBMC->FileExists(strFile.c_str(), false))
XBMC->DeleteFile(strFile.c_str());
if (FileUtils::FileExists(strFile.c_str()))
FileUtils::DeleteFile(strFile);

// M3U
if (settingName == "m3uPathType")
Expand Down
20 changes: 10 additions & 10 deletions src/iptvsimple/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,31 +131,31 @@ namespace iptvsimple
return defaultReturnValue;
}

std::string m_userPath = "";
std::string m_clientPath = "";
std::string m_userPath;
std::string m_clientPath;

PathType m_m3uPathType = PathType::REMOTE_PATH;
std::string m_m3uPath = "";
std::string m_m3uUrl = "";
std::string m_m3uPath;
std::string m_m3uUrl;
bool m_cacheM3U = false;
int m_startChannelNumber = 1;
bool m_numberChannelsByM3uOrderOnly = false;

PathType m_epgPathType = PathType::REMOTE_PATH;
std::string m_epgPath = "";
std::string m_epgUrl = "";
std::string m_epgPath;
std::string m_epgUrl;
bool m_cacheEPG = false;
int m_epgTimeShiftMins = 0;
bool m_tsOverride = true;

bool m_useEpgGenreTextWhenMapping = false;
PathType m_genresPathType = PathType::LOCAL_PATH;
std::string m_genresPath = "";
std::string m_genresUrl = "";
std::string m_genresPath;
std::string m_genresUrl;

PathType m_logoPathType = PathType::REMOTE_PATH;
std::string m_logoPath = "";
std::string m_logoBaseUrl = "";
std::string m_logoPath;
std::string m_logoBaseUrl;
EpgLogosMode m_epgLogosMode = EpgLogosMode::IGNORE_XMLTV;
};
} //namespace iptvsimple
2 changes: 1 addition & 1 deletion src/iptvsimple/data/EpgEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ bool EpgEntry::UpdateFrom(rapidxml::xml_node<>* channelNode, const std::string&
if (!episodeNumbersList.empty())
ParseEpisodeNumberInfo(episodeNumbersList);

xml_node<> *creditsNode = channelNode->first_node("credits");
xml_node<>* creditsNode = channelNode->first_node("credits");
if (creditsNode)
{
m_cast = GetJoinedNodeValues(creditsNode, "actor");
Expand Down
5 changes: 5 additions & 0 deletions src/iptvsimple/utilities/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ bool FileUtils::FileExists(const std::string& file)
return XBMC->FileExists(file.c_str(), false);
}

bool FileUtils::DeleteFile(const std::string& file)
{
return XBMC->DeleteFile(file.c_str());
}

bool FileUtils::CopyFile(const std::string& sourceFile, const std::string& targetFile)
{
bool copySuccessful = true;
Expand Down
1 change: 1 addition & 0 deletions src/iptvsimple/utilities/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace iptvsimple
static int GetCachedFileContents(const std::string& cachedName, const std::string& filePath,
std::string& content, const bool useCache = false);
static bool FileExists(const std::string& file);
static bool DeleteFile(const std::string& file);
static bool CopyFile(const std::string& sourceFile, const std::string& targetFile);
static bool CopyDirectory(const std::string& sourceDir, const std::string& targetDir, bool recursiveCopy);
static std::string GetSystemAddonPath();
Expand Down
6 changes: 2 additions & 4 deletions src/iptvsimple/utilities/XMLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ inline std::string GetJoinedNodeValues(const rapidxml::xml_node<Ch>* rootNode, c
{
std::string stringValue;

rapidxml::xml_node<Ch>* childNode = nullptr;
for (childNode = rootNode->first_node(tag); childNode; childNode = childNode->next_sibling(tag))
for (rapidxml::xml_node<Ch>* childNode = rootNode->first_node(tag); childNode; childNode = childNode->next_sibling(tag))
{
if (childNode)
{
Expand All @@ -59,8 +58,7 @@ inline std::vector<std::string> GetNodeValuesList(const rapidxml::xml_node<Ch>*
{
std::vector<std::string> stringValues;

rapidxml::xml_node<Ch>* childNode = nullptr;
for(childNode = rootNode->first_node(tag); childNode; childNode = childNode->next_sibling(tag))
for(rapidxml::xml_node<Ch>* childNode = rootNode->first_node(tag); childNode; childNode = childNode->next_sibling(tag))
{
if (childNode)
stringValues.emplace_back(childNode->value());
Expand Down

0 comments on commit 6dad75f

Please sign in to comment.