// load the color file in void CGUIColorManager::Load(const CStdString &colorFile) { Clear(); // load the global color map if it exists CXBMCTinyXML xmlDoc; if (xmlDoc.LoadFile(PTH_IC("special://xbmc/system/colors.xml"))) LoadXML(xmlDoc); // first load the default color map if it exists CStdString path, basePath; URIUtils::AddFileToFolder(g_SkinInfo->Path(), "colors", basePath); URIUtils::AddFileToFolder(basePath, "defaults.xml", path); if (xmlDoc.LoadFile(PTH_IC(path))) LoadXML(xmlDoc); // now the color map requested if (colorFile.CompareNoCase("SKINDEFAULT") == 0) return; // nothing to do URIUtils::AddFileToFolder(basePath, colorFile, path); CLog::Log(LOGINFO, "Loading colors from %s", path.c_str()); if (xmlDoc.LoadFile(path)) LoadXML(xmlDoc); }
void CSkinInfo::LoadIncludes() { CStdString includesPath = PTH_IC(GetSkinPath("includes.xml")); CLog::Log(LOGINFO, "Loading skin includes from %s", includesPath.c_str()); m_includes.ClearIncludes(); m_includes.LoadIncludes(includesPath); }
bool CLocalizeStrings::LoadXML(const CStdString &filename, CStdString &encoding, uint32_t offset /* = 0 */) { TiXmlDocument xmlDoc; if (!xmlDoc.LoadFile(PTH_IC(filename))) { CLog::Log(LOGDEBUG, "unable to load %s: %s at line %d", filename.c_str(), xmlDoc.ErrorDesc(), xmlDoc.ErrorRow()); return false; } XMLUtils::GetEncoding(&xmlDoc, encoding); TiXmlElement* pRootElement = xmlDoc.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueStr()!=CStdString("strings")) { CLog::Log(LOGERROR, "%s Doesn't contain <strings>", filename.c_str()); return false; } const TiXmlElement *pChild = pRootElement->FirstChildElement("string"); while (pChild) { // Load new style language file with id as attribute const char* attrId=pChild->Attribute("id"); if (attrId && !pChild->NoChildren()) { int id = atoi(attrId) + offset; if (m_strings.find(id) == m_strings.end()) m_strings[id] = ToUTF8(encoding, pChild->FirstChild()->Value()); } pChild = pChild->NextSiblingElement("string"); } return true; }
bool CTextureBundleXBT::OpenBundle() { Cleanup(); // Find the correct texture file (skin or theme) CStdString strPath; if (m_themeBundle) { // if we are the theme bundle, we only load if the user has chosen // a valid theme (or the skin has a default one) CStdString theme = g_guiSettings.GetString("lookandfeel.skintheme"); if (!theme.IsEmpty() && theme.CompareNoCase("SKINDEFAULT")) { CStdString themeXBT(URIUtils::ReplaceExtension(theme, ".xbt")); strPath = URIUtils::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media"); strPath = URIUtils::AddFileToFolder(strPath, themeXBT); } else { return false; } } else { strPath = URIUtils::AddFileToFolder(g_graphicsContext.GetMediaDir(), "media/Textures.xbt"); } strPath = PTH_IC(strPath); // Load the texture file if (!m_XBTFReader.Open(strPath)) { return false; } CLog::Log(LOGDEBUG, "%s - Opened bundle %s", __FUNCTION__, strPath.c_str()); m_TimeStamp = m_XBTFReader.GetLastModificationTimestamp(); if (lzo_init() != LZO_E_OK) { return false; } return true; }
// load the color file in void CGUIColorManager::Load(const CStdString &colorFile) { Clear(); // first load the default color map if it exists CStdString path, basePath; CUtil::AddFileToFolder(g_SkinInfo.GetBaseDir(), "colors", basePath); CUtil::AddFileToFolder(basePath, "defaults.xml", path); TiXmlDocument xmlDoc; if (xmlDoc.LoadFile(PTH_IC(path.c_str()))) LoadXML(xmlDoc); // now the color map requested if (colorFile.CompareNoCase("SKINDEFAULT") == 0) return; // nothing to do CUtil::AddFileToFolder(basePath, colorFile, path); CLog::Log(LOGINFO, "Loading colors from %s", path.c_str()); if (xmlDoc.LoadFile(path.c_str())) LoadXML(xmlDoc); }
bool CGUIWindowFullScreen::OnMessage(CGUIMessage& message) { switch (message.GetMessage()) { case GUI_MSG_WINDOW_INIT: { // check whether we've come back here from a window during which time we've actually // stopped playing videos if (message.GetParam1() == WINDOW_INVALID && !g_application.IsPlayingVideo()) { // why are we here if nothing is playing??? m_gWindowManager.PreviousWindow(); return true; } m_bLastRender = false; g_infoManager.SetShowInfo(false); g_infoManager.SetShowCodec(false); m_bShowCurrentTime = false; g_infoManager.SetDisplayAfterSeek(0); // Make sure display after seek is off. #ifdef HAS_XBOX_HARDWARE // Disable nav sounds if spindown is active as they are loaded // from HDD all the time. if ( !g_application.CurrentFileItem().IsHD() && (g_guiSettings.GetInt("harddisk.remoteplayspindown") || g_guiSettings.GetInt("harddisk.spindowntime")) ) { if (!g_guiSettings.GetBool("lookandfeel.soundsduringplayback")) g_audioManager.Enable(false); } #endif // setup the brightness, contrast and resolution CUtil::SetBrightnessContrastGammaPercent(g_stSettings.m_currentVideoSettings.m_Brightness, g_stSettings.m_currentVideoSettings.m_Contrast, g_stSettings.m_currentVideoSettings.m_Gamma, false); // switch resolution CSingleLock lock (g_graphicsContext); g_graphicsContext.SetFullScreenVideo(true); #ifdef HAS_VIDEO_PLAYBACK RESOLUTION res = g_renderManager.GetResolution(); g_graphicsContext.SetVideoResolution(res, false, false); #endif lock.Leave(); #ifdef HAS_VIDEO_PLAYBACK // make sure renderer is uptospeed g_renderManager.Update(false); #endif // now call the base class to load our windows CGUIWindow::OnMessage(message); m_bShowViewModeInfo = false; if (CUtil::IsUsingTTFSubtitles()) { CSingleLock lock (m_fontLock); CStdString fontPath = _P("Q:\\media\\Fonts\\"); fontPath += g_guiSettings.GetString("subtitles.font"); #ifdef __APPLE__ // We scale based on PAL16x9 - this at least ensures all sizing is constant across resolutions. // I'm picking 16x9 because the 4x3 aspect below gives me squashed subtitles. // CGUIFont *subFont = g_fontManager.LoadTTF("__subtitle__", PTH_IC(fontPath), color[g_guiSettings.GetInt("subtitles.color")], 0, g_guiSettings.GetInt("subtitles.height"), g_guiSettings.GetInt("subtitles.style"), 1.0f, 1.0f, PAL_16x9); #else // We scale based on PAL4x3 - this at least ensures all sizing is constant across resolutions CGUIFont *subFont = g_fontManager.LoadTTF("__subtitle__", PTH_IC(fontPath), color[g_guiSettings.GetInt("subtitles.color")], 0, g_guiSettings.GetInt("subtitles.height"), g_guiSettings.GetInt("subtitles.style"), 1.0f, 1.0f, PAL_4x3); #endif if (!subFont) CLog::Log(LOGERROR, "CGUIWindowFullScreen::OnMessage(WINDOW_INIT) - Unable to load subtitle font"); else m_subsLayout = new CGUITextLayout(subFont, true); } else m_subsLayout = NULL; return true; } case GUI_MSG_WINDOW_DEINIT: { CGUIWindow::OnMessage(message); CGUIDialog *pDialog = (CGUIDialog *)m_gWindowManager.GetWindow(WINDOW_OSD); if (pDialog) pDialog->Close(true); FreeResources(true); CSingleLock lock (g_graphicsContext); CUtil::RestoreBrightnessContrastGamma(); g_graphicsContext.SetFullScreenVideo(false); #ifndef HAS_SDL g_graphicsContext.SetVideoResolution(g_guiSettings.m_LookAndFeelResolution, TRUE); #endif lock.Leave(); #ifdef HAS_VIDEO_PLAYBACK // make sure renderer is uptospeed g_renderManager.Update(false); #endif CSingleLock lockFont(m_fontLock); if (m_subsLayout) { g_fontManager.Unload("__subtitle__"); delete m_subsLayout; m_subsLayout = NULL; } if (g_guiSettings.GetBool("lookandfeel.soundsduringplayback")) g_audioManager.Enable(true); return true; } case GUI_MSG_SETFOCUS: case GUI_MSG_LOSTFOCUS: if (message.GetSenderId() != WINDOW_FULLSCREEN_VIDEO) return true; break; } return CGUIWindow::OnMessage(message); }
HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { // Fail on unsupported items if (lpSecurityAttributes != NULL ) { CLog::Log(LOGERROR, "CreateFile does not support security attributes"); return INVALID_HANDLE_VALUE; } if (hTemplateFile != (HANDLE) 0) { CLog::Log(LOGERROR, "CreateFile does not support template file"); return INVALID_HANDLE_VALUE; } int flags = 0, mode=S_IRUSR | S_IRGRP | S_IROTH; if (dwDesiredAccess & FILE_WRITE_DATA) { flags = O_RDWR; mode |= S_IWUSR; } else if ( (dwDesiredAccess & FILE_READ_DATA) == FILE_READ_DATA) flags = O_RDONLY; else { CLog::Log(LOGERROR, "CreateFile does not permit access other than read and/or write"); return INVALID_HANDLE_VALUE; } switch (dwCreationDisposition) { case OPEN_ALWAYS: flags |= O_CREAT; break; case TRUNCATE_EXISTING: flags |= O_TRUNC; mode |= S_IWUSR; break; case CREATE_ALWAYS: flags |= O_CREAT|O_TRUNC; mode |= S_IWUSR; break; case CREATE_NEW: flags |= O_CREAT|O_TRUNC|O_EXCL; mode |= S_IWUSR; break; case OPEN_EXISTING: break; } int fd = 0; if (dwFlagsAndAttributes & FILE_FLAG_NO_BUFFERING) flags |= O_SYNC; // we always open files with fileflag O_NONBLOCK to support // cdrom devices, but we then turn it of for actual reads // apperently it's used for multiple things, read mode // and how opens are handled. devices must be opened // with this flag set to work correctly flags |= O_NONBLOCK; CStdString strResultFile(lpFileName); fd = open(lpFileName, flags, mode); // Important to check reason for fail. Only if its // "file does not exist" shall we try to find the file if (fd == -1 && errno == ENOENT) { // Failed to open file. maybe due to case sensitivity. // Try opening the same name in lower case. CStdString igFileName = PTH_IC(lpFileName); fd = open(igFileName.c_str(), flags, mode); if (fd != -1) { CLog::Log(LOGWARNING,"%s, successfuly opened <%s> instead of <%s>", __FUNCTION__, igFileName.c_str(), lpFileName); strResultFile = igFileName; } } if (fd == -1) { if (errno == 20) CLog::Log(LOGWARNING,"%s, error %d opening file <%s>, flags:%x, mode:%x. ", __FUNCTION__, errno, lpFileName, flags, mode); return INVALID_HANDLE_VALUE; } // turn of nonblocking reads/writes as we don't // support this anyway currently fcntl(fd, F_GETFL, &flags); fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); HANDLE result = new CXHandle(CXHandle::HND_FILE); result->fd = fd; #ifdef HAS_DVD_DRIVE // special case for opening the cdrom device if (strcmp(lpFileName, MEDIA_DETECT::CLibcdio::GetInstance()->GetDeviceFileName())==0) result->m_bCDROM = true; else #endif result->m_bCDROM = false; // if FILE_FLAG_DELETE_ON_CLOSE then "unlink" the file (delete) // the file will be deleted when the last open descriptor is closed. if (dwFlagsAndAttributes & FILE_FLAG_DELETE_ON_CLOSE) unlink(strResultFile); return result; }
bool WatchDog::CPingJob::InitPingRequest(CStdString& pingUrl,CStdString& strPingVersion) { BOXEE::BXXMLDocument bxinfo; CStdString bxinfoFilePath = PTH_IC(BXINFO_FILE_PATH); ////////////////////////////////// // Set the current ping version // ////////////////////////////////// if (bxinfo.LoadFromFile(bxinfoFilePath)) { TiXmlHandle handle(bxinfo.GetRoot()); TiXmlElement* version = handle.FirstChild("ping_version").ToElement(); if (version) { std::string strVersion = version->GetText(); if (!strVersion.empty()) { strPingVersion = strVersion; } } } if(strPingVersion.IsEmpty()) { strPingVersion = "0"; CLog::Log(LOGDEBUG,"CPingJob::InitPingRequest - Failed to get the PingVersion from [%s], so set the ping version to [%s] (ping)",bxinfoFilePath.c_str(),strPingVersion.c_str()); } ////////////////////// // Set the ping url // ////////////////////// pingUrl = BOXEE::BXConfiguration::GetInstance().GetStringParam("WatchDog.TestServerUrl","http://app.boxee.tv/"); if(g_application.GetInSlideshowScreensaver()) { pingUrl += "idle/"; } else { pingUrl += "ping/"; } pingUrl += BoxeeUtils::GetPlatformStr(); pingUrl += "/"; CStdString boxeeCurrentVersion = g_infoManager.GetVersion(); // For debug // /* if(boxeeCurrentVersion == "SVN") { boxeeCurrentVersion = g_localizeStrings.Get(53250); CLog::Log(LOGDEBUG,"CBoxeeVersionUpdateManager::PerformVersionUpdate - boxeeCurrentVersion is [SVN], so it was changed to [%s] (ping)",boxeeCurrentVersion.c_str()); } */ /////////////// pingUrl += boxeeCurrentVersion; pingUrl += "/"; pingUrl += strPingVersion; if (g_guiSettings.GetBool("update.allow_beta")) { pingUrl += "/1"; } else { pingUrl += "/0"; } return true; }
void WatchDog::CPingJob::DoWork() { if (!m_jobHandler) { CLog::Log(LOGWARNING,"CPingJob::DoWork - Can't execute the job. [jobHandler=NULL] (ping)"); return; } CLog::Log(LOGDEBUG,"CPingJob::DoWork - Enter function. [server=%d][internet=%d] (ping)",m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); if (!m_jobHandler->IsConnectedToInternet()) { CLog::Log(LOGDEBUG,"CPingJob::DoWork - There is no internet connection -> Don't try to send ping. [server=%d][internet=%d] (ping)",m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); return; } std::set<CStdString> allowedPaths; std::set<CStdString> allowedExt; allowedPaths.insert("special://xbmc"); allowedPaths.insert("special://home"); allowedPaths.insert("special://temp"); allowedExt.insert(".xml"); allowedExt.insert(".png"); allowedExt.insert(".gif"); allowedExt.insert(".jpg"); allowedExt.insert(".tbn"); // test boxee BOXEE::BXCurl curl; CStdString strClientPingVersion = ""; CStdString pingUrl = ""; bool succeed = InitPingRequest(pingUrl,strClientPingVersion); CLog::Log(LOGDEBUG,"CPingJob::DoWork - Call to InitPingRequest() returned [%d]. [strClientPingVersion=%s][pingUrl=%s] (ping)",succeed,strClientPingVersion.c_str(),pingUrl.c_str()); if(!succeed) { CLog::Log(LOGERROR,"CPingJob::DoWork - Call to InitPingParams() FAILED. [retVal=%d] (ping)",succeed); return; } int nClientPingVersion = atoi(strClientPingVersion.c_str()); CLog::Log(LOGWARNING,"CPingJob::DoWork - Going to check ping. [server=%d][internet=%d] (ping)",m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); std::string strResp = curl.HttpGetString(pingUrl, false); g_application.SetBoxeeServerIP(curl.GetServerIP()); long retCode = curl.GetLastRetCode(); CLog::Log(LOGWARNING,"CPingJob::DoWork - Check ping returned [retCode=%ld][Response-IsEmpty=%d]. [server=%d][internet=%d] (ping)",retCode,strResp.empty(),m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); m_jobHandler->SetIsConnectedToServer((retCode == 200)); BOXEE::BXXMLDocument reader; if (strResp.empty()) { CLog::Log(LOGDEBUG,"WatchDog::Process - Not handling server response to [pingUrl=%s] because it is empty (ping)",pingUrl.c_str()); return; } if(!reader.LoadFromString(strResp)) { CLog::Log(LOGERROR,"WatchDog::Process - Not handling server response to [pingUrl=%s] because failed to load it to BXXMLDocument (ping)",pingUrl.c_str()); return; } TiXmlElement* root = reader.GetRoot(); if(!root) { CLog::Log(LOGERROR,"WatchDog::Process - Failed to get root from BXXMLDocument of the ping response (ping)"); return; } if((strcmp(root->Value(),"ping") != 0)) { CLog::Log(LOGERROR,"WatchDog::Process - Failed to parse ping response because the root tag ISN'T <ping> (ping)"); return; } CLog::Log(LOGDEBUG,"CPingJob::DoWork - The root tag <ping> was found. Going to parse the ping response (ping)"); TiXmlElement* pingChildElem = NULL; pingChildElem = root->FirstChildElement(); while (pingChildElem) { if (strcmp(pingChildElem->Value(), "cmds") == 0) { CLog::Log(LOGDEBUG,"CPingJob::DoWork - The <cmds> tag was found (ping)"); CStdString strServerPingVersion = ""; strServerPingVersion = pingChildElem->Attribute("ping_version"); int nServerPingVersion = atoi(strServerPingVersion.c_str()); if (nServerPingVersion > nClientPingVersion) { CLog::Log(LOGDEBUG,"CPingJob::DoWork - Because [nServerPingVersion=%d] > [%d=nClientPingVersion] going to parse the <cmds> tag (ping)",nServerPingVersion,nClientPingVersion); TiXmlElement* cmdsChildElem = NULL; cmdsChildElem = pingChildElem->FirstChildElement(); while (cmdsChildElem) { if (strcmp(cmdsChildElem->Value(), "download") == 0) { CStdString url = cmdsChildElem->Attribute("url"); CStdString local = cmdsChildElem->Attribute("local"); CStdString hash = cmdsChildElem->Attribute("hash"); CLog::Log(LOGDEBUG,"CPingJob::DoWork - Found <download> tag with attributes [url=%s][local=%s][hash=%s] (ping)",url.c_str(),local.c_str(),hash.c_str()); if (!url.IsEmpty() && !local.IsEmpty()) { CStdString strDir; CStdString strLocal = local; CStdString ext = CUtil::GetExtension(strLocal); CStdString strName = CUtil::GetFileName(strLocal); CUtil::GetDirectory(strLocal, strDir); if (allowedExt.find(ext.c_str()) != allowedExt.end() && allowedPaths.find(CUtil::GetSpecialPathPrefix(local).c_str()) != allowedPaths.end() && CUtil::CreateDirectoryEx(strDir)) { CLog::Log(LOGDEBUG,"CPingJob::DoWork - Going to download [url=%s] (ping)",url.c_str()); BoxeeUtils::SafeDownload(url.c_str(), strLocal.c_str(), hash); } } } else if (strcmp(cmdsChildElem->Value(), "remove") == 0) { CStdString local = cmdsChildElem->Attribute("path"); CLog::Log(LOGDEBUG,"CPingJob::DoWork - Found <remove> tag with attributes [local=%s] (ping)",local.c_str()); CStdString strLocal = local; CStdString ext = CUtil::GetExtension(strLocal); if (allowedExt.find(ext.c_str()) != allowedExt.end() && allowedPaths.find(CUtil::GetSpecialPathPrefix(local).c_str()) != allowedPaths.end()) { CLog::Log(LOGDEBUG,"CPingJob::DoWork - Going to delete [strLocal=%s] (ping)",strLocal.c_str()); ::DeleteFile(strLocal); } } cmdsChildElem = cmdsChildElem->NextSiblingElement(); } if (!strServerPingVersion.IsEmpty()) { // currently - version is the only info kept so we take a shortcut... TiXmlDocument *infoDoc = NULL; CStdString strInfoDoc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?><info><ping_version>"+strServerPingVersion+"</ping_version></info>"; BOXEE::BXXMLDocument newinfo; if (newinfo.LoadFromString(strInfoDoc)) { infoDoc = newinfo.GetRoot()->GetDocument(); } if (infoDoc) { infoDoc->SaveFile(PTH_IC(BXINFO_FILE_PATH)); } } } else { CLog::Log(LOGDEBUG,"CPingJob::DoWork - Because [nServerPingVersion=%d] <= [%d=nClientPingVersion] NOT going to parse the <cmds> tag (ping)",nServerPingVersion,nClientPingVersion); } } #ifndef HAS_EMBEDDED else if (strcmp(pingChildElem->Value(),"version_update") == 0) { CLog::Log(LOGDEBUG,"CPingJob::DoWork - The <version_update> tag was found (ping)"); succeed = g_boxeeVersionUpdateManager.HandleVersionUpdate(root, pingChildElem); CLog::Log(LOGDEBUG,"CPingJob::DoWork - Call to CBoxeeVersionUpdateManager::HandleVersionUpdate returned [%d]",succeed); } #else else if (strcmp(pingChildElem->Value(),"timestamp") == 0) { time_t currentTime = time(NULL); time_t timeStamp = 0; char *endptr; CLog::Log(LOGDEBUG,"CPingJob::DoWork - The <timestamp> tag was found (ping)"); CStdString strTimestamp = pingChildElem->Attribute("utc"); timeStamp = strtol(strTimestamp.c_str(), &endptr, 10); if(abs(currentTime - timeStamp) > 60 * 60 ) { IHalServices& client = CHalServicesFactory::GetInstance(); client.SetTime(strTimestamp); } } #endif pingChildElem = pingChildElem->NextSiblingElement(); } //CLog::Log(LOGDEBUG,"CPingJob::DoWork - Exit function. [server=%d][internet=%d] (ping)",m_jobHandler->IsConnectedToServer(),m_jobHandler->IsConnectedToInternet()); }