int CXbtFile::Stat(const CURL& url, struct __stat64* buffer) { memset(buffer, 0, sizeof(struct __stat64)); // check if the file exists CXBTFReaderPtr reader; CXBTFFile file; if (!GetReaderAndFile(url, reader, file)) { // check if the URL points to the XBT file itself if (!url.GetFileName().empty() || !CFile::Exists(url.GetHostName())) return -1; // stat the XBT file itself if (XFILE::CFile::Stat(url.GetHostName(), buffer) != 0) return -1; buffer->st_mode = _S_IFDIR; return 0; } // stat the XBT file itself if (XFILE::CFile::Stat(url.GetHostName(), buffer) != 0) return -1; buffer->st_size = file.GetUnpackedSize(); return 0; }
void CreateSkeletonHeaderImpl(CXBTFWriter& xbtfWriter, std::string fullPath, std::string relativePath) { struct dirent* dp; struct stat stat_p; DIR *dirp = opendir(fullPath.c_str()); if (dirp) { while ((dp = readdir(dirp)) != NULL) { if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) { continue; } //stat to check for dir type (reiserfs fix) std::string fileN = fullPath + "/" + dp->d_name; if (stat(fileN.c_str(), &stat_p) == 0) { if (dp->d_type == DT_DIR || stat_p.st_mode & S_IFDIR) { std::string tmpPath = relativePath; if (tmpPath.size() > 0) { tmpPath += "/"; } CreateSkeletonHeaderImpl(xbtfWriter, fullPath + DIR_SEPARATOR + dp->d_name, tmpPath + dp->d_name); } else if (DecoderManager::IsSupportedGraphicsFile(dp->d_name)) { std::string fileName = ""; if (relativePath.size() > 0) { fileName += relativePath; fileName += "/"; } fileName += dp->d_name; CXBTFFile file; file.SetPath(fileName); xbtfWriter.AddFile(file); } } } closedir(dirp); } else { fprintf(stderr, "Error opening %s (%s)\n", fullPath.c_str(), strerror(errno)); } }
int CTextureBundleXBT::LoadAnim(const CStdString& Filename, CBaseTexture*** ppTextures, int &width, int &height, int& nLoops, int** ppDelays) { CStdString name = Normalize(Filename); CXBTFFile* file = m_XBTFReader.Find(name); if (!file) return false; if (file->GetFrames().size() == 0) return false; size_t nTextures = file->GetFrames().size(); *ppTextures = new CBaseTexture*[nTextures]; *ppDelays = new int[nTextures]; for (size_t i = 0; i < nTextures; i++) { CXBTFFrame& frame = file->GetFrames().at(i); if (!ConvertFrameToTexture(Filename, frame, &((*ppTextures)[i]))) { return false; } (*ppDelays)[i] = frame.GetDuration(); } width = file->GetFrames().at(0).GetWidth(); height = file->GetFrames().at(0).GetHeight(); nLoops = file->GetLoop(); return nTextures; }
bool CTextureBundleXBT::LoadTexture(const CStdString& Filename, CBaseTexture** ppTexture, int &width, int &height) { CStdString name = Normalize(Filename); CXBTFFile* file = m_XBTFReader.Find(name); if (!file) return false; if (file->GetFrames().size() == 0) return false; CXBTFFrame& frame = file->GetFrames().at(0); if (!ConvertFrameToTexture(Filename, frame, ppTexture)) { return false; } width = frame.GetWidth(); height = frame.GetHeight(); return true; }
bool CTextureBundleXBT::LoadTexture(const std::string& Filename, CBaseTexture** ppTexture, int &width, int &height) { std::string name = Normalize(Filename); CXBTFFile file; if (!m_XBTFReader->Get(name, file)) return false; if (file.GetFrames().empty()) return false; CXBTFFrame& frame = file.GetFrames().at(0); if (!ConvertFrameToTexture(Filename, frame, ppTexture)) { return false; } width = frame.GetWidth(); height = frame.GetHeight(); return true; }
bool CXBTFReader::Open(const std::string& path) { if (path.empty()) return false; m_path = path; #ifdef TARGET_WINDOWS std::wstring strPathW; g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(m_path), strPathW, false); m_file = _wfopen(strPathW.c_str(), L"rb"); #else m_file = fopen(m_path.c_str(), "rb"); #endif if (m_file == nullptr) return false; // read the magic word char magic[4]; if (!ReadString(m_file, magic, sizeof(magic))) return false; if (strncmp(XBTF_MAGIC.c_str(), magic, sizeof(magic)) != 0) return false; // read the version char version[1]; if (!ReadString(m_file, version, sizeof(version))) return false; if (strncmp(XBTF_VERSION.c_str(), version, sizeof(version)) != 0) return false; unsigned int nofFiles; if (!ReadUInt32(m_file, nofFiles)) return false; for (uint32_t i = 0; i < nofFiles; i++) { CXBTFFile xbtfFile; uint32_t u32; uint64_t u64; char path[CXBTFFile::MaximumPathLength]; memset(path, 0, sizeof(path)); if (!ReadString(m_file, path, sizeof(path))) return false; xbtfFile.SetPath(path); if (!ReadUInt32(m_file, u32)) return false; xbtfFile.SetLoop(u32); unsigned int nofFrames; if (!ReadUInt32(m_file, nofFrames)) return false; for (uint32_t j = 0; j < nofFrames; j++) { CXBTFFrame frame; if (!ReadUInt32(m_file, u32)) return false; frame.SetWidth(u32); if (!ReadUInt32(m_file, u32)) return false; frame.SetHeight(u32); if (!ReadUInt32(m_file, u32)) return false; frame.SetFormat(u32); if (!ReadUInt64(m_file, u64)) return false; frame.SetPackedSize(u64); if (!ReadUInt64(m_file, u64)) return false; frame.SetUnpackedSize(u64); if (!ReadUInt32(m_file, u32)) return false; frame.SetDuration(u32); if (!ReadUInt64(m_file, u64)) return false; frame.SetOffset(u64); xbtfFile.GetFrames().push_back(frame); } AddFile(xbtfFile); } // Sanity check uint64_t pos = static_cast<uint64_t>(ftell(m_file)); if (pos != GetHeaderSize()) return false; return true; }
bool CXBTFReader::Open(const std::string& fileName) { m_fileName = fileName; #ifdef TARGET_WINDOWS std::wstring strPathW; g_charsetConverter.utf8ToW(CSpecialProtocol::TranslatePath(m_fileName), strPathW, false); m_file = _wfopen(strPathW.c_str(), L"rb"); #else m_file = fopen(m_fileName.c_str(), "rb"); #endif if (m_file == NULL) { return false; } char magic[4]; READ_STR(magic, 4, m_file); if (strncmp(magic, XBTF_MAGIC, sizeof(magic)) != 0) { return false; } char version[1]; READ_STR(version, 1, m_file); if (strncmp(version, XBTF_VERSION, sizeof(version)) != 0) { return false; } unsigned int nofFiles; READ_U32(nofFiles, m_file); for (unsigned int i = 0; i < nofFiles; i++) { CXBTFFile file; unsigned int u32; uint64_t u64; READ_STR(file.GetPath(), 256, m_file); READ_U32(u32, m_file); file.SetLoop(u32); unsigned int nofFrames; READ_U32(nofFrames, m_file); for (unsigned int j = 0; j < nofFrames; j++) { CXBTFFrame frame; READ_U32(u32, m_file); frame.SetWidth(u32); READ_U32(u32, m_file); frame.SetHeight(u32); READ_U32(u32, m_file); frame.SetFormat(u32); READ_U64(u64, m_file); frame.SetPackedSize(u64); READ_U64(u64, m_file); frame.SetUnpackedSize(u64); READ_U32(u32, m_file); frame.SetDuration(u32); READ_U64(u64, m_file); frame.SetOffset(u64); file.GetFrames().push_back(frame); } m_xbtf.GetFiles().push_back(file); m_filesMap[file.GetPath()] = file; } // Sanity check int64_t pos = ftell(m_file); if (pos != (int64_t)m_xbtf.GetHeaderSize()) { printf("Expected header size (%" PRId64") != actual size (%" PRId64")\n", m_xbtf.GetHeaderSize(), pos); return false; } return true; }