bool CPODocument::LoadFile(const std::string &pofilename) { CURL poFileUrl(pofilename); if (!XFILE::CFile::Exists(poFileUrl)) return false; XFILE::CFile file; XFILE::auto_buffer buf; if (file.LoadFile(poFileUrl, buf) < 18) // at least a size of a minimalistic header { CLog::Log(LOGERROR, "%s: can't load file \"%s\" or file is too small", __FUNCTION__, pofilename.c_str()); return false; } m_strBuffer = '\n'; m_strBuffer.append(buf.get(), buf.size()); buf.clear(); ConvertLineEnds(pofilename); // we make sure, to have an LF at the end of buffer if (*m_strBuffer.rbegin() != '\n') { m_strBuffer += "\n"; } m_POfilelength = m_strBuffer.size(); if (GetNextEntry() && m_Entry.Type == MSGID_FOUND) return true; CLog::Log(LOGERROR, "POParser: unable to read PO file header from file: %s", pofilename.c_str()); return false; }
bool CBaseTexture::LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels, const std::string& strMimeType) { if (URIUtils::HasExtension(texturePath, ".dds")) { // special case for DDS images CDDSImage image; if (image.ReadFile(texturePath)) { Update(image.GetWidth(), image.GetHeight(), 0, image.GetFormat(), image.GetData(), false); return true; } return false; } unsigned int width = maxWidth ? std::min(maxWidth, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize(); unsigned int height = maxHeight ? std::min(maxHeight, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize(); // Read image into memory to use our vfs XFILE::CFile file; XFILE::auto_buffer buf; if (file.LoadFile(texturePath, buf) <= 0) return false; CURL url(texturePath); // make sure resource:// paths are properly resolved if (url.IsProtocol("resource")) { std::string translatedPath; if (XFILE::CResourceFile::TranslatePath(url, translatedPath)) url.Parse(translatedPath); } // handle xbt:// paths differently because it allows loading the texture directly from memory if (url.IsProtocol("xbt")) { XFILE::CXbtFile xbtFile; if (!xbtFile.Open(url)) return false; return LoadFromMemory(xbtFile.GetImageWidth(), xbtFile.GetImageHeight(), 0, xbtFile.GetImageFormat(), xbtFile.HasImageAlpha(), reinterpret_cast<unsigned char*>(buf.get())); } IImage* pImage; if(strMimeType.empty()) pImage = ImageFactory::CreateLoader(texturePath); else pImage = ImageFactory::CreateLoaderFromMimeType(strMimeType); if (!LoadIImage(pImage, (unsigned char *)buf.get(), buf.size(), width, height, autoRotate)) { CLog::Log(LOGDEBUG, "%s - Load of %s failed.", __FUNCTION__, texturePath.c_str()); delete pImage; return false; } delete pImage; return true; }
bool CBaseTexture::LoadFromFileInternal(const std::string& texturePath, unsigned int maxWidth, unsigned int maxHeight, bool autoRotate, bool requirePixels, const std::string& strMimeType) { if (URIUtils::HasExtension(texturePath, ".dds")) { // special case for DDS images CDDSImage image; if (image.ReadFile(texturePath)) { Update(image.GetWidth(), image.GetHeight(), 0, image.GetFormat(), image.GetData(), false); return true; } return false; } unsigned int width = maxWidth ? std::min(maxWidth, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize(); unsigned int height = maxHeight ? std::min(maxHeight, g_Windowing.GetMaxTextureSize()) : g_Windowing.GetMaxTextureSize(); // Read image into memory to use our vfs XFILE::CFile file; XFILE::auto_buffer buf; if (file.LoadFile(texturePath, buf) <= 0) return false; IImage* pImage; if(strMimeType.empty()) pImage = ImageFactory::CreateLoader(texturePath); else pImage = ImageFactory::CreateLoaderFromMimeType(strMimeType); if (!LoadIImage(pImage, (unsigned char *)buf.get(), buf.size(), width, height, autoRotate)) { delete pImage; pImage = ImageFactory::CreateFallbackLoader(texturePath); if (!LoadIImage(pImage, (unsigned char *)buf.get(), buf.size(), width, height)) { CLog::Log(LOGDEBUG, "%s - Load of %s failed.", __FUNCTION__, texturePath.c_str()); delete pImage; return false; } } delete pImage; return true; }
std::vector< CStdString > CKaraokeLyricsTextUStar::readFile(const CStdString & lyricsFile, bool report_errors ) { std::vector< CStdString > lines; XFILE::CFile file; XFILE::auto_buffer buf; if (file.LoadFile(lyricsFile, buf) <= 0) { if (report_errors) CLog::Log(LOGERROR, "%s: can't load \"%s\" file", __FUNCTION__, lyricsFile.c_str()); return std::vector< CStdString >(); } file.Close(); const size_t lyricSize = buf.size(); // Parse into the string array size_t offset = 0; size_t lineoffset = 0; while ( offset < lyricSize ) { // End of line? if (buf.get()[offset] == 0x0D || buf.get()[offset] == 0x0A) { // An empty line? if ( lineoffset != offset ) lines.push_back(std::string(buf.get() + lineoffset, offset - lineoffset)); // Point to the next symbol lineoffset = offset + 1; } offset++; } // Last line, if any if ( lineoffset < lyricSize ) lines.push_back(std::string(buf.get() + lineoffset, buf.size() - lineoffset)); return lines; }
bool CKaraokeLyricsTextLRC::Load() { XFILE::CFile file; // Clear the lyrics array clearLyrics(); XFILE::auto_buffer buf; if (file.LoadFile(m_lyricsFile, buf) <= 0) { CLog::Log(LOGERROR, "%s: can't load \"%s\" file", __FUNCTION__, m_lyricsFile.c_str()); return false; } file.Close(); // Parse the correction value int timing_correction = MathUtils::round_int( g_advancedSettings.m_karaokeSyncDelayLRC * 10 ); unsigned int offset = 0; CStdString songfilename = getSongFile(); // Skip windoze UTF8 file prefix, if any, and reject UTF16 files if (buf.size() > 3) { if ((unsigned char)buf.get()[0] == 0xFF && (unsigned char)buf.get()[1] == 0xFE) { CLog::Log( LOGERROR, "LRC lyric loader: lyrics file is in UTF16 encoding, must be in UTF8" ); return false; } // UTF8 prefix added by some windoze apps if ((unsigned char)buf.get()[0] == 0xEF && (unsigned char)buf.get()[1] == 0xBB && (unsigned char)buf.get()[2] == 0xBF) offset = 3; } if (checkMultiTime(buf.get() + offset, buf.size() - offset)) return ParserMultiTime(buf.get() + offset, buf.size() - offset, timing_correction); else return ParserNormal(buf.get() + offset, buf.size() - offset, timing_correction); }
int CNfoFile::Load(const std::string& strFile) { Close(); XFILE::CFile file; XFILE::auto_buffer buf; if (file.LoadFile(strFile, buf) > 0) { m_doc.assign(buf.get(), buf.size()); m_headPos = 0; return 0; } m_doc.clear(); return 1; }
bool CJpegIO::Open(const CStdString &texturePath, unsigned int minx, unsigned int miny, bool read) { Close(); m_texturePath = texturePath; XFILE::CFile file; XFILE::auto_buffer buf; if (file.LoadFile(texturePath, buf) <= 0) return false; m_inputBuffSize = buf.size(); m_inputBuff = (unsigned char*)buf.detach(); return Read(m_inputBuff, m_inputBuffSize, minx, miny); }
const CTextureArray& CGUITextureManager::Load(const std::string& strTextureName, bool checkBundleOnly /*= false */) { std::string strPath; static CTextureArray emptyTexture; int bundle = -1; int size = 0; if (!HasTexture(strTextureName, &strPath, &bundle, &size)) return emptyTexture; if (size) // we found the texture { for (int i = 0; i < (int)m_vecTextures.size(); ++i) { CTextureMap *pMap = m_vecTextures[i]; if (pMap->GetName() == strTextureName) { //CLog::Log(LOGDEBUG, "Total memusage %u", GetMemoryUsage()); return pMap->GetTexture(); } } // Whoops, not there. return emptyTexture; } for (ilistUnused i = m_unusedTextures.begin(); i != m_unusedTextures.end(); ++i) { CTextureMap* pMap = i->first; if (pMap->GetName() == strTextureName && i->second > 0) { m_vecTextures.push_back(pMap); m_unusedTextures.erase(i); return pMap->GetTexture(); } } if (checkBundleOnly && bundle == -1) return emptyTexture; //Lock here, we will do stuff that could break rendering CSingleLock lock(g_graphicsContext); #ifdef _DEBUG_TEXTURES int64_t start; start = CurrentHostCounter(); #endif if (bundle >= 0 && StringUtils::EndsWithNoCase(strPath, ".gif")) { CTextureMap* pMap = nullptr; CBaseTexture **pTextures = nullptr; int nLoops = 0, width = 0, height = 0; int* Delay = nullptr; int nImages = m_TexBundle[bundle].LoadAnim(strTextureName, &pTextures, width, height, nLoops, &Delay); if (!nImages) { CLog::Log(LOGERROR, "Texture manager unable to load bundled file: %s", strTextureName.c_str()); delete[] pTextures; delete[] Delay; return emptyTexture; } unsigned int maxWidth = 0; unsigned int maxHeight = 0; pMap = new CTextureMap(strTextureName, width, height, nLoops); for (int iImage = 0; iImage < nImages; ++iImage) { pMap->Add(pTextures[iImage], Delay[iImage]); maxWidth = std::max(maxWidth, pTextures[iImage]->GetWidth()); maxHeight = std::max(maxHeight, pTextures[iImage]->GetHeight()); } pMap->SetWidth((int)maxWidth); pMap->SetHeight((int)maxHeight); delete[] pTextures; delete[] Delay; if (pMap) { m_vecTextures.push_back(pMap); return pMap->GetTexture(); } } else if (StringUtils::EndsWithNoCase(strPath, ".gif") || StringUtils::EndsWithNoCase(strPath, ".apng")) { CTextureMap* pMap = nullptr; std::string mimeType; if (StringUtils::EndsWithNoCase(strPath, ".gif")) mimeType = "image/gif"; else if (StringUtils::EndsWithNoCase(strPath, ".apng")) mimeType = "image/apng"; XFILE::CFile file; XFILE::auto_buffer buf; CFFmpegImage anim(mimeType); pMap = new CTextureMap(strTextureName, 0, 0, 0); if (file.LoadFile(strPath, buf) <= 0 || !anim.Initialize((uint8_t*)buf.get(), buf.size()) || !pMap) { CLog::Log(LOGERROR, "Texture manager unable to load file: %s", CURL::GetRedacted(strPath).c_str()); file.Close(); return emptyTexture; } unsigned int maxWidth = 0; unsigned int maxHeight = 0; uint64_t maxMemoryUsage = 91238400;// 1920*1080*4*11 bytes, i.e, a total of approx. 12 full hd frames auto frame = anim.ReadFrame(); while (frame) { CTexture *glTexture = new CTexture(); if (glTexture) { glTexture->LoadFromMemory(anim.Width(), anim.Height(), frame->GetPitch(), XB_FMT_A8R8G8B8, true, frame->m_pImage); pMap->Add(glTexture, frame->m_delay); maxWidth = std::max(maxWidth, glTexture->GetWidth()); maxHeight = std::max(maxHeight, glTexture->GetHeight()); } if (pMap->GetMemoryUsage() <= maxMemoryUsage) { frame = anim.ReadFrame(); } else { CLog::Log(LOGDEBUG, "Memory limit (%" PRIu64 " bytes) exceeded, %i frames extracted from file : %s", (maxMemoryUsage/11)*12,pMap->GetTexture().size(), CURL::GetRedacted(strPath).c_str()); break; } } pMap->SetWidth((int)maxWidth); pMap->SetHeight((int)maxHeight); file.Close(); if (pMap) { m_vecTextures.push_back(pMap); return pMap->GetTexture(); } } CBaseTexture *pTexture = NULL; int width = 0, height = 0; if (bundle >= 0) { if (!m_TexBundle[bundle].LoadTexture(strTextureName, &pTexture, width, height)) { CLog::Log(LOGERROR, "Texture manager unable to load bundled file: %s", strTextureName.c_str()); return emptyTexture; } } else { pTexture = CBaseTexture::LoadFromFile(strPath); if (!pTexture) return emptyTexture; width = pTexture->GetWidth(); height = pTexture->GetHeight(); } if (!pTexture) return emptyTexture; CTextureMap* pMap = new CTextureMap(strTextureName, width, height, 0); pMap->Add(pTexture, 100); m_vecTextures.push_back(pMap); #ifdef _DEBUG_TEXTURES int64_t end, freq; end = CurrentHostCounter(); freq = CurrentHostFrequency(); char temp[200]; sprintf(temp, "Load %s: %.1fms%s\n", strPath.c_str(), 1000.f * (end - start) / freq, (bundle >= 0) ? " (bundled)" : ""); OutputDebugString(temp); #endif return pMap->GetTexture(); }