Пример #1
0
StreamReader* AssetArchive::open(const String& givenStreamName)
{
	String streamName = givenStreamName;

	AAsset* assetPeer = openAsset(streamName);
	if (assetPeer == NULL)
		return Archive::open(streamName);

	Ref<Asset> asset = new Asset(this, streamName);
	return asset->openWith(assetPeer);
}
Пример #2
0
StreamSource* AssetArchive::locateLocal(const String& givenStreamName)
{
	String streamName = givenStreamName;

	// HACK: There's no something like AAssetDir_exist(), so try to open and then close at once
	AAsset* assetPeer = openAsset(streamName);
	if (assetPeer == NULL)
		return NULL;

	AAsset_close(assetPeer);

	return new Asset(this, streamName);
}
Пример #3
0
bithorded::UpstreamRequestBinding::Ptr bithorded::AssetSessions::findAsset(const bithorde::BindRead& req)
{
	auto tigerId = findBithordeId(req.ids(), bithorde::HashType::TREE_TIGER);
	if (tigerId.empty())
		return UpstreamRequestBinding::Ptr();
	if (auto active = _tigerCache[tigerId])
		return active;

	UpstreamRequestBinding::Ptr res;
	if (auto asset = openAsset(req)) {
		res = boost::make_shared<UpstreamRequestBinding>(asset);
		add(tigerId, res);
	}
	return res;
}
Пример #4
0
bool JniJSModulesUnbundle::isUnbundle(
    AAssetManager *assetManager,
    const std::string& assetName) {
  if (!assetManager) {
    return false;
  }

  auto magicFileName = jsModulesDir(assetName) + MAGIC_FILE_NAME;
  auto asset = openAsset(assetManager, magicFileName.c_str());
  if (asset == nullptr) {
    return false;
  }

  magic_number_t fileHeader = 0;
  AAsset_read(asset.get(), &fileHeader, sizeof(fileHeader));
  return fileHeader == htole32(MAGIC_FILE_HEADER);
}
Пример #5
0
JSModulesUnbundle::Module JniJSModulesUnbundle::getModule(uint32_t moduleId) const {
  // can be nullptr for default constructor.
  FBASSERTMSGF(m_assetManager != nullptr, "Unbundle has not been initialized with an asset manager");

  std::ostringstream sourceUrlBuilder;
  sourceUrlBuilder << moduleId << ".js";
  auto sourceUrl = sourceUrlBuilder.str();

  auto fileName = m_moduleDirectory + sourceUrl;
  auto asset = openAsset(m_assetManager, fileName, AASSET_MODE_BUFFER);

  const char *buffer = nullptr;
  if (asset != nullptr) {
    buffer = static_cast<const char *>(AAsset_getBuffer(asset.get()));
  }
  if (buffer == nullptr) {
    throw ModuleNotFound(moduleId);
  }
  return {sourceUrl, std::string(buffer, AAsset_getLength(asset.get()))};
}