Exemplo n.º 1
0
HRESULT touchmind::shell::Clipboard::CopyNodeModel(IN HWND hWnd, IN const std::shared_ptr<touchmind::model::node::NodeModel> &node)
{
    HRESULT hr = _InitializeClipboard();
    if (SUCCEEDED(hr)) {
        if (!::OpenClipboard(hWnd)) {
            return E_FAIL;
        }
        ::EmptyClipboard();
        // customized xml format
        MSXML::IXMLDOMDocumentPtr pXMLDoc;
        hr = pXMLDoc.CreateInstance(__uuidof(MSXML::DOMDocument60), nullptr, CLSCTX_INPROC_SERVER);
        _bstr_t s_node(L"node");
        MSXML::IXMLDOMElementPtr pElement = pXMLDoc->createElement(s_node);
        pXMLDoc->appendChild(pElement);
        m_pNodeModelXMLEncoder->Encode(node, pXMLDoc, pElement);
        std::wstring xml(pXMLDoc->xml);
        _CopyXML(hWnd, xml);

        // text format
        touchmind::converter::NodeModelToTextConverter textConverter;
        std::wstring text;
        textConverter.ToText(node, text);
        _CopyTEXT(hWnd, text);

        ::CloseClipboard();
    }
    return hr;
}
Exemplo n.º 2
0
HRESULT touchmind::shell::Clipboard::PasteNodeModel(
    IN HWND hWnd,
    OUT std::shared_ptr<touchmind::model::node::NodeModel> &node,
    OUT std::vector<std::shared_ptr<model::link::LinkModel>> &links)
{
    HRESULT hr = _InitializeClipboard();
    if (SUCCEEDED(hr)) {
        int formatId = GetPriorityClipboardFormat(
                           &m_pFormatPriorityList.front(),
                           static_cast<int>(m_pFormatPriorityList.size()));
        if (formatId >= 0) {
            if (formatId == m_touchMindClipboardFormatId) {
                std::wstring s_xml;
                _PasteXML(hWnd, s_xml);
                LOG(SEVERITY_LEVEL_DEBUG) << s_xml;
                MSXML::IXMLDOMDocumentPtr pXMLDoc;
                hr = pXMLDoc.CreateInstance(__uuidof(MSXML::DOMDocument60), nullptr, CLSCTX_INPROC_SERVER);
                _bstr_t xml(s_xml.c_str());
                pXMLDoc->loadXML(xml);
                MSXML::IXMLDOMElementPtr pElement = pXMLDoc->firstChild;
                m_pNodeModelXMLDecoder->Decode(pElement, node, links, false, false);
            } else if (formatId == CF_UNICODETEXT) {
                std::wstring text;
                _PasteTEXT(hWnd, text);
                touchmind::converter::NodeModelToTextConverter textConverter;
                textConverter.SetSelectionManager(m_pSelectionManager);
                node = textConverter.FromText(text);
            }
        }
    }
    return hr;
}
Exemplo n.º 3
0
HRESULT CSolarSystemDoc::LoadFromXmlString(const CString& str)
{
	if (str.IsEmpty()) return E_FAIL;

	MSXML::IXMLDOMDocumentPtr pDocument;

	HRESULT hResult = pDocument.CreateInstance(__uuidof(DOMDocument));

	if (FAILED(hResult)) return hResult;

	try
	{
		pDocument->async = VARIANT_FALSE;

		if (VARIANT_FALSE == pDocument->loadXML(bstr_t(str)))
			return E_FAIL;

		ParseXmlDocument(pDocument);
	}
	catch (_com_error &e)
	{
		return e.Error();
	}

	return S_OK;
}
Exemplo n.º 4
0
void NewVersionDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);

	int iTotalTextLength = ctlDetails.GetWindowTextLength();
	ctlDetails.SetSel(iTotalTextLength, iTotalTextLength);
	BeginWaitCursor();
	CString sResult;
	CWebAccess webAccess;
	webAccess.Get("www.milow.net/site/projects/parnrar/pnrVersions.xml", sResult);

	if (sResult != "")
		{
		MSXML::IXMLDOMDocumentPtr domVersions;	

		if (CoCreateInstance( MSXML::CLSID_DOMDocument, 0, CLSCTX_INPROC_SERVER, MSXML::IID_IXMLDOMDocument, (void**)&domVersions ) != S_OK)
		{
			ctlDetails.ReplaceSel("Error: Failed to create DOMDocument object");
			goto CLEANUP;
		}
		domVersions->loadXML(sResult.GetBuffer(0));
		CString sXml = static_cast<char *>(domVersions->xml);
		if (sXml == "")
		{
			ctlDetails.ReplaceSel("Error: Failed to download version information");
			goto CLEANUP;
		}
		MSXML::IXMLDOMElementPtr eVer = domVersions->selectSingleNode("/Versions/Version");
		CString sVer = static_cast<char *>(_bstr_t(eVer->getAttribute("number")));
		if (sVer == theApp.GetMyVersion())
		{
			ctlDetails.ReplaceSel("You are currently running the latest version of Par-N-Rar");
			goto CLEANUP;
		}

		//Get all info about later versions
		CString sText = "You are currently running v" + theApp.GetMyVersion();
		sText += "\n";
		sText += "The latest version is v" + sVer;
		sText += "\n\n";

		MSXML::IXMLDOMNodeListPtr nlVersions = domVersions->selectNodes( "/Versions/Version");	
		for (long l=0; l<nlVersions->length; l++)
		{
			eVer = nlVersions->Getitem(l);
			sVer = static_cast<char *>(_bstr_t(eVer->getAttribute("number")));
			if (sVer == theApp.GetMyVersion())
				break;
			sText += "****************************************************\nVersion " + sVer;
			sText += ": \n";
			sText += static_cast<char *>(eVer->text);
			sText += "\n\n";
		}
		ctlDetails.ReplaceSel(sText);
	}

