Esempio n. 1
0
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;
}
Esempio n. 2
0
bool CXBMCTinyXML::LoadFile(const std::string& _filename, TiXmlEncoding encoding)
{
  value = _filename.c_str();

  XFILE::CFile file;
  XFILE::auto_buffer buffer;

  if (file.LoadFile(value, buffer) <= 0)
  {
    SetError(TIXML_ERROR_OPENING_FILE, NULL, NULL, TIXML_ENCODING_UNKNOWN);
    return false;
  }

  // Delete the existing data:
  Clear();
  location.Clear();

  std::string data(buffer.get(), buffer.length());
  buffer.clear(); // free memory early

  if (encoding == TIXML_ENCODING_UNKNOWN)
    Parse(data, file.GetContentCharset());
  else
    Parse(data, encoding);

  if (Error())
    return false;
  return true;
}