Пример #1
0
/*---------------------------------------------------
  initialize WinSock and read settings
---------------------------------------------------*/
BOOL InitSNTP(HWND hwndMain)
{
	WORD ver;
	WSADATA wsaData;
	char s[80];
	
	m_socket = INVALID_SOCKET;
	m_hGetHost = NULL;
	
	// initialize WinSock
	ver = 0x0101; // MAKEWORD(1, 1);
	if(WSAStartup(ver, &wsaData) != 0)
	{
		Log(NULL, "failed to initialize");
		return FALSE;
	}
	
	GetMyRegStr(m_section, "Server", m_servername, 80, "");
	m_nTimeOut = GetMyRegLong(m_section, "Timeout", 1000);
	if(!(0 < m_nTimeOut && m_nTimeOut <= 30000))
		m_nTimeOut = 1000;
	m_bSaveLog = GetMyRegLong(m_section, "SaveLog", TRUE);
	GetMyRegStr(m_section, "Sound", m_soundfile, MAX_PATH, "");
	
	m_nMinuteDif = 0;
	GetMyRegStr(m_section, "Dif", s, 80, "");
	if(s[0])
	{
		int h, m;
		time2int(&h, &m, s);
		m_nMinuteDif = h * 60 + m;
	}
	
	return TRUE;
}
Пример #2
0
/*---------------------------------------------------
    load settings for time syncronizing
---------------------------------------------------*/
void InitSyncTimeSetting(void)
{
	char section[] = "SNTP";
	char s[80];

	bSyncTimer = GetMyRegLong(section, "Timer", FALSE);
	bSyncADay = GetMyRegLong(section, "ADay", TRUE);
	nMinutes = GetMyRegLong(section, "Minutes", 60);
	bNoDial = FALSE;
	if(hRASAPI)
		bNoDial = GetMyRegLong(section, "NoDial", TRUE);
	nLastDay = GetMyRegLong(section, "LastDay", -1);

	GetMyRegStr(section, "Begin", s, 80, "");
	if(s[0])
	{
		time2int(&nHourStart, &nMinuteStart, s);
		GetMyRegStr(section, "End", s, 80, "");
		if(s[0])
			time2int(&nHourEnd, &nMinuteEnd, s);
		else nHourStart = nMinuteStart = -1;
	}
}
Пример #3
0
/*---------------------------------------------------
    command to start syncronizing
---------------------------------------------------*/
void StartSyncTime(HWND hwndParent, char* pServer, int nto)
{
	HWND hwnd;
	SYSTEMTIME st;
	char section[] = "SNTP";
	char server[80], s[80];

	if(g_socket != -1 || g_hGetHost != NULL) return;

	if(pServer == NULL || *pServer == 0)
	{
		GetMyRegStr(section, "Server", server, 80, "");
		pServer = server;
	}
	if(nto == 0)
		nto = GetMyRegLong(section, "Timeout", 1000);

	if(*pServer == 0) return;
	hwnd = GetDlgItem(hwndParent, 1);
	if(!hwnd) return;

	nMinuteDif = 0;
	GetMyRegStr(section, "Dif", s, 80, "");
	if(s[0])
	{
		int h, m;
		time2int(&h, &m, s);
		nMinuteDif = h * 60 + m;
	}

	GetLocalTime(&st);
	nLastDay = st.wDay;
	SetMyRegLong(section, "LastDay", nLastDay);
	dwTickCount = GetTickCount();
	bFirst = FALSE;

	nTimeout = nto;

	SNTPStart(hwnd, pServer);
}