コード例 #1
0
bool
CIniParser::SaveTo( CDataNode& rootNode ) const
{GUCEF_TRACE;

    TIniData::const_iterator i = m_iniData.begin();
    while ( i != m_iniData.end() )
    {
        const TIniSection& iniSection = (*i);
        const CValueList& sectionData = iniSection.sectionData;

        CString nodeName = iniSection.sectionName.SubstrToChar( '\\', false );
        CString sectionName;

        if ( nodeName.Length()+1 < iniSection.sectionName.Length() )
        {
            sectionName = iniSection.sectionName.CutChars( nodeName.Length()+1, false );
        }

        // We use the ordering in the ini of the different sections to implicitly denote going up and down
        // a tree thus allowing branches to be defined in an ini file which otherwise does not support this concept
        CDataNode* sectionNodeParent = NULL;
        if ( !sectionName.IsNULLOrEmpty() )
        {
            CDataNode::TDataNodeVector existingPaths = rootNode.SearchForAll( sectionName, '\\', true, true );
            if ( !existingPaths.empty() )
            {
                sectionNodeParent = *existingPaths.rbegin();
            }
            else
            {
                sectionNodeParent = rootNode.Structure( sectionName, '\\' );
            }
        }
        else
        {
            sectionNodeParent = &rootNode;
        }

        // Make a new child node symbolizing the end of the sequence of the section name
        // for example [My/New/Sequence] as a section name in the ini would result in
        // the whole sequence creates as nodes with Sequence being the parent node
        // where we add the key/value pairs from the ini section
        CDataNode* sectionNode = sectionNodeParent->AddChild( nodeName );

        CValueList::TValueMap::const_iterator n = sectionData.GetDataBeginIterator();
        while ( n != sectionData.GetDataEndIterator() )
        {
            const CString& key = (*n).first;
            const CValueList::TStringVector& values = (*n).second;

            // Since key/value pairs in an ini section have no uniqueness constraint we cannot
            // set the pairs as attributes. Instead they are child nodes using the simplistic value representation
            CValueList::TStringVector::const_iterator m = values.begin();
            while ( m != values.end() )
            {
                CDataNode* keyValueNode = sectionNode->AddChild( key );
                keyValueNode->SetValue( (*m) );

                ++m;
            }
            ++n;
        }
        ++i;
    }
    return true;
}
コード例 #2
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;
}