stdafx.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // stdafx.cpp : 只包括标准包含文件的源文件
  2. // lyfzRepair.pch 将作为预编译头
  3. // stdafx.obj 将包含预编译类型信息
  4. #include "stdafx.h"
  5. BOOL g_bClassicVer = TRUE;
  6. TCHAR g_szModelPath[MAX_PATH] = { 0 };
  7. CHAR g_szServerIPAddress[MAX_PATH] = { 0 };
  8. DWORD g_dwServerPort = 0;
  9. CHAR g_szClassicIPAddress[MAX_PATH] = { 0 };
  10. DWORD g_dwClassicPort = 0;
  11. void GetServerInfo()
  12. {
  13. CHAR szDrive[_MAX_DRIVE] = { 0 };
  14. CHAR szDir[_MAX_DIR] = { 0 };
  15. CHAR szFna[_MAX_DIR] = { 0 };
  16. CHAR szExt[_MAX_DIR] = { 0 };
  17. CHAR szModelPath[MAX_PATH] = { 0 };
  18. ::GetModuleFileNameA(NULL, szModelPath, sizeof(szModelPath));
  19. _splitpath_s(szModelPath, szDrive, szDir, szFna, szExt);
  20. strcpy_s(szModelPath, szDrive);
  21. strcat_s(szModelPath, szDir);
  22. CHAR szConfigFile[MAX_PATH] = { 0 };
  23. sprintf_s(szConfigFile, "%sConfig\\System.config", szModelPath);
  24. if (PathFileExistsA(szConfigFile))
  25. {
  26. // 加载xml文件;
  27. tinyxml2::XMLDocument xml;
  28. if (tinyxml2::XML_SUCCESS == xml.LoadFile(szConfigFile))
  29. {
  30. tinyxml2::XMLElement *pRootNode = xml.RootElement();
  31. if (stricmp(pRootNode->Name(), "xs:schema") == 0)
  32. {
  33. pRootNode = pRootNode->FirstChildElement();
  34. }
  35. if (pRootNode)
  36. {
  37. tinyxml2::XMLElement *pResultCode = pRootNode->FirstChildElement();
  38. while (pResultCode)
  39. {
  40. if (stricmp(pResultCode->Name(), "ServerPort") == 0)
  41. {
  42. g_dwServerPort = atoi(pResultCode->GetText());
  43. }
  44. if (stricmp(pResultCode->Name(), "ServerHostOrIP") == 0)
  45. {
  46. sprintf_s(g_szServerIPAddress, pResultCode->GetText());
  47. }
  48. pResultCode = pResultCode->NextSiblingElement();
  49. }
  50. }
  51. else
  52. {
  53. utility::WriteTextLog(_T("%s 加载头结点失败"), szConfigFile);
  54. }
  55. }
  56. else
  57. {
  58. utility::WriteTextLog(_T("%s 加载失败"), szConfigFile);
  59. }
  60. xml.Clear();
  61. }
  62. else
  63. {
  64. utility::WriteTextLog(_T("%s 不存在"), szConfigFile);
  65. }
  66. sprintf_s(szConfigFile, "%sHostInfo.ini", szModelPath);
  67. if ( PathFileExistsA(szConfigFile) )
  68. {
  69. // 获取服务器端TCP信息;
  70. GetPrivateProfileStringA("NetWorkInfo", "Host", "", g_szClassicIPAddress, MAX_PATH, szConfigFile);
  71. g_dwClassicPort = GetPrivateProfileIntA("NetWorkInfo", "CSPort", 0, szConfigFile);
  72. }
  73. }
  74. void GetModelPath()
  75. {
  76. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  77. TCHAR szDir[_MAX_DIR] = { 0 };
  78. TCHAR szFna[_MAX_DIR] = { 0 };
  79. TCHAR szExt[_MAX_DIR] = { 0 };
  80. //TCHAR szModelPath[MAX_PATH] = { 0 };
  81. ::GetModuleFileName(NULL, g_szModelPath, sizeof(g_szModelPath));
  82. _tsplitpath_s(g_szModelPath, szDrive, szDir, szFna, szExt);
  83. _tcscpy_s(g_szModelPath, szDrive);
  84. _tcscat_s(g_szModelPath, szDir);
  85. }