[32] | 1 | #include "StdAfx.h"
|
---|
| 2 | #include "LogParser.h"
|
---|
| 3 |
|
---|
| 4 | #include <iostream>
|
---|
| 5 |
|
---|
| 6 | #include "WindowFinder.h"
|
---|
| 7 |
|
---|
| 8 | LogParser::LogParser(void)
|
---|
| 9 | {
|
---|
| 10 |
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | LogParser::~LogParser(void)
|
---|
| 14 | {
|
---|
| 15 |
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | HRESULT STDMETHODCALLTYPE LogParser::startElement(
|
---|
| 20 | wchar_t __RPC_FAR *pwchNamespaceUri,
|
---|
| 21 | int cchNamespaceUri,
|
---|
| 22 | wchar_t __RPC_FAR *pwchLocalName,
|
---|
| 23 | int cchLocalName,
|
---|
| 24 | wchar_t __RPC_FAR *pwchRawName,
|
---|
| 25 | int cchRawName,
|
---|
| 26 | MSXML2::ISAXAttributes __RPC_FAR *pAttributes)
|
---|
| 27 | {
|
---|
| 28 | std::wstring localName(pwchLocalName);
|
---|
| 29 | if( localName.compare(L"session")==0 ) {
|
---|
| 30 | // TODO
|
---|
| 31 | }
|
---|
| 32 | else if( localName.compare(L"msg")==0 ) {
|
---|
| 33 | std::wstring type = GetAttributeValue(pAttributes, L"type", L"");
|
---|
| 34 | msgType = _wtoi(type.c_str());
|
---|
| 35 | std::wstring lParamStr = GetAttributeValue(pAttributes, L"LPARAM", L"");
|
---|
| 36 | lParam = _wtoi(lParamStr.c_str());
|
---|
| 37 | std::wstring wParamStr = GetAttributeValue(pAttributes, L"WPARAM", L"");
|
---|
| 38 | wParam = _wtoi(wParamStr.c_str());
|
---|
| 39 | std::wstring delayStr = GetAttributeValue(pAttributes, L"delay", L"");
|
---|
| 40 | delay = _wtoi(delayStr.c_str());
|
---|
| 41 | currentWindow = NULL;
|
---|
| 42 | currentParent = NULL;
|
---|
| 43 | }
|
---|
| 44 | else if( localName.compare(L"window")==0 ) {
|
---|
| 45 | WindowData * winData = new WindowData;
|
---|
| 46 | winData->name = GetAttributeValue(pAttributes, L"name", L"");
|
---|
| 47 | winData->className = GetAttributeValue(pAttributes, L"class", L"");
|
---|
| 48 | std::wstring resourceIdStr = GetAttributeValue(pAttributes, L"resourceId", L"");
|
---|
| 49 | winData->resourceId = _wtoi(resourceIdStr.c_str());
|
---|
| 50 | std::wstring isModalStr = GetAttributeValue(pAttributes, L"isModal", L"");
|
---|
| 51 | if( isModalStr.compare(L"true")==0 ) {
|
---|
| 52 | winData->isModal = true;
|
---|
| 53 | } else {
|
---|
| 54 | winData->isModal = false;
|
---|
| 55 | }
|
---|
| 56 | winData->child = NULL;
|
---|
| 57 | if( currentWindow==NULL ) {
|
---|
| 58 | currentWindow = winData;
|
---|
| 59 | } else {
|
---|
| 60 | currentParent->child = winData;
|
---|
| 61 | }
|
---|
| 62 | currentParent = winData;
|
---|
| 63 | }
|
---|
| 64 | return S_OK;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | HRESULT STDMETHODCALLTYPE LogParser::endElement(
|
---|
| 69 | wchar_t __RPC_FAR *pwchNamespaceUri,
|
---|
| 70 | int cchNamespaceUri,
|
---|
| 71 | wchar_t __RPC_FAR *pwchLocalName,
|
---|
| 72 | int cchLocalName,
|
---|
| 73 | wchar_t __RPC_FAR *pwchRawName,
|
---|
| 74 | int cchRawName)
|
---|
| 75 | {
|
---|
| 76 | std::wstring localName(pwchLocalName);
|
---|
| 77 | if( localName.compare(L"session")==0 ) {
|
---|
| 78 | // TODO
|
---|
| 79 | }
|
---|
| 80 | else if( localName.compare(L"msg")==0 ) {
|
---|
| 81 | WindowFinder finder;
|
---|
| 82 | HWND hwnd = finder.find(currentWindow);
|
---|
| 83 | sendMessage(hwnd);
|
---|
| 84 | deleteWindowData(currentWindow);
|
---|
| 85 | currentWindow = NULL;
|
---|
| 86 | }
|
---|
| 87 | else if( localName.compare(L"LPARAM")==0 ) {
|
---|
| 88 | WindowFinder finder;
|
---|
| 89 | HWND hwnd = finder.find(currentWindow);
|
---|
| 90 | lParam = (LPARAM) hwnd;
|
---|
| 91 | deleteWindowData(currentWindow);
|
---|
| 92 | currentWindow = NULL;
|
---|
| 93 | }
|
---|
| 94 | else if( localName.compare(L"WPARAM")==0 ) {
|
---|
| 95 | WindowFinder finder;
|
---|
| 96 | HWND hwnd = finder.find(currentWindow);
|
---|
| 97 | wParam = (WPARAM) hwnd;
|
---|
| 98 | deleteWindowData(currentWindow);
|
---|
| 99 | currentWindow = NULL;
|
---|
| 100 | }
|
---|
| 101 | return S_OK;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | std::wstring LogParser::GetAttributeValue(MSXML2::ISAXAttributes __RPC_FAR *pAttributes,
|
---|
| 105 | std::wstring name, std::wstring defvalue)
|
---|
| 106 | {
|
---|
| 107 | // get the number of attributes
|
---|
| 108 | int length = 0;
|
---|
| 109 | pAttributes->getLength(&length);
|
---|
| 110 |
|
---|
| 111 | // enumerate over all attributes
|
---|
| 112 | for ( int i=0; i<length; i++ )
|
---|
| 113 | {
|
---|
| 114 | wchar_t *attrname = NULL, * attrvalue = NULL;
|
---|
| 115 | int namelen = 0, valuelen = 0;
|
---|
| 116 |
|
---|
| 117 | // get the local name of the current attribute
|
---|
| 118 | pAttributes->getLocalName(i,&attrname,&namelen);
|
---|
| 119 | // get the value of the current attribute
|
---|
| 120 | pAttributes->getValue(i,&attrvalue,&valuelen);
|
---|
| 121 | // if current attribute is the one needed return its value
|
---|
| 122 | if(name.compare(std::wstring(attrname,namelen)) == 0)
|
---|
| 123 | return std::wstring(attrvalue, valuelen);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | // attribute not found; return the default value
|
---|
| 127 | return defvalue;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | void LogParser::sendMessage(HWND hwnd) {
|
---|
| 131 | std::wcout << L"Sending " << msgType << L" to " << hwnd << "L - LPARAM: " << lParam << L" - WPARAM: " << wParam << std::endl;
|
---|
| 132 | PostMessage(hwnd, msgType, wParam, lParam);
|
---|
| 133 | Sleep(defaultMsgDelay);
|
---|
| 134 | //Sleep(delay);
|
---|
| 135 | } |
---|