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; } } } }
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; } } } }
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::finalizeDestinationDirectories(DestDirList& destDirVector, DirectoryListing::Directory* root) { string szDiscard("<<<" + STRING(ADLS_DISCARD) + ">>>"); // Add non-empty destination directories to the top level for(vector<DestDir>::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) { if(id->dir->files.size() == 0 && id->dir->directories.size() == 0) { delete (id->dir); } else if(stricmp(id->dir->getName(), szDiscard) == 0) { delete (id->dir); } else { root->directories.push_back(id->dir); } } for(SearchCollection::iterator ip = collection.begin(); ip != collection.end(); ++ip) { ip->unprepare(); } }
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& destDirVector, DirectoryListing::Directory* root, StringMap& params) { // Load default destination directory (index = 0) destDirVector.clear(); vector<DestDir>::iterator id = destDirVector.insert(destDirVector.end(), DestDir()); id->name = "ADLSearch"; id->dir = new DirectoryListing::Directory(root, "<<<" + id->name + ">>>", true, true); // Scan all loaded searches for(SearchCollection::iterator is = collection.begin(); is != collection.end(); ++is) { // Check empty destination directory if(is->destDir.size() == 0) { // 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(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 id = destDirVector.insert(destDirVector.end(), DestDir()); id->name = is->destDir; id->dir = new DirectoryListing::Directory(root, "<<<" + id->name + ">>>", true, true); is->ddIndex = ddIndex; } } // Prepare all searches for(SearchCollection::iterator ip = collection.begin(); ip != collection.end(); ++ip) { ip->Prepare(params); } }