#include "stdafx.h"
#include "Global.h"
#include "crc32.h"


TCHAR g_szServerIP[100] = _T("");
TCHAR g_szCmdPort[10] = _T("");
TCHAR g_szFilePort[10] = _T("");
DWORD g_dwCmdPort = 0;
DWORD g_dwFilePort = 0;

// 1.
TCHAR g_szDBServer[MAX_PATH+1] = _T("");
DWORD g_dwDBServerPort = 0;
TCHAR g_szDBAccount[MAX_PATH+1] = _T("");
TCHAR g_szDBPassWord[MAX_PATH+1] = _T("");
TCHAR g_szDBName[MAX_PATH+1] = _T("");

// 2.
TCHAR g_ModulePath[_MAX_PATH] = {0};
TCHAR g_ModuleFileName[_MAX_PATH] = {0};

// 3.
int  g_nType = 0;
long g_nMachineNumber = 0;
long g_nLicense = 0;
long g_nComPort = 0;
long g_nBaudRate = 0;
char g_szTelNumber[MAX_PATH+1] = {0};
long g_nWaitDialTime = 0;
char g_szIpAddress[MAX_PATH+1] = {0};
long g_nPort = 0;
long g_nTimeOut = 0;
long g_nProtocolType = 0;
long g_nNetPassword = 0;

void GetServerIniInfo(const char *szPath/*=NULL*/, const char *szIniName/*=NULL*/)
{
	TCHAR szFile[MAX_PATH + 1] = _T("");
	if( szPath != NULL && szIniName != NULL)
		wsprintf(szFile, "%s\\%s", szPath, szIniName);
	else
		wsprintf(szFile,"%s\\lyfzServiceInfo.ini",g_ModulePath);

	g_dwCmdPort = GetPrivateProfileInt("ServerInfo", "cmdPort", 0, szFile);
	g_dwFilePort = GetPrivateProfileInt("ServerInfo", "filePort", 0, szFile);

	GetPrivateProfileString("ServerInfo", "cmdPort", "", g_szCmdPort, 10, szFile);
	GetPrivateProfileString("ServerInfo", "filePort", "", g_szFilePort, 10, szFile);

	GetPrivateProfileString("ServerDBInfo", "dbServer", "", g_szDBServer, MAX_PATH, szFile);
	g_dwDBServerPort = GetPrivateProfileInt("ServerDBInfo", "dbServerPort", 0, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbAccount", "", g_szDBAccount, MAX_PATH, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbPassWord", "", g_szDBPassWord, MAX_PATH, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbName", "", g_szDBName, MAX_PATH, szFile);
}

void GetClientIniInfo(const char *szPath/*=NULL*/, const char *szIniName/*=NULL*/)
{
	TCHAR szFile[MAX_PATH + 1] = _T("");
	if( szPath != NULL && szIniName != NULL)
		wsprintf(szFile, "%s\\%s", szPath, szIniName);
	else
		wsprintf(szFile,"%s\\ServiceInfo.ini",g_ModulePath);

	//g_dwCmdPort = GetPrivateProfileInt("ServerInfo", "cmdPort", 0, szFile);
	//g_dwFilePort = GetPrivateProfileInt("ServerInfo", "filePort", 0, szFile);

	GetPrivateProfileString("ServerInfo", "IP", "", g_szServerIP, 100, szFile);
	GetPrivateProfileString("ServerInfo", "cmdPort", "", g_szCmdPort, 10, szFile);
	GetPrivateProfileString("ServerInfo", "filePort", "", g_szFilePort, 10, szFile);

	g_dwDBServerPort = GetPrivateProfileInt("ServerDBInfo", "dbServerPort", 0, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbServer", "", g_szDBServer, MAX_PATH, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbAccount", "", g_szDBAccount, MAX_PATH, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbPassWord", "", g_szDBPassWord, MAX_PATH, szFile);
	GetPrivateProfileString("ServerDBInfo", "dbName", "", g_szDBName, MAX_PATH, szFile);
}