Example #1
0
void Win32::load()
{
    if(m_handle == 0)
    {
        // Opens the dynamic library.
        std::string lib(getFullPath(true).string());
        OSLM_TRACE("Opens the dynamic library " << lib);
        m_handle = LoadLibrary( lib.c_str() );
        if(m_handle == 0)
        {
            // Retrieves the last error message.
            DWORD lastError = GetLastError();
            char buffer[1024];
            FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, lastError, 0, buffer, 1024, 0 );

            // Builds the error message and throws the exception.
            std::string message( buffer );
            throw RuntimeException( message );
        }
    }
}
Example #2
0
bool FileSystem::fileExists(const char* filePath, bool external)
{
    GP_ASSERT(filePath);

    std::string fullPath;

#ifdef __ANDROID__
    fullPath = __assetPath;
    fullPath += resolvePath(filePath);

    if (androidFileExists(fullPath.c_str()))
    {
        return true;
    }
#endif

    getFullPath(filePath, fullPath, external);

    gp_stat_struct s;
    return stat(fullPath.c_str(), &s) == 0;

}
Example #3
0
/* Given a file name, try to determine the full path for that file. Starts
 * its search in the current directory, and then tries all paths in the 
 * search list in the order they are specified there.
 */
static const struct stat *findFile(const char *file, const char **fullPath)
{
	int i = 0;
	static struct stat sbuf;
	char *fileName;
	debug("finding file %s", file);
	*fullPath = file;
	if (0 == stat(file, &sbuf))
		return &sbuf;
	if (strchr(file, '/'))
		return 0;				/* If the path had a / we don't look in env var places */
	fileName = NULL;
	if (!fileName)
		fileName = (char *)file;
	while ((*fullPath = getFullPath(i++, fileName)))
	{
		if (0 == stat(*fullPath, &sbuf))
			return &sbuf;
	}
	;
	return 0;
}
Example #4
0
void StickyNoteActor::finishedEditing()
{
	// update the file
	if (_stickyNoteText.isModified())
	{
		writeStickyNote(getFullPath(), _stickyNoteText.toPlainText());
		
		// notify the user with a little animation
		setFreshnessAlphaAnim(1.0f, 25);
	}

	// animate back and then finish up the visuals
	if (_tmpAnimationActor)
	{
		Mat34 startPose;
		Vec3 startDims;
		int numTempActorSteps = StickyNoteActorNumTempActorSteps;
		int numStickySteps = StickyNoteActorNumStickySteps;
		if (_tmpAnimationActor->isAnimating())
		{
			animManager->removeAnimation(_tmpAnimationActor);
			startPose = _tmpAnimationActor->getGlobalPose();
			startDims = _tmpAnimationActor->getDims();
			numTempActorSteps = max(1, (int)((_tmpAnimationActor->getAlpha() / 1.0f) * numTempActorSteps));
			numStickySteps = max(1, (int)(((1.0f - getAlpha()) / 1.0f) * numStickySteps));
		}
		else
		{
			calculateDialogPoseDims(startPose, startDims);
		}
		
		_tmpAnimationActor->popActorType(Invisible);
		_tmpAnimationActor->setAlphaAnim(_tmpAnimationActor->getAlpha(), 0.0f, numTempActorSteps);
		_tmpAnimationActor->setSizeAnim(lerpRange(startDims, getDims(), numTempActorSteps, SoftEase));
		_tmpAnimationActor->setPoseAnim(slerpPose(startPose, getGlobalPose(), numTempActorSteps, SoftEase), (FinishedCallBack) FinishEditStickyNoteAfterAnim, NULL);
		_tmpAnimationActor = NULL;
		setAlphaAnim(getAlpha(), 1.0f, numStickySteps);
	}
}
Example #5
0
 Data FileUtil::getDataFromFile(const string& filename,bool isFullPath){
     if (filename.empty()) {
         return Data::Null;
     }
     
     FILE* fp = nullptr;
     if (!isFullPath) {
         auto fullpath = getFullPath(filename);
         fp = fopen(fullpath.c_str(),"rb");
     }else{
         fp = fopen(filename.c_str(),"rb");
     }
     
     fseek(fp,0,SEEK_END);
     size_t size = ftell(fp);
     fseek(fp,0,SEEK_SET);
     
     unsigned char* buffer = (unsigned char*)malloc(sizeof(unsigned char) * size);
     size_t readsize = fread(buffer, sizeof(unsigned char), size, fp);
     Data ret;
     ret.fastSet(buffer,readsize);
     return ret;
 }
Example #6
0
//***********************************************************************************************
bool CParticleWorkspace::CNode::loadPS()
{	
	nlassert(_WS);
	// manually load the PS shape (so that we can deal with exceptions)
	NL3D::CShapeStream ss;
	NLMISC::CIFile inputFile;
	// collapse name
	inputFile.open(getFullPath());
	ss.serial(inputFile);
	std::auto_ptr<NL3D::CShapeBank> sb(new NL3D::CShapeBank);
	std::string shapeName = NLMISC::CFile::getFilename(_RelativePath);
	sb->add(shapeName, ss.getShapePointer());
	NL3D::CShapeBank *oldSB = NL3D::CNELU::Scene->getShapeBank();
	NL3D::CNELU::Scene->setShapeBank(sb.get());
	NL3D::CTransformShape *trs = NL3D::CNELU::Scene->createInstance(shapeName);
	if (!trs)
	{
		NL3D::CNELU::Scene->setShapeBank(oldSB);
		return false;
	}
	NL3D::CParticleSystemModel *psm = dynamic_cast<NL3D::CParticleSystemModel *>(trs);
	if (!psm)
	{
		// Not a particle system
		NL3D::CNELU::Scene->deleteInstance(trs);
		return false;
	}
	NL3D::CNELU::Scene->setShapeBank(oldSB);		
	setup(*psm);
	unload();
	// commit new values
	_PS = psm->getPS();
	_PSM = psm;
	_ShapeBank = sb.release();
	_Modified = false;
	return true; 
}
// give the best string we can in the given amount of chars
CString CPathDescriptor::getDisplayPath(int nMaxChars)
{
	int nFullLen = GetLength();
	int nNameLen = getFileFullName().GetLength();
	CString s;

	if(nFullLen <= nMaxChars)
		return getFullPath();

	if(nNameLen>= nMaxChars)	// big file name
	{
		//favor the beginning of the file name
		// this commented out version adds the ellipses at the end to.  the other
		// version, which is better until I get dynamic re-figuring based on
		// column resizing, lets the list ctrl do the ellipsing on the right edge
		//s.Format( "...%s...", getFileFullName().Left(nMaxChars-6));
		s.Format( "...%s", getFileFullName().Left(nMaxChars-3));
		return s;
	}

	int nDir = (nMaxChars-nNameLen) - 3; // 3 for ellipses
	s.Format("...%s%s", m_sDirectory.Right(nDir), getFileFullName());
	return s;
}
Example #8
0
void DemoInfo::readMetaData( void )
{
    const size_t meta_data_c_size = 16*1024;
    char meta_data_c_str[meta_data_c_size];

    std::string fullName = getFullPath();
    size_t meta_data_realsize = trap::CL_ReadDemoMetaData( fullName.c_str(), meta_data_c_str, meta_data_c_size );

    metaData.clear();

    const char *s, *key, *value;
    const char *end = meta_data_c_str + std::min( meta_data_c_size, meta_data_realsize );
    for( s = meta_data_c_str; s < end && *s; ) {
        key = s;
        value = key + strlen( key ) + 1;
        if( value >= end ) {
            // key without the value pair, EOF
            break;
        }

        metaData[key] = COM_RemoveColorTokensExt( value, qfalse );
        s = value + strlen( value ) + 1;
    }
}
Example #9
0
std::string CollectionFileData::getKey() {
	return getFullPath();
}
	//---------------------------------------------------------------------
	WString UnicodeFileSystemArchive::getFullPath(const String& _filename) const
	{
		return getFullPath(toWString(_filename));
	}
    //-----------------------------------------------------------------------
	Ogre::DataStreamPtr UnicodeFileSystemArchive::open(const String& _filename, bool _readOnly) const
    {
		WString wfullpath = getFullPath(_filename);

		// Use filesystem to determine size 
		// (quicker than streaming to the end and back)
		struct _stat tagStat;
		int ret = _wstat(wfullpath.c_str(), &tagStat);
		if(ret != 0)
		{
			GOTHOGRE_EXCEPT(_filename << " - Problem getting file size"
				<< " (archive " << getName() << ").");
		}

		// Always open in binary mode
		// Also, always include reading
		std::ios::openmode mode = std::ios::in | std::ios::binary;
		std::istream* baseStream = 0;
		std::ifstream* roStream = 0;
		std::fstream* rwStream = 0;

		if (_readOnly)
		{
			roStream = OGRE_NEW_T(std::ifstream, MEMCATEGORY_GENERAL)();
			roStream->open(wfullpath.c_str(), mode);
			baseStream = roStream;
		}
		else
		{
			if (isReadOnly())
			{
				GOTHOGRE_EXCEPT(_filename << " - Cannot open a file for writing in"
					<< " read-only archive " << getName() << ".");
			}
			mode |= std::ios::out;
			rwStream = OGRE_NEW_T(std::fstream, MEMCATEGORY_GENERAL)();
			rwStream->open(wfullpath.c_str(), mode);
			baseStream = rwStream;
		}

		// Should check ensure open succeeded, in case fail for some reason.
		if (baseStream->fail())
		{
			OGRE_DELETE_T(roStream, basic_ifstream, MEMCATEGORY_GENERAL);
			OGRE_DELETE_T(rwStream, basic_fstream, MEMCATEGORY_GENERAL);
			GOTHOGRE_EXCEPT(_filename << " - Cannot open file in"
				<< " archive " << getName() << ".");
		}

		GOTHOGRE_INFO(_filename << " - " << (_readOnly ? "Loading from" : "Saving to")
			<< " archive " << getName() << ".");

		/// Construct return stream, tell it to delete on destroy
		FileStreamDataStream* stream = 0;
		if (rwStream)
		{
			// use the writeable stream 
			stream = OGRE_NEW FileStreamDataStream(_filename,
				rwStream, tagStat.st_size, true);
		}
		else
		{
			// read-only stream
			stream = OGRE_NEW FileStreamDataStream(_filename,
				roStream, tagStat.st_size, true);
		}
		return DataStreamPtr(stream);
    }
