Beispiel #1
0
StringList ShareManager::getRealPaths(const string& virtualPath) {
	if(virtualPath.empty())
		throw ShareException("empty virtual path");

	StringList ret;

	Lock l(cs);

	if(*(virtualPath.end() - 1) == '/') {
		// directory
		Directory::Ptr d = splitVirtual(virtualPath).first;

		// imitate Directory::getRealPath
		if(d->getParent()) {
			ret.push_back(d->getParent()->getRealPath(this,d->getName()));
		} else {
			for(auto& i: shares) {
				if(Util::stricmp(i.second, d->getName()) == 0) {
					// remove the trailing path sep
					if(FileFindIter(i.first.substr(0, i.first.size() - 1)) != FileFindIter()) {
						ret.push_back(i.first);
					}
				}
			}
		}

	} else {
		// file
		ret.push_back(toReal(virtualPath,false));
	}

	return ret;
}
void PropPageTextStyles::PopulateThemes() {
	ctrlTheme.ResetContent();
	
	if(themes.empty()) {
		string path = Util::getPath(Util::PATH_THEMES);
		for(FileFindIter i(path + "*.dctheme"); i != FileFindIter(); ++i) {
			string filepath = path + i->getFileName();
			themes.insert(make_pair(i->getFileName(), filepath));
		}
	}
	
	ctrlTheme.AddString(_T("[Select Theme]"));
	
	for(themeMap::const_iterator m = themes.begin(); m != themes.end(); ++m) {
		ctrlTheme.AddString(Text::toT(m->first).c_str());
	}

	ctrlTheme.SetCurSel(0);
}
Beispiel #3
0
int64_t File::getSize(const tstring& aFileName) noexcept
{
	auto i = FileFindIter(aFileName);
	return i != FileFindIter::end ? i->getSize() : -1;
}
Beispiel #4
0
ShareManager::Directory::Ptr ShareManager::buildTree(const string& realPath, const string& dirName, const Directory::Ptr& parent) {
	auto dir = Directory::create( (!dirName.empty()) ? dirName : Util::getLastDir(realPath), parent);
	auto lastFileIter = dir->files.begin();
#ifdef _WIN32
	for(FileFindIter i(realPath + "*"), end; i != end; ++i) {
#else
	//the fileiter just searches directorys for now, not sure if more
	//will be needed later
	for(FileFindIter i(realPath),end; i != end; ++i) {
#endif
		string name = i->getFileName();

		if(name.empty()) {
			LogManager::getInstance()->message(_("Invalid file name found while hashing folder ") + Util::addBrackets(realPath));
			continue;
		}

		if(name == "." || name == "..")
			continue;
		if(!SETTING(SHARE_HIDDEN) && i->isHidden())
			continue;
		if(!SETTING(FOLLOW_LINKS) && i->isLink())
 			continue;

		if(i->isDirectory()) {
			auto newRealPath = realPath + name + PATH_SEPARATOR;

			if(!checkInvalidPaths(newRealPath))
				continue;

			// don't share unfinished downloads
			if(newRealPath == SETTING(TEMP_DOWNLOAD_DIRECTORY)) { continue; }

			auto virtualName = name;
			if(dir->nameInUse(virtualName)) {
				uint32_t num = 0;
				do {
					++num;
					virtualName = name + " (" + Util::toString(num) + ")";
				} while(dir->nameInUse(virtualName));
			}

			dir->directories[virtualName] = buildTree(newRealPath, virtualName, dir);

			if(virtualName != name) {
				dir->directories[virtualName]->setRealName(move(name));
			}

		} else {
			// Not a directory, assume it's a file...make sure we're not sharing the settings file...
			if(name == "DCPlusPlus.xml" || name == "Favorites.xml") { continue; }

			auto size = i->getSize();
			auto fileName = realPath + name;
			
			if(!checkInvalidFileName(name))
				continue;

			if(!checkInvalidFileSize(size))
				continue;

			// don't share the private key file
			if(fileName == SETTING(TLS_PRIVATE_KEY_FILE)) { continue; }

			Directory::File f(name, size, dir,
				(HashManager::getInstance()->getTTH(fileName, size, i->getLastWriteTime())));
			f.validateName(realPath);
			lastFileIter = dir->files.insert(lastFileIter, move(f));
		}
	}

	return dir;
}

bool ShareManager::checkHidden(const string& realPath) const {
	FileFindIter ff = FileFindIter(realPath.substr(0, realPath.size() - 1));

	if (ff != FileFindIter()) {
		return (SETTING(SHARE_HIDDEN) || !ff->isHidden());
	}

	return true;
}