123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- #include "StdAfx.h"
- #include "XMLLoader.h"
- #include <vector>
- #include <shlwapi.h>
- //#include "debug.h"
- #include "common_def.h"
- #include "Common_Funcs.h"
- #include "ResDataObject.h"
- #pragma comment(lib, "shlwapi.lib")
- using namespace std;
- XMLLoader::XMLLoader(void)
- {
- }
- XMLLoader::~XMLLoader(void)
- {
- }
- BOOL XMLLoader::LoadFile(string &filename)
- {
- BOOL ret = FALSE;
- string path ;
- GetModulePath(path);
- //::CoInitialize(NULL);
- m_filename = path + filename + string(".xml");
- if(PathFileExists(m_filename.c_str()))
- {
- ret = TRUE;
- //PROJECT_XML::IXMLDOMDocumentPtr pDoc;
- //PROJECT_XML::IXMLDOMElementPtr xmlRoot ;
- //try{
- // HRESULT hr = pDoc.CreateInstance(__uuidof(PROJECT_XML::DOMDocument));
- // if(!SUCCEEDED(hr))
- // {
- // MessageBox(NULL,L"XML INIT FAILED",L"WTH",MB_OK);
- // return FALSE;
- // }
- // VARIANT_BOOL hr1;
- // hr1 = pDoc->load(m_filename.c_str());
- // if (hr1 != VARIANT_TRUE) {
- // MessageBox(NULL,L"Config file failed load",L"WTH",MB_OK);
- // return FALSE;
- // }
- // PROJECT_XML::IXMLDOMElementPtr root = pDoc->documentElement;
- // _variant_t strRootName = root->nodeName;
- // _bstr_t wstrRootName(strRootName.bstrVal);
- // if (wstrRootName != _bstr_t(L"ROOT"))
- // {
- // DebugPrint(_T("Failed Load <ROOT>.filename:%s\r\n"),m_filename.c_str());
- // return FALSE;
- // }
- // PROJECT_XML::IXMLDOMNodeListPtr plNode;
- // plNode = root->getElementsByTagName(L"COMMON");
- // if (plNode->Getlength() == 0) {
- // DebugPrint(_T("Failed Load <COMMON>.filename:%s\r\n"),m_filename.c_str());
- // return FALSE;
- // }
- // plNode = root->getElementsByTagName(L"WINDOW");
- // if (plNode->Getlength() == 0) {
- // DebugPrint(_T("Failed Load <WINDOW>.filename:%s\r\n"),m_filename.c_str());
- // return FALSE;
- // }
- //}
- //catch(...)
- //{
- // ret = FALSE;
- //}
- }
- //CoUninitialize();
- return ret;
- }
- BOOL XMLLoader::GetCommonPart(string &pName,INT &zOrder)
- {
- BOOL ret = TRUE;
- try{
- ResDataObject Res;
- if (Res.loadFile(m_filename.c_str()) == false)
- {
- MessageBox(NULL, "Config file failed load", "WTH", MB_OK);
- return FALSE;
- }
- pName = (const char*)(Res["ROOT"]["COMMON"]["PROCESSNAME"]);
- zOrder = (INT)(Res["ROOT"]["COMMON"]["ZORDER"]);
- }
- catch(...)
- {
- //DebugPrint(_T("Failed Load <ROOT> or <COMMON> Part.filename:%s\r\n"), m_filename.c_str());
- ret = FALSE;
- }
- return ret;
- }
- BOOL XMLLoader::GetWindowObject_Inside(ResDataObject &WindowRoot,WindowObject &Obj,string pName,INT zOrder)
- {
- BOOL ret = TRUE;
- try
- {
- INT Idx = WindowRoot.GetFirstOf("ID");
- if (Idx >= 0)
- {
- (*(Obj.m_ID)) = (const char *)WindowRoot["ID"];
- }
- Idx = WindowRoot.GetFirstOf("TITLE");
- if (Idx >= 0)
- {
- (*(Obj.m_ReqTitle)) = (const char *)WindowRoot["TITLE"];
- }
- Idx = WindowRoot.GetFirstOf("CLASS");
- if (Idx >= 0)
- {
- (*(Obj.m_Class)) = (const char *)WindowRoot["CLASS"];
- }
- Idx = WindowRoot.GetFirstOf("WIDTH");
- if (Idx >= 0)
- {
- Obj.m_Width = (INT)WindowRoot["WIDTH"];
- }
- Idx = WindowRoot.GetFirstOf("HEIGHT");
- if (Idx >= 0)
- {
- Obj.m_Height = (INT)WindowRoot["HEIGHT"];
- }
- Idx = WindowRoot.GetFirstOf("STYLE");
- if (Idx >= 0)
- {
- Obj.m_Style = (INT)WindowRoot["STYLE"];
- }
- Idx = WindowRoot.GetFirstOf("STYLEEX");
- if (Idx >= 0)
- {
- Obj.m_StyleEx = (INT)WindowRoot["STYLEEX"];
- }
- Idx = WindowRoot.GetFirstOf("GUIID");
- if (Idx >= 0)
- {
- Obj.m_GuiID = (DWORD)WindowRoot["GUIID"];
- }
- Idx = WindowRoot.GetFirstOf("DICT");
- if (Idx >= 0)
- {
- (*(Obj.m_Dict)) = (const char *)WindowRoot["DICT"];
- }
- Idx = WindowRoot.GetFirstOf("DICTKEY");
- if (Idx >= 0)
- {
- (*(Obj.m_DictKey)) = (const char *)WindowRoot["DICTKEY"];
- }
- Idx = WindowRoot.GetFirstOf("DICTRGB");
- if (Idx >= 0)
- {
- string rgbname = (const char *)WindowRoot["DICTRGB"];
- if (rgbname.size() > 0)
- {
- GetIntWithCheckT1(rgbname, Obj.m_DictRgb);
- }
- else
- {
- Obj.m_DictRgb = 0;
- }
- }
- Idx = WindowRoot.GetFirstOf("DICTAREA");
- if (Idx >= 0)
- {
- string areaname = (const char *)WindowRoot["DICTAREA"];
- if (areaname.size() > 0)
- {
- TCHAR *pToken = NULL;
- TCHAR seps[] = ",";
- TCHAR szLCMD[256] = { 0 };
- vector<string> Area1;
- strcpy_s(szLCMD, 256 * sizeof(TCHAR), areaname.c_str());
- pToken = strtok(szLCMD, seps);
- while (pToken)
- {
- string temp = pToken;
- if (temp.size() > 0)
- {
- Area1.push_back(temp);
- }
- pToken = strtok(NULL, seps);
- }
- if (Area1.size() == 4)
- {
- GetIntWithCheckT1(Area1[0], Obj.m_DictArea.left);
- GetIntWithCheckT1(Area1[1], Obj.m_DictArea.top);
- GetIntWithCheckT1(Area1[2], Obj.m_DictArea.right);
- GetIntWithCheckT1(Area1[3], Obj.m_DictArea.bottom);
- }
- else
- {
- Obj.m_DictArea.top = 0;
- Obj.m_DictArea.left = 0;
- Obj.m_DictArea.bottom = (Obj.m_Height > 0) ? (Obj.m_Height - 1) : 0;
- Obj.m_DictArea.right = (Obj.m_Width > 0) ? (Obj.m_Width - 1) : 0;
- }
- }
- }
- if ((*(Obj.m_ID)).size() == 0)
- {
- MessageBox(NULL, "We have Empty Window ID", "WTH", MB_OK);
- return FALSE;
- }
- (*(Obj.m_Process)) = pName;
- Obj.m_zOrder = zOrder;
- Idx = WindowRoot.GetFirstOf("WINDOW");
- while (Idx >= 0)
- {
- //need do loop
- WindowObject *pObjLocal = new WindowObject();
- int LocalzOrder = zOrder;
- if (LocalzOrder != ZORDER_ALLSEARCH)
- {
- LocalzOrder += 1;
- }
- if (GetWindowObject_Inside(WindowRoot[Idx], (*pObjLocal), pName, LocalzOrder))
- {
- (*(Obj.m_SubNodes))[(*(pObjLocal->m_ID))] = pObjLocal;
- }
- else
- {
- MessageBox(NULL, "We have Empty Window", "WTH", MB_OK);
- delete pObjLocal;
- return FALSE;
- }
- Idx = WindowRoot.GetNextOf("WINDOW", Idx);
- }
- }
- catch (...)
- {
- ret = FALSE;
- }
- return ret;
- }
- BOOL XMLLoader::GetWindowObject(WindowObject &mainObj)
- {
- BOOL ret = TRUE;
- try{
- ResDataObject Res;
- if (Res.loadFile(m_filename.c_str()) == false)
- {
- MessageBox(NULL, "Config file failed load", "WTH", MB_OK);
- return FALSE;
- }
- string pName = (const char*)(Res["ROOT"]["COMMON"]["PROCESSNAME"]);
- INT zOrder = (INT)(Res["ROOT"]["COMMON"]["ZORDER"]);
- ret = GetWindowObject_Inside(Res["ROOT"]["WINDOW"], mainObj, pName, zOrder);
- if (ret == FALSE)
- {
- MessageBox(NULL, "Config file failed load GetWindowObject", "WTH", MB_OK);
- }
- }
- catch(...)
- {
- MessageBox(NULL, "Config file failed load ROOT", "WTH", MB_OK);
- ret = FALSE;
- }
- return ret;
- }
|