XMLLoader.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #include "StdAfx.h"
  2. #include "XMLLoader.h"
  3. #include <vector>
  4. #include <shlwapi.h>
  5. //#include "debug.h"
  6. #include "common_def.h"
  7. #include "Common_Funcs.h"
  8. #include "ResDataObject.h"
  9. #pragma comment(lib, "shlwapi.lib")
  10. using namespace std;
  11. XMLLoader::XMLLoader(void)
  12. {
  13. }
  14. XMLLoader::~XMLLoader(void)
  15. {
  16. }
  17. BOOL XMLLoader::LoadFile(string &filename)
  18. {
  19. BOOL ret = FALSE;
  20. string path ;
  21. GetModulePath(path);
  22. //::CoInitialize(NULL);
  23. m_filename = path + filename + string(".xml");
  24. if(PathFileExists(m_filename.c_str()))
  25. {
  26. ret = TRUE;
  27. //PROJECT_XML::IXMLDOMDocumentPtr pDoc;
  28. //PROJECT_XML::IXMLDOMElementPtr xmlRoot ;
  29. //try{
  30. // HRESULT hr = pDoc.CreateInstance(__uuidof(PROJECT_XML::DOMDocument));
  31. // if(!SUCCEEDED(hr))
  32. // {
  33. // MessageBox(NULL,L"XML INIT FAILED",L"WTH",MB_OK);
  34. // return FALSE;
  35. // }
  36. // VARIANT_BOOL hr1;
  37. // hr1 = pDoc->load(m_filename.c_str());
  38. // if (hr1 != VARIANT_TRUE) {
  39. // MessageBox(NULL,L"Config file failed load",L"WTH",MB_OK);
  40. // return FALSE;
  41. // }
  42. // PROJECT_XML::IXMLDOMElementPtr root = pDoc->documentElement;
  43. // _variant_t strRootName = root->nodeName;
  44. // _bstr_t wstrRootName(strRootName.bstrVal);
  45. // if (wstrRootName != _bstr_t(L"ROOT"))
  46. // {
  47. // DebugPrint(_T("Failed Load <ROOT>.filename:%s\r\n"),m_filename.c_str());
  48. // return FALSE;
  49. // }
  50. // PROJECT_XML::IXMLDOMNodeListPtr plNode;
  51. // plNode = root->getElementsByTagName(L"COMMON");
  52. // if (plNode->Getlength() == 0) {
  53. // DebugPrint(_T("Failed Load <COMMON>.filename:%s\r\n"),m_filename.c_str());
  54. // return FALSE;
  55. // }
  56. // plNode = root->getElementsByTagName(L"WINDOW");
  57. // if (plNode->Getlength() == 0) {
  58. // DebugPrint(_T("Failed Load <WINDOW>.filename:%s\r\n"),m_filename.c_str());
  59. // return FALSE;
  60. // }
  61. //}
  62. //catch(...)
  63. //{
  64. // ret = FALSE;
  65. //}
  66. }
  67. //CoUninitialize();
  68. return ret;
  69. }
  70. BOOL XMLLoader::GetCommonPart(string &pName,INT &zOrder)
  71. {
  72. BOOL ret = TRUE;
  73. try{
  74. ResDataObject Res;
  75. if (Res.loadFile(m_filename.c_str()) == false)
  76. {
  77. MessageBox(NULL, "Config file failed load", "WTH", MB_OK);
  78. return FALSE;
  79. }
  80. pName = (const char*)(Res["ROOT"]["COMMON"]["PROCESSNAME"]);
  81. zOrder = (INT)(Res["ROOT"]["COMMON"]["ZORDER"]);
  82. }
  83. catch(...)
  84. {
  85. //DebugPrint(_T("Failed Load <ROOT> or <COMMON> Part.filename:%s\r\n"), m_filename.c_str());
  86. ret = FALSE;
  87. }
  88. return ret;
  89. }
  90. BOOL XMLLoader::GetWindowObject_Inside(ResDataObject &WindowRoot,WindowObject &Obj,string pName,INT zOrder)
  91. {
  92. BOOL ret = TRUE;
  93. try
  94. {
  95. INT Idx = WindowRoot.GetFirstOf("ID");
  96. if (Idx >= 0)
  97. {
  98. (*(Obj.m_ID)) = (const char *)WindowRoot["ID"];
  99. }
  100. Idx = WindowRoot.GetFirstOf("TITLE");
  101. if (Idx >= 0)
  102. {
  103. (*(Obj.m_ReqTitle)) = (const char *)WindowRoot["TITLE"];
  104. }
  105. Idx = WindowRoot.GetFirstOf("CLASS");
  106. if (Idx >= 0)
  107. {
  108. (*(Obj.m_Class)) = (const char *)WindowRoot["CLASS"];
  109. }
  110. Idx = WindowRoot.GetFirstOf("WIDTH");
  111. if (Idx >= 0)
  112. {
  113. Obj.m_Width = (INT)WindowRoot["WIDTH"];
  114. }
  115. Idx = WindowRoot.GetFirstOf("HEIGHT");
  116. if (Idx >= 0)
  117. {
  118. Obj.m_Height = (INT)WindowRoot["HEIGHT"];
  119. }
  120. Idx = WindowRoot.GetFirstOf("STYLE");
  121. if (Idx >= 0)
  122. {
  123. Obj.m_Style = (INT)WindowRoot["STYLE"];
  124. }
  125. Idx = WindowRoot.GetFirstOf("STYLEEX");
  126. if (Idx >= 0)
  127. {
  128. Obj.m_StyleEx = (INT)WindowRoot["STYLEEX"];
  129. }
  130. Idx = WindowRoot.GetFirstOf("GUIID");
  131. if (Idx >= 0)
  132. {
  133. Obj.m_GuiID = (DWORD)WindowRoot["GUIID"];
  134. }
  135. Idx = WindowRoot.GetFirstOf("DICT");
  136. if (Idx >= 0)
  137. {
  138. (*(Obj.m_Dict)) = (const char *)WindowRoot["DICT"];
  139. }
  140. Idx = WindowRoot.GetFirstOf("DICTKEY");
  141. if (Idx >= 0)
  142. {
  143. (*(Obj.m_DictKey)) = (const char *)WindowRoot["DICTKEY"];
  144. }
  145. Idx = WindowRoot.GetFirstOf("DICTRGB");
  146. if (Idx >= 0)
  147. {
  148. string rgbname = (const char *)WindowRoot["DICTRGB"];
  149. if (rgbname.size() > 0)
  150. {
  151. GetIntWithCheckT1(rgbname, Obj.m_DictRgb);
  152. }
  153. else
  154. {
  155. Obj.m_DictRgb = 0;
  156. }
  157. }
  158. Idx = WindowRoot.GetFirstOf("DICTAREA");
  159. if (Idx >= 0)
  160. {
  161. string areaname = (const char *)WindowRoot["DICTAREA"];
  162. if (areaname.size() > 0)
  163. {
  164. TCHAR *pToken = NULL;
  165. TCHAR seps[] = ",";
  166. TCHAR szLCMD[256] = { 0 };
  167. vector<string> Area1;
  168. strcpy_s(szLCMD, 256 * sizeof(TCHAR), areaname.c_str());
  169. pToken = strtok(szLCMD, seps);
  170. while (pToken)
  171. {
  172. string temp = pToken;
  173. if (temp.size() > 0)
  174. {
  175. Area1.push_back(temp);
  176. }
  177. pToken = strtok(NULL, seps);
  178. }
  179. if (Area1.size() == 4)
  180. {
  181. GetIntWithCheckT1(Area1[0], Obj.m_DictArea.left);
  182. GetIntWithCheckT1(Area1[1], Obj.m_DictArea.top);
  183. GetIntWithCheckT1(Area1[2], Obj.m_DictArea.right);
  184. GetIntWithCheckT1(Area1[3], Obj.m_DictArea.bottom);
  185. }
  186. else
  187. {
  188. Obj.m_DictArea.top = 0;
  189. Obj.m_DictArea.left = 0;
  190. Obj.m_DictArea.bottom = (Obj.m_Height > 0) ? (Obj.m_Height - 1) : 0;
  191. Obj.m_DictArea.right = (Obj.m_Width > 0) ? (Obj.m_Width - 1) : 0;
  192. }
  193. }
  194. }
  195. if ((*(Obj.m_ID)).size() == 0)
  196. {
  197. MessageBox(NULL, "We have Empty Window ID", "WTH", MB_OK);
  198. return FALSE;
  199. }
  200. (*(Obj.m_Process)) = pName;
  201. Obj.m_zOrder = zOrder;
  202. Idx = WindowRoot.GetFirstOf("WINDOW");
  203. while (Idx >= 0)
  204. {
  205. //need do loop
  206. WindowObject *pObjLocal = new WindowObject();
  207. int LocalzOrder = zOrder;
  208. if (LocalzOrder != ZORDER_ALLSEARCH)
  209. {
  210. LocalzOrder += 1;
  211. }
  212. if (GetWindowObject_Inside(WindowRoot[Idx], (*pObjLocal), pName, LocalzOrder))
  213. {
  214. (*(Obj.m_SubNodes))[(*(pObjLocal->m_ID))] = pObjLocal;
  215. }
  216. else
  217. {
  218. MessageBox(NULL, "We have Empty Window", "WTH", MB_OK);
  219. delete pObjLocal;
  220. return FALSE;
  221. }
  222. Idx = WindowRoot.GetNextOf("WINDOW", Idx);
  223. }
  224. }
  225. catch (...)
  226. {
  227. ret = FALSE;
  228. }
  229. return ret;
  230. }
  231. BOOL XMLLoader::GetWindowObject(WindowObject &mainObj)
  232. {
  233. BOOL ret = TRUE;
  234. try{
  235. ResDataObject Res;
  236. if (Res.loadFile(m_filename.c_str()) == false)
  237. {
  238. MessageBox(NULL, "Config file failed load", "WTH", MB_OK);
  239. return FALSE;
  240. }
  241. string pName = (const char*)(Res["ROOT"]["COMMON"]["PROCESSNAME"]);
  242. INT zOrder = (INT)(Res["ROOT"]["COMMON"]["ZORDER"]);
  243. ret = GetWindowObject_Inside(Res["ROOT"]["WINDOW"], mainObj, pName, zOrder);
  244. if (ret == FALSE)
  245. {
  246. MessageBox(NULL, "Config file failed load GetWindowObject", "WTH", MB_OK);
  247. }
  248. }
  249. catch(...)
  250. {
  251. MessageBox(NULL, "Config file failed load ROOT", "WTH", MB_OK);
  252. ret = FALSE;
  253. }
  254. return ret;
  255. }