Esempio 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;
}
Esempio 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;
}
Esempio 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;
}
Esempio n. 4
0
void foo() {

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

	//doc->async = false;
	doc->load( "EnshutsuAuto.xml" );
}
Esempio n. 5
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;
}
Esempio 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;
}
Esempio n. 7
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;
}