int QueueFileUtils::compareFiles(const QueueItemPtr& a, const QueueItemPtr& b, int aPropertyName) noexcept {
		switch (aPropertyName) {
		case PROP_NAME: {
			return Util::pathSort(a->getTarget(), b->getTarget());
		}
		case PROP_TYPE: {
			return Util::stricmp(Util::getFileExt(a->getTarget()), Util::getFileExt(b->getTarget()));
		}
		case PROP_PRIORITY: {
			COMPARE_FINISHED(a, b);

			return compare(static_cast<int>(a->getPriority()), static_cast<int>(b->getPriority()));
		}
		case PROP_STATUS: {
			COMPARE_FINISHED(a, b);
			return compare(
				a->getPercentage(QueueManager::getInstance()->getDownloadedBytes(a)), 
				b->getPercentage(QueueManager::getInstance()->getDownloadedBytes(b))
			);
		}
		case PROP_SOURCES: {
			COMPARE_FINISHED(a, b);

			auto countsA = QueueManager::getInstance()->getSourceCount(a);
			auto countsB = QueueManager::getInstance()->getSourceCount(b);

			return QueueItemBase::SourceCount::compare(countsA, countsB);
		}
		default:
			dcassert(0);
		}

		return 0;
	}
	string QueueFileUtils::getDisplayName(const QueueItemPtr& aItem) noexcept {
		if (aItem->getBundle() && !aItem->getBundle()->isFileBundle()) {
			return aItem->getTarget().substr(aItem->getBundle()->getTarget().size(), aItem->getTarget().size());
		}

		return aItem->getTargetFileName();
	}
Beispiel #3
0
	void ViewFileManager::on(QueueManagerListener::ItemAdded, const QueueItemPtr& aQI) noexcept {
		if (!isViewedItem(aQI)) {
			return;
		}

		auto file = createFile(aQI->getTarget(), aQI->getTTH(), aQI->isSet(QueueItem::FLAG_TEXT), false);
		if (file) {
			file->onAddedQueue(aQI->getTarget(), aQI->getSize());
		}
	}
	std::string QueueFileUtils::getStringInfo(const QueueItemPtr& aItem, int aPropertyName) noexcept {
		switch (aPropertyName) {
		case PROP_NAME: return getDisplayName(aItem);
		case PROP_TARGET: return aItem->getTarget();
		case PROP_TYPE: return Format::formatFileType(aItem->getTarget());
		case PROP_STATUS: return formatDisplayStatus(aItem);
		case PROP_PRIORITY: return AirUtil::getPrioText(aItem->getPriority());
		case PROP_SOURCES: return formatFileSources(aItem);
		case PROP_TTH: return aItem->getTTH().toBase32();
		default: dcassert(0); return Util::emptyString;
		}
	}
Beispiel #5
0
void BundleQueue::removeBundleItem(QueueItemPtr& aQI, bool aDownloadFinished) noexcept {
	dcassert(aQI->getBundle());
	aQI->getBundle()->removeQueue(aQI, aDownloadFinished);

	if (!aQI->getBundle()->isFileBundle()) {
		forEachPath(aQI->getBundle(), aQI->getTarget(), [&](PathInfo& aInfo) {
			if (aQI->isDownloaded()) {
				aInfo.finishedFiles--;
			} else {
				aInfo.queuedFiles--;
			}

			if (!aDownloadFinished) {
				aInfo.size -= aQI->getSize();
			}

#ifdef _DEBUG
			if (aInfo.queuedFiles == 0 && aInfo.finishedFiles == 0) {
				dcassert(aInfo.size == 0);
			}

			dcassert(aInfo.size >= 0 && aInfo.finishedFiles >= 0 && aInfo.queuedFiles >= 0);
#endif
		});
	}

	if (aDownloadFinished || !aQI->isDownloaded()) {
		queueSize -= aQI->getSize();
		dcassert(queueSize >= 0);
	}
}
	json QueueFileUtils::serializeFileProperty(const QueueItemPtr& aFile, int aPropertyName) noexcept {
		switch (aPropertyName) {
		case PROP_SOURCES:
		{
			auto c = QueueManager::getInstance()->getSourceCount(aFile);
			return Serializer::serializeSourceCount(c);
		}

		case PROP_STATUS:
		{
			return {
				{ "finished", aFile->isSet(QueueItem::FLAG_FINISHED) },
				{ "str", formatDisplayStatus(aFile) },
			};
		}
		case PROP_PRIORITY: {
			return Serializer::serializePriority(*aFile.get());
		}
		case PROP_TYPE:
		{
			return Serializer::serializeFileType(aFile->getTarget());
		}
		}

		dcassert(0);
		return nullptr;
	}
