Exemplo n.º 1
0
/**
 * @return true if the {@code crc} is 0, or matches the computed CRC of the file
 */
bool CheckSignature(const vfs::Path &filePath, const Signature crc) {
  Trace("Checking signature matches [" << crc << "] for file " << filePath.str());
  vfs::ifstream infile(filePath, std::ios::binary | std::ios::in);
  if (!infile.is_open()) {
    return false;
  }
  const Signature downloadCrc = core::hash::CRC32(
                                  std::istreambuf_iterator<char>(infile.rdbuf()),
                                  std::istreambuf_iterator<char>());
  Trace("Crc was: " << downloadCrc);
  return (crc == 0 || crc == downloadCrc);
}
Exemplo n.º 2
0
/**
 * Downloads a single file from the specified server.
 */
bool GetOneFile(
  const launcher::Settings &settings,
  const std::string &filename, const Signature crc) {

  Trace("Attempting to download " << filename);

  core::net::NetClient client(core::net::eConnectionMode::TCP_ASYNC);
  std::string hostName;
  for (auto server = settings.get_patch_server_begin(); server != settings.get_patch_server_end(); ++server) {
    client.start(settings.get_patch_server(0));
    if (client.valid()) {
      hostName = wrappers::net::http::Uri(server->get_dns_name()).getHost();
      break;
    }
  }

  if (!client.valid()) {
    Log(LL::Error) << "Unable to connect to any servers." << std::endl;
    return false;
  }

  wrappers::net::http::HttpHeader header = wrappers::net::http::HttpHeader::Builder()
      .setRequestType(wrappers::net::http::HttpHeader::eRequestType::HTTP_REQUEST_GET)
      .setRequestPath(std::string("/") + settings.get_server_patch_dir() + filename)
      .addHeader("host", hostName)
      .build();

  if (!header.valid()) {
    return false;
  }
  client.send(header.asBlob());

  const vfs::Path outputPath = GetOutputPath(filename);
  vfs::ofstream outfile(outputPath, std::ios::binary | std::ios::out);
  if (!outfile.is_open()) {
    Log(LL::Error) << "Unable to open file: " << outputPath.str() << std::endl;
    return false;
  }
  wrappers::net::http::HttpFileHandler fileHandler(outfile);
  while (client.valid() && !fileHandler.done()) {
    client.update(fileHandler);
    core::thread::thisthread::yield();
  }
  client.stop();
  outfile.flush();

  if (!fileHandler.success()) {
    return false;
  }

  return CheckSignature(outputPath, crc);
}
Exemplo n.º 3
0
iResourceLoader::eLoadState::type FontFromFile::postload() {
  if (m_fontDef.get_texture_size() == 0) {
    Log(LL::Error) << "Font has no textures in it." << std::endl;
    return eLoadState::LOAD_FAILURE;
  }

  // Load material
  if (!m_material.getHandle().isValid()) {
    MaterialDef::Builder materialBuilder;

    // Create temp textures
    for (u32 i = 0; i < m_fontDef.get_texture_size(); ++i) {
      const vfs::Path filename = vfs::Path("memfile/")
                                 + vfs::Path(vfs::Path(m_fontDef.get_texture(i).get_filename()).file());
      const std::string &data = m_fontDef.get_texture(i).get_image_data();

      vfs::getStaticMemFileSystem()->create(filename, core::memory::ConstBlob((const u8 *) data.data(), data.size()));
      materialBuilder.add_textures(filename.str());
    }

    if (m_fontDef.get_texture(0).get_is_distancefield()) {
      materialBuilder.set_alpha_test(fsengine::render::eAlphaTestMode::ALPHA_TEST_GEQUAL);
      materialBuilder.set_alpha_cutoff(0.5f);
      materialBuilder.set_blend_mode(fsengine::render::eBlendMode::BLEND_NONE);
      materialBuilder.set_name("font");
      materialBuilder.set_shader("data/shaders/tex0cutoffcolor");
    } else {
      materialBuilder.set_blend_mode(fsengine::render::eBlendMode::BLEND_NORMAL);
      materialBuilder.set_name("font");
      materialBuilder.set_shader("data/shaders/tex0color");
    }

    {
      const MaterialDef materialDef = materialBuilder.build();
      const vfs::Path filename = vfs::Path("memfile/")
                                 + vfs::Path(vfs::Path(m_id + "_mat").file());
      const size_t sz = materialDef.byte_size();
      m_materialData.resize(sz, ' ');
      core::memory::Blob blob((u8 *) &m_materialData[0], sz);
      core::base::BlobSink sink(blob);
      sink << materialBuilder.build();
      vfs::getStaticMemFileSystem()->create(filename, core::memory::ConstBlob((const u8 *) m_materialData.data(), m_materialData.size()));
      m_material = m_pLoader->asyncLoadResource<Material, MaterialFromFile>(filename.str());
    }
  }

  if (!m_material) {
    if (m_material.getManager()->isValidOrLocked(m_material.getHandle())) {
      return eLoadState::LOAD_DEPENDENCY;
    } else {
      return eLoadState::LOAD_FAILURE;
    }
  }

  // Create font
  if (!m_pResource->loadFromDef(m_fontDef)) {
    return eLoadState::LOAD_FAILURE;
  }

  // cleanup
  for (u32 i = 0; i < m_fontDef.get_texture_size(); ++i) {
    m_pResource->setTexture(i, m_material->m_pTexture[i]);

    const vfs::Path filename = vfs::Path("memfile/")
                               + vfs::Path(vfs::Path(m_fontDef.get_texture(i).get_filename()).file());
    vfs::util::Remove(filename);
  }
  const vfs::Path filename = vfs::Path("memfile/")
                             + vfs::Path(vfs::Path(m_id + "_mat").file());
  vfs::util::Remove(filename);

  m_pResource->setMaterial(m_material);

  return eLoadState::LOAD_SUCCESS;
}