Example #12
0
QString FileUtils::readAllText(const QString &fileName)
{
	QString fullPath = getFullPath(fileName);
	if(existsFullPath(fullPath)) return readAllTextFullPath(fullPath);
	return "";
}
Example #13
0
	bool UtlDirectory::scan(const std::string& sExtendedPattern) {
		bool bSuccess = true;
		if (_bScanned) {
			_bScanned = false;
			for (std::list<UtlDirectory*>::const_iterator iterateDirectories = _listOfDirectories.begin(); iterateDirectories != _listOfDirectories.end(); iterateDirectories++) {
				delete (*iterateDirectories);
			}
			_listOfDirectories = std::list<UtlDirectory*>();
			for (std::list<UtlFile*>::const_iterator iterateFiles = _listOfFiles.begin(); iterateFiles != _listOfFiles.end(); iterateFiles++) {
				delete (*iterateFiles);
			}
			_listOfFiles = std::list<UtlFile*>();
		}
		std::string sPattern = sExtendedPattern;
		std::string sPatternDirectory;
		{
			std::string::size_type iIndex = sPattern.find_last_of("/\\");
			if (iIndex != std::string::npos) {
				sPatternDirectory = sPattern.substr(0, iIndex);
				sPattern = sPattern.substr(iIndex + 1);
			}
		}
		std::string sPath = getFullPath();
		if (sPattern.empty()) sPath += "*";
		else sPath += sPattern;
#ifdef WIN32
		WIN32_FIND_DATA myFindData;
		HANDLE hFind = FindFirstFile(sPath.c_str(), &myFindData);
		bool bMore = (hFind != (HANDLE) -1);
		// bug under WIN 32: "*.bar" accepts also "*.bar~" !
		std::string::size_type iIndex = sPattern.find_last_of('*');
		std::string::size_type iTempIndex = sPattern.find_last_of('?');
		std::string sSuffix;
		if (iIndex != iTempIndex) {
			if ((iIndex == std::string::npos) || ((iIndex < iTempIndex) && (iTempIndex != std::string::npos))) iIndex = iTempIndex;
			iIndex++;
			if (iIndex < sPattern.size()) sSuffix = sPattern.substr(iIndex);
		}
		while (bMore) {
			if ((myFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
				char* tcName = (char*) myFindData.cFileName;
				std::string::size_type iLength = strlen(tcName);
				if (!sSuffix.empty() && (iLength > sSuffix.size()) && (strcmp(tcName + (iLength - sSuffix.size()), sSuffix.c_str()) != 0)) {
					// nothing, it shouldn't have been filtered
				} else if (matchPatternDirectory(sPatternDirectory)) {
					UtlFile* pNewFile = new UtlFile(*this, tcName);
					_listOfFiles.push_back(pNewFile);
				}
			}
			bMore = (FindNextFile(hFind, &myFindData) != 0);
		}
		FindClose(hFind);
		std::string sDirectoriesPath = getFullPath() + "*";
		WIN32_FIND_DATA myDirectoriesFindData;
		hFind = FindFirstFile(sDirectoriesPath.c_str(), &myDirectoriesFindData);
		bMore = (hFind != (HANDLE) -1);
		bSuccess = bMore;
		while (bMore) {
			if ((myDirectoriesFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
				char* tcName = (char*) myDirectoriesFindData.cFileName;
				if (tcName[0] != '.') {
					UtlDirectory* pNewDirectory = new UtlDirectory(*this, tcName);
					_listOfDirectories.push_back(pNewDirectory);
				}
			}
			bMore = (FindNextFile(hFind, &myDirectoriesFindData) != 0);
		}
		FindClose(hFind);
#else
		glob_t globbuf;
		memset(&globbuf, '\0', sizeof(globbuf));
		if (glob (sPath.c_str(), GLOB_DOOFFS|GLOB_MARK, NULL, &globbuf) == 0) {
			for (int i=0; i< globbuf.gl_pathc; ++i) {
				std::string sFileName = globbuf.gl_pathv[i];
				std::string::size_type iIndex = sFileName.find_last_of('/');
				if (iIndex != std::string::npos) {
					iIndex++;
					if (sFileName.size() == iIndex) continue;
					sFileName = sFileName.substr(iIndex);
				}
				if (matchPatternDirectory(sPatternDirectory)) {
					UtlFile* pNewFile = new UtlFile(*this, sFileName);
					_listOfFiles.push_back(pNewFile);
				}
			}
		}
		globfree (&globbuf);
		std::string sDirectoryPath = getFullPath() + "*";
		if (glob (sDirectoryPath.c_str(), GLOB_DOOFFS|GLOB_MARK, NULL, &globbuf) == 0) {
			for (int i=0; i< globbuf.gl_pathc; ++i) {
				std::string sDirectoryName = globbuf.gl_pathv[i];
				std::string::size_type iIndex = sDirectoryName.size() - 1;
				if (sDirectoryName[iIndex] == '/') {
					iIndex = sDirectoryName.find_last_of('/', iIndex - 1);
					if (iIndex != std::string::npos) sDirectoryName = sDirectoryName.substr(iIndex + 1);
					sDirectoryName = sDirectoryName.substr(0, sDirectoryName.size() - 1);
					if ((sDirectoryName == ".") || (sDirectoryName == "..")) continue;
					UtlDirectory* pNewDir = new UtlDirectory(*this, sDirectoryName);
					_listOfDirectories.push_back(pNewDir);
				}
			}
		}
		globfree (&globbuf);
#endif
		_bScanned = bSuccess;
		return bSuccess;
	}
void* handleConnection(void* aCon)
{
    connection con = *( (connection*) aCon );

    printf( "\nConnection with client %d established.", con );

    char* buffer;
    if ( readHttpRequest( con, &buffer ) != 0 ) {
        //printf( "\nError reading message." );
        sendHttpResponse( con, 500, ERROR_500 );
        end_contact( con );
        return 0;
    }

    struct Request req = parseRequest( buffer );

    printf( "\nReceived request from client:" );
    printRequestData( &req );

    if ( req.invalid != 0 ) {
        printf( "\nInvalid request: %s", buffer );
        sendHttpResponse( con, 400, ERROR_400 );
        freeRequest( &req );
        end_contact( con );
        return 0;
    }

    free( buffer );

    checkCommandValid( &req );

    if ( req.invalid != 0 ) {
        printf( "\nInvalid command: %s", req.command );
        sendHttpResponse( con, 405, ERROR_405 );
        freeRequest( &req );
        end_contact( con );
        return 0;
    }

    checkPathValid( &req );

    if ( req.invalid != 0 ) {
        printf( "\nInvalid path requested: %s", req.path );
        sendHttpResponse( con, 403, ERROR_403 );
        freeRequest( &req );
        end_contact( con );
        return 0;
    }

    getFullPath( &req );

    if ( req.invalid != 0 ) {
        printf( "\nUnknown file: %s", req.path );
        sendHttpResponse( con, 404, ERROR_404 );
        freeRequest( &req );
        end_contact( con );
        return 0;
    }

    FILE * fd = fopen( req.path, "r" );

    if( !fd )
    {
        printf( "\nCould not open file: %s", req.path );
        sendHttpResponse( con, 403, ERROR_403 );
        freeRequest( &req );
        end_contact( con );
        return 0;
    }

    if( sendHttpResponse( con, 200, STATUS_200 ) );
    {
        int num_bytes = 0;

        char * readbuf = malloc( 1024 );
        while( !feof( fd ) )
        {
            num_bytes = fread( readbuf, 1, 1, fd );
            if( num_bytes < 0 )
                break;

            if( write( con, readbuf, num_bytes ) < 0 )
                break;

        }

        write( con, "\r\n\r\n", 4 );
        fclose( fd );
        free( readbuf );
    }

    printf( "\nClosing Connection %d", con);
    end_contact( con );

    return 0;
}
Example #15
0
//~~ ast::I_element* find_element(const std::string& identifier) [I_element] ~~
for (int i = getNamespaceLevel(); i >= 0; i--)
{
    std::map<std::string,I_element*>::iterator it = object_list.find(getFullPath(i)+identifier);
    if (it != object_list.end())
        return ((*it).second);
}

return 0;
Example #16
0
void animSequenceLoad( tAnimSequence* pAnimSequence,
                       const char* szFileName,
                       tAnimHierarchy const* pAnimHierarchy,
                       CFactory<tVector4>* pVectorFactory,
                       CFactory<tQuaternion>* pQuaternionFactory )
{
    const float fDegreeToRadian = 3.14159f / 180.0f;
    
    char szFullPath[256];
    getFullPath( szFullPath, szFileName );
    
    TiXmlDocument doc( szFullPath );
    bool bLoaded = doc.LoadFile();
    if( bLoaded )
    {
        pAnimSequence->miNumFrames = 0;
        
        TiXmlNode* pNode = doc.FirstChild( "jointKeyframe" )->FirstChild( "keyframe" );
        while( pNode )
        {
            ++pAnimSequence->miNumFrames;
            pNode = pNode->NextSibling( "keyframe" );
        }
        
        pAnimSequence->mafTime = (float *)MALLOC( sizeof( float ) * pAnimSequence->miNumFrames );
        pAnimSequence->maPositions = pVectorFactory->alloc( pAnimSequence->miNumFrames );
        pAnimSequence->maRotation = pQuaternionFactory->alloc( pAnimSequence->miNumFrames );
        pAnimSequence->maScalings = pVectorFactory->alloc( pAnimSequence->miNumFrames );
        pAnimSequence->mapJoints = (tJoint **)MALLOC( sizeof( tJoint* ) * pAnimSequence->miNumFrames );
        
        pAnimSequence->maRotationVec = pVectorFactory->alloc( pAnimSequence->miNumFrames );
        
        pAnimSequence->miNumJoints = 0;
        pAnimSequence->mapUniqueJoints = (tJoint **)MALLOC( sizeof( tJoint* ) * pAnimSequence->miNumFrames );
        memset( pAnimSequence->mapUniqueJoints, 0, sizeof( tJoint* ) * pAnimSequence->miNumFrames );
        
        pAnimSequence->mfLastTime = 0.0f;
        
        int iFrame = 0;
        pNode = doc.FirstChild( "jointKeyframe" )->FirstChild( "keyframe" );
        while( pNode )
        {
            TiXmlElement* pElement = pNode->ToElement();
            
            const char* szName = pElement->Attribute( "joint" );
            const char* szTime = pElement->Attribute( "time" );
            
            const char* szRotX = pElement->Attribute( "rotatex" );
            const char* szRotY = pElement->Attribute( "rotatey" );
            const char* szRotZ = pElement->Attribute( "rotatez" );
            
            const char* szTranslateX = pElement->Attribute( "translatex" );
            const char* szTranslateY = pElement->Attribute( "translatey" );
            const char* szTranslateZ = pElement->Attribute( "translatez" );
            
            // 24 frames / sec
            pAnimSequence->mafTime[iFrame] = ( (float)atof( szTime ) - 1.0f ) / 23.0f;
            if( pAnimSequence->mfLastTime < pAnimSequence->mafTime[iFrame] )
            {
                pAnimSequence->mfLastTime = pAnimSequence->mafTime[iFrame];
            }
            
            tVector4* pPos = &pAnimSequence->maPositions[iFrame];
            tVector4* pScaling = &pAnimSequence->maScalings[iFrame];
            tQuaternion* pRotation = &pAnimSequence->maRotation[iFrame];
            
            tVector4* pRotVec = &pAnimSequence->maRotationVec[iFrame];
            
            tVector4 xAxis = { 1.0f, 0.0f, 0.0f, 1.0f };
            tVector4 yAxis = { 0.0f, 1.0f, 0.0f, 1.0f };
            tVector4 zAxis = { 0.0f, 0.0f, 1.0f, 1.0f };
            
            // total rotation
            tQuaternion xRot, yRot, zRot;
            quaternionInit( &xRot );
            quaternionInit( &yRot );
            quaternionInit( &zRot );
            
            float fRotX = (float)atof( szRotX );
            float fRotY = (float)atof( szRotY );
            float fRotZ = (float)atof( szRotZ );
            
            fRotX *= fDegreeToRadian;
            fRotY *= fDegreeToRadian;
            fRotZ *= fDegreeToRadian;
            
            quaternionFromAxisAngle( &xRot, &xAxis, fRotX );
            quaternionFromAxisAngle( &yRot, &yAxis, fRotY );
            quaternionFromAxisAngle( &zRot, &zAxis, fRotZ );
            
            tQuaternion zyRot;
            quaternionMultiply( &zyRot, &zRot, &yRot );
            quaternionMultiply( pRotation, &zyRot, &xRot );
            
            // scale
            pScaling->fX = pScaling->fY = pScaling->fZ = pScaling->fW = 1.0f;
            
            // position
            pPos->fX = (float)atof( szTranslateX );
            pPos->fY = (float)atof( szTranslateY );
            pPos->fZ = (float)atof( szTranslateZ );
            pPos->fW = 1.0f;
            
            // rotation vector
            pRotVec->fX = fRotX;
            pRotVec->fY = fRotY;
            pRotVec->fZ = fRotZ;
            pRotVec->fW = 1.0f;
            
            // look for the joint in the hierarchy
            int iNumJoints = pAnimHierarchy->miNumJoints;
            for( int i = 0; i < iNumJoints; i++ )
            {
                if( !strcmp( szName, pAnimHierarchy->maJoints[i].mszName ) )
                {
                    pAnimSequence->mapJoints[iFrame] = &pAnimHierarchy->maJoints[i];
                    break;
                }
            }
            
            //OUTPUT( "%s time = %.1f rot ( %f, %f, %f )\n", szName, pAnimSequence->mafTime[iFrame], fRotX, fRotY, fRotZ );
            
            pNode = pNode->NextSibling( "keyframe" );
            
            ++iFrame;
        }
    }
    
    // unique joints in the hierarchy
    pAnimSequence->mapUniqueJoints = (tJoint **)MALLOC( sizeof( tJoint* ) * pAnimHierarchy->miNumJoints );
    pAnimSequence->miNumJoints = pAnimHierarchy->miNumJoints;
    for( int i = 0; i < pAnimHierarchy->miNumJoints; i++ )
    {
        pAnimSequence->mapUniqueJoints[i] = &pAnimHierarchy->maJoints[i];
    }
    
    // sort using joint as the index key
    sortOnJoints( pAnimSequence );
    pAnimSequence->maiStartFrames = (unsigned int *)MALLOC( sizeof( int ) * pAnimSequence->miNumJoints );
    pAnimSequence->maiEndFrames = (unsigned int *)MALLOC( sizeof( int ) * pAnimSequence->miNumJoints );

    int iNumFrames = pAnimSequence->miNumFrames;
    int iNumJoints = pAnimSequence->miNumJoints;
    
    for( int i = 0; i < iNumJoints; i++ )
    {
        pAnimSequence->maiStartFrames[i] = -1;
        pAnimSequence->maiEndFrames[i] = -1;
    }

    // get start and end indices of the joint's keyframes
    for( int i = 0; i < iNumJoints; i++ )
    {
        tJoint* pJoint = pAnimSequence->mapUniqueJoints[i];
        for( int j = 0; j < iNumFrames; j++ )
        {
            // find start
            if( pAnimSequence->mapJoints[j] == pJoint )
            {
                // find end
                pAnimSequence->maiStartFrames[i] = j;
                for( int k = j + 1; k < iNumFrames; k++ )
                {
                    if( pAnimSequence->mapJoints[k] != pJoint )
                    {
                        pAnimSequence->maiEndFrames[i] = k - 1;
                        break;
                    }
                }
                
                if( pAnimSequence->maiEndFrames[i] == -1 )
                {
                    pAnimSequence->maiEndFrames[i] = iNumFrames - 1;
                }
                
                break;
            }
            
        }   // for j = 0 to num frames
        
    }   // for i = 0 to num joints
    
    /*for( int i = 0; i < pAnimSequence->miNumFrames; i++ )
    {
        OUTPUT( "%s time = %.1f rot ( %f, %f, %f )\n",
               pAnimSequence->mapJoints[i]->mszName,
               pAnimSequence->mafTime[i],
               pAnimSequence->maRotationVec[i].fX,
               pAnimSequence->maRotationVec[i].fY,
               pAnimSequence->maRotationVec[i].fZ );
    }*/
    
    sortOnTime( pAnimSequence );
    
    /*for( int i = 0; i < pAnimSequence->miNumFrames; i++ )
    {
        OUTPUT( "%s time = %.1f rot ( %f, %f, %f )\n",
                pAnimSequence->mapJoints[i]->mszName,
                pAnimSequence->mafTime[i],
                pAnimSequence->maRotationVec[i].fX,
                pAnimSequence->maRotationVec[i].fY,
               pAnimSequence->maRotationVec[i].fZ );
    }
    
    for( int i = 0; i < pAnimSequence->miNumJoints; i++ )
    {
        OUTPUT( "%s\t( %d, %d )\n",
                pAnimSequence->mapUniqueJoints[i]->mszName,
                pAnimSequence->maiStartFrames[i],
                pAnimSequence->maiEndFrames[i] );
    }*/
}
Example #17
0
void FileUtils::rmPath(const QString& strDir, const QString& exceptDir)
{
	QString dstDir = getFullPath(strDir);
	QFileInfo file(dstDir);
	delDir(file, getFullPath(exceptDir));
}
Example #18
0
Mesh* loadModel(const char *filename, float size, int flags) {
  /* faces: only quads or triangles at the moment */
  Mesh* mesh;
  Material *materials;

  FILE *f;
  char buf[120];
  char namebuf[120];
  char *path;

  float *vert;
  int *face;
  float *norm;
  int *normi;
  int *matIndex;
  
  float *vertex, *normal;

  int nNormals = 0;
  int nVertices = 0;
  int nFaces = 0;

  float *meshVerts;
  float *meshNorms;
  int *meshFacesize;
  int currentMat = 0;
  int matCount = 0;
  int *pMatCount = NULL;
  int iLine = 0;

  float t1[3], t2[3], t3[3];
  int c, i, j, k, l, pos;
  int hasNorms = 0;
  int hasTexture = 0;
  int inv;

  if((f = fopen(filename, "r")) == 0) {
    fprintf(stderr, "could not open file\n");
    return NULL;
  }

  vert = (float *) malloc(sizeof(float) * 3 * MAX_V);
  face = (int *) malloc(sizeof(int) * MODEL_FACESIZE * MAX_F);
  matIndex = (int *) malloc(sizeof(int) * MAX_F);
  normi = (int *) malloc(sizeof(int) * MODEL_FACESIZE * MAX_F);
  norm = (float *) malloc(sizeof(float) * 3 * MAX_N);
  
  while(fgets(buf, sizeof(buf), f)) {
    switch(buf[0]) {
    case 'm': /* material library? */
      if(sscanf(buf, "mtllib %s ", namebuf) == 1) {
	/* load material library */
	path = getFullPath(namebuf);
	if(path == NULL) {
	  fprintf(stderr, "fatal: can't find mtllib '%s'\n", namebuf);
	  exit(1);
	}
	matCount = loadMaterials(path, &materials);
	if(matCount <= 0) {
	  fprintf(stderr, "fatal: no Materials loaded\n");
	  exit(1);
	}
	/* printf("loaded %d Materials\n", matCount); */
	pMatCount = (int*) malloc(sizeof(int) * matCount);
	for(i = 0; i < matCount; i++)
	  pMatCount[i] = 0;
	currentMat = 0;
      } else
	fprintf(stderr, "warning: ignored line %d\n", iLine);
      break;
    case 'u': case 'g': /* material name */
      if(sscanf(buf, "usemtl %s ", namebuf) == 1) {
	for(i = 0; i < matCount; i++) {
	  if(strcmp(namebuf, (materials + i)->name) == 0) {
	    currentMat = i;
	    break; /* break out of if */
	  }
	}
      } else currentMat = 0;
      break;
    case 'v':
      switch(buf[1]) {
      case ' ': /* vertex data */
	if(nVertices >= MAX_V) {
	  FAIL("vertex limit exceeded\n") ;
	}
	c = sscanf(buf, "v %f %f %f ",
		   vert + nVertices * 3,
		   vert + nVertices * 3 + 1,
		   vert + nVertices * 3 + 2);

	for(i = c; i < 3; i++) {
	  printf("this should not happen\n");
	  *(vert + nVertices * 3 + i) = 0;
	}
	nVertices++;
	break;
      case 'n': /* vertex normal */
	hasNorms = 1;
	if(nVertices >= MAX_N) {
	  FAIL("normals limit exceeded\n") ;
	}
	c = sscanf(buf, "vn %f %f %f ", 
		   norm + nNormals * 3,
		   norm + nNormals * 3 + 1,
		   norm + nNormals * 3 + 2);
	for(i = c; i < 3; i++) {
	  printf("this should not happen\n");
	  *(norm + nNormals * 3 + i) = 0;
	  break;
	}
	nNormals++;
	break;
      case 't': /* texture coordinate - ignored */
	hasTexture = 1;
	break;
      }
      break;
    case 'f':
      if(nFaces * MODEL_FACESIZE >= MAX_F) {
	FAIL("face limit exceeded\n") ;
      }
      /* mark material */
      *(matIndex + nFaces) = currentMat;
      if(matCount > 0 && pMatCount != NULL)
	pMatCount[currentMat]++;

      if(hasNorms) {
	int dummy1, dummy2, dummy3, dummy4;
	if (hasTexture) {
	  c = sscanf(buf, "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d ",
		     face + nFaces * MODEL_FACESIZE, &dummy1,
		     normi + nFaces * MODEL_FACESIZE,
		     face + nFaces * MODEL_FACESIZE + 1, &dummy2,
		     normi + nFaces * MODEL_FACESIZE + 1,
		     face + nFaces * MODEL_FACESIZE + 2, &dummy3,
		     normi + nFaces * MODEL_FACESIZE + 2,
		     face + nFaces * MODEL_FACESIZE + 3, & dummy4,
		     normi + nFaces * MODEL_FACESIZE + 3); 
	} else {
	  c = sscanf(buf, "f %d//%d %d//%d %d//%d %d//%d ",
		     face + nFaces * MODEL_FACESIZE,
		     normi + nFaces * MODEL_FACESIZE,
		     face + nFaces * MODEL_FACESIZE + 1,
		     normi + nFaces * MODEL_FACESIZE + 1,
		     face + nFaces * MODEL_FACESIZE + 2,
		     normi + nFaces * MODEL_FACESIZE + 2,
		     face + nFaces * MODEL_FACESIZE + 3,
		     normi + nFaces * MODEL_FACESIZE + 3);
	}

	for(i = c / 2; i < MODEL_FACESIZE; i++) {
	  *(face + nFaces * MODEL_FACESIZE + i) = -1;
	  *(normi + nFaces * MODEL_FACESIZE + i) = -1;
	}

	nFaces++;
      } else {
	/* TODO: add if(hasTexture) */
	c = sscanf(buf, "f %d %d %d %d ",
		   face + nFaces * MODEL_FACESIZE,
		   face + nFaces * MODEL_FACESIZE + 1,
		   face + nFaces * MODEL_FACESIZE + 2,
		   face + nFaces * MODEL_FACESIZE + 3);
	for(i = c; i < MODEL_FACESIZE; i++)
	  *(face + nFaces * MODEL_FACESIZE + i) = -1;
	nFaces++;
      }
      break;
    }
    iLine++;
  }
  if(hasNorms == 0) {
    /* create Normals */
    for(i = 0; i < nFaces; i++) {
      t1[0] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 0) - 1) + 0);
      t1[1] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 0) - 1) + 1);
      t1[2] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 0) - 1) + 2);

      t2[0] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 1) - 1) + 0);
      t2[1] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 1) - 1) + 1);
      t2[2] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 1) - 1) + 2);

      t3[0] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 2) - 1) + 0);
      t3[1] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 2) - 1) + 1);
      t3[2] = *(vert + 3 * (*(face + i * MODEL_FACESIZE + 2) - 1) + 2);
      /*
      printf("face %d:\n", i);
      printf("v1: %f %f %f\n", t1[0], t1[1], t1[2]);
      printf("v2: %f %f %f\n", t2[0], t2[1], t2[1]);
      printf("v3: %f %f %f\n", t3[0], t3[1], t3[1]);
      */
      t1[0] -= t3[0];
      t1[1] -= t3[1];
      t1[2] -= t3[2];
      t2[0] -= t3[0];
      t2[1] -= t3[1];
      t2[2] -= t3[2];
      normcrossprod(t1, t2, t3);
      /* printf("normal: %f %f %f\n\n", t3[0], t3[1], t3[2]); */
      /* t3 now contains the face normal */
      for(j = 0; j < MODEL_FACESIZE; j++) 
	*(normi + i * MODEL_FACESIZE + j) = nNormals + 1;
      *(norm + nNormals * 3 + 0) = t3[0];
      *(norm + nNormals * 3 + 1) = t3[1];
      *(norm + nNormals * 3 + 2) = t3[2];
      nNormals++;
    }
    /* printf("generated %d normals\n", nNormals); */
  }


  if(matCount == 0) { /* create Default material */
    float spec[] = { 0.77, 0.77, 0.77, 1.0 };
    float dif[] = { 0.4, 0.4, 0.4, 1};
    float amb[] = { 0.25, 0.25, 0.25, 1};

    materials = (Material*) malloc(sizeof(Material));
    materials->name = (char*) malloc(strlen("default") + 1);
    sprintf(materials->name, "default");
    
    memcpy(materials->ambient, amb, 3 * sizeof(float));
    memcpy(materials->diffuse, dif, 3 * sizeof(float));
    memcpy(materials->specular, spec, 3 * sizeof(float));

    matCount = 1;
    pMatCount = (int*) malloc(sizeof(int));
    pMatCount[0] = nFaces;
  }
  /* everything is parsed, now allocate memory and */
  /* rescale and get bbox */
  /* copy data to Mesh structure */
  /* new: sort into sub meshes with by materials */

  if(flags & MODEL_INVERT_NORMALS) { /* invert normals */
    /* printf("inverting normals...really!\n"); */
    inv = -1;
  } else inv = 1;

  mesh = (Mesh*) malloc(sizeof(Mesh));

  /* rescale */

  rescaleVertices(vert, size, nVertices, mesh->bbox);

  mesh->nFaces = nFaces;
  mesh->nMaterials = matCount;
  mesh->materials = materials;
  mesh->meshparts = (MeshPart*) malloc(matCount * sizeof(MeshPart));
  for(i = 0; i < matCount; i++) {
    meshVerts = (float*) malloc(pMatCount[i] * 3 * MODEL_FACESIZE * sizeof(float));
    meshNorms = (float*) malloc(pMatCount[i] * 3 * MODEL_FACESIZE * sizeof(float));
    meshFacesize = (int*) malloc(pMatCount[i] * sizeof(int));

    /* printf("Material %d: %d faces\n", i, pMatCount[i]); */

    (mesh->meshparts + i)->nFaces = pMatCount[i];
    (mesh->meshparts + i)->vertices = meshVerts;
    (mesh->meshparts + i)->normals = meshNorms;
    (mesh->meshparts + i)->facesizes = meshFacesize;
    pos = 0;
    for(j = 0; j < nFaces; j++) { /* foreach face */
      if(matIndex[j] == i) {
	*(meshFacesize + pos) = 0;
	/* printf("face %d\n", j); */
	for(k = 0; k < MODEL_FACESIZE; k++) { /* foreach vertex of face */
	  if(*(face + j * MODEL_FACESIZE + k) != -1) {
	    *(meshFacesize + pos) += 1;
	    /* adjust facesize... */
	    /* copy face and normal data to meshVerts, meshNorms */
	    vertex = vert + 3 * ( *(face + j * MODEL_FACESIZE + k) - 1);
	    normal = norm + 3 * ( *(normi + j * MODEL_FACESIZE + k) - 1);
	    if(flags & MODEL_NORMALIZE)
	      normalize(normal);

	    for(l = 0; l < 3; l++) {
	      /* printf("%f ", vertex[l]); */
	      *(meshVerts + 3 * (pos * MODEL_FACESIZE + k) + l) = *(vertex + l);
	      *(meshNorms + 3 * (pos * MODEL_FACESIZE + k) + l) = inv * *(normal + l);
	    }
	    /* printf("\n"); */
	  }

	}
	pos++;
	if(pos > pMatCount[i]) {
	  fprintf(stderr, "fatal: more faces than accounted for\n");
	  exit(1);
	}
      }
    }
  }
  
  free(vert);
  free(face);
  free(norm);
  free(normi);
  free(pMatCount);
  free(matIndex);

  fclose (f);
  /* printf("loaded model: %d vertices, %d normals, %d faces, %d materials\n",
	nVertices, nNormals, nFaces, matCount); */

  return mesh;
}
Example #19
0
int Hbinstalltest::Init()
{
	int ret = -1;
	
	char * pPath =  getenv("BILLDIR");
	char   petcPath[1024] = {0};
	if(NULL == pPath)
	{
		Log::log(0,"取不到系统 BILLDIR 环境变量");
		return -1;
	}
	else
	{
		sprintf(petcPath,"%s/%s",pPath,"etc/hbtest");
	}
	
	ret = getFullPath(petcPath,"BILL_FILE","GATHER_PART_NODE",GATHER_PART_NODE,"data/yzy_src");
	if(ret != 0) return -1;
	ret = getFullPath(petcPath,"BILL_FILE","GATHER_PART_NODE2",GATHER_PART_NODE2,"data/yzy_src");
	if(ret != 0) return -1;
	ret = getFullPath(petcPath,"BILL_FILE","DUPPATH",DUPPATH,"data/dupdata");
	if(ret != 0) return -1;
	ret = getFullPath(petcPath,"BILL_FILE","DBPATH",DBPATH,"data/filedb");
	if(ret != 0) return -1;
	memset(TEST_LIST,0,sizeof(TEST_LIST));
	ret = getFullPath(petcPath,"BILL_FILE","TEST_LIST",TEST_LIST,"");
	if(ret != 0) return -1;
	ret = getFullPath(petcPath,"BILL_FILE","LIST_NAME",LIST_NAME,"");
	if(ret != 0) return -1;
	
	ret = getFullPath(petcPath,"OTHER_PATH","SQL_USERLOAD",SQL_USERLOAD,"sql/test2_loaduserinfo.sql");
	if(ret != 0) return -1;
	ret = getFullPath(petcPath,"OTHER_PATH","SQL_BILLFLOWCFG",SQL_BILLFLOWCFG,"sql/test2_billflow_cfg.sql");
	if(ret != 0) return -1;
	ret = getFullPath(petcPath,"OTHER_PATH","SET",SET,"shell/set.sh");
	if(ret != 0) return -1;
	
	/*
	ptr = RD.readIniString(petcPath,"OTHER_PATH","SQL_USERLOAD",SQL_USERLOAD,NULL);
	if ( access(SQL_USERLOAD, F_OK) || ptr == NULL || strlen(SQL_USERLOAD) == 0)
	{
		Log::log(0,"取不到 SQL_USERLOAD 路径 ,请看 hbtest 是否配置");
		return -1;
	}
	
	ptr = RD.readIniString(petcPath,"OTHER_PATH","SQL_BILLFLOWCFG",SQL_BILLFLOWCFG,NULL);
	if ( access(SQL_BILLFLOWCFG, F_OK) || ptr == NULL || strlen(SQL_BILLFLOWCFG) == 0)
	{
		Log::log(0,"取不到 SQL_BILLFLOWCFG 路径 ,请看 hbtest 是否配置");
		return -1;
	}
	
	ptr = RD.readIniString(petcPath,"OTHER_PATH","SET",SET,NULL);
	if ( access(SET, F_OK) || ptr == NULL || strlen(SET) == 0)
	{
		Log::log(0,"取不到 SET 路径 ,请看 hbtest 是否配置");
		return -1;
	}
	
	ptr = RD.readIniString(petcPath,"OTHER_PATH","BILLFLOWRUN",BILLFLOWRUN,NULL);
	if ( access(BILLFLOWRUN, F_OK) || ptr == NULL || strlen(BILLFLOWRUN) == 0)
	{
		Log::log(0,"取不到 BILLFLOWRUN 路径 ,请看 hbtest 是否配置");
		return -1;
	}
	
	ptr = RD.readIniString(petcPath,"OTHER_PATH","BILLFLOWDOWN",BILLFLOWDOWN,NULL);
	if ( access(BILLFLOWDOWN, F_OK) || ptr == NULL || strlen(BILLFLOWDOWN) == 0)
	{
		Log::log(0,"取不到 BILLFLOWDOWN 路径 ,请看 hbtest 是否配置");
		return -1;
	}
	*/
	return ret;
}
Example #20
0
void StickyNoteActor::syncStickyNoteWithFileContents()
{
	reauthorize(false);

	// clear the old texture
#ifdef DXRENDER
	SAFE_RELEASE(_stickyNoteTextureId);
#else
	if (_stickyNoteTextureId)
	{
		glDeleteTextures(1, &_stickyNoteTextureId);
		_stickyNoteTextureId = 0;
	}
#endif

	// get the font
	int fontSize = NxMath::max(20, themeManager->getValueAsInt("ui.stickyNote.font.size",0));
	FontDescription desc(themeManager->getValueAsFontFamilyName("ui.stickyNote.font.family",""), fontSize);
	QFont stickyNoteFont = fontManager->getFont(desc);

	// get the sticky note text
	QString stickyNoteStr;
	getStickyNote(getFullPath(), &stickyNoteStr);

	// layout the sticky note text
	QTextOption option;
		option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
	_stickyNoteText.setDefaultTextOption(option);
	_stickyNoteText.setDefaultFont(stickyNoteFont);
	_stickyNoteText.setDocumentMargin(12.5f);
	_stickyNoteText.setTextWidth(256);
	_stickyNoteText.setPlainText(stickyNoteStr);

	QSizeF textSize = _stickyNoteText.size();
	const int minStickyNoteFontSize = 10;
	while (textSize.height() > 256 && 
		   stickyNoteFont.pointSize() > minStickyNoteFontSize)
	{
		stickyNoteFont.setPointSize(stickyNoteFont.pointSize() - 1);
		_stickyNoteText.setDefaultFont(stickyNoteFont);
		textSize = _stickyNoteText.size();
	}

	// render the sticky note to a qimage
	const unsigned int bufferSize = 256;
	QImage image(bufferSize, bufferSize, QImage::Format_ARGB32);
	image.fill(Qt::red);
	QPainter p;
	p.begin(&image);
	p.setRenderHint(QPainter::Antialiasing, true);
	p.setRenderHint(QPainter::TextAntialiasing, true);
		p.drawImage(0, 0, _stickyNoteBackground);
		p.setPen(QColor(50, 50, 75));
		_stickyNoteText.drawContents(&p, QRect(0, 0, bufferSize, int(bufferSize - _stickyNoteText.documentMargin())));
	p.end();
#ifdef DXRENDER
	_stickyNoteTextureId = dxr->createTextureFromData(image.width(), image.height(), image.bits(), image.bytesPerLine());
#else
	// load the qimage into open gl
	glGenTextures(1, &_stickyNoteTextureId);
	glBindTexture(GL_TEXTURE_2D, _stickyNoteTextureId);

	float maximumAnisotropy = 0.0f;
	glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maximumAnisotropy);
	if (GLEW_ARB_texture_border_clamp)
	{
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB);
	}
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

	// copy the full image (glTexSubImage2D does not work well with GL_GENERATE_MIPMAP)
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(),
		0, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
