251 lines
7.1 KiB
C++
251 lines
7.1 KiB
C++
#include ".\updatescriptinfo.h"
|
|
#include <io.h>
|
|
|
|
CUpdateScriptParser* CUpdateScriptParser::m_pInstance = NULL;
|
|
|
|
CUpdateProcessInfo::CUpdateProcessInfo()
|
|
{
|
|
ZeroMemory( m_szFtpIP, MAX_PATH );
|
|
ZeroMemory( m_szID, MAX_PATH );
|
|
ZeroMemory( m_szPass, MAX_PATH );
|
|
ZeroMemory( m_szDownPath, MAX_PATH );
|
|
|
|
m_wFtpPort = 0;
|
|
m_nTotalProcessCount = 0;
|
|
m_nUpdateNumber = 0;
|
|
m_mapProcessInfo.clear();
|
|
}
|
|
|
|
PROCESS_INFO* CUpdateProcessInfo::GetProcessInfo( BYTE byUpateNumber )
|
|
{
|
|
PROCESS_INFO_MAP_ITER iter;
|
|
iter = m_mapProcessInfo.find( byUpateNumber );
|
|
if( iter != m_mapProcessInfo.end() )
|
|
return iter->second;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
CUpdateScriptParser::CUpdateScriptParser(void)
|
|
{
|
|
m_bLoad = FALSE;
|
|
}
|
|
|
|
CUpdateScriptParser::~CUpdateScriptParser(void)
|
|
{
|
|
}
|
|
|
|
BOOL CUpdateScriptParser::LoadData(void)
|
|
{
|
|
if( m_bLoad ) return TRUE;
|
|
|
|
char szDirPath[MAX_PATH], szFilePath[MAX_PATH];
|
|
GetModuleDirectory( szDirPath, MAX_PATH );
|
|
wsprintf( szFilePath, "%s%s", szDirPath, DEFAULT_UPDEATEINFO_FILE );
|
|
|
|
if( _access(szFilePath, 0) != -1 ) //파일이 존재하면..
|
|
{
|
|
if( !LoadProcessInfo( UPDATE_TYPE_LAUNCHER, szFilePath ) ) return FALSE;
|
|
if( !LoadProcessInfo( UPDATE_TYPE_APPLICATION, szFilePath ) ) return FALSE;
|
|
if( !LoadAgentInfo( szFilePath ) ) return FALSE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
|
|
m_bLoad = TRUE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
BOOL CUpdateScriptParser::LoadProcessInfo( BYTE byUpdateType, const char* pszFilePath )
|
|
{
|
|
CUpdateProcessInfo* pProcessInfo = NULL;
|
|
|
|
TCHAR szProcessType[MAX_PATH];
|
|
szProcessType[0] = '0';
|
|
if( byUpdateType == UPDATE_TYPE_APPLICATION )
|
|
{
|
|
strncpy( szProcessType, "APPLICATION", MAX_PATH );
|
|
pProcessInfo = &m_ApplicationInfo;
|
|
}
|
|
else if( byUpdateType == UPDATE_TYPE_LAUNCHER )
|
|
{
|
|
strncpy( szProcessType, "LAUNCHER", MAX_PATH );
|
|
pProcessInfo = &m_LauncherInfo;
|
|
}
|
|
else
|
|
return FALSE;
|
|
|
|
GetPrivateProfileString( szProcessType, "FTP_IP ", "", pProcessInfo->m_szFtpIP, MAX_PATH, pszFilePath );
|
|
pProcessInfo->m_wFtpPort = GetPrivateProfileInt( szProcessType, "FTP_PORT", 0, pszFilePath );
|
|
GetPrivateProfileString( szProcessType, "FTP_ID", "", pProcessInfo->m_szID, MAX_PATH, pszFilePath );
|
|
GetPrivateProfileString( szProcessType, "FTP_PASSWORD", "", pProcessInfo->m_szPass, MAX_PATH, pszFilePath );
|
|
GetPrivateProfileString( szProcessType, "BASIC_DOWNLOAD_PATH ", "", pProcessInfo->m_szDownPath, MAX_PATH, pszFilePath );
|
|
GetPrivateProfileString( szProcessType, "BASIC_EXECUTE_PATH ", "", pProcessInfo->m_szExecutePath, MAX_PATH, pszFilePath );
|
|
pProcessInfo->m_nTotalProcessCount = GetPrivateProfileInt( szProcessType, "UPDATE_TOTAL_COUNT", 0, pszFilePath );
|
|
pProcessInfo->m_nUpdateNumber = GetPrivateProfileInt( szProcessType, "UPDATE_NUMBER", 0, pszFilePath );
|
|
|
|
for(int i = 0; i < pProcessInfo->m_nTotalProcessCount; i++)
|
|
{
|
|
PROCESS_INFO* pInfo = new PROCESS_INFO;
|
|
|
|
//0. 업데이트 넘버.
|
|
pInfo->m_byUpdateNumber = i+1;
|
|
char szNum[10];
|
|
wsprintf(szNum, "%d", pInfo->m_byUpdateNumber );
|
|
|
|
//1. 어플리케이션 이름
|
|
string strName = "NAME";
|
|
strName += szNum;
|
|
GetPrivateProfileString( szProcessType, strName.c_str(), "", pInfo->m_szProcessName, MAX_PATH, pszFilePath );
|
|
|
|
//2. 어플리케이션 버전
|
|
string strVersion = "VERSION";
|
|
strVersion += szNum;
|
|
GetPrivateProfileString( szProcessType, strVersion.c_str(), "", pInfo->m_szProcessVer, MAX_PATH, pszFilePath );
|
|
|
|
//3. 어플리케이션 실행 프로세서
|
|
string strProcess = "PROCESS";
|
|
strProcess += szNum;
|
|
GetPrivateProfileString( szProcessType, strProcess.c_str(), "", pInfo->m_szCheckProcess, MAX_PATH, pszFilePath );
|
|
|
|
pProcessInfo->m_mapProcessInfo.insert( std::make_pair( i+1, pInfo ) );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void CUpdateScriptParser::GetModuleDirectory( char* szDirPath, int nSize )
|
|
{
|
|
ZeroMemory( szDirPath, nSize );
|
|
char szPath[MAX_PATH];
|
|
char szDrive[MAX_PATH], szDir[MAX_PATH];
|
|
GetModuleFileName( NULL, szPath, MAX_PATH);
|
|
_splitpath( szPath, szDrive, szDir, NULL, NULL);
|
|
wsprintf( szDirPath, "%s%s", szDrive, szDir);
|
|
}
|
|
|
|
|
|
|
|
BOOL CUpdateScriptParser::LoadAgentInfo( const char* pszFilePath )
|
|
{
|
|
ZeroMemory( &m_AgentInfo, sizeof(m_AgentInfo) );
|
|
|
|
m_AgentInfo.m_byAgentMode = GetPrivateProfileInt( "AGENT", "MODE", 0, pszFilePath );
|
|
GetPrivateProfileString( "AGENT", "IP", "127.0.0.1", m_AgentInfo.m_szAgentIP, DEFAULT_BUFFER_SIZE, pszFilePath );
|
|
m_AgentInfo.m_wAgentPort = GetPrivateProfileInt( "AGENT", "PORT", 20510, pszFilePath );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
BOOL CUpdateScriptParser::SaveVersion( BYTE byUpdateType, BYTE byUpdateNumber, CVersionInfo& rVerInfo )
|
|
{
|
|
TCHAR szProcessType[MAX_PATH];
|
|
szProcessType[0] = '0';
|
|
if( byUpdateType == UPDATE_TYPE_APPLICATION )
|
|
strncpy( szProcessType, "APPLICATION", MAX_PATH );
|
|
else if( byUpdateType == UPDATE_TYPE_LAUNCHER )
|
|
strncpy( szProcessType, "LAUNCHER", MAX_PATH );
|
|
else
|
|
return FALSE;
|
|
|
|
char szDirPath[MAX_PATH], szFilePath[MAX_PATH];
|
|
GetModuleDirectory( szDirPath, MAX_PATH );
|
|
wsprintf( szFilePath, "%s%s", szDirPath, "updateinfo.ini" );
|
|
|
|
if( _access(szFilePath, 0) != -1 ) //파일이 존재하면..
|
|
{
|
|
char szTemp[DEFAULT_BUFFER_SIZE], szVer[MAX_PATH];
|
|
rVerInfo.GetStringVersion( szTemp, DEFAULT_BUFFER_SIZE );
|
|
wsprintf(szVer, "Version%d", byUpdateNumber);
|
|
BOOL bRet = WritePrivateProfileString ( szProcessType, szVer, szTemp, szFilePath);
|
|
|
|
if( bRet == FALSE )
|
|
{
|
|
DWORD dwError = GetLastError();
|
|
if( dwError == 5 ) //접근 불가능..
|
|
{
|
|
//파일속성을 일반으로 변경..
|
|
SetFileAttributes( szFilePath, FILE_ATTRIBUTE_NORMAL );
|
|
WritePrivateProfileString ( szProcessType, szVer, szTemp, szFilePath);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
PROCESS_INFO* CUpdateScriptParser::GetProcessInfo( BYTE byUpdateType, BYTE byUpdateNumber )
|
|
{
|
|
PROCESS_INFO* pInfo = NULL;
|
|
if( byUpdateType == UPDATE_TYPE_LAUNCHER )
|
|
pInfo = m_LauncherInfo.GetProcessInfo( byUpdateNumber );
|
|
else if( byUpdateType == UPDATE_TYPE_APPLICATION )
|
|
pInfo = m_ApplicationInfo.GetProcessInfo( byUpdateNumber );
|
|
|
|
return pInfo;
|
|
}
|
|
|
|
BYTE CUpdateScriptParser::GetUpdateNumFromProcName( BYTE byUpdateType, TCHAR* pszProcessName )
|
|
{
|
|
if( !pszProcessName ) return FALSE;
|
|
|
|
BYTE byUpdateNumber = 0;
|
|
|
|
CUpdateProcessInfo* pProcessInfo = NULL;
|
|
|
|
if( byUpdateType == UPDATE_TYPE_APPLICATION )
|
|
{
|
|
pProcessInfo = &m_ApplicationInfo;
|
|
}
|
|
else if( byUpdateType == UPDATE_TYPE_LAUNCHER )
|
|
{
|
|
pProcessInfo = &m_LauncherInfo;
|
|
}
|
|
|
|
for( int i = 0; i < pProcessInfo->m_nTotalProcessCount; i++ )
|
|
{
|
|
PROCESS_INFO* pInfo = pProcessInfo->GetProcessInfo( i+1 );
|
|
if( !pInfo ) continue;
|
|
if( strcmp( pszProcessName, pInfo->m_szProcessName ) == 0 )
|
|
{
|
|
return byUpdateNumber = i+1;
|
|
}
|
|
}
|
|
|
|
return byUpdateType;
|
|
|
|
}
|
|
|
|
eUPDATE_TYPE CUpdateScriptParser::GetUpdateTypeFromProcName( TCHAR* pszProcessName )
|
|
{
|
|
//1. Launcher
|
|
PROCESS_INFO_MAP_ITER iter;
|
|
for( iter = m_LauncherInfo.m_mapProcessInfo.begin();
|
|
iter != m_LauncherInfo.m_mapProcessInfo.end(); ++iter )
|
|
{
|
|
PROCESS_INFO* pInfo = iter->second;
|
|
if( strcmp( pInfo->m_szProcessName, pszProcessName ) == 0 )
|
|
return UPDATE_TYPE_LAUNCHER;
|
|
}
|
|
|
|
//2. Application
|
|
for( iter = m_ApplicationInfo.m_mapProcessInfo.begin();
|
|
iter != m_ApplicationInfo.m_mapProcessInfo.end(); ++iter )
|
|
{
|
|
PROCESS_INFO* pInfo = iter->second;
|
|
|
|
if( strcmp( pInfo->m_szProcessName, pszProcessName ) == 0 )
|
|
return UPDATE_TYPE_APPLICATION;
|
|
}
|
|
|
|
return UPDATE_TYPE_UNKNOWN;
|
|
}
|