Пример #1
0
bool NZBFile::Parse()
{
    CoInitialize(NULL);

	HRESULT hr;

	MSXML::IXMLDOMDocumentPtr doc;
	hr = doc.CreateInstance(MSXML::CLSID_DOMDocument);
    if (FAILED(hr))
    {
        return false;
    }

    // Load the XML document file...
	doc->put_resolveExternals(VARIANT_FALSE);
	doc->put_validateOnParse(VARIANT_FALSE);
	doc->put_async(VARIANT_FALSE);

	// filename needs to be properly encoded
	char* szURL = (char*)malloc(strlen(m_szFileName)*3 + 1);
	EncodeURL(m_szFileName, szURL);
	debug("url=\"%s\"", szURL);
	_variant_t v(szURL);
	free(szURL);

	VARIANT_BOOL success = doc->load(v);
	if (success == VARIANT_FALSE)
	{
		_bstr_t r(doc->GetparseError()->reason);
		const char* szErrMsg = r;

		char szMessageText[1024];
		snprintf(szMessageText, 1024, "Error parsing nzb-file %s: %s", Util::BaseFileName(m_szFileName), szErrMsg);
		szMessageText[1024-1] = '\0';
		m_pNZBInfo->AddMessage(Message::mkError, szMessageText);

		return false;
	}

    if (!ParseNZB(doc))
	{
		return false;
	}

	if (GetNZBInfo()->GetFileList()->empty())
	{
		char szMessageText[1024];
		snprintf(szMessageText, 1024, "Error parsing nzb-file %s: file has no content", Util::BaseFileName(m_szFileName));
		szMessageText[1024-1] = '\0';
		m_pNZBInfo->AddMessage(Message::mkError, szMessageText);

		return false;
	}

	ProcessFiles();

    return true;
}
Пример #2
0
Result FileToXML(MSXML::IXMLDOMDocumentPtr& p, const string& fileName)
{
	Result r;

	try
	{
		HRESULT hr;
		if(FAILED(hr = p.CreateInstance("msxml.domdocument")))
		{
			r.Fail(Format("Failed to create instance of msxml.domdocument.  Error code: %").ul(hr).Str());
		}
		else
		{
      VARIANT_BOOL b = p->load(fileName.c_str());
			if(b == VARIANT_FALSE)
			{
				MSXML::IXMLDOMParseErrorPtr pErr = p->GetparseError();
				if(pErr == NULL)
				{
					r.Fail(_T("Failed to load XML into msxml.domdocument.  Could not get IXMLDOMParseErrorPtr for details."));
				}
				else
				{
					r.Fail(Format("Failed to parse xml.  %").s(pErr->reason).Str());
				}
			}
			else
			{
				r.Succeed();
			}
		}
	}
	catch(_com_error& e)
	{
		r.Fail(Format("Error loading XML into msxml.domdocument. % %").s(e.ErrorMessage()).s(e.Description()).Str());
	}

	return r;
}