Exemplo n.º 1
0
BOOL SApplication::_LoadXmlDocment( LPCTSTR pszXmlName ,LPCTSTR pszType ,pugi::xml_document & xmlDoc,IResProvider *pResProvider/* = NULL*/)
{
    if(!pResProvider) 
    {
        if(IsFileType(pszType))
        {
            pugi::xml_parse_result result= xmlDoc.load_file(pszXmlName,pugi::parse_default,pugi::encoding_utf8);
            SASSERT_FMTW(result,L"parse xml error! xmlName=%s,desc=%s,offset=%d",pszXmlName,result.description(),result.offset);
            return result;
        }else
        {
            pResProvider = GetMatchResProvider(pszType,pszXmlName);
        }
    }
    if(!pResProvider) return FALSE;
    
    DWORD dwSize=pResProvider->GetRawBufferSize(pszType,pszXmlName);
    if(dwSize==0) return FALSE;

    CMyBuffer<char> strXml;
    strXml.Allocate(dwSize);
    pResProvider->GetRawBuffer(pszType,pszXmlName,strXml,dwSize);

    pugi::xml_parse_result result= xmlDoc.load_buffer(strXml,strXml.size(),pugi::parse_default,pugi::encoding_utf8);
    SASSERT_FMTW(result,L"parse xml error! xmlName=%s,desc=%s,offset=%d",pszXmlName,result.description(),result.offset);
    return result;
}
Exemplo n.º 2
0
BOOL SApplication::_LoadXmlDocment( LPCTSTR pszXmlName ,LPCTSTR pszType ,pugi::xml_document & xmlDoc)
{
    DWORD dwSize=GetRawBufferSize(pszType,pszXmlName);
    if(dwSize==0) return FALSE;

    CMyBuffer<char> strXml;
    strXml.Allocate(dwSize);
    GetRawBuffer(pszType,pszXmlName,strXml,dwSize);

    pugi::xml_parse_result result= xmlDoc.load_buffer(strXml,strXml.size(),pugi::parse_default,pugi::encoding_utf8);
    SASSERT_FMTW(result,L"parse xml error! xmlName=%s,desc=%s,offset=%d",pszXmlName,result.description(),result.offset);
    return result;
}
Exemplo n.º 3
0
BOOL DuiResProviderFiles::Init( LPCTSTR pszPath )
{
    CMyBuffer<char>  xmlBuf;
    CDuiStringT strPathIndex=pszPath;
    strPathIndex+=_T("\\");
    strPathIndex+=INDEX_XML;
    FILE *f=_tfopen(strPathIndex,_T("rb"));
    if(!f) return(FALSE);
    int nLen=_filelength(_fileno(f));
    if(nLen>100*1024)
    {
        fclose(f);
        return FALSE;
    }
    xmlBuf.Allocate(nLen);
    if(nLen!=fread(xmlBuf,1,nLen,f))
    {
        fclose(f);
        return FALSE;
    }
    fclose(f);

	pugi::xml_document xmlDoc;
    CDuiStringT strFileName;
	if(!xmlDoc.load_buffer(xmlBuf,xmlBuf.size(),pugi::parse_default,pugi::encoding_utf8)) return FALSE;

	pugi::xml_node xmlNode=xmlDoc.child("resid");
    while(xmlNode)
    {
		DuiResID id(DUI_CA2T(xmlNode.attribute("type").value(),CP_UTF8),xmlNode.attribute("id").as_int(0));
		CDuiStringT strFile=DUI_CA2T(xmlNode.attribute("file").value(),CP_UTF8);
		if(!m_strPath.IsEmpty()) strFile.Format(_T("%s\\%s"),(LPCTSTR)m_strPath,(LPCTSTR)strFile);
		m_mapFiles[id]=strFile;
		xmlNode=xmlNode.next_sibling("resid");
    }

    m_strPath=pszPath;
    return TRUE;
}