Beispiel #1
0
bool WPL_PlaylistParser::Parse(std::string p_sContent)
{
	CXMLDocument* pDoc = new CXMLDocument();
	if(!pDoc->LoadFromString(p_sContent)) {
		delete pDoc;
		return false;
	}

  // Parse <head> data
  CXMLNode* pHead;
  pHead = pDoc->RootNode()->FindNodeByName("head");
  if (!pHead) {
    delete pDoc;
    return false;
  }
  
  // parse <body> data
  CXMLNode* pSeq;
  pSeq = pDoc->RootNode()->FindNodeByName("body");
  if (!pSeq) pSeq = pSeq->FindNodeByName("seq");
  if (!pSeq) {
    delete pDoc;
    return false;
  }
  
  int children = pSeq->ChildCount();
  CXMLNode* child;
  PlaylistEntry_t* pEntry;
  for (int i = 0; i < children; ++i) {
    child = pSeq->ChildNode(i);
		if(child->Name().compare("media") != 0) {
      continue;
    }
    
    pEntry = new PlaylistEntry_t();
    if(IsURL(child->Value())) {       
      pEntry->sFileName = child->Value();
      pEntry->bIsLocalFile = false;
    }
    else {
      pEntry->sFileName = FormatFileName(child->Value());
      pEntry->bIsLocalFile = true;
    }
    m_lEntries.push_back(pEntry);
  }

  if(!m_lEntries.empty()) {
    m_bEof = false;
    m_lEntriesIterator = m_lEntries.begin();
  }

  delete pDoc;
  return true;
}
Beispiel #2
0
int		wmain()
{
	//const TCHAR * pFileName = _T( "AttributeLoad.xml" );
	const TCHAR * pFileName = _T( "ElementLoad.xml" );
	//const TCHAR * pFileName = _T( "expat_test.vcproj" );
	//const TCHAR * pFileName = _T( "vcproj.xml" );

	CXMLDocument * pDoc = NULL;
	{
		CXMLReader clReader;
		pDoc = clReader.Load( pFileName );
		if( pDoc == NULL )
		{
			::wprintf( L"Parse error at file: %s, line %lu:\n%s\n",
					pFileName,
					clReader.GetErrorLine(),
					clReader.GetErrorString()
					);

			return 0;
		}
	}

	DumpAllXMLElement( CXMLDocument::GetElement( pDoc->GetRoot(), _T( "Root" ) ) );

	{
		CXMLElement * pElement = CXMLDocument::GetElement( pDoc->GetRoot(), _T( "/Root/Monster" ) );
		DumpAllXMLElement( pElement );

		CXMLElement * pNotFound = CXMLDocument::GetElement( pDoc->GetRoot(), _T( "/Rootadf/Monster" ) );
		if( pNotFound != NULL )
		{
			wprintf( L"Found! Name: %s\n", pNotFound->GetName() );
		}

		const TCHAR * pText = CXMLDocument::GetText( pElement, _T( "Name/" ) );
		if( pText != NULL )
		{
			wprintf( L"Name Text: %s\n", pText );
		}

		const TCHAR * pValue = CXMLDocument::GetAttr( pElement, _T( "/Name" ), _T( "Attr" ) );
		if( pValue != NULL )
		{
			wprintf( L"Name Attr: %s\n", pValue );
		}
	}

	return 0;
}
Beispiel #3
0
CWSDLBinding * CWSDLPort::GetBinding()
{
	if (m_pBinding != NULL)
	{
		return m_pBinding;
	}

	CXMLDocument *pDoc = GetParentDocument();
	if (pDoc != NULL)
	{
		CStringW strUri;
		if (SUCCEEDED(GetNamespaceUri(m_binding.GetPrefix(), strUri)))
		{
			if (strUri == pDoc->GetTargetNamespace())
			{
				if (pDoc->GetDocumentType() == WSDLDOC)
				{
					CWSDLDocument *pWSDLDoc = static_cast<CWSDLDocument *>(pDoc);
					m_pBinding = pWSDLDoc->GetBinding(m_binding.GetName());
					if (m_pBinding == NULL)
					{
						EmitFileError(IDS_SDL_UNRESOLVED_ELEM2, const_cast<CWSDLPort *>(this), 0,
							"binding", strUri, m_binding.GetName());
					}
				}
			}
			else
			{
				EmitFileError(IDS_SDL_UNRESOLVED_ELEM2, const_cast<CWSDLPort *>(this), 0, "binding", strUri, m_binding.GetName());
			}
		}
		else
		{
			EmitFileError(IDS_SDL_UNRESOLVED_NAMESPACE, const_cast<CWSDLPort *>(this), 0, m_binding.GetPrefix());
		}
	}

	return m_pBinding;
}
Beispiel #4
0
void CXMLDlg::OnLoad() 
{
	CWaitCursor Wait;

	UpdateData();

	HRESULT hr = S_OK;

	HTREEITEM hFirstItem = m_treeOutput.GetChildItem(TVI_ROOT);
	if (hFirstItem)
		m_treeOutput.Expand(hFirstItem, TVE_COLLAPSE);
	m_treeOutput.DeleteAllItems();

	CoInitialize(NULL);

	// Create an empty XML document
	CXMLDocument* pXMLDoc = new CXMLDocument;
	hr = pXMLDoc->RegisterCallback(&MyXMLCallback, (LPARAM)this);

	if (m_strFileName.IsEmpty())
	{
		hr = pXMLDoc->Build(); // load a document from in-memory string.
	}
	else
	{
		if (m_bStream)
			hr = pXMLDoc->LoadStream(m_strFileName);
		else
			hr = pXMLDoc->Load(m_strFileName, !!m_bAsync);
	}

	// Now walk the loaded XML document dumping the name-value pairs
	pXMLDoc->WalkTree(CString(""));

//j	// Test persistence of encoded XML doc in memory
//j	PBYTE pData = NULL;
//j	ULONG ulLen;
//j	hr = pXMLDoc->PersistToMemory(&pData, &ulLen);
//j	hr = pXMLDoc->LoadFromMemory(pData, ulLen);
//j	delete pData;
	
	delete pXMLDoc;
	CoUninitialize();
}
void CMaterialResource::Load()
{
	m_IsLoaded = true;
	CXMLDocument document;
	document.Load( m_FilePath.c_str() );

	CXMLNode rootNode = document.GetRootNode();
	//Read out shaders
	CXMLNode childNode = rootNode.GetChildNode( "Shader" );
	CXMLAttribute attribute = childNode.GetAttribute( "File" );

	std::string shaderPath; shaderPath += "../Content/";
	shaderPath += attribute.GetValue();
	
	//Read out defines
	childNode = rootNode.GetChildNode( "ShaderDefine" );

	while ( childNode.IsEmpty() == false )
	{
		attribute = childNode.GetAttribute( "Name" );
		const Char* name = attribute.GetValue( "" );
		if ( strcmp( name, "" ) != 0 )
		{
			m_ShaderDefines.push_back( name );
		}
		childNode = childNode.GetNextSibling();
	}

	//Build hash
	Uint hash = HashString( shaderPath.c_str() );
	hash += m_ShaderDefines.size();
	for ( Uint i = 0; i < m_ShaderDefines.size(); ++i )
	{
		hash += HashString( m_ShaderDefines[i].c_str() );
	}

	CResource* shaderResource;
	if ( ( shaderResource = CResourceManager::GetInstance()->GetResourceByHash( hash ) ) == NULL )
	{
		shaderResource = CResourceManager::GetInstance()->AddShaderResource( shaderPath.c_str(), hash, m_ShaderDefines );
	}

	m_ShaderResource = (CShaderResource*)shaderResource;
	m_Shader = m_ShaderResource->GetShader();

	//Read terms
	childNode = rootNode.GetChildNode( "Terms" );
	//Emmisive
	CXMLNode termNode = childNode.GetChildNode( "Emissive" );
	attribute = termNode.GetAttribute( "R" ); m_EmissiveTerm.X = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "G" ); m_EmissiveTerm.Y = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "B" ); m_EmissiveTerm.Z = (Float)atof( attribute.GetValue() );
	//Diffuse
	termNode = childNode.GetChildNode( "Diffuse" );
	attribute = termNode.GetAttribute( "R" ); m_DiffuseTerm.X = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "G" ); m_DiffuseTerm.Y = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "B" ); m_DiffuseTerm.Z = (Float)atof( attribute.GetValue() );
	//Specular
	termNode = childNode.GetChildNode( "Specular" );
	attribute = termNode.GetAttribute( "R" ); m_SpecularTerm.X = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "G" ); m_SpecularTerm.Y = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "B" ); m_SpecularTerm.Z = (Float)atof( attribute.GetValue() );
	//Ambient
	termNode = childNode.GetChildNode( "Ambient" );
	attribute = termNode.GetAttribute( "R" ); m_AmbientTerm.X = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "G" ); m_AmbientTerm.Y = (Float)atof( attribute.GetValue() );
	attribute = termNode.GetAttribute( "B" ); m_AmbientTerm.Z = (Float)atof( attribute.GetValue() );
	//Specular power
	termNode = childNode.GetChildNode( "SpecularPower" );	
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_SpecularPower = (Float)atof( attribute.GetValue( "1.0f" ) );
	}

	termNode = childNode.GetChildNode( "Reflection" );	
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_Reflection = (Float)atof( attribute.GetValue( "0.0f" ) );
	}

	termNode = childNode.GetChildNode( "Refraction" );	
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_Refraction = (Float)atof( attribute.GetValue( "0.0f" ) );
	}	

	termNode = childNode.GetChildNode( "Transmittance" );	
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_Transmittance = (Float)atof( attribute.GetValue( "0.0f" ) );
	}

	termNode = childNode.GetChildNode( "FresnelPower" );	
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_FresnelValues.X = (Float)atof( attribute.GetValue( "1.0f" ) );
	}

	termNode = childNode.GetChildNode( "FresnelScale" );
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_FresnelValues.Y = (Float)atof( attribute.GetValue( "1.0f" ) );
	}

	termNode = childNode.GetChildNode( "FresnelBias" );
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_FresnelValues.Z = (Float)atof( attribute.GetValue( "0.0f" ) );
	}

	termNode = childNode.GetChildNode( "TextureWeight" );
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_TextureWeight = (Float)atof( attribute.GetValue( "0.0f" ) );
	}

	termNode = childNode.GetChildNode( "ParallaxScale" );
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_ParallaxScale = (Float)atof( attribute.GetValue( "0.0f" ) );
	}


	termNode = childNode.GetChildNode( "ParallaxBias" );
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "Value" ); 
		m_ParallaxBias = (Float)atof( attribute.GetValue( "0.0f" ) );
	}

	termNode = childNode.GetChildNode( "RefractiveIndices" );
	if ( termNode.IsEmpty() == false )
	{
		attribute = termNode.GetAttribute( "R" ); m_RefractiveIndices.X = (Float)atof( attribute.GetValue( "1.0f" ) );
		attribute = termNode.GetAttribute( "G" ); m_RefractiveIndices.Y = (Float)atof( attribute.GetValue( "1.0f" ) );
		attribute = termNode.GetAttribute( "B" ); m_RefractiveIndices.Z = (Float)atof( attribute.GetValue( "1.0f" ) );
	}

	//Read out textures
	childNode = rootNode.GetChildNode( "Texture2D" );

	while ( childNode.IsEmpty() == false )
	{
		attribute = childNode.GetAttribute( "Name" );
		const Char* name = attribute.GetValue();

		attribute = childNode.GetAttribute( "Hash" );
		const Uint hash = (Uint)strtoul( attribute.GetValue(), NULL, 0 );
		//Check if the resource already exists and is loaded		
		CResource* resource = m_DependentResources.find( hash )->second;
		Uint textureID = 0;
		if ( resource != NULL )
		{
			CTextureResource* textureResource = (CTextureResource*)resource;
			if ( textureResource->IsLoaded() )
			{
				textureID = textureResource->GetTextureID();
			}
		}

		attribute = childNode.GetAttribute( "Type" );
		const Char* type = attribute.GetValue();
		attribute = childNode.GetAttribute( "UVChannel" );
		const Uint uvChannel = atoi( attribute.GetValue() );
		attribute = childNode.GetAttribute( "Mapping" );
		const Char* mapping = attribute.GetValue();
		
		CXMLNode mapNode = childNode.GetChildNode( "MapMode" );
		attribute = mapNode.GetAttribute( "X" );
		const Char* mapModeX = attribute.GetValue();
		attribute = mapNode.GetAttribute( "Y" );
		const Char* mapModeY = attribute.GetValue();
		
		TextureMapMode mapModes[2];
		mapModes[0] = (TextureMapMode)ConvertMapMode( mapModeX );
		mapModes[1] = (TextureMapMode)ConvertMapMode( mapModeY );
		CTexture2D* texture = new CTexture2D( name, hash, (TextureMapping)ConvertMapping( mapping ), mapModes, (TextureMapType)ConvertTextureType( type ), uvChannel, textureID );
		m_2DTextures.push_back( texture );
		childNode = childNode.GetNextSibling();
	}

	childNode = rootNode.GetChildNode( "TextureCube" );

	while ( childNode.IsEmpty() == false )
	{
		attribute = childNode.GetAttribute( "FileBase" );
		const Char* fileBase = attribute.GetValue();

		attribute = childNode.GetAttribute( "UniformName" );
		const Char* uniformName = attribute.GetValue();

		attribute = childNode.GetAttribute( "Extension" );
		const Char* extension = attribute.GetValue();

		CTextureCube* texture = new CTextureCube( fileBase, uniformName, extension );
		m_3DTextures.push_back( texture );
		childNode = childNode.GetNextSibling();
	}	


}
BOOL CInstanceTree::UpdateTargets()
{
    // only do update if something has changed in the target view
    if (!(m_pProjectManager->GetTargetTree())->m_bTargetTreeChanged)
    {
        return TRUE;
    }

    BOOL ret;
    CXMLDocument    tTargetDoc;
    TStringList listNewTargets;
    CXMLNode nodeTargetRoot;
    CXMLNode nodeInstanceRoot;

    // update lists
    TStringList listUpdateChanged;
    TStringList listUpdateNew;
    TStringList listUpdateDeleted;

    (m_pProjectManager->GetTargetTree())->m_bTargetTreeChanged = FALSE;

    // get instance tree root node
    if (!m_domDocument.GetRootNode(nodeInstanceRoot))
    {
        return FALSE;
    }

    // get root node of target view
    IUnknown*   pTmp = NULL;
    HRESULT hr = m_pProjectManager->GetTargetViewDOM(&pTmp);
    if(hr != S_OK)
    {
        return FALSE;
    }
    tTargetDoc.SetIXMLDocument(pTmp);
    pTmp->Release();
    // add target nodes as children
    if(!tTargetDoc.GetRootNode(nodeTargetRoot))
    {
        return FALSE;
    }

    // get new targets from target view
    if (!GetTargetsFromTargetTree(listNewTargets))
    {
        return FALSE;
    }

    // empty xml tree
    nodeInstanceRoot.RemoveAllChilds();

    // mark all nodes not used:
    POSITION posH = m_mapInstanceTargets.GetStartPosition();
    while(posH)
    {
        CString strId;
        TInstanceTargetInfo* pInfo;
        m_mapInstanceTargets.GetNextAssoc(posH, strId, pInfo);
        if (pInfo)
        {
            pInfo->bUsed = FALSE;
        }
    }
    


    // look at all new targets, hang targets into the tree:
    // test if target is a new target or the attributes have changed or it is the same
    // in the last two cases, take the old node and only change attributes if necessary
    POSITION posNewTargets = listNewTargets.GetHeadPosition();
    while(posNewTargets)
    {
        CXMLNode nodeTarget;
        CXMLNode nodeInstance;
        CXMLNode nodeLink;

        // attributes of the target node
        CString     strTText;                // node text
        CString     strTId;                  // node id
        CString     strTType;                // node type (KAD type)
        CString     strTAddress;             // connect info
        CString     strTUserAddress;         // user connect info
        CString     strTConsoleAddress;      // console address
        CString     strTAssignedResource;    // assigned resource
        CString     strTSource;              // source file for add on action
        
        CString     strParseSource;         // parser source help var
        CString     strParseSourceNew;      // parser source
        CString     strInstType;             // type of the instance node

        CString     strIdPathTarg;          // id path of target node in target tree
        CString     strIdPathInst;          // id path of target instance in instance tree
        CString     strTargetId;
        CString     strWaitForTarget;
        
        strIdPathTarg = listNewTargets.GetNext(posNewTargets);

        strTargetId = strIdPathTarg;
        int iFind = strTargetId.ReverseFind(CE_XML_IDPATH_SEP_CHAR);
        ASSERT(iFind>0);
        if (iFind>0)
        {
            strTargetId = strTargetId.Mid(iFind+1);
        }

        // get target node
        ret = nodeTargetRoot.GetNodeFromIdPath(strIdPathTarg, nodeTarget);
        ASSERT(ret);
        if (!ret)
        {
            continue;
        }

        // get attributes of the target node
        nodeTarget.GetAttribute(CE_XMLATTR_TEXT, strTText);
        nodeTarget.GetAttribute(CE_XMLATTR_ID, strTId);
        nodeTarget.GetAttribute(CE_XMLATTR_TYPE, strTType);
        nodeTarget.GetAttribute(CE_XMLATTR_ADDR, strTAddress);
        nodeTarget.GetAttribute(CE_XMLATTR_USERADDR, strTUserAddress);
        nodeTarget.GetAttribute(CE_XMLATTR_CONSOLE_ADDR, strTConsoleAddress);
        nodeTarget.GetAttribute(CE_XMLATTR_RESOURCE, strTAssignedResource);
        nodeTarget.GetAttribute(CE_XMLATTR_SOURCE, strTSource);
        nodeTarget.GetAttribute(CE_XMLATTR_WAIT_TARGET_CONN , strWaitForTarget);

        strInstType = strTType + CE_XML_INST_ADD;
        strParseSource = strTId + _T(".") + CE_INSTANCE_EXT;
        strParseSourceNew = CString(CE_GEN_PATH) + _T("\\") + strTId + _T("\\") + strParseSource;

        // does node already exist in instance tree:
        TInstanceTargetInfo* pInstTargetInfo = NULL;
        CString strLowerId = strTargetId;
        strLowerId.MakeLower();
        if (m_mapInstanceTargets.Lookup(strLowerId, pInstTargetInfo))
        {
            // *** existing node ***
            ASSERT(pInstTargetInfo);
            pInstTargetInfo->bUsed = TRUE;
            nodeInstance = pInstTargetInfo->xmlNode;
            ret = nodeInstanceRoot.AppendChild(nodeInstance, TRUE);
            ASSERT(ret);

            // check if attributes have changed
            // get instance node attributes
            CString strInstText;
            CString strInstId;
            //CString strInstType;
            CString strInstAddress;
            CString strInstUserAddress;
            CString strInstConsoleAddress;
            CString strInstAssignedResource;
            CString strInstSource;

            nodeInstance.GetAttribute(CE_XMLATTR_TEXT, strInstText);
            nodeInstance.GetAttribute(CE_XMLATTR_ID, strInstId);
            //nodeInstance.GetAttribute(CE_XMLATTR_TYPE, strInstType); // type can't change
            nodeInstance.GetAttribute(CE_XMLATTR_ADDR, strInstAddress);
            nodeInstance.GetAttribute(CE_XMLATTR_USERADDR, strInstUserAddress);
            nodeInstance.GetAttribute(CE_XMLATTR_CONSOLE_ADDR, strInstConsoleAddress);
            nodeInstance.GetAttribute(CE_XMLATTR_RESOURCE, strInstAssignedResource);
            nodeInstance.GetAttribute(CE_XMLATTR_SOURCE, strInstSource);
            
            if ((strInstText.CompareNoCase(strTText)!=0)
                || (strInstId.CompareNoCase(strTId)!=0)
                //|| (strInstType.CompareNoCase(strType)!=0)
                || (strInstAddress.CompareNoCase(strTAddress)!=0)
                || (strInstConsoleAddress.CompareNoCase(strTConsoleAddress)!=0)
                || (strInstAssignedResource.CompareNoCase(strTAssignedResource)!=0)
                || (strInstSource.CompareNoCase(strTSource) != 0))
            {
                // node has changed -> update nodes
                nodeInstance.SetAttribute(CE_XMLATTR_TEXT, strTText);
                nodeInstance.SetAttribute(CE_XMLATTR_ID, strTId);
                //nodeInstance.SetAttribute(CE_XMLATTR_TYPE, strType);
                nodeInstance.SetAttribute(CE_XMLATTR_ADDR, strTAddress);
                nodeInstance.SetAttribute(CE_XMLATTR_USERADDR, strTUserAddress);
                nodeInstance.SetAttribute(CE_XMLATTR_CONSOLE_ADDR, strTConsoleAddress);
                nodeInstance.SetAttribute(CE_XMLATTR_RESOURCE, strTAssignedResource);
                nodeInstance.SetAttribute(CE_XMLATTR_SOURCE, strTSource);

                listUpdateChanged.AddTail(pInstTargetInfo->strIdPath);
            }
           
        }
        else // *** new node ***
        {
            if(!m_domDocument.CreateNode(nodeInstance, CE_XMLTAG_NODE))
            {
                continue;
            }

            // set attributes of target instance node
            nodeInstance.SetAttribute(CE_XMLATTR_TEXT, strTText);
            nodeInstance.SetAttribute(CE_XMLATTR_ID, strTId);
            nodeInstance.SetAttribute(CE_XMLATTR_ADDR, strTAddress);
            nodeInstance.SetAttribute(CE_XMLATTR_USERADDR, strTUserAddress);
            nodeInstance.SetAttribute(CE_XMLATTR_CONSOLE_ADDR, strTConsoleAddress);
            nodeInstance.SetAttribute(CE_XMLATTR_RESOURCE, strTAssignedResource);
            nodeInstance.SetAttribute(CE_XMLATTR_TARGET_TYPE, strTType);
            nodeInstance.SetAttribute(CE_XMLATTR_SOURCE, strTSource);

            nodeInstance.SetAttribute(CE_XMLATTR_TYPE, strInstType);
            if (!strWaitForTarget.IsEmpty())
            {
                nodeInstance.SetAttribute(CE_XMLATTR_WAIT_TARGET_CONN, strWaitForTarget);
            }

            // create new instance info struct
            ASSERT(pInstTargetInfo==NULL);
            pInstTargetInfo = new TInstanceTargetInfo;
            ASSERT(pInstTargetInfo);
            if (!pInstTargetInfo)
            {
                continue;
            }

            ret = nodeInstanceRoot.AppendChild(nodeInstance, TRUE);
            ASSERT(ret);

            nodeInstance.GetIdPath(strIdPathInst);
            pInstTargetInfo->strIdPath = strIdPathInst;
            pInstTargetInfo->strTargetId = strTId;
            pInstTargetInfo->xmlNode = nodeInstance;
            pInstTargetInfo->bUsed = TRUE;

            strLowerId = strTId;
            strLowerId.MakeLower();

            m_mapInstanceTargets.SetAt(strLowerId, pInstTargetInfo);

            // add to update list (new node)
            listUpdateNew.AddTail(strIdPathInst);

           

            // now create target link node: the link that will be replaced by compiler outpu
            if((!m_domDocument.CreateNode(nodeLink, CE_XMLTAG_LINK))
                ||(!nodeInstance.AppendChild(nodeLink)) )
            {
                continue;
            }

            nodeLink.SetAttribute(CE_XMLATTR_PARSERSOURCE, strParseSourceNew);
            nodeLink.SetAttribute(CE_XMLATTR_ID, strTId);

            TSourceFileInfo* pFileInfo;
            pFileInfo = CreateSourceFileInfo(strParseSourceNew, nodeLink, "");
            SourceFileMap_SetAt(strParseSourceNew, pFileInfo, m_mapSourceFiles);

            AddSourceFileToReparse(strParseSourceNew);
        }
    }

   
    

    // find deleted nodes:
    posH = m_mapInstanceTargets.GetStartPosition();
    while(posH)
    {
        CString strId;
        TInstanceTargetInfo* pInfo;
        m_mapInstanceTargets.GetNextAssoc(posH, strId, pInfo);
        if (pInfo)
        {
            if (pInfo->bUsed == FALSE)
            {
                listUpdateDeleted.AddTail(pInfo->strIdPath);
                delete pInfo;
                m_mapInstanceTargets.RemoveKey(strId);
            }
        }
    }

    if (m_bInit)
    {
        return TRUE;
    }

    // send update messages
    POSITION lPos;
    lPos = listUpdateDeleted.GetHeadPosition();
    while(lPos)
    {
        CString strIdPath = listUpdateDeleted.GetNext(lPos);
        if (!strIdPath.IsEmpty())
        {
            FireUpdateTree(strIdPath, eUpdateDelete);
            CString strId = strIdPath;
            int iFind = strId.ReverseFind(CE_XML_IDPATH_SEP_CHAR);
            ASSERT(iFind>0);
            if (iFind>0)
            {
                strId = strId.Mid(iFind+1);
            }
            CComBSTR sId = strId;
            m_pProjectManager->Fire_TargetInstanceRemoved(sId);
        }
    }
    lPos = listUpdateChanged.GetHeadPosition();
    while(lPos)
    {
        CString strIdPath = listUpdateChanged.GetNext(lPos);
        if (!strIdPath.IsEmpty())
        {
            FireUpdateTree(strIdPath, eUpdateAttributes);
            CString strId = strIdPath;
            int iFind = strId.ReverseFind(CE_XML_IDPATH_SEP_CHAR);
            ASSERT(iFind>0);
            if (iFind>0)
            {
                strId = strId.Mid(iFind+1);
            }
            CComBSTR sId = strId;
            CComBSTR sIdPath = strIdPath;
            m_pProjectManager->Fire_TargetInstanceAdded(sId, sIdPath);
        }
    }
    lPos = listUpdateNew.GetHeadPosition();
    while(lPos)
    {
        CString strIdPath = listUpdateNew.GetNext(lPos);
        if (!strIdPath.IsEmpty())
        {
            FireUpdateTree(strIdPath, eUpdateInsert);
            CString strId = strIdPath;
            int iFind = strId.ReverseFind(CE_XML_IDPATH_SEP_CHAR);
            ASSERT(iFind>0);
            if (iFind>0)
            {
                strId = strId.Mid(iFind+1);
            }
            CComBSTR sId = strId;
            CComBSTR sIdPath = strIdPath;
            m_pProjectManager->Fire_TargetInstanceAdded(sId, sIdPath);
        }
    }

    Reparse(FALSE);
    
    return TRUE;
}
// 15.12.05 SIS >>
// added parameter crstrIndex
// to save index range
bool CCeWatchElement::SaveToNode(CXMLNode& rtNode, CXMLDocument& rtDocument, const CString& crstrIndexRange)
// 15.12.05 SIS <<
{
    bool bReturn = true;
	// don't forget to increment the version string if you change anything here
	CString str;

    if(m_bInitExpanded)
    {
        rtNode.SetAttribute(CEWATCH_XMLATTR_EXPANDED, _T("1"));
    }

	CString strExpression = m_Name;
	if(!crstrIndexRange.IsEmpty())
	{
		strExpression.Format(_T("%s, %s"), m_Name, crstrIndexRange);
	}
	rtNode.SetAttribute(CEWATCH_XMLATTR_EXPRESSION, strExpression);

	if (m_Type.GetName().GetLength() > 0)
	{
		str.Format("%s;%d", m_Type.GetName(), (int)m_Type.GetVarKind());
        rtNode.SetAttribute(CEWATCH_XMLATTR_TYPE, str);
	}
    rtNode.SetAttribute(CEWATCH_XMLATTR_VALUE, m_strValue);

	if (m_strFormat.GetLength() > 0)
    {
        rtNode.SetAttribute(CEWATCH_XMLATTR_FORMAT, m_strFormat);
    }

	// #2149 10.10.06 SIS >>
	// only save visible array elements
    int iNumChildren = GetChildrenCount();
	int	iChildStart = 0;
	int iChildStop = iNumChildren-1;
	if(m_Type.IsArray())
	{
		VERIFY(ExtractArrayIndices(crstrIndexRange, iChildStart, iChildStop));
		iChildStart = max(iChildStart - m_Type.GetArrayLowerBound(), 0);
		iChildStop = min(iChildStop - m_Type.GetArrayLowerBound(), iNumChildren-1);
	}
	CCeWatchElement* pElem = NULL;
	for (int iChild = iChildStart; iChild <= iChildStop; iChild++)
	// #2149 10.10.06 SIS <<
    {
        CXMLNode    tNodeChild;
        if(rtDocument.CreateNode(tNodeChild, CEWATCH_XMLTAG_VARNODE))
        {
			pElem = GetChild(iChild);
			if(!pElem)
			{
				break;
			}
		    bReturn &= pElem->SaveToNode(tNodeChild, rtDocument, _T(""));
            if(!bReturn)
            {
                break;
            }
            rtNode.AppendChild(tNodeChild);
        }
    }

    return bReturn;
}
Beispiel #8
0
void CMapReader::Generate(CGenInfo *pInfo)
{
	m_OverallBenchmark.Unpause();
	
	// create folders
	
	char aGeneratedFolder[256];
	sprintf(aGeneratedFolder, "%sgenerated/%s", pInfo->m_aCurrentDir, pInfo->m_aMap);
	
	char aGeneratedMapresFolder[256];
	sprintf(aGeneratedMapresFolder, "%s/mapres", aGeneratedFolder);
	
	MakeDir(aGeneratedFolder);
	MakeDir(aGeneratedMapresFolder);
	
	// check map version
	
	CMapItemVersion *pVersion = (CMapItemVersion *)m_Reader.FindItem(MAPITEMTYPE_VERSION, 0);
	if(!pVersion || pVersion->m_Version != 1)
		return;
	
	// create generating file
	
	char aGenerating[256];
	sprintf(aGenerating, "%s/generating", aGeneratedFolder);
	
	FILE *pGeneratingFile = fopen(aGenerating, "wb");
	if(pGeneratingFile)
		fclose(pGeneratingFile);
	
	// load images
	m_ImagesBenchmark.Unpause();
	
	int ImagesStart;
	int ImagesNum;
	m_Reader.GetType(MAPITEMTYPE_IMAGE, &ImagesStart, &ImagesNum);
	
	CMapItemImage *pImages = NULL;
	
	if(ImagesNum > 0)
	{
		pImages = new CMapItemImage[ImagesNum];
		
		for(int i = ImagesStart; i < ImagesStart+ImagesNum; i++)
		{
			CMapItemImage *pImage = (CMapItemImage *)m_Reader.GetItem(i, NULL, NULL);
			
			if(!pImage->m_External && pInfo->m_DumpEmbedded)
			{
				const char *pName = (char *)m_Reader.GetData(pImage->m_ImageName);
				unsigned char *pData = (unsigned char *)m_Reader.GetData(pImage->m_ImageData);
				
				char aImageFilename[512];
				sprintf(aImageFilename, "%s/%s.png", aGeneratedMapresFolder, pName);
				
				CImageWrite Image;
				Image.Open(aImageFilename, pImage->m_Width, pImage->m_Height);
				Image.SetPixels(pData);
				Image.Save();
			}
			
			pImages[i-ImagesStart] = *pImage;
		}
	}
	
	m_ImagesBenchmark.Pause();
	
	// load groups and layers
	
	int GroupsStart;
	int GroupsNum;
	m_Reader.GetType(MAPITEMTYPE_GROUP, &GroupsStart, &GroupsNum);
	
	int LayersStart;
	int LayersNum;
	m_Reader.GetType(MAPITEMTYPE_LAYER, &LayersStart, &LayersNum);
	
	for(int g = GroupsStart; g < GroupsStart+GroupsNum; g++)
	{
		CMapItemGroup *pGroup = (CMapItemGroup *)m_Reader.GetItem(g, NULL, NULL);
		
		if(pGroup->m_Version < 1 || pGroup->m_Version > 2)
			continue;
		
		for(int l = LayersStart + pGroup->m_StartLayer; l < LayersStart + pGroup->m_StartLayer+pGroup->m_NumLayers; l++)
		{
			if(l >= LayersStart+LayersNum)
				break;
			
			CMapItemLayer *pLayer = (CMapItemLayer *)m_Reader.GetItem(l, NULL, NULL);
			
			if(pLayer->m_Type == LAYERTYPE_TILES)
			{
				m_TilemapsBenchmark.Unpause();
				
				CMapItemLayerTilemap *pTilesLayer = (CMapItemLayerTilemap *)pLayer;
				
				bool GameLayer = (pTilesLayer->m_Flags & TILESLAYERFLAG_GAME) ? true : false;
				
				if((GameLayer && !pInfo->m_DumpGameTilemap) || (!GameLayer && !pInfo->m_DumpTilemaps))
					continue;
				
				if(!GameLayer && pTilesLayer->m_Image < 0)
					continue;
				
				CMapItemImage *pImage = NULL;
				if(!GameLayer)
					pImage = &pImages[pTilesLayer->m_Image];
				
				const char *pTilesetName;
				if(GameLayer)
					pTilesetName = pInfo->m_aEntities;
				else
					pTilesetName = (char *)m_Reader.GetData(pImage->m_ImageName);
				
				CTileset Src;
				if(GameLayer || pImage->m_External)
				{
					char aTilesetFilename[512];
					sprintf(aTilesetFilename, "%smapres/%s.png", pInfo->m_aCurrentDir, pTilesetName);
					
					bool Success = Src.Open(aTilesetFilename);
					if(!Success)
						continue;
				}
				else
				{
					bool Success = Src.OpenFromBuffer((unsigned char *)m_Reader.GetData(pImage->m_ImageData), pImage->m_Width, pImage->m_Height);
					if(!Success)
						continue;
				}
				
				char aTilemapFilename[512];
				if(GameLayer)
					sprintf(aTilemapFilename, "%s/tiles_game_%d.png", aGeneratedFolder, pTilesLayer->m_Data);
				else
					sprintf(aTilemapFilename, "%s/tiles_%d.png", aGeneratedFolder, pTilesLayer->m_Data);
				
				CTilemap Dest;
				bool Success = Dest.Open(aTilemapFilename, pTilesLayer->m_Width, pTilesLayer->m_Height, &Src, pInfo->m_TileSize);
				if(!Success)
					continue;
				
				CTile *pTilesData = (CTile *)m_Reader.GetData(pTilesLayer->m_Data);
				
				for(int x = 0; x < pTilesLayer->m_Width; x++)
				{
					for(int y = 0; y < pTilesLayer->m_Height; y++)
					{
						CTile *pTile = &pTilesData[y*pTilesLayer->m_Width + x];
						
						if(pTile->m_Index == 0)
							continue;
						
						Dest.SetTile(x, y, pTile->m_Index, pTile->m_Flags);
					}
				}
				
				Dest.Colorize(&pTilesLayer->m_Color);
				
				Dest.Save();
				Src.Close();
				
				m_TilemapsBenchmark.Pause();
			}
			
			else if(pLayer->m_Type == LAYERTYPE_QUADS)
			{
				m_QuadsBenchmark.Unpause();
				
				CMapItemLayerQuads *pQuadsLayer = (CMapItemLayerQuads *)pLayer;
				
				if(!pInfo->m_DumpQuads)
					continue;
				
				CImageRead Src;
				
				CMapItemImage *pImage = NULL;
				if(pQuadsLayer->m_Image >= 0)
					pImage = &pImages[pQuadsLayer->m_Image];
				
				if(pQuadsLayer->m_Image >= 0)
				{
					const char *pImageName = (char *)m_Reader.GetData(pImage->m_ImageName);
					
					if(pImage->m_External)
					{
						char aImageFilename[512];
						sprintf(aImageFilename, "%smapres/%s.png", pInfo->m_aCurrentDir, pImageName);
						
						bool Success = Src.Open(aImageFilename);
						if(!Success)
							continue;
					}
					else
					{
						bool Success = Src.OpenFromBuffer((unsigned char *)m_Reader.GetData(pImage->m_ImageData), pImage->m_Width, pImage->m_Height);
						if(!Success)
							continue;
					}
				}
				
				CQuad *pQuadsData = (CQuad *)m_Reader.GetData(pQuadsLayer->m_Data);
				
				for(int q = 0; q < pQuadsLayer->m_NumQuads; q++)
				{
					CQuad *pQuad = &pQuadsData[q];
					
					int MinX = min(min(min(pQuad->m_aPoints[0].x, pQuad->m_aPoints[1].x), pQuad->m_aPoints[2].x), pQuad->m_aPoints[3].x) / 1024;
					int MinY = min(min(min(pQuad->m_aPoints[0].y, pQuad->m_aPoints[1].y), pQuad->m_aPoints[2].y), pQuad->m_aPoints[3].y) / 1024;
					int MaxX = max(max(max(pQuad->m_aPoints[0].x, pQuad->m_aPoints[1].x), pQuad->m_aPoints[2].x), pQuad->m_aPoints[3].x) / 1024;
					int MaxY = max(max(max(pQuad->m_aPoints[0].y, pQuad->m_aPoints[1].y), pQuad->m_aPoints[2].y), pQuad->m_aPoints[3].y) / 1024;
					
					int Width = MaxX-MinX;
					int Height = MaxY-MinY;
					
					if(Width <= 0 || Height <= 0)
						continue;
					
					char aQuadsFilename[512];
					sprintf(aQuadsFilename, "%s/quads_%d_%d.png", aGeneratedFolder, pQuadsLayer->m_Data, q);
					
					CQuads Dest;
					bool Success = Dest.Open(aQuadsFilename, Width, Height, pInfo->m_TileSize);
					if(!Success)
						continue;
					
					if(pQuadsLayer->m_Image < 0)
						Dest.FillWhite();
					else
						Dest.DrawImage(&Src);
					
					Dest.DrawGradient(pQuad->m_aColors);
					
					Dest.Save();
				}
				
				m_QuadsBenchmark.Pause();
			}
		}
	}
	
	// dump metadata

	if(pInfo->m_DumpMetadata)
	{
		m_MetadataBenchmark.Unpause();
		
		CXMLDocument Doc;
		CXMLItem *pMainItem = Doc.Open("map");
		pMainItem->AddAttributeInt("version", pVersion->m_Version);
		
		for(int i = 0; i < ImagesNum; i++)
		{
			const char *pName = (char *)m_Reader.GetData(pImages[i].m_ImageName);

			CXMLItem *pImageItem = pMainItem->AddChild("image");
			pImageItem->AddAttributeInt("version", pImages[i].m_Version);
			pImageItem->AddAttributeInt("width", pImages[i].m_Width);
			pImageItem->AddAttributeInt("height", pImages[i].m_Height);
			pImageItem->AddAttributeBool("external", pImages[i].m_External);
			pImageItem->AddAttributeStr("name", pName);
		}
		
		for(int g = GroupsStart; g < GroupsStart+GroupsNum; g++)
		{
			CMapItemGroup *pGroup = (CMapItemGroup *)m_Reader.GetItem(g, NULL, NULL);
			
			CXMLItem *pGroupItem = pMainItem->AddChild("group");
			pGroupItem->AddAttributeInt("version", pGroup->m_Version);
			pGroupItem->AddAttributeInt("offset_x", pGroup->m_OffsetX);
			pGroupItem->AddAttributeInt("offset_y", pGroup->m_OffsetY);
			pGroupItem->AddAttributeInt("parallax_x", pGroup->m_ParallaxX);
			pGroupItem->AddAttributeInt("parallax_y", pGroup->m_ParallaxY);
			if(pGroup->m_Version >= 2)
			{
				pGroupItem->AddAttributeBool("use_clipping", pGroup->m_UseClipping);
				pGroupItem->AddAttributeInt("clip_x", pGroup->m_ClipX);
				pGroupItem->AddAttributeInt("clip_y", pGroup->m_ClipY);
				pGroupItem->AddAttributeInt("clip_w", pGroup->m_ClipW);
				pGroupItem->AddAttributeInt("clip_h", pGroup->m_ClipH);
			}
			
			for(int l = LayersStart + pGroup->m_StartLayer; l < LayersStart + pGroup->m_StartLayer+pGroup->m_NumLayers; l++)
			{
				if(l >= LayersStart+LayersNum)
					break;
				
				CMapItemLayer *pLayer = (CMapItemLayer *)m_Reader.GetItem(l, NULL, NULL);
				
				CXMLItem *pLayerItem = pGroupItem->AddChild("layer");
				if(pLayer->m_Type == LAYERTYPE_TILES)
					pLayerItem->AddAttributeStr("type", "tiles");
				else if(pLayer->m_Type == LAYERTYPE_QUADS)
					pLayerItem->AddAttributeStr("type", "quads");
				else
					pLayerItem->AddAttributeStr("type", "invalid");
				pLayerItem->AddAttributeBool("detail", pLayer->m_Flags&TILESLAYERFLAG_GAME);
				
				if(pLayer->m_Type == LAYERTYPE_TILES)
				{
					CMapItemLayerTilemap *pTilesLayer = (CMapItemLayerTilemap *)pLayer;
					
					const char *pImageName = "";
					if(pTilesLayer->m_Image >= 0 && pTilesLayer->m_Image < ImagesNum)
						pImageName = (char *)m_Reader.GetData(pImages[pTilesLayer->m_Image].m_ImageName);
					
					pLayerItem->AddAttributeInt("version", pTilesLayer->m_Version);
					pLayerItem->AddAttributeInt("width", pTilesLayer->m_Width);
					pLayerItem->AddAttributeInt("height", pTilesLayer->m_Height);
					pLayerItem->AddAttributeBool("game", pTilesLayer->m_Flags&TILESLAYERFLAG_GAME);
					pLayerItem->AddAttributeInt("color_env", pTilesLayer->m_ColorEnv);
					pLayerItem->AddAttributeInt("color_env_offset", pTilesLayer->m_ColorEnvOffset);
					pLayerItem->AddAttributeStr("image", pImageName);
					pLayerItem->AddAttributeInt("data", pTilesLayer->m_Data);
					
					CXMLItem *pColorItem = pLayerItem->AddChild("color");
					pColorItem->AddAttributeInt("r", pTilesLayer->m_Color.r);
					pColorItem->AddAttributeInt("g", pTilesLayer->m_Color.g);
					pColorItem->AddAttributeInt("b", pTilesLayer->m_Color.b);
					pColorItem->AddAttributeInt("a", pTilesLayer->m_Color.a);
				}
				else if(pLayer->m_Type == LAYERTYPE_QUADS)
				{
					CMapItemLayerQuads *pQuadsLayer = (CMapItemLayerQuads *)pLayer;
					
					const char *pImageName = "";
					if(pQuadsLayer->m_Image >= 0 && pQuadsLayer->m_Image < ImagesNum)
						pImageName = (char *)m_Reader.GetData(pImages[pQuadsLayer->m_Image].m_ImageName);
					
					pLayerItem->AddAttributeInt("version", pQuadsLayer->m_Version);
					pLayerItem->AddAttributeStr("image", pImageName);
					pLayerItem->AddAttributeInt("data", pQuadsLayer->m_Data);
					
					CQuad *pQuadsData = (CQuad *)m_Reader.GetData(pQuadsLayer->m_Data);
					
					for(int q = 0; q < pQuadsLayer->m_NumQuads; q++)
					{
						CQuad *pQuad = &pQuadsData[q];
						
						CXMLItem *pQuadItem = pLayerItem->AddChild("quad");
						pQuadItem->AddAttributeInt("pos_env", pQuad->m_PosEnv);
						pQuadItem->AddAttributeInt("pos_env_offset", pQuad->m_PosEnvOffset);
						pQuadItem->AddAttributeInt("color_env", pQuad->m_ColorEnv);
						pQuadItem->AddAttributeInt("color_env_offset", pQuad->m_ColorEnvOffset);
						pQuadItem->AddAttributeInt("data", q);
						
						for(int k = 0; k < 5; k++)
						{
							CXMLItem *pPointItem = pQuadItem->AddChild("point");
							pPointItem->AddAttributeInt("x", fx2f(pQuad->m_aPoints[k].x));
							pPointItem->AddAttributeInt("y", fx2f(pQuad->m_aPoints[k].y));
						}
						
						for(int k = 0; k < 4; k++)
						{
							CXMLItem *pColorItem = pQuadItem->AddChild("color");
							pColorItem->AddAttributeInt("r", pQuad->m_aColors[k].r);
							pColorItem->AddAttributeInt("g", pQuad->m_aColors[k].g);
							pColorItem->AddAttributeInt("b", pQuad->m_aColors[k].b);
							pColorItem->AddAttributeInt("a", pQuad->m_aColors[k].a);
						}
						
						for(int k = 0; k < 4; k++)
						{
							CXMLItem *pTexcoordItem = pQuadItem->AddChild("texcoord");
							pTexcoordItem->AddAttributeInt("x", fx2f(pQuad->m_aTexcoords[k].x));
							pTexcoordItem->AddAttributeInt("y", fx2f(pQuad->m_aTexcoords[k].y));
						}
					}
				}
			}
		}
		
		int EnvPointsStart;
		int EnvPointsNum;
		m_Reader.GetType(MAPITEMTYPE_ENVPOINTS, &EnvPointsStart, &EnvPointsNum);
		
		CEnvPoint *pPoints = 0;
		if(EnvPointsNum)
			pPoints = (CEnvPoint *)m_Reader.GetItem(EnvPointsStart, NULL, NULL);
		
		int EnvStart;
		int EnvNum;
		m_Reader.GetType(MAPITEMTYPE_ENVELOPE, &EnvStart, &EnvNum);
		
		for(int e = EnvStart; e < EnvStart+EnvNum; e++)
		{
			CMapItemEnvelope *pEnv = (CMapItemEnvelope *)m_Reader.GetItem(e, NULL, NULL);
			
			CXMLItem *pEnvItem = pMainItem->AddChild("envelope");
			pEnvItem->AddAttributeInt("version", pEnv->m_Version);
			if(pEnv->m_Channels == 3)
				pEnvItem->AddAttributeStr("type", "pos");
			else if(pEnv->m_Channels == 4)
				pEnvItem->AddAttributeStr("type", "color");
			else
				pEnvItem->AddAttributeStr("type", "invalid");
			if(pEnv->m_aName[0] != -1)
			{
				char aEnvName[64];
				IntsToStr(pEnv->m_aName, sizeof(pEnv->m_aName)/sizeof(int), aEnvName);
				pEnvItem->AddAttributeStr("name", aEnvName);
			}
			
			for(int p = pEnv->m_StartPoint; p < pEnv->m_StartPoint+pEnv->m_NumPoints; p++)
			{
				CXMLItem *pEnvPointItem = pEnvItem->AddChild("envpoint");
				pEnvPointItem->AddAttributeInt("time", pPoints[p].m_Time);
				if(p != pEnv->m_StartPoint+pEnv->m_NumPoints -1)
				{
					if(pPoints[p].m_Curvetype == CURVETYPE_STEP)
						pEnvPointItem->AddAttributeStr("curvetype", "step");
					else if(pPoints[p].m_Curvetype == CURVETYPE_LINEAR)
						pEnvPointItem->AddAttributeStr("curvetype", "linear");
					else if(pPoints[p].m_Curvetype == CURVETYPE_SLOW)
						pEnvPointItem->AddAttributeStr("curvetype", "slow");
					else if(pPoints[p].m_Curvetype == CURVETYPE_FAST)
						pEnvPointItem->AddAttributeStr("curvetype", "fast");
					else if(pPoints[p].m_Curvetype == CURVETYPE_SMOOTH)
						pEnvPointItem->AddAttributeStr("curvetype", "smooth");
					else
						pEnvPointItem->AddAttributeStr("curvetype", "invalid");
				}
				if(pEnv->m_Channels == 3)
				{
					pEnvPointItem->AddAttributeInt("x", fx2f(pPoints[p].m_aValues[0]));
					pEnvPointItem->AddAttributeInt("y", fx2f(pPoints[p].m_aValues[1]));
					pEnvPointItem->AddAttributeInt("r", fx2f(pPoints[p].m_aValues[2]));
				}
				else if(pEnv->m_Channels == 4)
				{
					pEnvPointItem->AddAttributeInt("r", fx2f(pPoints[p].m_aValues[0])*255);
					pEnvPointItem->AddAttributeInt("g", fx2f(pPoints[p].m_aValues[1])*255);
					pEnvPointItem->AddAttributeInt("b", fx2f(pPoints[p].m_aValues[2])*255);
					pEnvPointItem->AddAttributeInt("a", fx2f(pPoints[p].m_aValues[3])*255);
				}
			}
		}
		
		char aMetadataFilename[512];
		sprintf(aMetadataFilename, "%s/metadata.xml", aGeneratedFolder);
		Doc.Save(aMetadataFilename);
		Doc.Close();
		
		m_MetadataBenchmark.Pause();
	}
	
	if(ImagesNum > 0)
		delete pImages;
	
	remove(aGenerating);
	
	m_OverallBenchmark.Pause();
	
	if(pInfo->m_ShowBenchmark)
	{
		printf("Benchmark results:\n");
		printf("  Images dumping:\t%dms\n", m_ImagesBenchmark.GetTime());
		printf("  Tilemaps dumping:\t%dms\n", m_TilemapsBenchmark.GetTime());
		printf("  Quads dumping:\t%dms\n", m_QuadsBenchmark.GetTime());
		printf("  Metadata dumping:\t%dms\n", m_MetadataBenchmark.GetTime());
		printf("  Overall:\t\t%dms\n", m_OverallBenchmark.GetTime());
	}
}
Beispiel #9
0
bool RSS_PlaylistParser::Parse(std::string p_sContent)
{
		
	CXMLDocument* pDoc = new CXMLDocument();
	if(!pDoc->LoadFromString(p_sContent)) {
      // TODO Log the incorrect format
		delete pDoc;
		return false;
	}
	
	CXMLNode* pTmp;
	pTmp = pDoc->RootNode()->FindNodeByName("channel");
	if(!pTmp) {
      // TODO Log the incorrect format
		delete pDoc;
		return false;
	}
	
	for(int i = 0; i < pTmp->ChildCount(); i++) {
		if(pTmp->ChildNode(i)->Name().compare("item") != 0) {
      // TODO Log the incorrect format
			continue;
		}
		
		CXMLNode* pEnc = pTmp->ChildNode(i)->FindNodeByName("enclosure");
		if(!pEnc) {
      // TODO Log the incorrect format
			continue;
		}
		
		PlaylistEntry_t* pEntry = new PlaylistEntry_t();	
			
		pEntry->sFileName = pEnc->Attribute("url");
		pEntry->nSize = pEnc->AttributeAsUInt("length");
		pEntry->sMimeType = pEnc->Attribute("type");
		
		pEntry->bIsLocalFile = false;
			
		if(pTmp->ChildNode(i)->FindNodeByName("title")) {
			pEntry->sTitle = pTmp->ChildNode(i)->FindNodeByName("title")->Value();
		}
			
		m_lEntries.push_back(pEntry);
		
	}
		
/*		<channel>
	<title>Marillion Online Podcast</title>
	<link>http://www.marillion.com</link>
	<language>en</language>
	<copyright>&#x2117; &amp; &#xA9; 2006 Marillion</copyright>
	<pubDate>Wed, 13 Dec 2006 15:00:00 GMT</pubDate>
	<itunes:subtitle>Find a Better Way of Life at marillion.com</itunes:subtitle>
	<itunes:author>Marillion</itunes:author>
	<itunes:summary>Official insider information for British rock band Marillion. Whether writing in the studio, recording new material, preparing for a live show, or on the road - get the scoop DIRECT from the band members themselves. Find a Better Way of Life at marillion.com</itunes:summary>
	<description>Official insider information for British rock band Marillion. Whether writing in the studio, recording new material, preparing for a live show, or on the road - get the scoop DIRECT from the band members themselves. Find a Better Way of Life at marillion.com</description>
				
		
		<item>
		<title>Album Number 14 Begins</title>
		<itunes:author>Marillion</itunes:author>
		<itunes:subtitle>Recording is set to begin on the next studio album</itunes:subtitle>
		<itunes:summary>26 May 2006. Marillion have been jamming song ideas since the beginning of 2006 and have now come up with a short-list of contenders for the next studio album. Coming to you direct from the live room at the Racket Club studio with Mark Kelly, Ian Mosley, Pete Trewavas, Mike Hunter, and the Racket Records Peanut Gallery.</itunes:summary>
		<enclosure url="http://media.marillion.com/podcast/20060526.mp3" length="3361560" type="audio/mpeg" />
		<guid>http://media.marillion.com/podcast/20060526.mp3</guid>
		<pubDate>Fri, 26 May 2006 09:00:00 GMT</pubDate>
		<itunes:duration>4:00</itunes:duration>
		<itunes:explicit>yes</itunes:explicit>
		<itunes:keywords>marillion, studio, new, album, recording, update, racket, hogarth, kelly, mosley, trewavas, rothery</itunes:keywords>
	</item>	*/
		
	delete pDoc;
		
  if(!m_lEntries.empty()) {
    m_bEof = false;
    m_lEntriesIterator = m_lEntries.begin();
  }

	return true;
}
Beispiel #10
0
void CFYSPrintDoc::UnpackFiles()
{
	CString strTemp;
	CString strSep("\\");
	CString strFileName = m_strFYSTempPath + FORYOURSOUL_TXT;
	FILE* input = NULL;
	errno_t err = fopen_s(&input, strFileName, "rb");
	if (!input || err != 0)
	{
		SetError(String("Failed to open %s", strFileName));
		return;
	}

	HGLOBAL hMemory;
	BYTE* pMemory;

	// unpack the mini header
	hMemory = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(BYTE));
	pMemory = (BYTE*)::GlobalLock(hMemory);
	char xz = ']';
	do
	{
		fread(pMemory, sizeof(BYTE), 1, input);
		strTemp += (char)*pMemory;
	}while((*(char*)pMemory) != xz);

	::GlobalUnlock(hMemory);
	::GlobalFree(hMemory);

	// unpack streamheader
	strTemp = strTemp.Mid(1, strTemp.Find(',', 0)-1);
	DWORD dwSize = atoi(strTemp);

	hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize);
	pMemory = (BYTE*)::GlobalLock(hMemory);

	fread(pMemory, sizeof(BYTE), dwSize, input);

	CString strPath = m_strFYSTempPath + XML_PATH + strSep;
	strTemp.Format("%sXP_%s", strPath, STREAMHDR_XML);

	FILE* output = NULL;
	err = fopen_s(&output, strTemp, "wb");
	if (!output || err != 0)
	{
		SetError(String("Failed to open %s", strTemp));
	}
	else
	{
		fwrite(pMemory, sizeof(BYTE), dwSize, output);
		fclose(output);
		output = NULL;
	}

	::GlobalUnlock(hMemory);
	::GlobalFree(hMemory);

	// time to read the stream header into a xml class 
	CXMLDocument* pXMLDoc = new CXMLDocument;
	pXMLDoc->Load(strTemp, false);
	CString strCount = pXMLDoc->GetStringValue("//FYS_DataStreamHeader//Files", "Count");
	int nFileCount = atoi(strCount);
	for (int i=0, offset=0; i<nFileCount; i++)
	{
		CString strSrch = String("//FYS_DataStreamHeader//Files//File[@StartOffset = '%ld']", offset);
		CString strType = pXMLDoc->GetStringValue(strSrch, "Type");
		CString strName = pXMLDoc->GetStringValue(strSrch, "Name");
		CString strSize = pXMLDoc->GetStringValue(strSrch, "Size");
		DWORD dwSize = atoi(strSize);

		hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize);
		pMemory = (BYTE*)::GlobalLock(hMemory);
		fread(pMemory, sizeof(BYTE), dwSize, input);

		if (strType == "DataEnvelope")
			strPath = m_strFYSTempPath + XML_PATH + strSep;
		if (strType == "Image")
			strPath = m_strFYSTempPath + IMAGES_PATH + strSep;
		if (strType == "Font")
			strPath = m_strFYSTempPath + FONTS_PATH + strSep;

		strTemp.Format("%sXP_%s", strPath, strName);
		err = fopen_s(&output, strTemp, "wb");
		if (!output || err != 0)
		{
			SetError(String("Failed to open %s", strTemp));
		}
		else
		{
			fwrite(pMemory, sizeof(BYTE), dwSize, output);
			fclose(output);
			output = NULL;
		}

		::GlobalUnlock(hMemory);
		::GlobalFree(hMemory);

		offset += dwSize;
	}

	fclose(input);
	delete pXMLDoc;
}
Beispiel #11
0
bool CFYSPrintDoc::SendXmlDoc(CString strURL)
{
	CComPtr<IWebBrowser2> pBrowser;
	HRESULT hr = pBrowser.CoCreateInstance(_bstr_t("InternetExplorer.Application"));
	if (hr != S_OK)
	{
		SetError("Failed to start IE!.");
		return false;
	}
	
	CString strSendFile = m_strFYSTempPath + FORYOURSOUL_TXT;
	CHTTPClient *pHttpClient = new CHTTPClient(pBrowser);
	pHttpClient->AddPostArguments("File1", strSendFile, true);
	BOOL bRetVal = pHttpClient->Request(strURL, CHTTPClient::RequestPostMethodMultiPartsFormData);
	//pHttpClient->Request("http://localhost/simpleupload/Receiver.aspx", CHTTPClient::RequestPostMethodMultiPartsFormData);

	VARIANT_BOOL bBusy = true;
	int ix = 300;
	while (bBusy)
	{
		::Sleep(100);
		pBrowser->get_Busy(&bBusy);
		if (--ix <= 0)
			break;
	}

	if (!bRetVal)
	{
		m_strErrorMsg.Format("Failed to send project to the website.");
		return false;
	}

	CComPtr<IDispatch> spDisp;

	hr = pBrowser->get_Document(&spDisp);
	if (FAILED(hr) || !spDisp)
	{
		delete pHttpClient;
		return false;
	}

	CComQIPtr<IHTMLDocument2> spDoc(spDisp);
	if (!spDoc)
	{
		m_strErrorMsg.Format("Invalid response from website after sending project successfully.");
		delete pHttpClient;
		return false;
	}
	
	CComPtr<IHTMLElement> spElem;
	hr = spDoc->get_body(&spElem);
	if (FAILED(hr) || !spDisp)
	{
		m_strErrorMsg.Format("Invalid response from website after sending project successfully.");
		delete pHttpClient;
		return false;
	}

	CString strTxt;
	CComBSTR bstr;
	spElem->get_innerHTML(&bstr);
	strTxt = bstr;

#ifdef _DEBUG
	spElem->get_innerText(&bstr);
	strTxt = bstr;
#endif

	delete pHttpClient;

	if (strTxt.Find("<FYS_DATASTREAMACKNOWLEDGMENT") < 0)
	{
		m_strErrorMsg.Format("Invalid response from website after sending project successfully.");
		return false;
	}

	strTxt = strTxt.Mid(strTxt.Find("<FYS_DATASTREAMACKNOWLEDGMENT"));

	CString strSrchPtrn("//FYS_DATASTREAMACKNOWLEDGMENT");
	CXMLDocument* pXMLDoc = new CXMLDocument;
	pXMLDoc->LoadString(strTxt);
	pXMLDoc->RegisterCallback(MyXMLCallback, (LPARAM)this);
	if (pXMLDoc->WalkTree(strSrchPtrn) != S_OK)
	{
		pXMLDoc->SetFYSError();
		m_strErrorMsg = pXMLDoc->GetErrorMsg();
		delete pXMLDoc;
		return false;
	}

	delete pXMLDoc;
	return true;
}