📄 update.cpp
字号:
bRet = TRUE;
}
return bRet;
}
WZ_DECLAREDLL BOOL CWZUpdateModule::UpdateStop()
{
//诀单捞飘 吝捞扼绰扒 泅犁 促款肺靛 静饭靛啊 倒绊 乐促绰 舵捞促.
m_bCancelUpdate = TRUE;
m_bUseEventProc = FALSE;
WaitForSingleObject( m_hUpdateThread, 1000 );
m_bUseEventProc = TRUE;
AddEvent( EVENT_FILEDOWNLOAD_STOP );
return TRUE;
}
WZ_DECLAREDLL BOOL CWZUpdateModule::SetEventCallBackProc (LPFUNC_RECEIVEEVENT lpFN_EventCallbackFunc )
{
if( lpFN_EventCallbackFunc == NULL)
return FALSE;
m_lpFN_EventCallbackProc = lpFN_EventCallbackFunc;
return TRUE;
}
WZ_DECLAREDLL void CWZUpdateModule::SetUseEventProc ( BOOL bUse )
{
m_bUseEventProc = bUse;
}
// 01.02.03 苞 鞍篮 巩磊凯俊辑 阿阿狼 滚傈阑 惶酒郴绰 窃荐.
WZ_DECLAREDLL void CWZUpdateModule::GetVersionFromString( char* pszVersion, byte& byVer1, byte& byVer2, byte& byVer3 )
{
// char* szTok;
string strVersion = pszVersion;
int nCnt = 0;
byte byVersion[3];
while( strVersion.size() != 0)
{
int nIdx = strVersion.find('.');
if( nIdx == string::npos )
{
if( !strVersion.empty() )
{
byVersion[nCnt] = atoi( strVersion.c_str() );
}
strVersion.clear();
}
else
{
string strVer = strVersion.substr( 0, nIdx );
byVersion[nCnt] = atoi( strVer.c_str() );
strVersion.erase( 0, nIdx + 1);
nCnt++;
}
}
//府畔蔼 措涝.
byVer1= byVersion[0];
byVer2= byVersion[1];
byVer3= byVersion[2];
}
//阿 滚傈狼 蜡老茄 蔼阑 鞍扁困茄 配呕 滚傈 拌魂..
WZ_DECLAREDLL unsigned int CWZUpdateModule::GetTotalVersion( const byte byVer1, const byte byVer2, const byte byVer3 )
{
return (byVer1*65536)+(byVer2*256)+byVer3;
}
//捞 窃荐绰 AutoUpdater俊辑 龋免等促.
//StartUpdate
//滚傈颇老阑 促款罐酒 滚傈阑 眉农秦辑 诀单捞飘 且 滚傈捞 乐栏搁,
//诀单捞飘 thread甫 倒妨辑, 颇老阑 促款肺靛 茄促.
WZ_DECLAREDLL BOOL CWZUpdateModule::StartUpdate()
{
// 泅犁 混酒 乐绰 努扼捞攫飘 橇肺技辑啊 乐绰瘤 绝绰瘤 眉农茄促.
BOOL bRet = CheckLiveProcess();
if(bRet == TRUE) //橇肺技辑啊 混酒 乐栏搁..
{
AddEvent( EVENT_LIVE_PROCESS );
return FALSE;
}
// 滚傈眉农甫 茄促.
eRESULT_CONSTANT eRC = CheckUpdateFiles();
if ( eRC == RESULT_FAIL )
return FALSE;
else if( eRC == RESULT_NOMORE_UPDATE_FILES )
{
// 歹 捞惑 绝单捞飘 且 荐 绝栏搁, 泅犁 滚傈沥焊绰 0 锅 硅凯俊 乐促..
m_strtUpdatingFileInfo.btVer1 = m_strtUpdateFolderInfo[0].m_btVer1;
m_strtUpdatingFileInfo.btVer2 = m_strtUpdateFolderInfo[0].m_btVer2;
m_strtUpdatingFileInfo.btVer3 = m_strtUpdateFolderInfo[0].m_btVer3;
AddEvent( EVENT_NOMORE_UPDATEFILE );
return FALSE;
}
m_iCurrentState = STATE_FILE_DOWNLOADING;
//Update Thread 啊悼
m_nUpdateThreadID = 1;
m_hUpdateThread = (HANDLE) _beginthreadex (NULL, NULL, UpdateWorkerThread, (LPVOID) this, 0, &m_nUpdateThreadID);
if (m_hUpdateThread == INVALID_HANDLE_VALUE)
{
if (m_lpFN_EventCallbackProc)
{
SetLastErrorMsg(CWZUpdateModule::ERROR_SYSTEM, GetLastError());
return FALSE;
}
}
return TRUE; // 父老 FALSE扼搁 诀单捞飘 橇肺技胶 辆丰
}
//扁夯利栏肺 沥狼 登绢 乐绰 扁夯蔼阑 汲沥茄促.
WZ_DECLAREDLL void CWZUpdateModule::SetDefaultData(void)
{
if( IsUpdateInfoLoad() )
strcpy (m_szVersionFileName, m_info.m_szFTP_VersionFileName );
else
strcpy (m_szVersionFileName, DEFAULT_VERSION_FILE);
}
WZ_DECLAREDLL void CWZUpdateModule::SetVersionFile(const char* pszFile)
{
strcpy(m_szVersionFileName, pszFile);
}
WZ_DECLAREDLL void CWZUpdateModule::SetDownloadDirectory(const char* pszDirectory)
{
if(pszDirectory == NULL || (strcmp(pszDirectory, "") == 0) )
m_strDownDirectory = "";
else
m_strDownDirectory = pszDirectory;
}
WZ_DECLAREDLL const string CWZUpdateModule::GetDownloadDirectory()
{
return m_strDownDirectory;
}
//肺拿狼 促款肺靛 例措 版肺甫 掘绰促.
WZ_DECLAREDLL void CWZUpdateModule::GetLocalDownAbsoluteDir(string strRelativeDir, string& strAbsolteDir)
{
if( strRelativeDir.length() == 0 )
strRelativeDir = "\\";
//父老 m_strDownDirectory 啊 null 捞 甸绢 乐阑荐 乐促.. 蝶扼辑 弊锭绰..
//泅犁 角青吝牢 叼泛配府肺 汲沥茄促.
// 促款肺靛 叼泛配府俊 strRelativeDir(惑措版肺)甫 怠嘿咯辑 历厘矫懦 泅犁 肺拿狼 例措版肺甫 掘绰促.
if(m_strDownDirectory.length() == 0)
{
char szDir[MAX_PATH];
GetModuleDirectory( szDir, MAX_PATH );
strAbsolteDir = szDir;
strAbsolteDir += strRelativeDir;
}
else
{
strAbsolteDir = m_strDownDirectory;
strAbsolteDir += "\\";
strAbsolteDir += m_info.m_szServerName[m_nServerNumber];
strAbsolteDir += strRelativeDir;
}
}
//泅犁 哪腔磐俊 诀单捞飘窍绊 乐绰 橇肺弊伐捞 角青吝牢瘤 眉农.
//角青吝牢 橇肺弊伐捞 窍唱扼档 乐栏搁 TRUE府畔
//酒聪搁 FASLE甫 府畔..
WZ_DECLAREDLL BOOL CWZUpdateModule::CheckLiveProcess()
{
//橇肺技辑狼 MAX蔼篮 0-9鳖瘤 10俺捞促.
for(int i = 0; i < MAX_LIVE_PROCESS; i++)
{
// 橇肺技胶 眉农 繁媚唱 霸烙 努扼捞攫飘啊 角青吝牢瘤 眉农茄促
HANDLE hSnapShot;
//Get the snapshot of the system
hSnapShot = CreateToolhelp32Snapshot (TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof(pEntry);
//Get first process
Process32First (hSnapShot,&pEntry);
//Iterate thru all processes
DWORD dwPID = GetCurrentProcessId();
while(TRUE)
{
BOOL hRes = Process32Next (hSnapShot,&pEntry);
if(hRes == FALSE)
break;
if(dwPID == pEntry.th32ProcessID)
continue;
// 角青 吝牢瘤 眉农窍档废 茄促.
if( strcmp(pEntry.szExeFile, m_info.m_szProcess[i] ) == 0 ) //泅犁 鞍篮 橇肺弊伐捞 角青吝捞扼搁..
{
return TRUE;
}
}// End While
}// End For
return FALSE;
}
WZ_DECLAREDLL void CWZUpdateModule::GetModuleDirectory( char* szDirPath, int nSize )
{
ZeroMemory( szDirPath, nSize );
char szPath[128];
char szDrive[40], szDir[256];
GetModuleFileName( NULL, szPath, 128);
_splitpath( szPath, szDrive, szDir, NULL, NULL );
sprintf( szDirPath, "%s%s", szDrive, szDir);
}
WZ_DECLAREDLL BOOL CWZUpdateModule::Init( )
{
//肺弊单捞磐 檬扁拳.
char szDir[MAX_PATH];
GetModuleDirectory( szDir, MAX_PATH );
BOOL bRet = m_info.LoadData();
if( bRet == TRUE)
{
m_bLoadUpdateInfo = TRUE;
strncpy( m_szIPADDR, m_info.m_szFTP_IP, MAX_PATH );
m_wPORT = m_info.m_nFTP_Port;
SetDefaultDirectory( m_info.m_szServerName[m_nServerNumber] );
}
else
{
m_bLoadUpdateInfo = FALSE;
ZeroMemory( m_szIPADDR, MAX_PATH );
strncpy( m_szIPADDR, "127.0.0.1", MAX_PATH );
m_wPORT = DEFAULT_FTP_PORT;
}
if( !LoadLocalVerInfo() )
return FALSE;
SetDefaultData();
return TRUE;
}
WZ_DECLAREDLL void CWZUpdateModule::SetDefaultDirectory( char* pszDir )
{
if( !pszDir ) return;
strncpy( m_szDefaultDirectory, pszDir, MAX_PATH );
}
//扁夯 叼泛配府 版肺甫 器窃窍绰 FTP辑滚惑狼 滚傈颇老 版肺甫 备茄促.
WZ_DECLAREDLL void CWZUpdateModule::GetVersionFilePath( TCHAR* pszVerFilePath, int nSize )
{
if( m_szDefaultDirectory == NULL || (strcmp( m_szDefaultDirectory, "" ) == 0 ) )
strncpy( pszVerFilePath, m_szVersionFileName, nSize ); //父老 叼弃飘 叼泛配府啊 绝栏搁 风飘俊辑 茫绰促.
else
_snprintf( pszVerFilePath, nSize, "%s\\%s", m_szDefaultDirectory, m_szVersionFileName );
}
//颇老府胶飘 颇老篮 馆靛矫 促款肺靛 罐绰 滚傈弃歹俊 粮犁秦具 茄促.
//抗 : AgentServer\00.00.01\filelist.dat
WZ_DECLAREDLL void CWZUpdateModule::GetFileListFilePath( char* pszFilePath, int nSize, const char* pszVerFolder )
{
if( m_szDefaultDirectory == NULL || (strcmp( m_szDefaultDirectory, "" ) == 0 ) )
_snprintf( pszFilePath, nSize, "%s\\%s", pszVerFolder, DEFAULT_FILELIST_FILE );
else
_snprintf( pszFilePath, nSize, "%s\\%s\\%s", m_szDefaultDirectory, pszVerFolder, DEFAULT_FILELIST_FILE );
}
//滚傈弃歹狼 版肺甫 馆券茄促.
WZ_DECLAREDLL void CWZUpdateModule::GetVersionFolderPath( char* pszFileName, int nSize, const char* pszVerFolder )
{
if( m_szDefaultDirectory == NULL || (strcmp( m_szDefaultDirectory, "" ) == 0 ) )
strncpy( pszFileName, pszVerFolder, nSize );
else
_snprintf( pszFileName, nSize, "%s\\%s", m_szDefaultDirectory, pszVerFolder );
}
WZ_DECLAREDLL void CWZUpdateModule::GetServerName( char* pszServerName, int nSize )
{
_snprintf( pszServerName, nSize, "%s", m_info.m_szServerName[m_nServerNumber] );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -