コード例 #1
0
CORE::CString
GetUniqueFileName( const CORE::CString& filename )
{GUCEF_TRACE;

    CORE::CString fileExt = CORE::ExtractFileExtention( filename );
    CORE::CString fileWithoutExt;

    if ( fileExt.IsNULLOrEmpty() )
    {
        fileWithoutExt = filename;
    }
    else
    {
        fileWithoutExt = filename.CutChars( fileExt.Length()+1, false );
    }

    CORE::UInt32 i = 2;
    CORE::CString filenameToTest = filename;
    while ( CORE::FileExists( filenameToTest ) )
    {
        filenameToTest = fileWithoutExt + '(' + CORE::UInt32ToString( i ) + ")." + fileExt;
        ++i;
    }

    return filenameToTest;
}
コード例 #2
0
void 
Win32EnumPorts( std::list<Int32>& portlist )
{
	portlist.clear();

	// use querydosdevice on NT/2000/xp (no need to open ports...)
	if ( VER_PLATFORM_WIN32_NT == Win32GetOSVersion() )
	{
		const int bufferSize = 65535;        
        CORE::CDynamicBuffer deviceNameBuffer( bufferSize, true );

        // Read the list of devices into the buffer
		Int32 len = ::QueryDosDevice( 0, deviceNameBuffer.AsTypePtr< char >(), bufferSize );
		for ( Int32 n=0; n<len; ++n )
		{
			// if found "COM", then add number to list
			if ( 0 == _stricmp( deviceNameBuffer.AsConstTypePtr< char >( n ), "COM" ) )
            {
                portlist.push_back( atoi( deviceNameBuffer.AsConstTypePtr< char >( n+3 ) ) );
            }

			// find next null pointer
			while ( deviceNameBuffer.AsConstType< char >( n ) != '\0' )
            {
				++n;
            }
		}
	}
	
	// else, open port 1-255
	else
	{
		CORE::CString basePath( "\\\\.\\COM" );
        for ( Int32 i=1; i<255; ++i )
		{
			CORE::CString portPath = basePath + CORE::Int32ToString( i );

			// try to open port
			bool result = false;			
			::HANDLE handle = ::CreateFile( portPath.C_String(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0 );
			
			if ( INVALID_HANDLE_VALUE == handle ) continue;
			::CloseHandle( handle );
  		
			portlist.push_back( i );
		}
	}
}
コード例 #3
0
bool
RenameFileAsBackup( const CORE::CString& filepath )
{GUCEF_TRACE;

    CORE::CString newFilepath = filepath + ".backup";     
    if ( 0 != CORE::Move_File( newFilepath.C_String() , 
                               filepath.C_String()    ) )
    {
        GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "File \"" + filepath + "\" has been renamed to \"" + newFilepath + "\"" );
        return true;
    }
    else
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Failed to rename file \"" + filepath + "\" to \"" + newFilepath + "\"" );
        return false;
    }
}
コード例 #4
0
bool
DeleteFileBackup( const CORE::CString& filepath )
{GUCEF_TRACE;

    CORE::CString newFilepath = filepath + ".backup";
    if ( CORE::FileExists( newFilepath ) )
    {
        if ( 0 != CORE::Delete_File( newFilepath.C_String() ) )
        {
            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "File \"" + newFilepath + "\" has been deleted" );
            return true;
        }
        else
        {
            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Failed to delete file \"" + newFilepath + "\"" );
            return false;
        }
    }
    return true;
}
コード例 #5
0
bool
CLogSvcClient::OnTaskCycleLog( const TLogMsgType logMsgType    ,
                               const CORE::Int32 logLevel      ,
                               const CORE::CString& logMessage ,
                               const CORE::UInt32 threadId     )
{GUCEF_TRACE;

    CORE::Int16 logMsgTypeValue = logMsgType;
    CORE::Int8 msgHeader[ 16 ];  // 16 = 1+4+1+2+4+4
    CORE::UInt32 logMsgLength = logMessage.Length() + 11;

    msgHeader[ 0 ] = (CORE::Int8) LOGSVCMSGTYPE_DELIMITER;   // set delimiter for message: 1 byte
    memcpy( msgHeader+1, &logMsgLength, 4 );                 // set the total message length : 4 bytes
    msgHeader[ 5 ] = (CORE::Int8) LOGSVCMSGTYPE_LOGMSG;      // set TCP msg type: 1 byte
    memcpy( msgHeader+6, &logMsgTypeValue, 2 );              // set log msg type: 2 bytes
    memcpy( msgHeader+8, &logLevel, 4 );                     // set log level: 4 bytes
    memcpy( msgHeader+12, &threadId, 4 );                    // set thread id: 4 bytes

    if ( m_connectionInitialized )
    {
        // Send the logging msg header
        if ( m_tcpClient.Send( msgHeader, 16 ) )
        {
            // Now send the logging text
            m_tcpClient.Send( logMessage.C_String() ,
                              logMessage.Length()   );
        }
    }
    else
    {
        // The logging connection is not initialized yet
        // queue the msg until the connection is initialized

        TLogMessage queueItem;
        memcpy( queueItem.msgHeader, msgHeader, 16 );
        queueItem.logMsg = logMessage;

        m_logQueue.push_back( queueItem );
    }
    return true;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: LiberatorUSA/GUCEF
bool
LoadConfig( const CORE::CString& configPath ,
            CORE::CValueList& keyValueList  )
{GUCEF_TRACE;

    #ifdef GUCEF_DEBUG_MODE
    const CORE::CString configFile = "ProjectGenerator_d.ini";
    #else
    const CORE::CString configFile = "ProjectGenerator.ini";
    #endif

    CORE::CString configFilePath;
    bool foundViaParam = false;
    if ( !configPath.IsNULLOrEmpty() )
    {
        GUCEF_LOG( CORE::LOGLEVEL_BELOW_NORMAL, "Checking for config file @ " + configPath );
        foundViaParam = CORE::FileExists( configPath );
        configFilePath = configPath;
    }

    if ( !foundViaParam )
    {
        CORE::CString configFilePath = CORE::CombinePath( "$CURWORKDIR$", configFile );
        configFilePath = CORE::RelativePath( configFilePath );

        GUCEF_LOG( CORE::LOGLEVEL_BELOW_NORMAL, "Checking for config file @ " + configFilePath );
        if ( !CORE::FileExists( configFilePath ) )
        {
            configFilePath = CORE::CombinePath( "$MODULEDIR$", configFile );
            configFilePath = CORE::RelativePath( configFilePath );

            GUCEF_LOG( CORE::LOGLEVEL_BELOW_NORMAL, "Checking for config file @ " + configFilePath );
            if ( !FileExists( configFilePath ) )
            {
                GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "Unable to locate any config file, will rely on params" );
                return false;
            }
        }
    }
    GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Located config file @ " + configFilePath );

    keyValueList.SetConfigNamespace( "Bootstrap/Main/AppArgs" );
    keyValueList.SetUseGlobalConfig( true );
    keyValueList.SetAllowDuplicates( false );
    keyValueList.SetAllowMultipleValues( true );

    CORE::CConfigStore& configStore = CORE::CCoreGlobal::Instance()->GetConfigStore();
    configStore.SetConfigFile( configFilePath );
    return configStore.LoadConfig();
}
コード例 #7
0
bool
CResArchive::LoadArchive( const VFS::CString& archiveName ,
                          const VFS::CString& archivePath ,
                          const bool writableRequest      )
{GUCEF_TRACE;

    // We do not support writable archives
    if ( writableRequest ) return false;

    // Since we always need both the index file and the resource file
    // already construct the paths for both

    CORE::CString fileExt = CORE::ExtractFileExtention( archivePath ).Uppercase();
    if ( fileExt.IsNULLOrEmpty() )
    {
        m_idxPath = m_resPath = archivePath;
        m_idxPath += ".IDX";
        m_resPath += ".RES";
    }
    else
    if ( fileExt.Equals( "RES", false ) )
    {
        m_resPath = archivePath;
        m_idxPath = archivePath.CutChars( 4, false, 0 ) + ".IDX";
    }
    else
    if ( fileExt.Equals( "IDX", false ) )
    {
        m_idxPath = archivePath;
        m_resPath = archivePath.CutChars( 4, false, 0 ) + ".RES";
    }

    m_archiveName = archiveName;
    m_archivePath = archivePath;

    return LoadIndex();
}
コード例 #8
0
bool
CGUIDriverOgre::Init( GUI::TWindowContextPtr windowContext )
{
    if ( !m_ceGuiInitialized )
    {
        try
        {
            Ogre::RenderTarget* renderTarget = nullptr;
            CORE::CString renderTargetPtrStr = windowContext->GetProperty( "Ogre::RenderTarget" );
            if ( !renderTargetPtrStr.IsNULLOrEmpty() )
            {
                renderTarget = static_cast< Ogre::RenderTarget* >( CORE::StringToPointer( renderTargetPtrStr ) );
                if ( NULL == renderTarget )
                    return false;
            }
            Ogre::SceneManager* sceneManager = nullptr;
            CORE::CString sceneManagerPtrStr = windowContext->GetProperty( "Ogre::SceneManager" );
            if ( !sceneManagerPtrStr.IsNULLOrEmpty() )
            {
                sceneManager = static_cast< Ogre::SceneManager* >( CORE::StringToPointer( sceneManagerPtrStr ) );
                if ( NULL == sceneManager )
                    return false;
            }
            
            // Auto-create a viewport here if none exists yet
            unsigned short viewportCount = renderTarget->getNumViewports();
            if ( 0 == viewportCount )
            {
                Ogre::Camera* camera = sceneManager->createCamera( "CEGUI" );
                camera->setPosition( Ogre::Vector3( 0, 0, 500 ) );
                camera->lookAt( Ogre::Vector3( 0, 0, -300 ) );
                camera->setNearClipDistance( 5 );

                // Create a viewport covering whole window
                Ogre::Viewport* viewport = renderTarget->addViewport( camera );
                viewport->setBackgroundColour( Ogre::ColourValue( 0.0f, 0.0f, 0.0f, 0.0f ) );
                viewport->setOverlaysEnabled( true );
                                                  
                // Update the camera aspect ratio to that of the viewport
                camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() ) );                
            }

            CEGUI::Sizef displaySize( (float) windowContext->GetWidth(), (float) windowContext->GetHeight() );
            m_guiRenderer = &CEGUI::OgreRenderer::create( *renderTarget );// displaySize );//, CEGUI::OpenGLRenderer::TTT_AUTO );
            m_guiRenderer->setDefaultRootRenderTarget( *renderTarget );
            m_guiSystem = &CEGUI::System::create( *m_guiRenderer, &m_vfsResourceProvider, &m_xmlParserAdapter, m_imageCodecAdapter );

            // setup default group for validation schemas
            CEGUI::XMLParser* parser = m_guiSystem->getXMLParser();
            if ( nullptr != parser && parser->isPropertyPresent( "SchemaDefaultResourceGroup" )  )
                parser->setProperty( "SchemaDefaultResourceGroup", m_schemasResourceGroup );

            // Load the fonts
            CEGUI::FontManager::getSingleton().createAll( m_defaultFont, CEGUI::Font::getDefaultResourceGroup() );
        
            // Load the scheme
            try
            {
                CEGUI::SchemeManager::getSingleton().createFromFile( "Generic.scheme" );
            }
            catch ( CEGUI::Exception& e )
            {
                CORE::CString info = e.getMessage() + " - at - " + e.getFileName() + ":" + e.getFunctionName() + ":" + CORE::UInt32ToString( e.getLine() ).STL_String();
                GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "Unhandled exception during CEGUI initialization: " + info );
            }
            CEGUI::SchemeManager::getSingleton().createFromFile( m_schemeToUse );
        
            // Set the defaults
            CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont( m_defaultFont );
            CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage( m_defaultCursorImage );
            CEGUI::Window* rootWindow = CEGUI::WindowManager::getSingleton().createWindow( "DefaultWindow", "root" );
            CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow( rootWindow );
            
            // clearing this queue actually makes sure it's created(!)
            CEGUI::System::getSingleton().getDefaultGUIContext().clearGeometry( CEGUI::RQ_OVERLAY );                                             
        
            m_ceGuiInitialized = true;
        }
        catch ( CEGUI::Exception& e )
        {
            CORE::CString info = e.getMessage() + " - at - " + e.getFileName() + ":" + e.getFunctionName() + ":" + CORE::UInt32ToString( e.getLine() ).STL_String();
            GUCEF_EXCEPTION_LOG( CORE::LOGLEVEL_IMPORTANT, "Unhandled exception during CEGUI initialization: " + info );

            m_ceGuiInitialized = false;
        }
    }
    return m_ceGuiInitialized;
}
コード例 #9
0
bool
COgreWindowContext::Initialize( const GUI::CString& title                ,
                                const GUI::CVideoSettings& videoSettings ,
                                const GUI::CString& ogreRenderSystem     )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    // First create a regular O/S window
    if ( m_osWindow->WindowCreate( title                                       ,
                                   0                                           ,
                                   0                                           ,
                                   videoSettings.GetResolutionWidthInPixels()  ,
                                   videoSettings.GetResolutionHeightInPixels() ) )
    {
        // Display the new window
        m_osWindow->Show();
        m_osWindow->SendToForegound();
        m_osWindow->GrabFocus();

	    // Now proceed with setting up the Ogre specifics
        
        // We grab the O/S window identifier 'the handle' 
        // This is passed to Ogre to tie things together
        CORE::Int64 windowRef = 0; 
        CORE::CString windowIntStr = m_osWindow->GetProperty( "WINDOWINT" );
        if ( !windowIntStr.IsNULLOrEmpty() )
        {
            windowRef = CORE::StringToInt64( windowIntStr );
        }
        Ogre::NameValuePairList options;         
        options[ "externalWindowHandle" ] = Ogre::StringConverter::toString( (size_t) windowRef ); 

        Ogre::Root* ogreRoot = Ogre::Root::getSingletonPtr();
        if ( ogreRoot == nullptr )
        {            
            ogreRoot = OGRE_NEW Ogre::Root( "", "", "" ); 
        }

        if ( !ogreRoot->isInitialised() )
        {
            // Load any Ogre plugins not loaded yet from the bootstrap group
            CORE::CCoreGlobal::Instance()->GetPluginControl().LoadPluginGroup( "Ogre" );
            
            const Ogre::RenderSystemList& rsList = ogreRoot->getAvailableRenderers();
            if ( rsList.size() == 0 )
            {
                GUCEF_ERROR_LOG( CORE::LOGLEVEL_IMPORTANT, "OgreWindowContext: No Ogre render systems are available, cannot initialize" );
                return false;
            }

            Ogre::RenderSystem* renderSystem = nullptr;
            Ogre::RenderSystemList::const_iterator i = rsList.begin();
            while ( i != rsList.end() )
            {
                GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Available Ogre render system: " + (*i)->getFriendlyName() );
                if ( ogreRenderSystem == (*i)->getName() )
                {
                    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Found desired/preferred Ogre render system: " + (*i)->getFriendlyName() );
                    renderSystem = (*i); 
                }
                ++i;
            }
            if ( renderSystem == nullptr )
            {
                GUCEF_WARNING_LOG( CORE::LOGLEVEL_IMPORTANT, "OgreWindowContext: Preferred Ogre render systems not available, using first available alternative: " + (*rsList.begin())->getFriendlyName() );
                renderSystem = *rsList.begin();
            }

            ogreRoot->setRenderSystem( renderSystem );
            m_sceneManager = ogreRoot->createSceneManager( Ogre::ST_GENERIC );

            m_renderWindow = ogreRoot->initialise( false, title );
        }

        m_renderWindow = ogreRoot->createRenderWindow( title, 
                                                       videoSettings.GetResolutionWidthInPixels(), 
                                                       videoSettings.GetResolutionHeightInPixels(), 
                                                       videoSettings.GetFullscreenState(),
                                                       &options ); 

        // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
        CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator(); 
        pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
        SubscribeTo( &pulseGenerator );

        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Succesfully created Ogre rendering context" );
        m_initialized = true;
        return true;
    }
    return false;
}
コード例 #10
0
void
MirrorDirsAndFiles( const CORE::CString& srcDir    ,
                    const CORE::CString& dstDir    ,
                    bool mirrorExistingFilesOnly   ,
                    const TStringSet* fileTypes    ,
                    const TStringSet* dirsToIgnore )
{GUCEF_TRACE;

    if ( mirrorExistingFilesOnly )    
    {
        // We have a seperare function for mirroring existing files only
        // It is more efficient since it can use the destination as the template
        // avoiding unnessary operations
        MirrorExistingDirsAndFiles( srcDir       ,
                                    dstDir       ,
                                    fileTypes    ,
                                    dirsToIgnore );
        return;
    }

    // Get a list of all source files
    TFileEntryVector files;
    BuildFileList( srcDir       ,
                   files        ,
                   fileTypes    ,
                   dirsToIgnore );

    // Iterate the list of files and make sure we mirror all of them
    TFileEntryVector::iterator i = files.begin();
    while ( i != files.end() )
    {
        TFileEntry& fileEntry = (*i);

        CORE::CString srcFilePath = srcDir;
        CORE::AppendToPath( srcFilePath, fileEntry.filedir );
        CORE::AppendToPath( srcFilePath, fileEntry.filename );
        
        CORE::CString destFilePath = dstDir;
        CORE::AppendToPath( destFilePath, fileEntry.filedir );
        
        // Make sure destination directory exists
        if ( CORE::CreateDirs( destFilePath ) )
        {
            CORE::AppendToPath( destFilePath, fileEntry.filename );
            
            bool fileExisted = CORE::FileExists( destFilePath );                        
            if ( fileExisted )
            {
                if ( !RenameFileAsBackup( destFilePath ) )
                {
                    GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Unable to rename existing destination file: " + destFilePath );
                    ++i;
                    continue;
                }
                GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully renamed destination file \"" + destFilePath + "\"" );
            }
                        
            if ( 0 != CORE::Copy_File( destFilePath.C_String()  , 
                                       srcFilePath.C_String() ) )
            {
                GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully copied file from \"" + srcFilePath + "\" to \"" + destFilePath + "\"" );
                if ( fileExisted )
                {
                    if ( DeleteFileBackup( destFilePath ) )
                    {
                        GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully deleted backup file after successfull copy for file \"" + destFilePath + "\"" );
                    }
                }
            }
            else
            {
                GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Failed to copy file from \"" + srcFilePath + "\" to \"" + destFilePath + "\"" );
                if ( fileExisted )
                {
                    if ( !UndoRenameFileAsBackup( destFilePath ) )
                    {
                        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Failed to undo renaming of file: " + destFilePath );
                    }
                }
            }
        }
        else
        {
            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Unable to create directory: " + destFilePath );
        }
        ++i;
    }
}
コード例 #11
0
void
MirrorExistingDirsAndFiles( const CORE::CString& srcDir    ,
                            const CORE::CString& dstDir    ,
                            const TStringSet* fileTypes    ,
                            const TStringSet* dirsToIgnore )
{
    // Get a list of all destination files
    TFileEntryVector files;
    BuildFileList( dstDir       ,
                   files        ,
                   fileTypes    ,
                   dirsToIgnore );

    // Iterate the list of files and make sure we mirror all of them
    TFileEntryVector::iterator i = files.begin();
    while ( i != files.end() )
    {
        TFileEntry& fileEntry = (*i);

        CORE::CString srcFilePath = srcDir;
        CORE::AppendToPath( srcFilePath, fileEntry.filedir );
        CORE::AppendToPath( srcFilePath, fileEntry.filename );
        
        CORE::CString destFilePath = dstDir;
        CORE::AppendToPath( destFilePath, fileEntry.filedir );
        CORE::AppendToPath( destFilePath, fileEntry.filename );
        
        if ( !CORE::FileExists( srcFilePath ) )
        {
            // Skip this one, we are configured to only mirror files for which 
            // a target file already exists
            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Skipping file \"" + destFilePath + "\" because there is no source file available" );
            ++i;
            continue;
        }

        if ( !RenameFileAsBackup( destFilePath ) )
        {
            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Unable to rename existing destination file: " + destFilePath );
            ++i;
            continue;
        }
            
        GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully renamed destination file \"" + destFilePath + "\"" );
            
        if ( 0 != CORE::Copy_File( destFilePath.C_String()  , 
                                   srcFilePath.C_String() ) )
        {
            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully copied file from \"" + srcFilePath + "\" to \"" + destFilePath + "\"" ); 
            if ( DeleteFileBackup( destFilePath ) )
            {
                GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully deleted backup file after successfull copy for file \"" + destFilePath + "\"" );
            }
        }
        else
        {
            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Failed to copy file from \"" + srcFilePath + "\" to \"" + destFilePath + "\"" );
            if ( !UndoRenameFileAsBackup( destFilePath ) )
            {
                GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Failed to undo renaming of file: " + destFilePath );
            }
        }
        ++i;
    }
}
コード例 #12
0
void
CopyOverMatchedFiles( const CORE::CString& srcDirRoot  ,
                      const CORE::CString& destDirRoot ,
                      TMatchEntryVector& matches       )
{GUCEF_TRACE;

    TMatchEntryVector::iterator i = matches.begin();
    while ( i != matches.end() )
    {
        TMatchEntry& matchEntry = (*i);
        
        CORE::CString sourceFilePath = srcDirRoot;
        CORE::AppendToPath( sourceFilePath, matchEntry.source.filedir );
        CORE::AppendToPath( sourceFilePath, matchEntry.source.filename );
        
        TFileEntryVector& destinations = matchEntry.destinations;

        if ( destinations.empty() )
        {
            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "File \"" + sourceFilePath + "\" cannot be copied since it doesnt have any destination locations" );
        }
        else
        { 
            TFileEntryVector::iterator n = destinations.begin();
            while ( n != destinations.end() )
            {
                TFileEntry& destEntry = (*n);
                
                CORE::CString destFilePath = destDirRoot;
                CORE::AppendToPath( destFilePath, destEntry.filedir );
                CORE::AppendToPath( destFilePath, destEntry.filename );
                
                // Delete whatever backup file might have gotten left behind from a previous run                
                DeleteFileBackup( destFilePath );
                
                GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Preparing to copy file from \"" + sourceFilePath + "\" to \"" + destFilePath + "\"" );            
                GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Backing up destination file \"" + destFilePath + "\"" ); 
                if ( RenameFileAsBackup( destFilePath ) )
                {
                    GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully renamed destination file \"" + destFilePath + "\"" );
                    
                    if ( 0 != CORE::Copy_File( destFilePath.C_String()   , 
                                               sourceFilePath.C_String() ) )
                    {
                        GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully copied file from \"" + sourceFilePath + "\" to \"" + destFilePath + "\"" );
                        DeleteFileBackup( destFilePath );
                    }
                    else
                    {
                        GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Failed to copy file from \"" + sourceFilePath + "\" to \"" + destFilePath + "\"" );
                        UndoRenameFileAsBackup( destFilePath );
                    }
                }
                else
                {
                    GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Failed to delete destination file \"" + destFilePath + "\"" );
                }
                
                ++n;
            }
        }        
        ++i;
    }
}
コード例 #13
0
CORE::CString
GenerateContentForAndroidProjectMakefile( const CORE::CString& projectName             ,
                                          const TModuleInfoEntryPairVector& mergeLinks ,
                                          const CORE::CString& outputDir               ,
                                          bool addGeneratorCompileTimeToOutput         ,
                                          const TStringSet& ndkModulesUsed             )
{GUCEF_TRACE;

    GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Generating Android makefile content for overall project file regarding project \"" + projectName + "\"" );

    CORE::CString contentPrefix = makefileHeader;

    contentPrefix +=
      "#\n"
      "# This is the project makefile which includes all modules which are part of this project\n"
      "#\n";

    contentPrefix +=
      "# PROJECT: \"" + projectName + "\"\n#\n\n";

    if ( addGeneratorCompileTimeToOutput )
    {
        contentPrefix +=
          "#"
          "# The project generator version used was compiled on " __TIME__ __DATE__ "\n"
          "#\n\n";
    }

    contentPrefix +=
      "ifndef PROJECT_ROOT_PATH\n"
      "  PROJECT_ROOT_PATH := $(call my-dir)\n"
      "endif\n\n"
      "include $(CLEAR_VARS)\n\n";

    // Include makefiles for NDK modules used
    CORE::CString moduleListSection;

/* ->  Not needed
    if ( !ndkModulesUsed.empty() )
    {
        TStringSet::iterator i = ndkModulesUsed.find( "android_native_app_glue" );
        if ( i != ndkModulesUsed.end() ) 
        {
            moduleListSection += "MY_MODULE_PATH := $(ANDROIDNDK)/sources/android/native_app_glue\n";
            moduleListSection += "include $(MY_MODULE_PATH)/Android.mk\n\n";
        }
        i = ndkModulesUsed.find( "cpufeatures" );
        if ( i != ndkModulesUsed.end() ) 
        {
            moduleListSection += "MY_MODULE_PATH := $(ANDROIDNDK)/sources/android/cpufeatures\n";
            moduleListSection += "include $(MY_MODULE_PATH)/Android.mk\n\n";
        }
    }
*/
    // Include each module's makefile in the order listed as their build order
    const TModuleInfo* currentModule = FindFirstModuleAccordingToBuildOrder( mergeLinks );
    while ( NULL != currentModule )
    {
        if ( ( MODULETYPE_HEADER_INCLUDE_LOCATION != currentModule->moduleType )   &&
             ( MODULETYPE_HEADER_INTEGRATE_LOCATION != currentModule->moduleType ) &&
             ( MODULETYPE_CODE_INTEGRATE_LOCATION != currentModule->moduleType )    )
        {
            // Get relative path from the outputDir to the other module
            const TModuleInfoEntry* fullModuleInfo = FindModuleInfoEntryForMergedInfo( mergeLinks, *currentModule );
            CORE::CString relativePathToModule = CORE::GetRelativePathToOtherPathRoot( outputDir, fullModuleInfo->rootDir );
            relativePathToModule = relativePathToModule.ReplaceChar( '\\', '/' );

            // Add entry for this module to the project file
            moduleListSection += "MY_MODULE_PATH := $(PROJECT_ROOT_PATH)/" + relativePathToModule + "\n";
            moduleListSection += "include $(MY_MODULE_PATH)/Android.mk\n\n";
        }

        // Done with this module, go to the next one
        currentModule = FindNextModuleAccordingToBuildOrder( mergeLinks, *currentModule );
    }

    return contentPrefix + moduleListSection;
}
コード例 #14
0
CORE::CString
GenerateContentForAndroidMakefile( const TModuleInfoEntryPairVector& mergeLinks ,
                                   const TModuleInfo& moduleInfo                ,
                                   const CORE::CString& moduleRoot              ,
                                   bool addGeneratorCompileTimeToOutput         ,
                                   TStringSet& ndkModulesUsed                   )
{GUCEF_TRACE;

    CORE::CString contentPrefix = makefileHeader;

    if ( addGeneratorCompileTimeToOutput )
    {
        contentPrefix +=
          "#"
          "# The project generator version used was compiled on " __TIME__ __DATE__ "\n"
          "#\n\n";
    }

    contentPrefix +=
      "ifndef MY_MODULE_PATH\n"
      "  MY_MODULE_PATH := $(call my-dir)\n"
      "endif\n"
      "LOCAL_PATH := $(MY_MODULE_PATH)\n\n"
      "include $(CLEAR_VARS)\n\n"
      "@echo Module path: $(MY_MODULE_PATH)\n"
      "LOCAL_MODULE := " + moduleInfo.name + "\n";

    if ( ( MODULETYPE_SHARED_LIBRARY == moduleInfo.moduleType ) ||
         ( MODULETYPE_STATIC_LIBRARY == moduleInfo.moduleType )  )
    {
        contentPrefix += "LOCAL_MODULE_FILENAME := lib" + moduleInfo.name + "\n";
    }
    contentPrefix += "@echo Module name: $(LOCAL_MODULE)\n\n";

    // Generate the source files section
    CORE::CString srcFilesSection = "LOCAL_SRC_FILES := \\\n";
    bool firstLoop = true;
    TStringVectorMap::const_iterator i = moduleInfo.sourceDirs.begin();
    while ( i != moduleInfo.sourceDirs.end() )
    {
        const CORE::CString& srcDir = (*i).first;
        const TStringVector& srcFiles = (*i).second;

        TStringVector::const_iterator n = srcFiles.begin();
        while ( n != srcFiles.end() )
        {
            if ( !firstLoop )
            {
                srcFilesSection += " \\\n";
            }
            firstLoop = false;

            CORE::CString relFilePath = srcDir;
            CORE::AppendToPath( relFilePath, (*n) );

            srcFilesSection += "  " + relFilePath.ReplaceChar( '\\', '/' );

            ++n;
        }
        ++i;
    }

    // Add some spacing for readability
    srcFilesSection += "\n\n";

    // Generate the included files section
    // for android make files we only need the path
    // it will locate the header file on its own
    CORE::CString includeFilesSection = "LOCAL_C_INCLUDES := \\\n";
    i = moduleInfo.includeDirs.begin();
    firstLoop = true;
    while ( i != moduleInfo.includeDirs.end() )
    {
        if ( !firstLoop )
        {
            includeFilesSection += " \\\n";
        }
        firstLoop = false;

        const CORE::CString& dir = (*i).first;
        if ( !dir.IsNULLOrEmpty() )
        {
            includeFilesSection += "  $(MY_MODULE_PATH)/" + dir.ReplaceChar( '\\', '/' );
        }
        else
        {
            // Support the use-case where the include dir is empty because the moduleinfo dir == include dir
            includeFilesSection += "  $(MY_MODULE_PATH)";
        }

        ++i;
    }

    // We also need to add the include paths required to find headers
    // refered to because of dependencies
    TStringSet::const_iterator n = moduleInfo.dependencyIncludeDirs.begin();
    while ( n != moduleInfo.dependencyIncludeDirs.end() )
    {
        if ( !firstLoop )
        {
            includeFilesSection += " \\\n";
        }
        firstLoop = false;

        includeFilesSection += "  $(MY_MODULE_PATH)/" + (*n).ReplaceChar( '\\', '/' );

        ++n;
    }

    // Add some spacing for readability
    includeFilesSection += "\n\n";

    // Now we add the preprocessor definitions
    CORE::CString preprocessorSection;
    if ( !moduleInfo.preprocessorSettings.defines.empty() )
    {
        preprocessorSection = "LOCAL_CFLAGS :=";

        TStringSet::const_iterator m = moduleInfo.preprocessorSettings.defines.begin();
        while ( m != moduleInfo.preprocessorSettings.defines.end() )
        {
            preprocessorSection += " -D" + (*m);
            ++m;
        }

        // Add some spacing for readability
        preprocessorSection += "\n\n";
    }

    // Now we add the compiler flags, if any
    // For Android we only support the GCC compilers
    CORE::CString compilerSection;
    TStringMap::const_iterator p = moduleInfo.compilerSettings.compilerFlags.find( "GCC" );
    if ( p != moduleInfo.compilerSettings.compilerFlags.end() )
    {
        compilerSection = "LOCAL_CFLAGS +=" + (*p).second + "\n\n";
    }
    p = moduleInfo.compilerSettings.compilerFlags.find( "G++" );
    if ( p != moduleInfo.compilerSettings.compilerFlags.end() )
    {
        compilerSection = "LOCAL_CPPFLAGS +=" + (*p).second + "\n\n";
    }

    // Now we will add all the dependency linking instructions.
    // For some reason it matters, at specification time, to Android's build
    // system whether the module you are linking to is a dynamically linked module
    // or a statically linked module. As such we have to figure out which is which.
    //
    // We make an alphabetical list instead of creating the section right away because
    // we dont want the order to vary in the makefile because such changes cause the NDK
    // to build the code again for no reason.
    CORE::CString linkingErrorSection;
    TStringSet linkedSharedLibraries;
    TStringSet linkedStaticLibraries;
    TStringSet linkedRuntimeLibraries;
    TModuleTypeMap::const_iterator m = moduleInfo.linkerSettings.linkedLibraries.begin();
    while ( m != moduleInfo.linkerSettings.linkedLibraries.end() )
    {
        const CORE::CString& linkedLibName = (*m).first;
        TModuleType linkedLibType = (*m).second;
        switch ( linkedLibType )
        {
            case MODULETYPE_EXECUTABLE:
            {
                // This is really nasty but the best option for now...
                // It is possible to link to exported symbols from an executable
                // under linux and as such we will leverage this here
                linkedSharedLibraries.insert( linkedLibName );
                break;
            }
            case MODULETYPE_SHARED_LIBRARY:
            {
                linkedSharedLibraries.insert( linkedLibName );
                break;
            }
            case MODULETYPE_STATIC_LIBRARY:
            {
                linkedStaticLibraries.insert( linkedLibName );
                break;
            }
            case MODULETYPE_CODE_INTEGRATE_LOCATION:
            case MODULETYPE_HEADER_INTEGRATE_LOCATION:
            case MODULETYPE_HEADER_INCLUDE_LOCATION:
            {
                // Skip this, no linking required
                break;
            }
            default:
            {
                // Since the depedendency module type was not predefined we will investigate among
                // the other modules to try to determine the nature of the linked module
                const TModuleInfo* linkedDependency = FindModuleByName( mergeLinks, linkedLibName );
                if ( NULL != linkedDependency )
                {
                    // The module we are linking too is part of this project.
                    // As such we can simply check the other module's info
                    // to find out wheter its a dynamically linked module or not
                    // which in turn tells us how to instruct the Android build system
                    // to link.
                    switch( linkedDependency->moduleType )
                    {
                        case MODULETYPE_SHARED_LIBRARY:
                        {
                            linkedSharedLibraries.insert( linkedLibName );
                            break;
                        }
                        case MODULETYPE_STATIC_LIBRARY:
                        {
                            linkedStaticLibraries.insert( linkedLibName );
                            break;
                        }
                        case MODULETYPE_EXECUTABLE:
                        {
                            // This is really nasty but the best option for now...
                            // It is possible to link to exported symbols from an executable
                            // under linux and as such we will leverage this here
                            linkedSharedLibraries.insert( linkedLibName );
                            break;
                        }
                        case MODULETYPE_HEADER_INTEGRATE_LOCATION:
                        case MODULETYPE_CODE_INTEGRATE_LOCATION:
                        {
                            // Dont do anything.
                            // The files for this 'module' have already been merged into the dependent module
                            break;
                        }
                        case MODULETYPE_HEADER_INCLUDE_LOCATION:
                        {
                            // Don't have to do anything.
                            // Due to the auto-dependency tracking of include paths the header paths will have been added to
                            // whatever module depends on this 'module'
                            break;
                        }
                        default:
                        {
                            linkingErrorSection +=
                              "# *** ERROR *** Finish me\n"
                              "# Unable to determing module type from the source information\n"
                              "# Please edit the line below to manually set the correct linking method for this dependency\n";
                            linkingErrorSection += "#LOCAL_<(LDLIBS???)> += " + moduleInfo.name + "\n\n";

                            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Error: the module " + moduleInfo.name + " does not have a useable module type set, you will have to manually edit the file to correct the error" );
                            break;
                        }
                    }
                }
                else
                {
                    // If we get here then this dependency is not on a module which is part of the project
                    // As such we cannot build this module thus the only approriote linking method would seem
                    // to be the one where we simply instruct the linker to load this dependency at runtime.
                    // This will typically be the case for any Android NDK modules we have to link to.
                    linkedRuntimeLibraries.insert( linkedLibName );
                }
            }
        }
        ++m;
    }

    CORE::CString linkingSection;
    CORE::CString linkedSharedLibrariesSection = "\nLOCAL_SHARED_LIBRARIES := \\\n";
    CORE::CString linkedStaticLibrariesSection = "\nLOCAL_STATIC_LIBRARIES := \\\n";
    CORE::CString linkedRuntimeLibrariesSection = "\nLOCAL_LDLIBS := \\\n";

    // Based on what was found we will construct the linking section
    bool first = true;
    n = linkedSharedLibraries.begin();
    while ( n != linkedSharedLibraries.end() )
    {
        if ( !first )
        {
             linkedSharedLibrariesSection += " \\\n";
        }
        linkedSharedLibrariesSection += "  " + (*n);
        first = false;
        ++n;
    }
    first = true;
    n = linkedStaticLibraries.begin();
    while ( n != linkedStaticLibraries.end() )
    {
        if ( !first )
        {
             linkedStaticLibrariesSection += " \\\n";
        }
        linkedStaticLibrariesSection += "  " + (*n);
        first = false;
        ++n;
    }
    first = true;
    n = linkedRuntimeLibraries.begin();
    while ( n != linkedRuntimeLibraries.end() )
    {
        if ( !first )
        {
             linkedRuntimeLibrariesSection += " \\\n";
        }
        linkedRuntimeLibrariesSection += "  -l" + (*n);
        first = false;
        ++n;
    }

    if ( !linkedSharedLibraries.empty() )
    {
        linkingSection += linkedSharedLibrariesSection + "\n\n";
    }
    if ( !linkedStaticLibraries.empty() )
    {
        linkingSection += linkedStaticLibrariesSection + "\n\n";
    }
    if ( !linkedRuntimeLibraries.empty() )
    {
        linkingSection += linkedRuntimeLibrariesSection + "\n\n";
    }
    linkingSection += linkingErrorSection;

    // Check if we have a file on disk of information which is to be inserted into
    // our automatically generated make file
    CORE::CString manualContent;
    CORE::CString manualContentFilePath = moduleRoot;
    CORE::AppendToPath( manualContentFilePath, "AndroidAddition.mk" );
    if ( CORE::FileExists( manualContentFilePath ) )
    {
        if ( CORE::LoadTextFileAsString( manualContentFilePath ,
                                         manualContent         ) )
        {
            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Successfully loaded manually defined content for module " + moduleInfo.name + " from addition file " + manualContentFilePath );
        }
        else
        {
            manualContent =
              "# *** ERROR *** Finish me\n"
              "# Unable to load manually defined content from detected AndroidAddition.mk file\n"
              "# Please manually insert its contents here\n\n";
            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Error: the module " + moduleInfo.name + " has manually defined content in a AndroidAddition.mk file but it could not be loaded, you will have to manually edit the file to correct the error" );
        }
    }

    // Now generate the latter part of the file which contains more meta data about the module
    CORE::CString contentSuffix;
    switch ( moduleInfo.moduleType )
    {
        case MODULETYPE_SHARED_LIBRARY:
        {
            contentSuffix += "include $(BUILD_SHARED_LIBRARY)\n\n";
            break;
        }
        case MODULETYPE_STATIC_LIBRARY:
        {
            contentSuffix += "include $(BUILD_STATIC_LIBRARY)\n\n";
            break;
        }
        case MODULETYPE_EXECUTABLE:
        {
            contentSuffix += "include $(BUILD_EXECUTABLE)\n\n";
            break;
        }
        default:
        {
            contentSuffix +=
              "# *** ERROR *** Finish me\n"
              "# Unable to determine module type from the source information\n"
              "# Please edit the line below to manually set the correct module type to build\n"
              "#include $(BUILD_???)\n\n";

            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Error: the module " + moduleInfo.name + " does not have a useable module type set, you will have to manually edit the file to correct the error" );
            break;
        }
    }

    // Check for NDK static libraries to import
    if ( !linkedStaticLibraries.empty() )
    {
        TStringSet::iterator a = linkedStaticLibraries.find( "android_native_app_glue" );
        if ( a != linkedStaticLibraries.end() )
        {
            ndkModulesUsed.insert( "android_native_app_glue" );
            contentSuffix += "$(call import-module,android/native_app_glue)\n";
        }
        a = linkedStaticLibraries.find( "cpufeatures" );
        if ( a != linkedStaticLibraries.end() )
        {
            ndkModulesUsed.insert( "cpufeatures" );
            contentSuffix += "$(call import-module,android/cpufeatures)\n";
        }
    }

    return contentPrefix + srcFilesSection + includeFilesSection + preprocessorSection + compilerSection + linkingSection + manualContent + contentSuffix;
}
コード例 #15
0
void
BuildFileList( const CORE::CString& srcDir         ,
               const CORE::CString& relativeSrcDir ,
               TFileEntryVector& files             ,
               const TStringSet* fileTypes         ,
               const TStringSet* dirsToIgnore      )
{GUCEF_TRACE;

    struct CORE::SDI_Data* dirEntry = CORE::DI_First_Dir_Entry( srcDir.C_String() );
    if ( dirEntry != NULL )    
    {
        do 
        {
            CORE::CString entryName = CORE::DI_Name( dirEntry );
            if ( ( entryName != "." )  &&
                 ( entryName != ".." )  )
            {
                // Check if this is a dir we have to ignore
                if ( 0 == CORE::DI_Is_It_A_File( dirEntry ) )
                {
                    if ( NULL != dirsToIgnore )
                    {
                        if ( dirsToIgnore->find( entryName.Lowercase() ) != dirsToIgnore->end() )
                        {
                            // do not process further
                            CORE::CString ignoredDir = srcDir;
                            CORE::AppendToPath( ignoredDir, entryName );
                            GUCEF_LOG( CORE::LOGLEVEL_NORMAL, "Ignoring directory \"" + ignoredDir + "\"" );
                            continue;
                        }
                    }
                }
                
                if ( 0 != CORE::DI_Is_It_A_File( dirEntry ) )
                {
                    if ( NULL != fileTypes )
                    {
                        CORE::CString fileExt = CORE::Extract_File_Ext( entryName.C_String() );
                        fileExt = fileExt.Lowercase();
                        if ( fileTypes->find( fileExt ) == fileTypes->end() )
                        {
                            // skip this entry as instructed, not a matching filetype
                            continue;
                        }
                    }
                    
                    TFileEntry fileEntry;
                    fileEntry.filedir = relativeSrcDir;
                    fileEntry.filename = entryName;
                    
                    files.push_back( fileEntry );
                }
                else
                {
                    // We found a sub-dir, process it
                    CORE::CString subDirPath = srcDir;
                    CORE::AppendToPath( subDirPath, entryName );
                    
                    CORE::CString subRelSrcDir = relativeSrcDir;
                    CORE::AppendToPath( subRelSrcDir, entryName );
                    
                    BuildFileList( subDirPath   ,
                                   subRelSrcDir ,
                                   files        ,
                                   fileTypes    ,
                                   dirsToIgnore );
                }
            }            
        } 
        while ( CORE::DI_Next_Dir_Entry( dirEntry ) != 0 );
        
        // clean up our toys
        CORE::DI_Cleanup( dirEntry );
    }
}
コード例 #16
0
bool
CCEGUIDriver::LoadConfig( const CORE::CDataNode& treeroot )
{GUCEF_TRACE;

    const CORE::CDataNode* ceguiConfig = treeroot.Find( "CEGUI" );
    if ( nullptr == ceguiConfig )
    {   
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_IMPORTANT, "CGUIDriver:LoadConfig: Cannot find CEGUI config and as such will not be able to initialize" );
        return false;
    }

    m_schemeToUse = ceguiConfig->GetAttributeValueOrChildValueByName( "Scheme" );
    m_defaultFont = ceguiConfig->GetAttributeValueOrChildValueByName( "DefaultFont" );
    m_defaultCursorImage = ceguiConfig->GetAttributeValueOrChildValueByName( "DefaultCursorImage" );
     
    // the default is the fallback resource group if none is passed to the adapter
    CORE::CString defaultResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "DefaultResourceGroup" );
    if ( defaultResourceGroup.IsNULLOrEmpty() )
        defaultResourceGroup = "CEGUI";
    m_vfsResourceProvider.setDefaultResourceGroup( defaultResourceGroup );

    CORE::CString imageSetsResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "ImageSetsResourceGroup" );
    CORE::CString fontsResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "FontsResourceGroup" );
    CORE::CString schemesResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "SchemesResourceGroup" );
    CORE::CString lookNFeelResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "LookNFeelsResourceGroup" );
    CORE::CString layoutsResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "LayoutsResourceGroup" );
    CORE::CString animationsResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "AnimationsResourceGroup" );
    CORE::CString scriptsResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "ScriptsResourceGroup" );
    m_schemasResourceGroup = ceguiConfig->GetAttributeValueOrChildValueByName( "SchemasResourceGroup" );

    // set the default resource groups to be used
    CEGUI::ImageManager::setImagesetDefaultResourceGroup( imageSetsResourceGroup );
    CEGUI::Font::setDefaultResourceGroup( fontsResourceGroup );
    CEGUI::Scheme::setDefaultResourceGroup( schemesResourceGroup );
    CEGUI::WidgetLookManager::setDefaultResourceGroup( lookNFeelResourceGroup );
    CEGUI::WindowManager::setDefaultResourceGroup( layoutsResourceGroup );
    CEGUI::AnimationManager::setDefaultResourceGroup( animationsResourceGroup );
    CEGUI::ScriptModule::setDefaultResourceGroup( scriptsResourceGroup );

    // setup default group for validation schemas
    CEGUI::System* ceguiSystem = CEGUI::System::getSingletonPtr();
    if ( nullptr != ceguiSystem )
    {
        CEGUI::XMLParser* parser = ceguiSystem->getXMLParser();
        if ( nullptr != parser && parser->isPropertyPresent( "SchemaDefaultResourceGroup" )  )
            parser->setProperty( "SchemaDefaultResourceGroup", m_schemasResourceGroup );
    }

    const CORE::CDataNode* ceguiVfsConfig = treeroot.Search( "CEGUI/VFSAdapter", '/', false );
    if ( nullptr != ceguiVfsConfig )
    {   
        CORE::CDataNode::TConstDataNodeSet grpNodes = ceguiVfsConfig->FindChildrenOfType( "ResourceGroup" );
        CORE::CDataNode::TConstDataNodeSet::iterator i = grpNodes.begin();
        while ( i != grpNodes.end() )
        {
            CORE::CString groupName = (*i)->GetAttributeValueOrChildValueByName( "Name" );
            CORE::CString vfsPath = (*i)->GetAttributeValueOrChildValueByName( "Path" );

            m_vfsResourceProvider.setResourceGroupDirectory( groupName, vfsPath );

            ++i;
        }
    }

    return true;
}
コード例 #17
0
bool
CPatcherAppConfig::LoadConfig( const CORE::CDataNode& treeroot )
{GUCEF_TRACE;

    CORE::CDataNode::TConstDataNodeSet configNodes( treeroot.FindChildrenOfType( "PatcherAppConfig", true ) );
    CORE::CDataNode::TConstDataNodeSet::iterator i = configNodes.begin();
    if ( i != configNodes.end() )
    {
        const CORE::CDataNode* configNode = (*i);

        CORE::CString value = configNode->GetAttributeValueOrChildValueByName( "LogFilePath" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_logfilePath = value;
        }
        value = configNode->GetAttributeValueOrChildValueByName( "IsFileLoggerEnabled" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_isFileLoggerEnabled = CORE::StringToBool( value );
        }
        value = configNode->GetAttributeValueOrChildValueByName( "IsConsoleLoggerEnabled" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_isConsoleLoggerEnabled = CORE::StringToBool( value );
        }
        value = configNode->GetAttributeValueOrChildValueByName( "IsConsoleWindowEnabled" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_isConsoleWindowEnabled = CORE::StringToBool( value );
        }

        value = configNode->GetAttributeValueOrChildValueByName( "WindowManager" );
        if ( !value.IsNULLOrEmpty() )
        {
            m_windowManagerName = value;
        }

        CORE::CDataNode::TConstDataNodeSet nodeSet( configNode->FindChildrenOfType( "InitialForm", true ) );
        CORE::CDataNode::TConstDataNodeSet::iterator n = nodeSet.begin();
        if ( n != nodeSet.end() )
        {
            const CORE::CDataNode* formInfoNode = (*n);

            m_guiBackendName = formInfoNode->GetAttributeValueOrChildValueByName( "GuiBackend" );
            if ( !m_guiBackendName.IsNULLOrEmpty() )
            {
                m_initialFormTypeName = formInfoNode->GetChildValueByName( "FormTypeName" );
                m_initialFormResourcePath = formInfoNode->GetChildValueByName( "FormResource" );
            }
        }

        nodeSet = configNode->FindChildrenOfType( "FontsToLoadFromAssets", true );
        n = nodeSet.begin();
        while ( n != nodeSet.end() )
        {
            const CORE::CDataNode* fontInfoNode = (*n);
            CString fontAsset = fontInfoNode->GetAttributeValueOrChildValueByName( "FontAsset" );
            if ( !fontAsset.IsNULLOrEmpty() )
            {
                m_fontAssetsToLoad.push_back( fontAsset );
            }
            ++n;
        }

    }
    return true;
}
コード例 #18
0
void
CLogSvcServer::ProcessReceivedMessage( TClientInfo& clientInfo                   ,
                                       COMCORE::CTCPServerConnection* connection ,
                                       const CORE::CDynamicBuffer& messageBuffer )
{GUCEF_TRACE;

    try
    {
        // First read the message type and handle accordingly
        CORE::UInt8 msgType = messageBuffer.AsConstType< CORE::UInt8 >( 0 );
        switch ( msgType )
        {
            case LOGSVCMSGTYPE_CLIENTINFO:
            {
                CClientInitMessage initMessage;
                if ( initMessage.ReadFromBuffer( messageBuffer, false ) )
                {
                    clientInfo.logClientVersion = initMessage.GetClientVersion();
                    clientInfo.appName = initMessage.GetApplicationName();
                    clientInfo.processId = initMessage.GetProcessId();
                    clientInfo.processName = initMessage.GetProcessName();

                    // Set the client's address and port for easy unique addressability
                    clientInfo.addressAndPort = connection->GetRemoteIP().AddressAndPortAsString();

                    // If we got here without an exception then the we successfully received all info required to
                    // consider the connection as initialized.
                    clientInfo.initialized = true;

                    // tell the loggers we have a new client for which we can begin logging
                    TLoggerList::iterator i = m_loggers.begin();
                    while ( i != m_loggers.end() )
                    {
                        (*i)->StartOfLoggingForClient( clientInfo );
                        ++i;
                    }

                    // Send notification to the client that the initialization was successfull
                    CORE::UInt8 statusCode = LOGSVCMSGTYPE_INITIALIZED;
                    connection->Send( &statusCode, 1 );
                }
                else
                {
                    // Something is wrong with this msg buffer, kill the connection
                    connection->Close();
                }
                break;
            }
            case LOGSVCMSGTYPE_FLUSHLOG:
            {
                // We are being asked to flush the log
                TLoggerList::iterator i = m_loggers.begin();
                while ( i != m_loggers.end() )
                {
                    (*i)->FlushLog( clientInfo );
                    ++i;
                }
                break;
            }
            case LOGSVCMSGTYPE_LOGMSG:
            {
                // This is what its all about, we have been given a log message.
                // Parse the log message from the transmission
                CORE::UInt32 offset = 1;
                CILogSvcServerLogger::TLogMsgType logMsgTypeValue = (CILogSvcServerLogger::TLogMsgType) messageBuffer.AsConstType< CORE::Int16 >( offset );
                offset += 2;
                CORE::Int32 logLevel = messageBuffer.AsConstType< CORE::Int32 >( offset );
                offset += 4;
                CORE::UInt32 threadId = messageBuffer.AsConstType< CORE::UInt32 >( offset );
                offset += 4;
                CORE::CString logMessage;
                CORE::UInt32 strLength = messageBuffer.GetDataSize() - offset;
                logMessage.Set( messageBuffer.AsConstTypePtr< char >( offset, strLength ), strLength );

                // Now send the log message to all loggers
                TLoggerList::iterator i = m_loggers.begin();
                while ( i != m_loggers.end() )
                {
                    (*i)->Log( clientInfo, logMsgTypeValue, logLevel, logMessage, threadId );
                    ++i;
                }
                break;
            }
            default:
            {
                // We should not get here if the protocol is correctly adhered to and there is no
                // corruption in the stream. This is a fatal error for the connection.
                connection->Close();
            }
        }
    }
    catch ( CORE::CDynamicBuffer::EIllegalCast& )
    {
        // Something is wrong with this msg buffer, kill the connection
        connection->Close();
    }
}
コード例 #19
0
CEGUI::Texture* 
ImageCodecAdapter::load( const CEGUI::RawDataContainer& data , 
                         CEGUI::Texture* result              )
{GUCEF_TRACE;

    if ( NULL == result ) 
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Unable to load texture since no texture object was provided" );
        return NULL;
    }

    CORE::CString imgType = CORE::ExtractFileExtention( result->getName() );
    if ( imgType.IsNULLOrEmpty() )
    {
        if ( NULL != m_vfsResourceProvider )
        {
            VfsResourceProvider::DataContainerInfoPtr containerInfo = m_vfsResourceProvider->GetInfoOnLoadedContainer( data );
            if ( !containerInfo.IsNULL() )
            {
                imgType = CORE::ExtractFileExtention( containerInfo->requestFilename );
            }
        }
    }

    if ( imgType.IsNULLOrEmpty() )
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Unable to load texture since no image type could be derived from the the texture name" );
        return NULL;
    }

    IMAGE::CImageCodecRegistry& codecRegistry = IMAGE::CImageGlobal::Instance()->GetImageCodecRegistry();
    
    IMAGE::CImageCodecRegistry::TImageCodecPtr codec;
    if ( !codecRegistry.TryLookup( imgType, codec ) )
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Unable to load texture since no image codec could be found for type: " + imgType );
        return NULL;
    }

    CORE::CDynamicBufferAccess bufferAccess;
    bufferAccess.LinkTo( data.getDataPtr(), data.getSize() );

    IMAGE::CImage image;
    if ( !codec->Decode( bufferAccess, image ) )
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Unable to load texture since the image codec decoding failed for type: " + imgType );
        return NULL;
    }

    IMAGE::TPixelMapPtr pixelMap;
    if ( !image.TryGetPixelMap( 0, 0, pixelMap ) )
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Unable to get the pixel map from the image" );
        return NULL;
    }
    
    // CEGUI does not support single channel formats
    if ( pixelMap->GetNumberOfChannelsPerPixel() < 3 )
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle images with less than 3 channels per pixels" );
        return NULL;        
    }
    
    // CEGUI only supports a subset of formats, convert as needed
    IMAGE::TPixelStorageFormat sourceFormat = pixelMap->GetPixelStorageFormat();
    switch ( sourceFormat )
    {
        case IMAGE::PSF_BGR:
        {
            IMAGE::TPixelMapPtr newPixelMap;
            if ( !pixelMap->ConvertFormatTo( IMAGE::PSF_RGB, MT::DATATYPE_UINT8, newPixelMap ) )
            {
                GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle BGR images and we were unable to convert" );
                return NULL;
            }
            if ( newPixelMap )
            {
                GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle BGR images, we successfully converted the image" );
                pixelMap = newPixelMap;
            }
            break;
        } 
        case IMAGE::PSF_BGRA:
        {
            IMAGE::TPixelMapPtr newPixelMap;
            if ( !pixelMap->ConvertFormatTo( IMAGE::PSF_RGBA, MT::DATATYPE_UINT8, newPixelMap ) )
            {
                GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle BGRA images and we were unable to convert" );
                return NULL;
            }
            if ( newPixelMap )
            {
                GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle BGRA images, we sucecssfully converted the image" );
                pixelMap = newPixelMap;
            }
            break;
        } 
    }

    // CEGUI only supports a subset of channel sizes, convert as needed
    // If we get here then the pixels are stored in a supported format either due to conversion or they were already
    // However the channelsize can still be wrong in the latter case
    CORE::UInt32 channelSize = pixelMap->GetPixelChannelSize();
    if ( channelSize > 1 )
    {
        IMAGE::TPixelStorageFormat sourceFormat = pixelMap->GetPixelStorageFormat();
        IMAGE::TPixelMapPtr newPixelMap;
        if ( !pixelMap->ConvertFormatTo( sourceFormat, MT::DATATYPE_UINT8, newPixelMap ) )
        {
            GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle images with multi-byte channels and we were unable to convert" );
            return NULL;
        }
        
        if ( newPixelMap )
        {
            GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: CEGUI cannot handle images with multi-byte channels, we sucecssfully converted the image to single byte" );
            pixelMap = newPixelMap;
        }
        channelSize = pixelMap->GetPixelChannelSize();
    }
    
    // Now that we have the image in a format we know CEGUI can handle,.. convert the type enum
    CEGUI::Texture::PixelFormat ceguiPixelFormat;
    if ( !TryConvertPixelFormat( pixelMap->GetPixelStorageFormat(), channelSize, ceguiPixelFormat ) )
    {
        GUCEF_WARNING_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Failed to map pixel storage format to a CEGUI supported type" );
        return NULL;        
    }
        
    CEGUI::Sizef imageSizeInPixels( (float) pixelMap->GetWidthInPixels(), (float) pixelMap->GetHeightInPixels() );
    result->loadFromMemory( pixelMap->GetDataPtr(), imageSizeInPixels, ceguiPixelFormat );
    GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "ImageCodecAdapter:load: Successfully loaded image into texture obj" );
    return result;
}