Пример #1
0
void FileNameHandler::finishedDownload(const NameLookupHandler::Callback &cb,
	const std::string &filename, DenseDataPtr data, bool success)
{
	bool exists = false;
	RemoteFileId foundURI;
	if (success) {
		for (const unsigned char *iter = data->begin(); iter != data->end();) {
			const unsigned char *newlinepos = std::find(iter, data->end(), '\n');
			if (newlinepos == data->end()) {
				break;
			}
			const unsigned char *spacepos = std::find(iter, newlinepos, ' ');
			if (std::string(iter, spacepos) != filename) {
				iter = newlinepos + 1;
				continue;
			}
			if (spacepos == newlinepos || spacepos + 1 == newlinepos) {
				// the name does not exist.
				exists = false;
			} else {
				exists = true;
				foundURI = RemoteFileId(URI(std::string(spacepos+1, newlinepos)));
			}
			iter = newlinepos + 1;
		}
	}
	if (exists) {
		cb(foundURI.fingerprint(), foundURI.uri().toString(), true);
	} else {
		cb(Fingerprint::null(), std::string(), false);
	}
}
Пример #2
0
SharedResourcePtr GraphicsResourceManager::getResourceAsset(const URI &id, GraphicsResource::Type resourceType)
{
  WeakResourcePtr curWeakPtr;
  SharedResourcePtr curSharedPtr;
  if (ResourceManager::getSingleton().isMHashScheme(id)) {
    try {
      curWeakPtr = getResource(RemoteFileId(id).fingerprint().convertToHexString());
      curSharedPtr = curWeakPtr.lock();
    } catch (std::invalid_argument &ia) {
    }
  }
  if (!curSharedPtr) {
    curWeakPtr = getResource(id.toString());
    curSharedPtr = curWeakPtr.lock();
  }
  if (curSharedPtr)
    return curSharedPtr;
  else {
    try {
      if (ResourceManager::getSingleton().isMHashScheme(id)) {
        // std::invalid_argument may be thrown, but is caught by the "catch" below.
        RemoteFileId resourceId(id);
        if (resourceType == GraphicsResource::MESH) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceMesh>(resourceId);
        }
        else if (resourceType == GraphicsResource::MATERIAL) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceMaterial>(resourceId);
        }
        else if (resourceType == GraphicsResource::TEXTURE) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceTexture>(resourceId);
        }
        else if (resourceType == GraphicsResource::SHADER) {
          curSharedPtr = GraphicsResource::construct<GraphicsResourceShader>(resourceId);
        }
        else {
          assert(false);
        }
      }
      else {
        curSharedPtr = GraphicsResource::construct<GraphicsResourceName>(id, resourceType);
      }

      mIDResourceMap[curSharedPtr->getID()] = curSharedPtr;
      mResources.insert(curSharedPtr.get());
    }
    catch (std::invalid_argument& exc) {

    }

    return curSharedPtr;
  }
}
Пример #3
0
	void hashedDownload(const Callback &cb, const URI &origNamedUri, ServiceIterator *iter) {
		ServiceParams params;
		URI uri(origNamedUri);

		RemoteFileId rfid;
		bool success = false;
		if (iter->tryNext(ServiceIterator::SUCCESS,uri,params)) {
			delete iter;
			try {
        			rfid = RemoteFileId(origNamedUri);
        			success = true;
			} catch (std::invalid_argument &) {
				SILOG(transfer,error,"Received an exception when trying to parse hash URI " <<
				    origNamedUri);
			}
		}
		cb(origNamedUri, success ? &rfid : NULL);
	}
Пример #4
0
	virtual void download(const URI &name, const EventListener &listener, const Range &range) {
		listener(DownloadEventPtr(new DownloadEvent(FAIL_UNIMPLEMENTED, RemoteFileId(), NULL)));
	}