Пример #1
0
int XMLStack::loadXMLFile(const char *xmlFilePath)

{

  const char *verifiedPath = MediaPathManager::lookUpMediaPath(xmlFilePath);

  size_t      pathLength   =    0;

  char       *progress     = 0,

             *stream       = 0;



  bufferProgress = 0;

  bufferSize     = 0;



  flush();

  if(!verifiedPath)

    return (state = XML_FILE_NOT_FOUND);



  pathLength = stx_strlen(verifiedPath);



  for(size_t t = 0; t < pathLength; t++)

  {

    if(verifiedPath[t] == '.')

      break;

    logFilePath += verifiedPath[t];

  }



  logFilePath += ".err";



  state        = XML_SUCCESS;

  std::string fn=stx_convertpath(verifiedPath);

  LOG_PRINT("XMLStack::loadXMLFile:ifstream=%s\n", fn.c_str());

  ifstream fileInputStream(fn.c_str(), ifstream::in | ifstream::binary);

  fileInputStream.seekg(0, ios::end);



  bufferSize  = fileInputStream.tellg();

  stream      = new char[bufferSize + 1];

  progress    =  stream;



  memset(stream, 0, bufferSize + 1);

  fileInputStream.seekg(0, ios::beg);

  fileInputStream.read(stream, bufferSize);

  fileInputStream.close();



  do

  {

    XMLElement *parent = new XMLElement();

    progress = parseXMLStream(progress, parent);

    addChild(parent);

  }

  while(*progress && (state == XML_SUCCESS));





  deleteArray(stream);

  if(state != XML_SUCCESS)

  {

    flush();

    NatureScene::Logger::writeErrorLog(NSString("Failed to parse the XML File at <") +

                                 verifiedPath + ">");

	return -1;//???

  }

  return XML_SUCCESS;

}
void FileTransferRequestHandler::md5Requested()
{
  WinFilePath fullPathName;

  UINT64 offset;
  UINT64 dataLen;

  {
    m_input->readUTF8(&fullPathName);

    offset = m_input->readUInt64();
    dataLen = m_input->readUInt64();
  } // end of reading block.

  m_log->message(_T("md5 \"%s\" %d %d command requested"), fullPathName.getString(), offset, dataLen);

  checkAccess();

  //
  // Action
  //

  MD5 md5calculator;

  File file(fullPathName.getString());

  StringStorage path;
  file.getPath(&path);
  WinFileChannel fileInputStream(path.getString(), F_READ, FM_OPEN);
  fileInputStream.seek(offset);

  //
  // Begin reading needed file data
  //

  DWORD bytesToRead = 1024 * 1024;
  UINT64 bytesToReadTotal = dataLen;
  size_t bytesRead = 0;
  UINT64 bytesReadTotal = 0;

  if (dataLen < (UINT64)bytesToRead) {
    bytesToRead = (DWORD)dataLen;
  }

  std::vector<UINT8> buffer(bytesToRead);

  while (bytesToReadTotal > 0) {
    bytesRead = fileInputStream.read(&buffer.front(), bytesToRead);
    bytesReadTotal += bytesRead;
    bytesToReadTotal -= bytesRead;

    if (bytesToReadTotal < (UINT64)bytesToRead) {
      bytesToRead = (DWORD)bytesToReadTotal;
    }

    md5calculator.update(&buffer.front(), (UINT32)bytesRead);
  } // while

  md5calculator.finalize();

  {
    AutoLock l(m_output);

    m_output->writeUInt32(FTMessage::MD5_REPLY);
    m_output->writeFully((const char *)md5calculator.getHash(), 16);

    m_output->flush();
  }
}