Exemple #1
0
void ADLSearchManager::MatchesDirectory(DestDirList& destDirVector, DirectoryListing::Directory* currentDir, string& fullPath) {
	// Add to any substructure being stored
	for(DestDirList::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) {
		if(id->subdir != NULL) {
			DirectoryListing::Directory* newDir =
				new DirectoryListing::AdlDirectory(fullPath, id->subdir, currentDir->getName());
			id->subdir->directories.push_back(newDir);
			id->subdir = newDir;
		}
	}

	// Prepare to match searches
	if(currentDir->getName().size() < 1) {
		return;
	}

	// Match searches
	for(SearchCollection::iterator is = collection.begin(); is != collection.end(); ++is) {
		if(destDirVector[is->ddIndex].subdir != NULL) {
			continue;
		}
		if(is->MatchesDirectory(currentDir->getName())) {
			destDirVector[is->ddIndex].subdir =
				new DirectoryListing::AdlDirectory(fullPath, destDirVector[is->ddIndex].dir, currentDir->getName());
			destDirVector[is->ddIndex].dir->directories.push_back(destDirVector[is->ddIndex].subdir);
			if(breakOnFirst) {
				// Found a match, search no more
				break;
			}
		}
	}
}
Exemple #2
0
void ADLSearchManager::finalizeDestinationDirectories(DestDirList& destDirVector, DirectoryListing::Directory* root)
{
	string szDiscard("<<<" + STRING(ADLS_DISCARD) + ">>>");
	
	// Add non-empty destination directories to the top level
	for (auto id = destDirVector.begin(); id != destDirVector.end(); ++id)
	{
		if (id->dir->m_files.empty() && id->dir->directories.empty())
		{
			safe_delete(id->dir);
		}
		else if (stricmp(id->dir->getName(), szDiscard) == 0)
		{
			safe_delete(id->dir);
		}
		else
		{
			root->directories.push_back(id->dir);
		}
	}
	
	for (auto ip = collection.begin(); ip != collection.end(); ++ip)
	{
		ip->unprepare();
	}
}
Exemple #3
0
void ADLSearchManager::stepUpDirectory(DestDirList& destDirVector) {
	for(DestDirList::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) {
		if(id->subdir != NULL) {
			id->subdir = id->subdir->getParent();
			if(id->subdir == id->dir) {
				id->subdir = NULL;
			}
		}
	}
}
void ADLSearchManager::MatchesFile(DestDirList& destDirVector, DirectoryListing::File *currentFile, string& fullPath) {
	// Add to any substructure being stored
	for(DestDirList::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) {
		if(id->subdir != NULL) {
			DirectoryListing::File *copyFile = new DirectoryListing::File(*currentFile, true);
			dcassert(id->subdir->getAdls());
			
			id->subdir->files.push_back(copyFile);
		}
		id->fileAdded = false;	// Prepare for next stage
	}

	// Prepare to match searches
	if(currentFile->getName().size() < 1) {
		return;
	}

	string filePath = fullPath + "\\" + currentFile->getName();
	// Match searches
	for(SearchCollection::iterator is = collection.begin(); is != collection.end(); ++is) {
		if(destDirVector[is->ddIndex].fileAdded) {
			continue;
		}
		if(is->MatchesFile(currentFile->getName(), filePath, currentFile->getSize(), /*RSX++*/currentFile->getTTH()/*END*/)) {
			DirectoryListing::File *copyFile = new DirectoryListing::File(*currentFile, true);
			if(is->isForbidden) {
				copyFile->setPoints(is->adlsPoints);
				copyFile->setAdlsComment(is->adlsComment);
				copyFile->setOverRidePoints(is->overRidePoints);
				copyFile->setAdlsRaw(is->adlsRaw);
				copyFile->setKickString(is->kickString);
				copyFile->setFromFavs(is->fromFavs);
			}

			destDirVector[is->ddIndex].dir->files.push_back(copyFile);
			destDirVector[is->ddIndex].fileAdded = true;

			if(is->isAutoQueue) {
				try {
					QueueManager::getInstance()->add(SETTING(DOWNLOAD_DIRECTORY) + currentFile->getName(),
						currentFile->getSize(), currentFile->getTTH(), getUser());
				} catch(const Exception&) {	}
			}

			if(breakOnFirst) {
				// Found a match, search no more
				break;
			}
		}
	}
}
Exemple #5
0
void ADLSearchManager::stepUpDirectory(DestDirList& destDirVector) const
{
	for (auto id = destDirVector.begin(); id != destDirVector.end(); ++id)
	{
		if (id->subdir != nullptr)
		{
			id->subdir = id->subdir->getParent();
			if (id->subdir == id->dir)
			{
				id->subdir = nullptr;
			}
		}
	}
}
Exemple #6
0
void ADLSearchManager::matchesFile(DestDirList& destDirVector, DirectoryListing::File *currentFile, string& fullPath) {
	// Add to any substructure being stored
	for(DestDirList::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) {
		if(id->subdir != NULL) {
			DirectoryListing::File *copyFile = new DirectoryListing::File(*currentFile, true);
			dcassert(id->subdir->getAdls());
			
			id->subdir->files.push_back(copyFile);
		}
		id->fileAdded = false;	// Prepare for next stage
	}

	// Prepare to match searches
	if(currentFile->getName().size() < 1) {
		return;
	}

	string filePath = fullPath + "\\" + currentFile->getName();
	// Match searches
	for(SearchCollection::iterator is = collection.begin(); is != collection.end(); ++is) {
		if(destDirVector[is->ddIndex].fileAdded) {
			continue;
		}
		if(is->matchesFile(currentFile->getName(), filePath, currentFile->getSize())) {
			DirectoryListing::File *copyFile = new DirectoryListing::File(*currentFile, true);
			if(is->isForbidden && !getSentRaw()) {
				char buf[256];
				snprintf(buf, sizeof(buf), CSTRING(CHECK_FORBIDDEN), currentFile->getName().c_str());
				
				ClientManager::getInstance()->setClientStatus(user, buf, is->raw, false);

				setSentRaw(true);
			}
			destDirVector[is->ddIndex].dir->files.push_back(copyFile);
			destDirVector[is->ddIndex].fileAdded = true;

			if(is->isAutoQueue) {
				try {
					QueueManager::getInstance()->add(SETTING(DOWNLOAD_DIRECTORY) + currentFile->getName(),
						currentFile->getSize(), currentFile->getTTH(), getUser());
				} catch(const Exception&) {	}
			}

			if(breakOnFirst) {
				// Found a match, search no more
				break;
			}
		}
	}
}
void ADLSearchManager::MatchesDirectory(DestDirList& destDirVector, DirectoryListing::Directory* currentDir, string& fullPath) {
	// Add to any substructure being stored
	for(DestDirList::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) {
		if(id->subdir != NULL) {
			DirectoryListing::Directory* newDir = 
				new DirectoryListing::AdlDirectory(fullPath, id->subdir, currentDir->getName());
			id->subdir->directories.push_back(newDir);
			id->subdir = newDir;
		}
	}

	// Prepare to match searches
	if(currentDir->getName().size() < 1) {
		return;
	}

	// Match searches
	for(SearchCollection::iterator is = collection.begin(); is != collection.end(); ++is) {
		if(destDirVector[is->ddIndex].subdir != NULL) {
			continue;
		}
		if(is->MatchesDirectory(currentDir->getName())) {
			destDirVector[is->ddIndex].subdir = 
				new DirectoryListing::AdlDirectory(fullPath, destDirVector[is->ddIndex].dir, currentDir->getName());
			//RSX++
			if(is->isForbidden) {
				destDirVector[is->ddIndex].subdir->setPoints(is->adlsPoints);
				destDirVector[is->ddIndex].subdir->setAdlsComment(is->adlsComment);
				destDirVector[is->ddIndex].subdir->setOverRidePoints(is->overRidePoints);
				destDirVector[is->ddIndex].subdir->setAdlsRaw(is->adlsRaw);
				destDirVector[is->ddIndex].subdir->setKickString(is->kickString);
				destDirVector[is->ddIndex].subdir->setFromFavs(is->fromFavs);
			}
			//END
			destDirVector[is->ddIndex].dir->directories.push_back(destDirVector[is->ddIndex].subdir);
			if(breakOnFirst) {
				// Found a match, search no more
				break;
			}
		}
	}
}
void ADLSearchManager::prepareDestinationDirectories(DestDirList& destDirs, DirectoryListing::Directory* root, StringMap &params) {
    // Load default destination directory (index = 0)
    destDirs.clear();
    DestDir dir = { "ADLSearch", new DirectoryListing::Directory(root, "<<<ADLSearch>>>", true, true), nullptr, false };
    destDirs.push_back(std::move(dir));

    // Scan all loaded searches
    for(auto& is: collection) {
        // Check empty destination directory
        if(is.destDir.empty()) {
            // Set to default
            is.ddIndex = 0;
            continue;
        }

        // Check if exists
        bool isNew = true;
        long ddIndex = 0;
        for(auto id = destDirs.cbegin(); id != destDirs.cend(); ++id, ++ddIndex) {
            if(Util::stricmp(is.destDir.c_str(), id->name.c_str()) == 0) {
                // Already exists, reuse index
                is.ddIndex = ddIndex;
                isNew = false;
                break;
            }
        }

        if(isNew) {
            // Add new destination directory
            DestDir dir = { is.destDir, new DirectoryListing::Directory(root, "<<<" + is.destDir + ">>>", true, true), nullptr, false };
            destDirs.push_back(std::move(dir));
            is.ddIndex = ddIndex;
        }
    }
    // Prepare all searches
    for(auto& ip: collection) {
        ip.prepare(params);
    }
}
Exemple #9
0
void ADLSearchManager::prepareDestinationDirectories(DestDirList& destDirVector, DirectoryListing::Directory* root, StringMap& params)
{
	// Load default destination directory (index = 0)
	destDirVector.clear();
	auto id = destDirVector.insert(destDirVector.end(), DestDir());
	id->name = "ADLSearch";
	id->dir  = new DirectoryListing::Directory(nullptr, root, "<<<" + id->name + ">>>", true, true, true);
	
	// Scan all loaded searches
	for (auto is = collection.begin(); is != collection.end(); ++is)
	{
		// Check empty destination directory
		if (is->destDir.empty())
		{
			// Set to default
			is->ddIndex = 0;
			continue;
		}
		
		// Check if exists
		bool isNew = true;
		long ddIndex = 0;
		for (id = destDirVector.begin(); id != destDirVector.end(); ++id, ++ddIndex)
		{
			if (stricmp(is->destDir.c_str(), id->name.c_str()) == 0)
			{
				// Already exists, reuse index
				is->ddIndex = ddIndex;
				isNew = false;
				break;
			}
		}
		
		if (isNew)
		{
			// Add new destination directory
			id = destDirVector.insert(destDirVector.end(), DestDir());
			id->name = is->destDir;
			id->dir  = new DirectoryListing::Directory(nullptr, root, "<<<" + id->name + ">>>", true, true, true);
			is->ddIndex = ddIndex;
		}
	}
	// Prepare all searches
	for (auto ip = collection.begin(); ip != collection.end(); ++ip)
	{
		ip->prepare(params);
	}
}
Exemple #10
0
void ADLSearchManager::matchesFile(DestDirList& destDirVector, DirectoryListing::File *currentFile, const string& fullPath)
{
	// Add to any substructure being stored
	for (auto id = destDirVector.begin(); id != destDirVector.end(); ++id)
	{
		if (id->subdir != NULL)
		{
			auto copyFile = new DirectoryListing::File(*currentFile, true);
			copyFile->setFlags(currentFile->getFlags());
			dcassert(id->subdir->getAdls());
			
			id->subdir->m_files.push_back(copyFile);
		}
		id->fileAdded = false;  // Prepare for next stage
	}
	
	// Prepare to match searches
	if (currentFile->getName().size() < 1)
	{
		return;
	}
	
	string filePath = fullPath + "\\" + currentFile->getName();// TODO Crash
	// Match searches
	for (auto is = collection.cbegin(); is != collection.cend(); ++is)
	{
		if (destDirVector[is->ddIndex].fileAdded)
		{
			continue;
		}
		if (is->matchesFile(currentFile->getName(), filePath, currentFile->getSize()))
		{
			auto copyFile = new DirectoryListing::File(*currentFile, true);
			copyFile->setFlags(currentFile->getFlags());
#ifdef IRAINMAN_INCLUDE_USER_CHECK
			if (is->isForbidden && !getSentRaw())
			{
				AutoArray<char> buf(FULL_MAX_PATH);
				_snprintf(buf, FULL_MAX_PATH, CSTRING(CHECK_FORBIDDEN), currentFile->getName().c_str());
				
				ClientManager::setClientStatus(user, buf.data(), is->raw, false);
				
				setSentRaw(true);
			}
#endif
			
			destDirVector[is->ddIndex].dir->m_files.push_back(copyFile);
			destDirVector[is->ddIndex].fileAdded = true;
			
			if (is->isAutoQueue)
			{
				try
				{
					QueueManager::getInstance()->add(0,/* [-] IRainman needs for support download to specify extension dir. SETTING(DOWNLOAD_DIRECTORY) + */currentFile->getName(),
					                                 currentFile->getSize(), currentFile->getTTH(), getUser()/*, Util::emptyString*/);
				}
				catch (const Exception& e)
				{
					LogManager::message("QueueManager::getInstance()->add Error = " + e.getError());
				}
			}
			
			if (breakOnFirst)
			{
				// Found a match, search no more
				break;
			}
		}
	}
}