diff options
Diffstat (limited to 'guilib')
-rw-r--r-- | guilib/SkinInfo.cpp | 163 | ||||
-rw-r--r-- | guilib/SkinInfo.h | 20 |
2 files changed, 77 insertions, 106 deletions
diff --git a/guilib/SkinInfo.cpp b/guilib/SkinInfo.cpp index da649802db..4f96be8fa5 100644 --- a/guilib/SkinInfo.cpp +++ b/guilib/SkinInfo.cpp @@ -28,7 +28,7 @@ #include "Util.h" #include "Settings.h" #include "utils/log.h" -#include "tinyXML/tinyxml.h" +#include "XMLUtils.h" using namespace std; using namespace XFILE; @@ -42,7 +42,7 @@ CSkinInfo::CSkinInfo() m_DefaultResolution = RES_PAL_4x3; m_DefaultResolutionWide = RES_INVALID; m_strBaseDir = ""; - m_effectsSlowDown = 1.0; + m_effectsSlowDown = 1.0f; m_onlyAnimateToHome = true; m_Version = 1.0; m_skinzoom = 1.0f; @@ -51,132 +51,61 @@ CSkinInfo::CSkinInfo() CSkinInfo::~CSkinInfo() {} -void CSkinInfo::Load(const CStdString& strSkinDir) +void CSkinInfo::Load(const CStdString& strSkinDir, bool loadIncludes) { m_strBaseDir = strSkinDir; m_DefaultResolution = RES_PAL_4x3; m_DefaultResolutionWide = RES_INVALID; - m_effectsSlowDown = 1.0; + m_effectsSlowDown = 1.0f; + m_skinzoom = 1.0f; + m_Version = 1.0; // Load from skin.xml TiXmlDocument xmlDoc; CStdString strFile = m_strBaseDir + "\\skin.xml"; if (xmlDoc.LoadFile(strFile)) { // ok - get the default skin folder out of it... - TiXmlElement* pRootElement = xmlDoc.RootElement(); - CStdString strValue = pRootElement->Value(); - if (strValue != "skin") + const TiXmlNode* root = xmlDoc.RootElement(); + if (root && root->ValueStr() == "skin") { - CLog::Log(LOGERROR, "file :%s doesnt contain <skin>", strFile.c_str()); - } - else - { // get the default resolution - TiXmlNode *pChild = pRootElement->FirstChild("defaultresolution"); - if (pChild) - { // found the defaultresolution tag - CStdString strDefaultDir = pChild->FirstChild()->Value(); - strDefaultDir = strDefaultDir.ToLower(); - if (strDefaultDir == "pal") m_DefaultResolution = RES_PAL_4x3; - else if (strDefaultDir == "pal16x9") m_DefaultResolution = RES_PAL_16x9; - else if (strDefaultDir == "ntsc") m_DefaultResolution = RES_NTSC_4x3; - else if (strDefaultDir == "ntsc16x9") m_DefaultResolution = RES_NTSC_16x9; - else if (strDefaultDir == "720p") m_DefaultResolution = RES_HDTV_720p; - else if (strDefaultDir == "1080i") m_DefaultResolution = RES_HDTV_1080i; - } - CLog::Log(LOGINFO, "Default 4:3 resolution directory is %s", CUtil::AddFileToFolder(m_strBaseDir, GetDirFromRes(m_DefaultResolution)).c_str()); + GetResolution(root, "defaultresolution", m_DefaultResolution); + if (!GetResolution(root, "defaultwideresolution", m_DefaultResolutionWide)) + m_DefaultResolutionWide = m_DefaultResolution; - pChild = pRootElement->FirstChild("defaultresolutionwide"); - if (pChild && pChild->FirstChild()) - { // found the defaultresolution tag - CStdString strDefaultDir = pChild->FirstChild()->Value(); - strDefaultDir = strDefaultDir.ToLower(); - if (strDefaultDir == "pal") m_DefaultResolutionWide = RES_PAL_4x3; - else if (strDefaultDir == "pal16x9") m_DefaultResolutionWide = RES_PAL_16x9; - else if (strDefaultDir == "ntsc") m_DefaultResolutionWide = RES_NTSC_4x3; - else if (strDefaultDir == "ntsc16x9") m_DefaultResolutionWide = RES_NTSC_16x9; - else if (strDefaultDir == "720p") m_DefaultResolutionWide = RES_HDTV_720p; - else if (strDefaultDir == "1080i") m_DefaultResolutionWide = RES_HDTV_1080i; - } - else - m_DefaultResolutionWide = m_DefaultResolution; // default to same as 4:3 + CLog::Log(LOGINFO, "Default 4:3 resolution directory is %s", CUtil::AddFileToFolder(m_strBaseDir, GetDirFromRes(m_DefaultResolution)).c_str()); CLog::Log(LOGINFO, "Default 16:9 resolution directory is %s", CUtil::AddFileToFolder(m_strBaseDir, GetDirFromRes(m_DefaultResolutionWide)).c_str()); - // get the version - pChild = pRootElement->FirstChild("version"); - if (pChild && pChild->FirstChild()) - { - m_Version = atof(pChild->FirstChild()->Value()); - CLog::Log(LOGINFO, "Skin version is: %s", pChild->FirstChild()->Value()); - } - - // get the effects slowdown parameter - pChild = pRootElement->FirstChild("effectslowdown"); - if (pChild && pChild->FirstChild()) - m_effectsSlowDown = atof(pChild->FirstChild()->Value()); - - // get the skin zoom parameter. it's how much skin should be enlarged to get rid of overscan - pChild = pRootElement->FirstChild("zoom"); - if (pChild && pChild->FirstChild()) - m_skinzoom = (float)atof(pChild->FirstChild()->Value()); - else - m_skinzoom = 1.0f; + XMLUtils::GetDouble(root, "version", m_Version); + XMLUtils::GetFloat(root, "effectsslowdown", m_effectsSlowDown); + XMLUtils::GetFloat(root, "zoom", m_skinzoom); // now load the startupwindow information - LoadStartupWindows(pRootElement->FirstChildElement("startupwindows")); + LoadStartupWindows(root->FirstChildElement("startupwindows")); } + else + CLog::Log(LOGERROR, "%s - %s doesnt contain <skin>", __FUNCTION__, strFile.c_str()); } // Load the skin includes - LoadIncludes(); + if (loadIncludes) + LoadIncludes(); } bool CSkinInfo::Check(const CStdString& strSkinDir) { - bool bVersionOK = false; - // Load from skin.xml - TiXmlDocument xmlDoc; - CStdString strFile = CUtil::AddFileToFolder(strSkinDir, "skin.xml"); - CStdString strGoodPath = strSkinDir; - if (xmlDoc.LoadFile(strFile)) - { // ok - get the default res folder out of it... - TiXmlElement* pRootElement = xmlDoc.RootElement(); - CStdString strValue = pRootElement->Value(); - if (strValue == "skin") - { // get the default resolution - TiXmlNode *pChild = pRootElement->FirstChild("defaultresolution"); - if (pChild) - { // found the defaultresolution tag -#ifndef _LINUX - strGoodPath += "\\"; -#else - strGoodPath += "/"; -#endif - CStdString resolution = pChild->FirstChild()->Value(); - if (resolution == "pal") resolution = "PAL"; - else if (resolution == "pal16x9") resolution = "PAL16x9"; - else if (resolution == "ntsc") resolution = "NTSC"; - else if (resolution == "ntsc16x9") resolution = "NTSC16x9"; - strGoodPath = CUtil::AddFileToFolder(strGoodPath, resolution); - } - // get the version - pChild = pRootElement->FirstChild("version"); - if (pChild) - { - float parsedVersion; - parsedVersion = (float)atof(pChild->FirstChild()->Value()); - bVersionOK = parsedVersion >= SKIN_MIN_VERSION; - - CLog::Log(LOGINFO, "Skin version is: %s (%f)", pChild->FirstChild()->Value(), parsedVersion); - } - } + CSkinInfo info; + info.Load(strSkinDir, false); + if (info.GetVersion() < GetMinVersion()) + { + CLog::Log(LOGERROR, "%s(%s) version is to old (%f versus %f)", __FUNCTION__, strSkinDir.c_str(), info.GetVersion(), GetMinVersion()); + return false; } - // Check to see if we have a good path - CStdString strFontXML = CUtil::AddFileToFolder(strGoodPath, "Font.xml"); - CStdString strHomeXML = CUtil::AddFileToFolder(strGoodPath, "Home.xml"); - if ( CFile::Exists(strFontXML) && - CFile::Exists(strHomeXML) && bVersionOK ) + RESOLUTION res; + if (!CFile::Exists(info.GetSkinPath("Home.xml", &res)) + || !CFile::Exists(info.GetSkinPath("Font.xml", &res))) { - return true; + CLog::Log(LOGERROR, "%s(%s) does not contain Home.xml or Font.xml", __FUNCTION__, strSkinDir.c_str()); + return false; } - return false; + return true; } CStdString CSkinInfo::GetSkinPath(const CStdString& strFile, RESOLUTION *res, const CStdString& strBaseDir /* = "" */) const @@ -375,3 +304,31 @@ void CSkinInfo::GetSkinPaths(std::vector<CStdString> &paths) const paths.push_back(CUtil::AddFileToFolder(m_strBaseDir, GetDirFromRes(m_DefaultResolutionWide))); paths.push_back(CUtil::AddFileToFolder(m_strBaseDir, GetDirFromRes(m_DefaultResolution))); } + +bool CSkinInfo::GetResolution(const TiXmlNode *root, const char *tag, RESOLUTION &res) const +{ + CStdString strRes; + if (XMLUtils::GetString(root, tag, strRes)) + { + strRes.ToLower(); + if (strRes == "pal") + res = RES_PAL_4x3; + else if (strRes == "pal16x9") + res = RES_PAL_16x9; + else if (strRes == "ntsc") + res = RES_NTSC_4x3; + else if (strRes == "ntsc16x9") + res = RES_NTSC_16x9; + else if (strRes == "720p") + res = RES_HDTV_720p; + else if (strRes == "1080i") + res = RES_HDTV_1080i; + else + { + CLog::Log(LOGERROR, "%s invalid resolution specified for <%s>, %s", __FUNCTION__, tag, strRes.c_str()); + return false; + } + return true; + } + return false; +} diff --git a/guilib/SkinInfo.h b/guilib/SkinInfo.h index 7e4e12e5dc..6dbcdd3f32 100644 --- a/guilib/SkinInfo.h +++ b/guilib/SkinInfo.h @@ -26,6 +26,8 @@ #define CREDIT_LINE_LENGTH 50 +class TiXmlNode; + class CSkinInfo { public: @@ -43,7 +45,11 @@ public: CSkinInfo(); ~CSkinInfo(); - void Load(const CStdString& strSkinDir); // load the skin.xml file if it exists, and configure our directories etc. + /*! \brief Load information regarding the skin from the given skin directory + \param skinDir name of the skin to load + \param loadIncludes whether the includes from the skin should also be loaded (defaults to true) + */ + void Load(const CStdString& skinDir, bool loadIncludes = true); bool HasSkinFile(const CStdString &strFile) const; CStdString GetSkinPath(const CStdString& strFile, RESOLUTION *res, const CStdString& strBaseDir="") const; // retrieve the best skin file for the resolution we are in - res will be made the resolution we are loading from @@ -56,7 +62,7 @@ public: bool ResolveConstant(const CStdString &constant, float &value) const; bool ResolveConstant(const CStdString &constant, unsigned int &value) const; - double GetEffectsSlowdown() const { return m_effectsSlowDown; }; + float GetEffectsSlowdown() const { return m_effectsSlowDown; }; const std::vector<CStartupWindow> &GetStartupWindows() const { return m_startupWindows; }; @@ -78,6 +84,14 @@ protected: */ CStdString GetDirFromRes(RESOLUTION res) const; + /*! \brief grab a resolution tag from an XML node + \param node XML node to look for the given tag + \param tag name of the tag to look for + \param res resolution to return + \return true if we find a valid XML node containing a valid resolution, false otherwise + */ + bool GetResolution(const TiXmlNode *node, const char *tag, RESOLUTION &res) const; + void LoadIncludes(); bool LoadStartupWindows(const TiXmlElement *startup); @@ -86,7 +100,7 @@ protected: CStdString m_strBaseDir; double m_Version; - double m_effectsSlowDown; + float m_effectsSlowDown; CGUIIncludes m_includes; std::vector<CStartupWindow> m_startupWindows; |