#endif
}
Example #21
0
bool HttpResponse::addHeading ()
{
	bool more = false;

	if ( getAttributes() & FILE_ATTRIBUTE_HIDDEN )
	{
		// never show hidden files
		addError( idHttpForbidden );
	}
	else if ( getAttributes() & FILE_ATTRIBUTE_DIRECTORY )
	{
		if ( _server->getAllowListing() )
		{
			// create a directory listing
			addStatus( idHttpOk );
			addString( CRLF );
			more = true;
		}
		else
			addError( idHttpForbidden );
	}
	else
	{
		LPCTSTR fileName = getFullPath().c_str();

		if ( _file.openFastRead(getFullPath()) )
		{
			if ( getStatus() != REQ_SIMPLE )
			{
				TimeStamp timeIfMod;

				string strIfMod = getHeaderValue( idParamIfModifiedSince );

				if ( strIfMod.size() > 0 &&
					HttpUtil::fromHttpTime( strIfMod, timeIfMod ) &&
					!HttpUtil::ifModSince( _file, timeIfMod ) )
				{
					// eh, it hasn't been modified
					addStatus( idHttpNotModified );

					// don't need it anymore
					_file.close();
				}
				else
				{
					// send it off
					addStatus( idHttpOk );

					// set content type and length
					long contentLength = _file.size();

					addContentType();
					addHeader( idParamContentLength, contentLength );

					// get the last modified time
					FILETIME ft;
					if ( GetFileTime( _file, NULL, NULL, &ft ) )
					{
						string strTime = HttpUtil::getHttpDate( &ft );
						addHeader( idParamLastModified, strTime );
					}

					more = true;
				}

				// blank line
				addString( CRLF );
			}
			else
			{
				more = true;
			}
		}
		else
		{
			// couldn't open; try again later
			addError( idHttpUnavailable );
		}
	}
	return more;
}
Example #22
0
void HttpResponse::addListing ()
{
	bool bRoot = false;
	bool bIcons = _server->getListIcon();
	string strIcon;

	string strLine = 
	string("http://") 
		+ _server->getServer()
		+ getUrl();

	string strDir  = getUrl();
	string strMask = getFullPath();

	// make sure URL ends in a slash
	if ( strDir[ strDir.size()-1 ] != '/' )
		strDir += '/';

	// is this the server's root folder?
	else if ( strDir.compare( "/" ) == 0 )
		bRoot = true;

	// create the file search mask
	HttpUtil::addFile( strMask, IDS_DIRMASK );

	addString( IDS_CONTENTS_PRE );
	addString( strLine );
	addString( IDS_CONTENTS_POST );

	if ( bRoot )
		addString( IDS_CONTENTS_DESC );

	if ( bIcons )
		StringUtil::loadString( strIcon, IDS_ICON_BLANK );

	StringUtil::formatString( strLine, IDS_CONTENTS_HEADING, strIcon );
	addString( strLine );

	int nFiles = 0;

	WIN32_FIND_DATA fd;

	// find the first file that matches the mask
	HANDLE fh = FindFirstFile( strMask.c_str(), &fd );
	if ( fh != INVALID_HANDLE_VALUE )
	{
		// create a line for the found file
		nFiles += addListingFile( &fd, strDir, bIcons );

		// loop through all other files
		while ( FindNextFile( fh, &fd ) )
			nFiles += addListingFile( &fd, strDir, bIcons );
	}

	if ( nFiles == 0 )
		addString( IDS_CONTENTS_EMPTY );

	addString( IDS_CONTENTS_FOOTER );
	// only add the parent link if there is one
	if ( !bRoot )
	{
		if ( bIcons )
		{
			StringUtil::loadString( strIcon, IDS_ICON_PARENT );
		}

		StringUtil::formatString( strLine, IDS_CONTENTS_PARENT, strIcon );
		addString( strLine );
	}
	// add the note and end it
	addString( IDS_CONTENTS_NOTE );
	addString( CRLF );
}
//==============================================================================
CString CDiskItem::getFullName() const
{
	CString strResult = getFullPath();
	strResult = AddWithSlash( strResult, m_strName );
	return strResult;
}
Example #24
0
bool FileUtils::existsFullPath(const QString& fileName)
{
	QFileInfo file(getFullPath(fileName));
	return file.exists();
}
Example #25
0
string getFullPath(cchar *envVarName, cchar* path, cchar* filename)
{
    string envDirPath = getEnvDirPath(envVarName);
    return getFullPath(envDirPath, path, filename);
}
Example #26
0
bool FileUtils::exists(const QString& fileName)
{
	QString newFileName = getFullPath(fileName);
	return existsFullPath(newFileName);
}
Example #27
0
bool createNewJavaVM( const char* PLUGIN_PATH, JavaVM** jvm, JNIEnv** env )
{
    char* fileBuffer = (char*)malloc( 16384 );
    
    if ( JAVA_HOME == NULL )
    {
        logg( "ERROR: Could not locate JAVA_HOME." );
        
        return ( false );
    }
    
    memcpy( fileBuffer, "Using Java from folder \"", 24 );
    memcpy( fileBuffer + 24, JAVA_HOME, strlen( JAVA_HOME ) );
    memcpy( fileBuffer + 24 + strlen( JAVA_HOME ), "\".", 3 );

    logg( fileBuffer );
    if(JAVA_VERSION == 7)
	{
		getFullPath( JAVA_HOME, "bin\\msvcr100.dll", fileBuffer );
		logg( "    Loading msvcr100.dll...", false );
	}
	else
	{
		getFullPath( JAVA_HOME, "bin\\msvcr71.dll", fileBuffer );
		logg( "    Loading msvcr71.dll...", false );
	}
    HMODULE msvcdll = LoadLibrary( fileBuffer );
    
    if ( msvcdll == NULL )
    {
        if(JAVA_VERSION == 7)
			logg( " ERROR: Failed to load msvcr100.dll." );
		else
			logg( " ERROR: Failed to load msvcr71.dll." );
        return ( false );
    }
    else
    {
        logg( " done." );
    }
    
    getFullPath( JAVA_HOME, "bin\\client\\jvm.dll", fileBuffer );
    logg( "    Loading jvm.dll...", false );
    HMODULE jvmdll = LoadLibrary( fileBuffer );
    
    if ( jvmdll == NULL )
    {
        logg( " ERROR: Failed to load jvm.dll." );
        return ( false );
    }
    else
    {
        logg( " done." );
    }
    
    logg( "Successfully loaded Java dlls." );
    
    logg( "Invoking Java VM..." );
    
    setBuffer( "-Djava.class.path=", fileBuffer );
    addPostFix( PLUGIN_PATH, fileBuffer );
    addPostFix( "\\rfdynhud.jar", fileBuffer );
    addPostFix( ";", fileBuffer );
    addPostFix( PLUGIN_PATH, fileBuffer );
    if ( isRFactor2() )
        addPostFix( "\\rfdynhud_gamedata_rfactor2.jar", fileBuffer );
    else
        addPostFix( "\\rfdynhud_gamedata_rfactor1.jar", fileBuffer );
    
	const bool WITH_PROFILER = false;
	const unsigned int nOptions = WITH_PROFILER ? 11 : 10;
    JavaVMOption options[nOptions];
    
    unsigned int i = 0;
	options[i++].optionString = cropBuffer2( fileBuffer );
    options[i++].optionString = cropBuffer2( addPreFix( "-Dworkdir=", setBuffer( PLUGIN_PATH, fileBuffer ) ) );
    options[i++].optionString = "-Xms96m";
    options[i++].optionString = "-Xmx96m";
    options[i++].optionString = "-XX:MaxGCPauseMillis=5";
    options[i++].optionString = "-XX:+UseAdaptiveSizePolicy";
    options[i++].optionString = "-Xincgc";
    options[i++].optionString = "-Dsun.java2d.opengl=true";
    options[i++].optionString = "-Dsun.java2d.d3d=false";
    options[i++].optionString = "-Dsun.java2d.noddraw=true";
	if ( WITH_PROFILER )
		options[i++].optionString = "-agentpath:c:\\Program Files (x86)\\YourKit Java Profiler 9.0.8\\bin\\win32\\yjpagent.dll";
    
    free( fileBuffer );
    
    logg( "JVM options:" );
    for ( i = 0; i < nOptions; i++ )
        logg2( "    ", options[i].optionString, true );
    
    JavaVMInitArgs vm_args;
    
    vm_args.version = JNI_VERSION_1_6;
    vm_args.options = options;
    vm_args.nOptions = nOptions;
    vm_args.ignoreUnrecognized = TRUE;
    
    CreateJavaVMPROC CreateJavaVM = (CreateJavaVMPROC)GetProcAddress( jvmdll, "JNI_CreateJavaVM" );
    
    if ( CreateJavaVM == NULL )
    {
        logg( "ERROR: Failed to get proc address of JNI_CreateJavaVM." );
        return ( false );
    }
    
    jint res = CreateJavaVM( jvm, (void **)env, &vm_args );
    
    if ( res < 0 )
    {
        logg( "ERROR: Failed to create Java virtual machine." );
        return ( false );
    }
    
    jclass System = (*env)->FindClass( "java/lang/System" );
    jmethodID getProperty = (*env)->GetStaticMethodID( System, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;" );
    loggSystemProperty( *env, System, getProperty, "java.vm.vendor" );
    loggSystemProperty( *env, System, getProperty, "java.vm.name" );
    loggSystemProperty( *env, System, getProperty, "java.vm.version" );
    loggSystemProperty( *env, System, getProperty, "java.runtime.version" );
    loggSystemProperty( *env, System, getProperty, "java.awt.graphicsenv" );
    
    logg( "Successfully invoked Java VM." );
    
    return ( true );
}
Example #28
0
void StickyNoteActor::modifyWithString(QString msg)
{
	if (!isFileSystemType(StickyNote))
		return;
	writeStickyNote(getFullPath(), msg);
}
std::shared_ptr<Font>& AlloyContext::loadFont(const std::string& name,
		const std::string& file) {
	fonts.push_back(
			std::shared_ptr<Font>(new Font(name, getFullPath(file), this)));
	return fonts.back();
}
 osg::Node* traverseAIScene( const std::string& filename, const struct aiScene* aiScene, const struct aiNode* aiNode,
                             TextureMap& textures, const osgDB::Options* options ) const
 {
     osg::Geode* geode = new osg::Geode;
     for ( unsigned int n=0; n<aiNode->mNumMeshes; ++n )
     {
         // Create geometry basic properties
         const struct aiMesh* mesh = aiScene->mMeshes[ aiNode->mMeshes[n] ];
         osg::Geometry* geom = new osg::Geometry;
         geode->addDrawable( geom );
         
         osg::Vec3Array* va = new osg::Vec3Array(mesh->mNumVertices);
         osg::Vec3Array* na = (mesh->mNormals ? new osg::Vec3Array(mesh->mNumVertices) : NULL);
         osg::Vec4Array* ca = (mesh->mColors[0] ? new osg::Vec4Array(mesh->mNumVertices) : NULL);
         for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
         {
             const aiVector3D& v = mesh->mVertices[i];
             (*va)[i].set( v.x, v.y, v.z );
             if ( na )
             {
                 const aiVector3D& n = mesh->mNormals[i];
                 (*na)[i].set( n.x, n.y, n.z );
             }
             if ( ca )
             {
                 const aiColor4D& c = mesh->mColors[0][i];
                 (*ca)[i].set( c.r, c.g, c.b, c.a );
             }
         }
         
         geom->setVertexArray( va );
         if ( na )
         {
             geom->setNormalArray( na );
             geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX );
         }
         if ( ca )
         {
             geom->setColorArray( ca );
             geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
         }
         
         // Create geometry texture coordinates
         unsigned int unit = 0;
         const aiVector3D* aiTexCoords = mesh->mTextureCoords[unit];
         while ( aiTexCoords!=NULL )
         {
             switch ( mesh->mNumUVComponents[unit] )
             {
             case 1:
                 {
                     osg::FloatArray* ta = new osg::FloatArray(mesh->mNumVertices);
                     for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
                         (*ta)[i] = aiTexCoords[i].x;
                     geom->setTexCoordArray( unit, ta );
                 }
                 break;
             case 2:
                 {
                     osg::Vec2Array* ta = new osg::Vec2Array(mesh->mNumVertices);
                     for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
                     {
                         const aiVector3D& t = aiTexCoords[i];
                         (*ta)[i].set( t.x, t.y );
                     }
                     geom->setTexCoordArray( unit, ta );
                 }
                 break;
             case 3:
                 {
                     osg::Vec3Array* ta = new osg::Vec3Array(mesh->mNumVertices);
                     for ( unsigned int i=0; i<mesh->mNumVertices; ++i )
                     {
                         const aiVector3D& t = aiTexCoords[i];
                         (*ta)[i].set( t.x, t.y, t.z );
                     }
                     geom->setTexCoordArray( unit, ta );
                 }
                 break;
             }
             aiTexCoords = mesh->mTextureCoords[++unit];
         }
         
         // Create geometry primitives
         osg::ref_ptr<osg::DrawElementsUInt> de[5];
         de[1] = new osg::DrawElementsUInt(GL_POINTS);
         de[2] = new osg::DrawElementsUInt(GL_LINES);
         de[3] = new osg::DrawElementsUInt(GL_TRIANGLES);
         de[4] = new osg::DrawElementsUInt(GL_QUADS);
         de[0] = new osg::DrawElementsUInt(GL_POLYGON);
         
         osg::DrawElementsUInt* current = NULL;
         for ( unsigned int f=0; f<mesh->mNumFaces; ++f )
         {
             const struct aiFace& face = mesh->mFaces[f];
             if ( face.mNumIndices>4 ) current = de[0].get();
             else current = de[face.mNumIndices].get();
             
             for ( unsigned i=0; i<face.mNumIndices; ++i )
                 current->push_back( face.mIndices[i] );
         }
         
         for ( unsigned int i=0; i<5; ++i )
         {
             if ( de[i]->size()>0 )
                 geom->addPrimitiveSet( de[i].get() );
         }
         
         // Create textures
         osg::StateSet* ss = geom->getOrCreateStateSet();
         const aiMaterial* aiMtl = aiScene->mMaterials[mesh->mMaterialIndex];
         aiReturn texFound = AI_SUCCESS;
         aiTextureOp envOp = aiTextureOp_Multiply;
         aiTextureMapMode wrapMode[3] = {aiTextureMapMode_Clamp};
         unsigned int texIndex = 0;
         aiString path;
         
         while ( texFound==AI_SUCCESS )
         {
             texFound = aiMtl->GetTexture(
                 aiTextureType_DIFFUSE, texIndex++, &path, NULL, &unit, NULL, &envOp, &(wrapMode[0]) );
             if ( unit>0 ) unit--;  // The output UV seems to start at 1?
             if ( texFound!=AI_SUCCESS ) break;
             
             std::string texFile(path.data);
             if ( !osgDB::isAbsolutePath(texFile) ) texFile = getFullPath( filename, texFile );
             
             TextureMap::iterator itr = textures.find(texFile);
             if ( itr==textures.end() )
             {
                 osg::ref_ptr<osg::Texture2D> tex2D = new osg::Texture2D;
                 tex2D->setWrap( osg::Texture::WRAP_S, getWrapMode(wrapMode[0]) );
                 tex2D->setWrap( osg::Texture::WRAP_T, getWrapMode(wrapMode[1]) );
                 tex2D->setWrap( osg::Texture::WRAP_R, getWrapMode(wrapMode[2]) );
                 tex2D->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
                 tex2D->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
                 tex2D->setImage( osgDB::readImageFile(texFile, options) );
                 textures[texFile] = tex2D;
             }
             
             ss->setTextureAttributeAndModes( unit, textures[texFile].get() );
             if ( unit>0 ) ss->setTextureAttributeAndModes( unit, new osg::TexEnv(getEnvMode(envOp)) );
         }
         
         // Create materials
         createMaterialData( ss, aiMtl );
     }
     
     aiMatrix4x4 m = aiNode->mTransformation;
     m.Transpose();
     
     // Create the node and continue looking for children
     osg::ref_ptr<osg::MatrixTransform> mt;
     mt = new osg::MatrixTransform;
     mt->setMatrix( osg::Matrixf((float*)&m) );
     for ( unsigned int n=0; n<aiNode->mNumChildren; ++n )
     {
         osg::Node* child = traverseAIScene( filename, aiScene, aiNode->mChildren[n], textures, options );
         if ( child ) mt->addChild( child );
     }
     mt->addChild( geode );
     return mt.release();
 }