123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #include "stdafx.h"
- #include "CheckDog.h"
- #include "SNRegister.h"
- #include <time.h> //头文件
- #include "resource.h"
- HANDLE g_hReadDogThread = NULL;
- #if IS_RAND_WRITE_DOG
- HANDLE g_hWriteDogThread = NULL;
- #endif
- VOID TerminateLastProcess();
- //初始化软件狗
- int InitDog( void )
- {
- CHAR szSNName[MAX_LIST_LENGTH + 1] = "";
- wsprintf(szSNName, "%s\\register.sn", g_strDirectory);
- CFileStatus Sfile;
- if (CFile::GetStatus(szSNName,Sfile) == FALSE) {
- LOG4C((LOG_NOTICE,"SN文件不存在"));
- return -1;
- }
- CSNRegister snrig;
- if ( !snrig.itf_IsCorrectSN(szSNName)) {
- LOG4C((LOG_NOTICE,"无效SN文件"));
- return -1;
- }
- if ( strcmp(snrig.itf_returnSnCode(),g_strSNCode) != 0) {
- LOG4C((LOG_NOTICE,"末注册,试用."));
- CheckDogThreadStart();
- return 0;
- }
- else
- {
- LOG4C((LOG_NOTICE,"已注册,正常使用."));
- return 0;
- }
- //return 0;
- }
- int UnInitDog(void)
- {
- CheckDogThreadEnd();
- return 0;
- }
- BOOL CheckDogThreadStart()
- {
- DWORD dwThreadId = 0;
- MTVERIFY( g_hReadDogThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReadDogThreadProc, NULL, 0, &dwThreadId) );
- #if IS_RAND_WRITE_DOG
- MTVERIFY( g_hWriteDogThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)WriteDogThreadProc, NULL, 0, &dwThreadId) );
- #endif
- return TRUE;
- }
- BOOL CheckDogThreadEnd()
- {
- // 关闭线程
- if (NULL != g_hReadDogThread)
- {
- MTVERIFY( WaitForSingleObject( g_hReadDogThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hReadDogThread ) );
- g_hReadDogThread = NULL;
- }
- #if IS_RAND_WRITE_DOG
- if (NULL != g_hWriteDogThread)
- {
- MTVERIFY( WaitForSingleObject( g_hWriteDogThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hWriteDogThread ) );
- g_hWriteDogThread = NULL;
- }
- #endif
- return TRUE;
- }
- DWORD WINAPI ReadDogThreadProc(LPVOID lpParameter)
- {
- char szSNName[MAX_PATH] = {0};
- sprintf(szSNName,"%s\\register.sn",g_strDirectory);
- CTimeSpan ts = NULL;
- CTime t_et = NULL;
- CTime t_ct = CTime::GetCurrentTime();
-
- CFileStatus Sfile;
- CSNRegister snrig;
- do
- {
- if (!CFile::GetStatus(szSNName,Sfile))
- {
- LOG4C((LOG_NOTICE,"SN文件不存在"));
- TerminateLastProcess();
- return 0;
- }
- if(!snrig.itf_IsCorrectSN(szSNName))
- {
- LOG4C((LOG_NOTICE,"SN文件无效"));
- TerminateLastProcess();
- return 0;
- }
- if ((long)snrig.itf_returnLeftTime() < 0){
- LOG4C((LOG_NOTICE,"试用期限到"));
- TerminateLastProcess();
- return 0;
- }
- t_et = CTime::GetCurrentTime();
- ts = t_et - t_ct;
- if (ts.GetMinutes() > 5)
- {
- t_ct = t_et;
- snrig.itf_SavebyLTime(snrig.itf_returnLeftTime() - ts.GetMinutes(),szSNName);
- LOG4C((LOG_NOTICE,"时差 = %d",ts.GetMinutes()));
- }
- }while( WaitForSingleObject(g_hRunObject, 10000L) == WAIT_TIMEOUT );
- return 0;
- }
- #if IS_RAND_WRITE_DOG
- DWORD WINAPI WriteDogThreadProc(LPVOID lpParameter)
- {
- INT iIvrIndex = 0;
- CString strError;
- for (; ;)
- {
- Sleep(10000);
-
- }
- return 0;
- }
- #endif
|