//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimScriptCollection * RimScriptCollection::findScriptCollection(const QString& path)
{
    if (!this->directory().isEmpty())
    {
        QFileInfo otherPath(path);
        QFileInfo thisPath(directory());
        if (otherPath == thisPath) return this;
    }

    for (size_t i = 0; i < this->subDirectories.size(); ++i)
    {
         RimScriptCollection* foundColl = NULL;
         if (this->subDirectories[i]) foundColl = this->subDirectories[i]->findScriptCollection(path);
         if (foundColl) return foundColl;
    }

    return NULL;
}
示例#2
0
文件: bolt.cpp 项目: daemondn/Bolt
    std::string fileToString(const std::string &fileName)
    {
        std::ifstream infile (fileName);
        if (infile.fail() ) {
#if defined( _WIN32 )
            TCHAR osPath[ MAX_PATH ];

            //	If loading the .cl file fails from the specified path, then make a last ditch attempt (purely for convenience) to find the .cl file right to the executable,
            //	regardless of what the CWD is
            //	::GetModuleFileName( ) returns TCHAR's (and we define _UNICODE for windows); but the fileName string is char's, 
            //	so we needed to create an abstraction for string/wstring
            if( ::GetModuleFileName( NULL, osPath, MAX_PATH ) )
            {
                bolt::tstring thisPath( osPath );
                bolt::tstring::size_type pos = thisPath.find_last_of( _T( "\\" ) );

                bolt::tstring newPath;
                if( pos != bolt::tstring::npos )
                {
                    bolt::tstring exePath	= thisPath.substr( 0, pos + 1 );	// include the \ character

                    //	Narrow to wide conversion should always work, but beware of wide to narrow!
                    bolt::tstring convName( fileName.begin( ), fileName.end( ) );
                    newPath = exePath + convName;
                }

                infile.open( newPath.c_str( ) );
            }
#endif
            if (infile.fail() ) {
                //  Note:  Commented out because this widestr not initialized yet if called from global scope
                //TCHAR cCurrentPath[FILENAME_MAX];
                //if (_tgetcwd(cCurrentPath, sizeof(cCurrentPath) / sizeof(TCHAR))) {
                //    bolt::tout <<  _T( "CWD=" ) << cCurrentPath << std::endl;
                //};
                std::cout << "error: failed to open file: " << fileName << std::endl;
                throw;
            } 
        }

        std::string str((std::istreambuf_iterator<char>(infile)),
            std::istreambuf_iterator<char>());
        return str;
    };