void DirectoryListingManager::on(QueueManagerListener::ItemRemoved, const QueueItemPtr& qi, bool aFinished) noexcept {
	if (!qi->isSet(QueueItem::FLAG_USER_LIST))
		return;

	auto u = qi->getSources()[0].getUser();
	if (qi->isSet(QueueItem::FLAG_DIRECTORY_DOWNLOAD) && !aFinished)
		removeDirectoryDownload(u, qi->getTempTarget(), qi->isSet(QueueItem::FLAG_PARTIAL_LIST));

	if (qi->isSet(QueueItem::FLAG_CLIENT_VIEW)) {
		DirectoryListingPtr dl = nullptr;

		{
			RLock l(cs);
			auto p = viewedLists.find(u);
			if (p == viewedLists.end()) {
				dcassert(0);
				return;
			}

			dl = p->second;
		}

		dl->onListRemovedQueue(qi->getTarget(), qi->getTempTarget(), aFinished);

		bool closing = (dl->getClosing() || !dl->hasCompletedDownloads());
		if (!aFinished && !dl->hasDownloads() && closing) {
			removeList(u);
		}
	}
}
void FileQueue::add(QueueItemPtr& qi) noexcept {
	if (!qi->isSet(QueueItem::FLAG_USER_LIST) && !qi->isSet(QueueItem::FLAG_CLIENT_VIEW) && !qi->isSet(QueueItem::FLAG_FINISHED)) {
		dcassert(qi->getSize() >= 0);
		queueSize += qi->getSize();
	}
	dcassert(queueSize >= 0);
	queue.emplace(const_cast<string*>(&qi->getTarget()), qi);
	tthIndex.emplace(const_cast<TTHValue*>(&qi->getTTH()), qi);
}
Beispiel #9
0
	void ViewFileManager::on(QueueManagerListener::ItemStatusUpdated, const QueueItemPtr& aQI) noexcept {
		if (!isViewedItem(aQI)) {
			return;
		}

		auto file = getFile(aQI->getTTH());
		if (file) {
			file->onProgress(aQI->getTarget(), aQI->getDownloadedBytes());
		}
	}
void DirectoryListingManager::on(QueueManagerListener::ItemAdded, const QueueItemPtr& aQI) noexcept {
	if (!aQI->isSet(QueueItem::FLAG_CLIENT_VIEW) || !aQI->isSet(QueueItem::FLAG_USER_LIST))
		return;

	auto user = aQI->getSources()[0].getUser();
	auto dl = hasList(user);
	if (dl) {
		dl->onAddedQueue(aQI->getTarget());
		return;
	}

	if (!aQI->isSet(QueueItem::FLAG_PARTIAL_LIST)) {
		dl = createList(user, false, aQI->getListName(), false);
	} else {
		dl = createList(user, true, Util::emptyString, false);
	}

	dl->onAddedQueue(aQI->getTarget());
}
Beispiel #11
0
	void ViewFileManager::on(QueueManagerListener::ItemFinished, const QueueItemPtr& aQI, const string&, const HintedUser&, int64_t /*aSpeed*/) noexcept {
		if (!isViewedItem(aQI))
			return;

		auto file = getFile(aQI->getTTH());
		if (file) {
			file->onRemovedQueue(aQI->getTarget(), true);
			fire(ViewFileManagerListener::FileFinished(), file);
		}
	}