CLEANUP:
	Resize();
	EndWaitCursor();
}
Exemplo n.º 5
0
void foo() {

	MSXML::IXMLDOMDocumentPtr doc;
	HRESULT hr = doc.CreateInstance( MSXML::CLSID_DOMDocument );

	//doc->async = false;
	doc->load( "EnshutsuAuto.xml" );
}
Exemplo n.º 6
0
/** @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;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
void CSolarSystemDoc::ParseXmlDocument(MSXML::IXMLDOMDocumentPtr& pDocument)
{
	m_SolarSystem.m_Bodies.clear();

	{
		MSXML::IXMLDOMNodeListPtr pSolarSystem = pDocument->getElementsByTagName(L"SolarSystem");
		if (pSolarSystem)
		{
			pSolarSystem->reset();
			MSXML::IXMLDOMNodePtr pRecordNode = pSolarSystem->nextNode();
			m_Thread.m_timestep = static_cast<unsigned int>(GetXmlIntValue(pRecordNode, L"TimeStep", 300));
		}
	}

	MSXML::IXMLDOMNodeListPtr pRecordsList = pDocument->getElementsByTagName(L"Body");

	if (pRecordsList)
	{
		pRecordsList->reset();

		MSXML::IXMLDOMNodePtr pRecordNode = pRecordsList->nextNode();

		//for each group in the xml file
		while (pRecordNode)
		{
			m_SolarSystem.m_Bodies.emplace_back(MolecularDynamics::Body());
			m_SolarSystem.m_BodyProperties.emplace_back(BodyProperties());

			LoadBodyXml(pRecordNode, m_SolarSystem.m_Bodies.back(), m_SolarSystem.m_BodyProperties.back());
			
			pRecordNode = pRecordsList->nextNode();
		}
	}

	m_SolarSystem.m_Bodies.shrink_to_fit();
	m_SolarSystem.m_BodyProperties.shrink_to_fit();
}