示例#3
0
QSet<QString> StelFileMgr::listContents(const QString& path, const StelFileMgr::Flags& flags, bool recursive)
{
	QSet<QString> result;

	if (recursive)
	{
		QSet<QString> dirs = listContents(path, Directory, false);
		result = listContents(path, flags, false); // root
		// add results for each sub-directory
		for (const auto& d : dirs)
		{
			QSet<QString> subDirResult = listContents(path + "/" + d, flags, true);
			for (const auto& r : subDirResult)
			{
				result.insert(d + "/" + r);
			}
		}
		return result;
	}

	// If path is "complete" (a full path), we just look in there, else
	// we append relative paths to the search paths maintained by this class.
	QStringList listPaths = QFileInfo(path).isAbsolute() ? QStringList("/") : fileLocations;

	for (const auto& li : listPaths)
	{
		QFileInfo thisPath(QDir(li).filePath(path));
		if (!thisPath.isDir())
			continue;

		QDir thisDir(thisPath.absoluteFilePath());
		for (const auto& fileIt : thisDir.entryList())
		{
			if (fileIt == ".." || fileIt == ".")
				continue;
			QFileInfo fullPath(thisDir.filePath(fileIt));
			if (fileFlagsCheck(fullPath, flags))
				result.insert(fileIt);
		}
	}

	return result;
}
void GLC_WorldTo3dxml::writeExtensionAttributes(GLC_Attributes* pAttributes)
{
	QList<QString> attributesNames= pAttributes->names();
	const int size= attributesNames.size();
	for (int i= 0; i < size; ++i)
	{
		const QString name= attributesNames.at(i);
		QString value= pAttributes->value(name);
		m_pOutStream->writeStartElement("Attribute");
			m_pOutStream->writeAttribute("name", name);
			if (name == "FILEPATH")
			{
				QDir thisPath(m_AbsolutePath);
				value= thisPath.relativeFilePath(value);
			}
			m_pOutStream->writeAttribute("value", value);
		m_pOutStream->writeEndElement(); // Attribute
	}
}
示例#5
0
//-----------------------------------------------------------------------------
//Function Name : void* __dlopen_r(const char* filename, int flag)
//Description   : To open the given dll filename.
//Return Value  : Valid handle value if no error, Null if dll couldn't be loaded 
//-----------------------------------------------------------------------------
void* __dlopen_r(const char* filename,const int flag)
	{
	//convert filename to TFileName
	TPtrC8 ptr8( (unsigned char*)filename);
	TFileName fileNameBuf;
	CnvUtfConverter::ConvertToUnicodeFromUtf8(fileNameBuf, ptr8);
	TParsePtr filePathName(fileNameBuf);
	
	//if file name contains wild character
	if ( filePathName.IsWild() )
		{
		SetError(KDlOpenErrNoSupport);
		return NULL;
		}
	//to load dll	
	RLibrary library;	
	TInt err;
	TBool isLibraryLoaded = EFalse;
	RFs fs;
	err = fs.Connect();
	if ( KErrNone == err )
		{
		TUint tempAtt;
		//if path is there load from this path
		if ( filePathName.PathPresent() )
			{
			err = fs.Att(filePathName.FullName(), tempAtt);
			fs.Close();	
			if ( KErrNotFound != err && KErrPathNotFound != err)
				{
				err = library.Load(filePathName.FullName());
				if ( KErrNone != err )
					{
					SetError(KDlOpenErrLoading);
					return NULL;
					}
				isLibraryLoaded = ETrue;	
				}
			}
		else//if there is no path its only file name
			{
			TPtrC fileName(filePathName.NameAndExt());
			char* envPathName = getenv("LD_LIBRARY_PATH");
			if ( envPathName )
				{
				TPtrC8 tempPtr8((unsigned char*)envPathName);
				TFileName envPathBuf;
				CnvUtfConverter::ConvertToUnicodeFromUtf8(envPathBuf, tempPtr8);
				TPtrC envPath(envPathBuf);
				TChar delim(';');
				TFileName fileToLoad;
				TInt pos = envPath.Locate(delim);
				//if delim does not found and still envPath contains value
				//i.e. this one is last path without delim(';') so take 
				//this also, for this length is checked
				while ( KErrNotFound != pos || envPath.Length())
					{
					//if there is no delim
					if (KErrNotFound == pos )
						{// so last path without delim
						pos = envPath.Length();
						}
					TPtrC thisPath(envPath.Left(pos));
					fileToLoad = thisPath;
					fileToLoad.Trim();
					//to check ";;" and ";   ;"
					if (fileToLoad.Length())
						{
						//if path does not conatin trailing \ add one
						if ( L'\\' != fileToLoad[fileToLoad.Length()-1] )
							{
							fileToLoad.Append(TChar(L'\\'));					
							}
						fileToLoad.Append(fileName);
					
						err = fs.Att(fileToLoad, tempAtt);
						if ( KErrNotFound != err && KErrPathNotFound != err)
							{
							//load file from this path
							err = library.Load(fileToLoad);
							if ( KErrNone == err )
								{
								// dll loaded successfully from thispath
								isLibraryLoaded = ETrue;	
								break;
								}	
							}
						}
					if ( pos == envPath.Length())		
						{
						break;
						}
					else
						{
						envPath.Set(envPath.Mid(pos + 1));
						}
					pos = envPath.Locate(delim);
					}
				fs.Close();	
				}
			else//load dll if only name is there and LD_LIBRARY_PATH path not set
				{
				fs.Close();	
				TInt err = library.Load(filePathName.NameAndExt());
				if ( KErrNone != err )
					{
					SetError(KDlOpenErrLoading);
					return NULL;
					}
				isLibraryLoaded = ETrue;		
				}
			}
	
		//if library is loaded	
		if ( isLibraryLoaded )	
			{
			//handle value to return 
			void* handle  = NULL;
			//lock list before any operation
			LoadedDlls()->Lock();
			//is this dll already there
			TInt listIdx = LoadedDlls()->Find(library);
			//if not already open
			if ( KErrNotFound == listIdx )
				{				
				TDllEntry dllEntry(library, flag);
				dllEntry.iSymbolHeader = (TE32ExpSymInfoHdr*)library.Lookup(0);
				
				err = dllEntry.iLibrary.Duplicate(RThread());	
				//Close the library irrespective of the result of duplicate
				library.Close();
				if ( KErrNone != err )
					{
					SetError(KDlOpenErrLoading);
					LoadedDlls()->UnLock();
					return NULL;
					}
				//add to list	
				err = LoadedDlls()->Add(dllEntry);
				handle = (void*) dllEntry.iLibrary.Handle();
				LoadedDlls()->UnLock();
				if ( KErrNone != err )
					{
					SetError(KDlOpenErrNoMemory);
					dllEntry.iLibrary.Close();
					return NULL;
					}
				}
			else//if this dll is already in list.
				{
				//close library we already have loaded
				library.Close();
				TDllEntry& dllEntry = LoadedDlls()->At(listIdx);
				//if flag is RTLD_GLOBAL store it otherwise ignore
				//as RTLD_LAZY and RTLD_NOW both means RTLD_NOW
				//so can be ignored. RTLD_LOCAL does not change previous flag
				if ( flag & RTLD_GLOBAL )
					{
					dllEntry.iFlags |= RTLD_GLOBAL;
					}
				dllEntry.iRefCount++;	
				handle = (void*) dllEntry.iLibrary.Handle();
				LoadedDlls()->UnLock();	
				}	
			return handle;			
			}
		}
	SetError(KDlOpenErrLoading);
	return NULL;		
	}