pair<QueueItem::StringMap::const_iterator, bool> FileQueue::add(QueueItemPtr& qi) noexcept {
	dcassert(queueSize >= 0);
	auto ret = queue.emplace(const_cast<string*>(&qi->getTarget()), qi);
	if (ret.second) {
		tthIndex.emplace(const_cast<TTHValue*>(&qi->getTTH()), qi);
		if (!qi->isSet(QueueItem::FLAG_USER_LIST) && !qi->isSet(QueueItem::FLAG_CLIENT_VIEW) && !qi->isSet(QueueItem::FLAG_FINISHED)) {
			dcassert(qi->getSize() >= 0);
			queueSize += qi->getSize();
		}
	}
	return ret;
}
void FinishedManager::on(QueueManagerListener::Finished, const QueueItemPtr& qi, const string&, const HintedUser& aUser, int64_t aSpeed) noexcept {
		
	if(!qi->isSet(QueueItem::FLAG_USER_LIST) || SETTING(LOG_FILELIST_TRANSFERS)) {
		
		FinishedItemPtr item = new FinishedItem(qi->getTarget(), aUser, qi->getSize(), static_cast<int64_t>(aSpeed), GET_TIME(), qi->getTTH().toBase32());
		{
			Lock l(cs);
			downloads.push_back(item);
		}
			
		fire(FinishedManagerListener::AddedDl(), item);
		if(SETTING(SYSTEM_SHOW_DOWNLOADS)) {
			size_t BUF_SIZE = STRING(FINISHED_DOWNLOAD).size() + UNC_MAX_PATH + 128;
			char* buf = new char[BUF_SIZE];
			snprintf(buf, BUF_SIZE, CSTRING(FINISHED_DOWNLOAD), Util::getFileName(qi->getTarget()).c_str(), 
			Util::toString(ClientManager::getInstance()->getNicks(aUser)).c_str());

			LogManager::getInstance()->message(buf, LogManager::LOG_INFO);
			delete[] buf;
		}
	}
}
Beispiel #14
0
void FinishedManager::on(QueueManagerListener::Finished, const QueueItemPtr& qi, const string&, const DownloadPtr& p_download) noexcept
{
	if (!ClientManager::isShutdown())
	{
		const bool isFile = !qi->isAnySet(QueueItem::FLAG_USER_LIST | QueueItem::FLAG_DCLST_LIST | QueueItem::FLAG_USER_GET_IP);
		if (isFile)
		{
			PLAY_SOUND(SOUND_FINISHFILE);
		}
		if (isFile || (qi->isAnySet(QueueItem::FLAG_USER_LIST | QueueItem::FLAG_DCLST_LIST) && BOOLSETTING(LOG_FILELIST_TRANSFERS)))
		{
			auto item = std::make_shared<FinishedItem>(qi->getTarget(), p_download->getHintedUser(),
			                                           qi->getSize(), p_download->getRunningAverage(),
			                                           GET_TIME(), qi->getTTH(), p_download->getActual(), p_download->getUser()->getIPAsString());
			if (SETTING(DB_LOG_FINISHED_DOWNLOADS))
			{
				CFlylinkDBManager::getInstance()->save_transfer_history(false, e_TransferDownload, item);
			}
			rotation_items(item, e_Download);
			fly_fire2(FinishedManagerListener::AddedDl(), item, false);
			log(p_download->getUser()->getCID(), qi->getTarget(), STRING(FINISHED_DOWNLOAD));
		}
	}
}
Beispiel #15
0
void BundleQueue::addBundleItem(QueueItemPtr& aQI, BundlePtr& aBundle) noexcept {
	dcassert(!aQI->getBundle());
	aBundle->addQueue(aQI);
	aQI->setBundle(aBundle);

	if (!aBundle->isFileBundle()) {
		forEachPath(aBundle, aQI->getTarget(), [&](PathInfo& aInfo) {
			if (aQI->isDownloaded()) {
				aInfo.finishedFiles++;
			} else {
				aInfo.queuedFiles++;
			}

			aInfo.size += aQI->getSize();
		});
	}

	if (!aQI->isDownloaded()) {
		queueSize += aQI->getSize();
	}
}
void FileQueue::remove(QueueItemPtr& qi) noexcept {
	//TargetMap
	auto f = queue.find(const_cast<string*>(&qi->getTarget()));
	if (f != queue.end()) {
		queue.erase(f);
		if (!qi->isSet(QueueItem::FLAG_USER_LIST) && (!qi->isSet(QueueItem::FLAG_FINISHED) || !qi->getBundle()) && !qi->isSet(QueueItem::FLAG_CLIENT_VIEW)) {
			dcassert(qi->getSize() >= 0);
			queueSize -= qi->getSize();
		}
	}
	dcassert(queueSize >= 0);

	//TTHIndex
	auto s = tthIndex.equal_range(const_cast<TTHValue*>(&qi->getTTH()));
	dcassert(s.first != s.second);

	auto k = find(s | map_values, qi);
	if (k.base() != s.second) {
		tthIndex.erase(k.base());
	}
}
Beispiel #17
0
void FileQueue::move(QueueItemPtr& qi, const string& aTarget) noexcept {
	pathQueue.erase(const_cast<string*>(&qi->getTarget()));
	qi->setTarget(aTarget);
	pathQueue.emplace(const_cast<string*>(&qi->getTarget()), qi);
}