Global.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "stdafx.h"
  2. #include "Global.h"
  3. #include "crc32.h"
  4. TCHAR g_szServerIP[100] = _T("");
  5. TCHAR g_szCmdPort[10] = _T("");
  6. TCHAR g_szFilePort[10] = _T("");
  7. DWORD g_dwCmdPort = 0;
  8. DWORD g_dwFilePort = 0;
  9. // 1.
  10. TCHAR g_szDBSource[MAX_PATH+1] = _T("");
  11. DWORD g_dwDBServerPort = 0;
  12. TCHAR g_szDBAccount[MAX_PATH+1] = _T("");
  13. TCHAR g_szDBPassWord[MAX_PATH+1] = _T("");
  14. TCHAR g_szDBName[MAX_PATH+1] = _T("");
  15. // 2.
  16. TCHAR g_ModulePath[_MAX_PATH] = _T("");
  17. TCHAR g_ModuleFileName[_MAX_PATH] = _T("");
  18. TCHAR g_szConnectString[MAX_PATH] = _T(""); // DB连接串;
  19. // 3.
  20. int g_nType = 0;
  21. long g_nMachineNumber = 0;
  22. long g_nLicense = 0;
  23. long g_nComPort = 0;
  24. long g_nBaudRate = 0;
  25. char g_szTelNumber[MAX_PATH+1] = _T("");
  26. long g_nWaitDialTime = 0;
  27. char g_szIpAddress[MAX_PATH+1] = _T("");
  28. long g_nPort = 0;
  29. long g_nTimeOut = 0;
  30. long g_nProtocolType = 0;
  31. long g_nNetPassword = 0;
  32. STFileInfobody *g_pSTFileInfobody = NULL;
  33. DWORD g_dwRecived; // 已接收的长度;
  34. BOOL g_bGetRoutinePath = FALSE;
  35. void GetRoutinePath()
  36. {
  37. TCHAR szDrive[_MAX_DRIVE];
  38. TCHAR szDir[_MAX_DIR];
  39. ::GetModuleFileName(NULL, g_ModulePath, sizeof(g_ModulePath)/sizeof(TCHAR));
  40. sprintf_s(g_ModuleFileName,"%s",g_ModulePath);
  41. _tsplitpath(g_ModulePath, szDrive, szDir, NULL, NULL);
  42. _tcscpy(g_ModulePath, szDrive);
  43. _tcscat(g_ModulePath, szDir);
  44. }
  45. /*
  46. void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext );
  47. void _wsplitpath( const wchar_t *path, wchar_t *drive, wchar_t *dir, wchar_t *fname, wchar_t *ext );
  48. path:全路径(IN)
  49. drive:盘符(OUT)
  50. dir:除去盘符和文件名,中间的那段路径(OUT)
  51. fname:文件名,不包含扩展名(OUT)
  52. ext:文件扩展名,包含那个点.(OUT)
  53. */
  54. void GetFileName(IN const TCHAR *pFullName,OUT TCHAR *pFileName)
  55. {
  56. TCHAR szExt[_MAX_EXT];
  57. _tsplitpath(pFullName, NULL, NULL, pFileName, szExt);
  58. _tcscat(pFileName, szExt);
  59. }
  60. unsigned int VerifyIntegrityPacket(IN void *pIntegrityPacket,IN unsigned int nPacketSize)
  61. {
  62. unsigned int checksum = 0;
  63. //if ( nPacketSize <= sizeof(STProtocolheader) )
  64. //{
  65. // return 0;
  66. //}
  67. unsigned char *pBody = &((unsigned char*)pIntegrityPacket)[sizeof(STProtocolheader)];
  68. if( pBody )
  69. checksum = crc32( 0, pBody, nPacketSize-sizeof(STProtocolheader) );
  70. return checksum;
  71. }
  72. int GetServerIniInfo(const char *szPath/*=NULL*/, const char *szIniName/*=NULL*/)
  73. {
  74. if ( !g_bGetRoutinePath )
  75. GetRoutinePath();
  76. TCHAR szFile[MAX_PATH + 1] = _T("");
  77. if( szPath != NULL && szIniName != NULL)
  78. wsprintf(szFile, "%s\\%s", szPath, szIniName);
  79. else
  80. wsprintf(szFile,"%s\\lyfzServiceInfo.ini",g_ModulePath);
  81. OFSTRUCT ofStruct;
  82. OpenFile(szFile,&ofStruct,OF_EXIST);
  83. if( ERROR_FILE_NOT_FOUND == GetLastError())
  84. {
  85. return -1;
  86. }
  87. g_dwCmdPort = GetPrivateProfileInt("ServerInfo", "cmdPort", 0, szFile);
  88. g_dwFilePort = GetPrivateProfileInt("ServerInfo", "filePort", 0, szFile);
  89. GetPrivateProfileString("ServerInfo", "cmdPort", "", g_szCmdPort, 10, szFile);
  90. GetPrivateProfileString("ServerInfo", "filePort", "", g_szFilePort, 10, szFile);
  91. GetPrivateProfileString("DatabaseInfo", "dbSource", "", g_szDBSource, MAX_PATH, szFile);
  92. g_dwDBServerPort = GetPrivateProfileInt("DatabaseInfo", "dbServerPort", 0, szFile);
  93. GetPrivateProfileString("DatabaseInfo", "dbAccount", "", g_szDBAccount, MAX_PATH, szFile);
  94. GetPrivateProfileString("DatabaseInfo", "dbPassWord", "", g_szDBPassWord, MAX_PATH, szFile);
  95. GetPrivateProfileString("DatabaseInfo", "dbName", "", g_szDBName, MAX_PATH, szFile);
  96. if( g_dwDBServerPort != 0)
  97. sprintf(g_szConnectString,"driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s",
  98. g_szDBSource,g_dwDBServerPort,g_szDBName,g_szDBAccount,g_szDBPassWord);
  99. else
  100. sprintf(g_szConnectString,"driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s",
  101. g_szDBSource,g_szDBName,g_szDBAccount,g_szDBPassWord);
  102. return 0;
  103. }
  104. int GetClientIniInfo(const char *szPath/*=NULL*/, const char *szIniName/*=NULL*/)
  105. {
  106. if ( !g_bGetRoutinePath )
  107. GetRoutinePath();
  108. TCHAR szFile[MAX_PATH + 1] = _T("");
  109. if( szPath != NULL && szIniName != NULL)
  110. wsprintf(szFile, "%s\\%s", szPath, szIniName);
  111. else
  112. wsprintf(szFile,"%s\\ServiceInfo.ini",g_ModulePath);
  113. OFSTRUCT ofStruct;
  114. OpenFile(szFile,&ofStruct,OF_EXIST);
  115. if( ERROR_FILE_NOT_FOUND == GetLastError())
  116. {
  117. return -1;
  118. }
  119. //g_dwCmdPort = GetPrivateProfileInt("ServerInfo", "cmdPort", 0, szFile);
  120. //g_dwFilePort = GetPrivateProfileInt("ServerInfo", "filePort", 0, szFile);
  121. GetPrivateProfileString("ServerInfo", "IP", "", g_szServerIP, 100, szFile);
  122. GetPrivateProfileString("ServerInfo", "cmdPort", "", g_szCmdPort, 10, szFile);
  123. GetPrivateProfileString("ServerInfo", "filePort", "", g_szFilePort, 10, szFile);
  124. g_dwDBServerPort = GetPrivateProfileInt("DatabaseInfo", "dbServerPort", 0, szFile);
  125. GetPrivateProfileString("DatabaseInfo", "dbSource", "", g_szDBSource, MAX_PATH, szFile);
  126. GetPrivateProfileString("DatabaseInfo", "dbAccount", "", g_szDBAccount, MAX_PATH, szFile);
  127. GetPrivateProfileString("DatabaseInfo", "dbPassWord", "", g_szDBPassWord, MAX_PATH, szFile);
  128. GetPrivateProfileString("DatabaseInfo", "dbName", "", g_szDBName, MAX_PATH, szFile);
  129. return 0;
  130. }