/** @brief Load all Application settings in one shot from the XML file.
* @remarks CoInitialize() or CoInitializeEx() must have been called before using this method.
* @param _sFileName the full path name of an existing file
*/
bool MenuCommandSetCfg::_LoadFile(const std::string& _sFileName)
{
	const _bstr_t XMLDOM_OBJECT= _T("Microsoft.XMLDOM");
	const _bstr_t NODE_DART(_T("uicfg"));
	const _bstr_t NODE_COMMANDS(_T("commands"));
	const _bstr_t NODE_VERSION(_T("version"));
	const _bstr_t NODE_COMMANDLIST(_T("commandlist"));
	const _bstr_t NODE_MENULIST(_T("menulist"));

	bool bResult= false;

	try
	{
		MSXML::IXMLDOMDocumentPtr XMLDom;
		HRESULT hResult = XMLDom.CreateInstance((LPCSTR)XMLDOM_OBJECT);
		if(S_OK==hResult)
		{
			_ClearLists();

			_bstr_t FileName(_sFileName.c_str());

			if(XMLDom->load(FileName))
			{
				MSXML::IXMLDOMNodePtr Root= XMLDom->selectSingleNode(NODE_DART);
				MSXML::IXMLDOMNodePtr XMLNode;
				MSXML::IXMLDOMNodePtr XMLNode2;
				if( Root != NULL )
				{
					//load the file version
					XMLNode = Root->selectSingleNode(NODE_VERSION);
					_LoadFileVersion(XMLNode);

					//load the list of menu items
					XMLNode = Root->selectSingleNode(NODE_COMMANDS);
					if(XMLNode){
						XMLNode2= XMLNode->selectSingleNode(NODE_COMMANDLIST);
						_LoadMenuItemList(XMLNode2);

						XMLNode2= XMLNode->selectSingleNode(NODE_MENULIST);
						_LoadMenuList(XMLNode2);
					}
					bResult= true;
				}
			}
		}
		else{
			TRACE(_T("Failed to load XMLDom (%x)\n"), hResult);
		}
	}
	catch(...){
		TRACE(_T("Exception while loading config file\n"));
	}
	return bResult;
}
Example #2
0
bool CHelpDB::Open(TSTRING& sFileName)
{
    HRESULT hr = 0;
    bool r = false;
    Close();

    g_pLog->msg(_T("Attempting to open %s"), sFileName.c_str());

    try
    {
        if(SUCCEEDED(m_doc.CreateInstance("Msxml.DOMDocument")))
        {
            if(VARIANT_TRUE == m_doc->load(_variant_t(sFileName.c_str())))
            {
                m_sFileName = sFileName;

                // Get the top level node for later use.
                MSXML::IXMLDOMNodePtr Root;

                if(FAILED(hr = m_doc.QueryInterface(__uuidof(MSXML::IXMLDOMNode), &Root)))
                {
                    throw _com_error(hr);
                }

                try
                {
                    m_root = Root->selectSingleNode(_bstr_t(_T("/") TAG_HELPMSGS));

                    if(m_root != 0)
                    {
                        r = true;
                    }
                }
                catch(_com_error& e)
                {
                    sprintf(m_err, _T("COM Error: %08x"), e.Error());
                }
            }
            else
            {
                // Deal with an error from m_doc->load().
                MSXML::IXMLDOMParseErrorPtr pParse = m_doc->parseError;
                try
                {
                    if(pParse != 0)
                    {
                        TSTRING sReason, sText, sURL;
                        long lErrCode = pParse->errorCode;
                        long lFilePos = pParse->filepos;
                        long lLine = pParse->line;
                        long lCol = pParse->linepos;
                        if(pParse->reason.length()) HW2T(sReason, (BSTR)(pParse->reason));
                        if(pParse->srcText.length()) HW2T(sText, (BSTR)(pParse->srcText));
                        if(pParse->url.length()) HW2T(sURL, (BSTR)(pParse->url));

                        // Format the error.
                        sprintf(m_err, _T("Parsing Error #%d [%s] (line %d, col %d, filepos: %d, url %s, text: %s)"),
                            lErrCode, sReason.c_str(), lLine, lCol, lFilePos, sURL.c_str(), sText.c_str());
                        g_pLog->msg(_T("%s"), m_err.c_str());
                    }
                }
                catch(_com_error& e)
                {
                    TSTRING s = e.Description();
                    sprintf(m_err, _T("COM Error: %08x: %s"), e.Error(), s.c_str());
                    g_pLog->msg(_T("%s"), m_err.c_str());
                }
            }
        }
    }
    catch(_com_error& e)
    {
        sprintf(m_err, _T("COM Error: %08x"), e.Error());
        g_pLog->msg(_T("%s"), m_err.c_str());
    }

    if(!r)
    {
        // free up stuff.
        g_pLog->msg(_T("Failed to open %s"), sFileName.c_str());
        Close();
    }
    else
    {
        g_pLog->msg(_T("Successfully opened %s"), sFileName.c_str());
    }

    return r;
}
Example #3
0
bool NZBFile::ParseNZB(IUnknown* nzb)
{
	MSXML::IXMLDOMDocumentPtr doc = nzb;
	MSXML::IXMLDOMNodePtr root = doc->documentElement;

	MSXML::IXMLDOMNodePtr node = root->selectSingleNode("/nzb/head/meta[@type='password']");
	if (node)
	{
		_bstr_t password(node->Gettext());
		m_szPassword = strdup(password);
	}

	MSXML::IXMLDOMNodeListPtr fileList = root->selectNodes("/nzb/file");
	for (int i = 0; i < fileList->Getlength(); i++)
	{
		node = fileList->Getitem(i);
		MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("subject");
		if (!attribute) return false;
		_bstr_t subject(attribute->Gettext());
        FileInfo* pFileInfo = new FileInfo();
		pFileInfo->SetSubject(subject);

		attribute = node->Getattributes()->getNamedItem("date");
		if (attribute)
		{
			_bstr_t date(attribute->Gettext());
			pFileInfo->SetTime(atoi(date));
		}

		MSXML::IXMLDOMNodeListPtr groupList = node->selectNodes("groups/group");
		for (int g = 0; g < groupList->Getlength(); g++)
		{
			MSXML::IXMLDOMNodePtr node = groupList->Getitem(g);
			_bstr_t group = node->Gettext();
			pFileInfo->GetGroups()->push_back(strdup((const char*)group));
		}

		MSXML::IXMLDOMNodeListPtr segmentList = node->selectNodes("segments/segment");
		for (int g = 0; g < segmentList->Getlength(); g++)
		{
			MSXML::IXMLDOMNodePtr node = segmentList->Getitem(g);
			_bstr_t id = node->Gettext();
            char szId[2048];
            snprintf(szId, 2048, "<%s>", (const char*)id);

			MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("number");
			if (!attribute) return false;
			_bstr_t number(attribute->Gettext());

			attribute = node->Getattributes()->getNamedItem("bytes");
			if (!attribute) return false;
			_bstr_t bytes(attribute->Gettext());

			int partNumber = atoi(number);
			int lsize = atoi(bytes);

			if (partNumber > 0)
			{
				ArticleInfo* pArticle = new ArticleInfo();
				pArticle->SetPartNumber(partNumber);
				pArticle->SetMessageID(szId);
				pArticle->SetSize(lsize);
				AddArticle(pFileInfo, pArticle);
			}
		}

		AddFileInfo(pFileInfo);
	}
	return true;
}