Ejemplo n.º 1
0
Downloader::Downloader(const string *url, bool post, const string *postData, bool async, bool callbackImmediately, DownloadCallback callback,
                       void *callbackArg, const map<string, string> *headers)
{
    init();

    downloadURL(url, post, postData, async, callbackImmediately, callback, callbackArg, headers);

}
Ejemplo n.º 2
0
ofxSimpleHttpResponse ofxSimpleHttp::fetchURLBlocking(string  url){

	response.url = url;
	response.downloadCanceled = false;
	response.fileName = extractFileFromUrl(url);
	response.extension = extractExtensionFromFileName(response.fileName);
	response.notifyOnSuccess = true;
	bool ok = downloadURL(&response,
						  false/*send res through events*/,
						  true/*beingCalledFromMainThread*/,
						  false/*to disk*/
						  );
	return response;
}
Ejemplo n.º 3
0
InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
{
	if (isMeta())
	{
		MinecraftVersion *version = new MinecraftVersion((MinecraftVersion *)m_linkedVersion);
		return version;
	}
	else
	{
		MinecraftVersion *version = new MinecraftVersion(
					descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
		version->setVersionType(versionType());
		version->setIsForNewLauncher(isForNewLauncher());
		return version;
	}
}
Ejemplo n.º 4
0
void *downloadSingleURL(void *x)
{
	struct thread_args* args = (struct thread_args*)x;
	zlog_info(c, "Downloading Single URL");
	if(args->callback == NULL){
		zlog_info(c, "Abort - callback function was null\n");
		return (void*)0;
	}


	unsigned int self = (unsigned int)pthread_self();

	args->callback(1, "[%u] In Thread loop\n", self);
	CURL *curl;
	curl = curl_easy_init();
	if (!curl) {
		args->callback(1, "Exiting... Curl didn't seem to init correctly\n");
		return (void*)0;
	}
	args->callback(1, "[After init] In Thread loop\n");
	if (args->queue == NULL) {
		args->callback(1, "Queue was null...");
	}
	;
	args->callback(1, "[%u] Starting up thread while()..\n", self);
	int tries = 3;
	while (tries > 0) {
		while (QSize(args->queue) > 0) {
			if(tries == 1){
				tries++;
			}
				downloadURL(lock, args, self, curl);

			int _sz = QSize(args->queue);
			args->callback(1, "[Thread %u] Computing size ", self);
			args->callback(1, "[Thread %u] Iteration Complete [%d] ", _sz, self);
			//free(response_string.ptr);
		}
		tries--;
		sleep(1);
		args->callback(1, "[%u] Loop end... tries are now %d", self, tries);
	}
	args->callback(1, "[Thread %u] Complete and exiting (errors=%d)... ", self, args->error_code);
	curl_easy_cleanup(curl);
	return (void*)0;

}
Ejemplo n.º 5
0
void ofxSimpleHttp::threadedFunction(){

	#ifdef TARGET_OSX
	pthread_setname_np("ofxSimpleHttp");
	#endif

	ofLogVerbose("ofxSimpleHttp", "start threadedFunction");
	queueLenEstimation = 0;

	lock();
	queueLenEstimation = q.size();

	while( queueLenEstimation > 0 && timeToStop == false && isThreadRunning()){

			ofxSimpleHttpResponse * r = q.front();

		unlock();
			downloadURL(	r,		/*response*/
							true,	/*sendResultThroughEvents*/
							false,	/*calling from main thread*/
							r->downloadToDisk
						);
		lock();
			q.pop();
			if(r->emptyWholeQueue){
				queue<ofxSimpleHttpResponse*> tempQ;
				q = tempQ;
			}
			delete r;
			queueLenEstimation = q.size();
	}

	unlock();

	//if no more pending requests, let the thread die...
	ofLogVerbose("ofxSimpleHttp", "exiting threadedFunction (queue len %d)", queueLenEstimation);

	#if  defined(TARGET_OSX) || defined(TARGET_LINUX) /*I'm not 100% sure of linux*/
	if (!timeToStop){ //if we are naturally exiting the thread; if TimeToStop==true it means we are being destructed, and the thread will be joined (so no need to detach!)
		pthread_detach( pthread_self() ); //this is a workaround for this issue https://github.com/openframeworks/openFrameworks/issues/2506
	}
	#endif
}
Ejemplo n.º 6
0
    void SelfUpdater::downloadNewVersion()
    {
        qDebug() << "SelfUpdater::downloadNewVersion";

        QString downloadURL(versionInfo["url"].toString());

        QNetworkRequest request(downloadURL);

        downloadManager.setDownloadFolder(downloadFolder);
        downloadManager.setDownloadMode(Downloader::DownloadItem::DownloadMode::SkipIfExists);
        downloadManager.setQueueMode(Downloader::DownloadManager::QueueMode::Serial);
        downloadManager.get(request);

        Downloader::TransferItem *transfer = downloadManager.findTransfer(downloadURL);
        connect(transfer, SIGNAL(transferFinished(Downloader::TransferItem*)), this, SLOT(extract()));

        // finally: invoke downloading
        QMetaObject::invokeMethod(&downloadManager, "checkForAllDone", Qt::QueuedConnection);
    }
Ejemplo n.º 7
0
ofxSimpleHttpResponse ofxSimpleHttp::fetchURLtoDiskBlocking(string  url, string dirWhereToSave){

	string savePath = dirWhereToSave == "" ? extractFileFromUrl(url) : ofToDataPath(dirWhereToSave) + "/" + extractFileFromUrl(url);

	ofDirectory d;
	d.createDirectory(dirWhereToSave, true, true); //create the download dir first

	response.absolutePath = savePath;
	response.url = url;
	response.downloadCanceled = false;
	response.fileName = extractFileFromUrl(url);
	response.extension = extractExtensionFromFileName(response.fileName);
	response.notifyOnSuccess = true;
	response.downloadToDisk = true;
	bool ok = downloadURL(&response,
						  false,/*send result through events*/
						  true, /*beingCalledFromMainThread*/
						  true/*to disk*/
						  );
	return response;
}