示例#1
0
bool vfs::CVirtualFileSystem::removeFileFromFS(vfs::Path const& sFilePath)
{
	vfs::Path sPath,sFile;
	sFilePath.splitLast(sPath,sFile);
	vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
	if(pProf)
	{
		vfs::IBaseLocation *pBL = pProf->getLocation(sPath);
		if(pBL && pBL->implementsWritable())
		{
			vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pBL);
			if(pDir)
			{
				bool bSuccess = false;
				// remove file from virtual structures first
				vfs::IBaseFile* file = pDir->getFile(sFilePath);
				if(file)
				{
					vfs::Path sDir,sFile;
					sFilePath.splitLast(sDir,sFile);
					vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sDir);
					if(pVLoc)
					{
						bSuccess = pVLoc->removeFile(file);
					}
				}
				// delete actual file
				return bSuccess && pDir->deleteFileFromDirectory(sFilePath);
			}
		}
	}
	return false;
}
示例#2
0
bool vfs::CVirtualFileSystem::createNewFile(vfs::Path const& sFilename)
{
	vfs::Path sPath,sFile;
	sFilename.splitLast(sPath,sFile);
	vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
	if(pProf)
	{
		bool bIsExclusive = false;
		bool bNewLocation = false;
		vfs::IBaseLocation *pProfLoc = pProf->getLocation(sPath);
		if(!pProfLoc)
		{
			// try to find closest match
			vfs::Path sTemp, sCreateDir, sRight, sLeft = sPath;
			while(!pProfLoc && !sLeft.empty())
			{
				sLeft.splitLast(sTemp,sRight);
				sLeft = sTemp;
				sCreateDir = sRight + sCreateDir;
				pProfLoc = pProf->getLocation(sLeft);
			}
			// see if the closest match is exclusive
			// if yes, then the the new path is a subdirectory and has to be exclusive too
			vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sLeft,true);
			if(pVLoc)
			{
				bIsExclusive = pVLoc->getIsExclusive();
			}
			//else
			//{
			//	VFS_THROW(L"location (closest match) should exist");
			//}
			bNewLocation = true;
		}
		if(pProfLoc && pProfLoc->implementsWritable())
		{
			// create file and add to location
			vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pProfLoc);
			vfs::IBaseFile* pFile = pDir->addFile(sFilename);
			if(bNewLocation)
			{
				pProf->addLocation(pProfLoc);
			}
			if(pFile)
			{
				CVirtualLocation* pLoc = this->getVirtualLocation(sPath,true);
				if(bIsExclusive)
				{
					pLoc->setIsExclusive(bIsExclusive);
				}
				pLoc->addFile(pFile,pProf->cName);
				return true;
			}
		}
	}
	// throw ?
	return false;
}
示例#3
0
vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem* pVFS)
: tBaseClass(), m_VFS(pVFS)
{
	if(sPattern() == vfs::Const::STAR())
	{
		m_sLocPattern =  vfs::Path(vfs::Const::STAR());
		m_sFilePattern = vfs::Path(vfs::Const::STAR());
	}
	else
	{
		sPattern.splitLast(m_sLocPattern,m_sFilePattern);
	}

	_vloc_iter = m_VFS->m_mapFS.begin();
	while(_vloc_iter != m_VFS->m_mapFS.end())
	{
		if( matchPattern(m_sLocPattern(),_vloc_iter->second->cPath()) )
		{
			bool bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
			_vfile_iter = _vloc_iter->second->iterate();
			while(!_vfile_iter.end())
			{
				vfs::IBaseFile* pFile = NULL;
				if(bExclusiveVLoc)
				{
					pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
				}
				else
				{
					pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
				}
				if(pFile)
				{
					vfs::Path const& filename = pFile->getName();
					if( matchPattern(m_sFilePattern(),filename()) )
					{
						return;
					}
				}
				_vfile_iter.next();
			}
		}
		_vloc_iter++;
	}
}