コード例 #1
0
ファイル: Registry.cpp プロジェクト: lemonxiao0/peerproject
CString CRegistry::GetString(LPCTSTR pszSection, LPCTSTR pszName, LPCTSTR pszDefault, LPCTSTR pszSubKey, BOOL bIgnoreHKCU)
{
	CString strSection( pszSubKey ? pszSubKey : _T("Software\\PeerProject\\PeerProject") );
	if ( pszSection && *pszSection )
	{
		if ( pszSection[0] != _T('\\') )
			strSection += _T("\\");
		strSection += pszSection;
	}

	// Read from HKCU then from HKLM
	DWORD nType = 0, nSize = 0;
	LONG nErrorCode = SHRegGetUSValue( (LPCTSTR)strSection, pszName, &nType,
		NULL, &nSize, bIgnoreHKCU, NULL, 0 );
	if ( nErrorCode == ERROR_SUCCESS && nType == REG_SZ && nSize >= sizeof( TCHAR ) && ( nSize & 1 ) == 0 )
	{
		CString strValue;
		nErrorCode = SHRegGetUSValue( (LPCTSTR)strSection, pszName, &nType,
			strValue.GetBuffer( nSize / sizeof( TCHAR ) ), &nSize, bIgnoreHKCU, NULL, 0 );
		strValue.ReleaseBuffer( nSize / sizeof( TCHAR ) - 1 );
		if ( nErrorCode == ERROR_SUCCESS )
			return strValue;
	}

	return pszDefault ? CString( pszDefault ) : CString();
}
コード例 #2
0
ファイル: KillerDlg.cpp プロジェクト: caidongyun/PcGuard
void CKillerDlg::SaveUserSet()
{
	char appPath[256];
	GetCurrentDirectory(256,appPath);	//取得应用程序当前路径
	CString  filePath;					//保存Ini文件名
	filePath.Format("%s",appPath);
	filePath +="\\";
	filePath += "virus.ini";	
	
	if(m_VirusLibLIst.empty())// 病毒库列表为空时
		return;

	//删除原来的文件
	DeleteFile(filePath);
	int		nIndex = 0;
	
	//遍历整个链表
	for (VirusList::iterator it = m_VirusLibLIst.begin(); it != m_VirusLibLIst.end(); ++it)
	{	
		VIRUS_DATA da=(*it);
		CString strSection("section");							
		
		//section
		CString strIndex;
		strIndex.Format("%d",nIndex);
		strSection += strIndex;
		// 特征码长度
		CString strdataLen;								
		strdataLen.Format("%ld", (long)da.dataLen);
		// 特征码内容
		CString strOffset;
		strOffset.Format("%d",da.offset);
		CString strdata;
		strdata=(char *)(LPCTSTR)da.VirusData;
			//写病毒名称48字节
		WritePrivateProfileString(strSection, _T("VirusName"), da.VirusName, filePath);	
			//特征码长度
		WritePrivateProfileString(strSection, _T("DataLen"), strdataLen, filePath);
		//文件类型
		WritePrivateProfileString(strSection, _T("ExtName"), da.ExtName,filePath);	
		// 偏移地址
		WritePrivateProfileString(strSection, _T("OffSet"),strOffset ,filePath);
		//特征码内容
		WritePrivateProfileString(strSection, _T("VirusData"),strdata,filePath);	
		++nIndex;
	}

	//将病毒数量写入ini文件
	CString strCount;
	strCount.Format("%d", nIndex);
	::WritePrivateProfileString("VirusCount", "Count", strCount, filePath);	
	
	
	m_VirusLibLIst.clear();//删除链表所有节点
}
コード例 #3
0
ファイル: Registry.cpp プロジェクト: lemonxiao0/peerproject
BOOL CRegistry::SetDword(LPCTSTR pszSection, LPCTSTR pszName, DWORD nValue, LPCTSTR pszSubKey)
{
	CString strSection( pszSubKey ? pszSubKey : _T("Software\\PeerProject\\PeerProject") );
	if ( pszSection && *pszSection )
	{
		if ( pszSection[0] != _T('\\') )
			strSection += _T("\\");
		strSection += pszSection;
	}

	LONG nErrorCode = SHRegSetUSValue( (LPCTSTR)strSection, pszName, REG_DWORD,
		(LPCVOID)&nValue, sizeof( nValue ), SHREGSET_FORCE_HKCU );
	return ( nErrorCode == ERROR_SUCCESS );
}
コード例 #4
0
ファイル: Registry.cpp プロジェクト: lemonxiao0/peerproject
BOOL CRegistry::SetString(LPCTSTR pszSection, LPCTSTR pszName, LPCTSTR pszValue, LPCTSTR pszSubKey)
{
	CString strSection( pszSubKey ? pszSubKey : _T("Software\\PeerProject\\PeerProject") );
	if ( pszSection && *pszSection )
	{
		if ( pszSection[0] != _T('\\') )
			strSection += _T("\\");
		strSection += pszSection;
	}

	LONG nErrorCode = SHRegSetUSValue( (LPCTSTR)strSection, pszName, REG_SZ,
		(LPCVOID)pszValue, ( lstrlen( pszValue ) + 1 ) * sizeof( TCHAR ), SHREGSET_FORCE_HKCU );
	return ( nErrorCode == ERROR_SUCCESS );
}
コード例 #5
0
ファイル: LogFactory.cpp プロジェクト: winwingy/Study
BOOL CLogFactory::CreateLogName(BSTR AppName, 
								BSTR Configue, 
								BSTR Section, 
								LONG FileType, 
								CString &strLogName)
{
	CString strError;
	CString strAppPath(AppName);
	CString strFileName(Configue);
	CString strSection(Section);

	if (!IsFileExisted(strAppPath))
	{
		strError.Format(_T("AppName:%s is not existed. CLogFactory::CreateLogName return FALSE."), strAppPath);
		LOGGER_WRITE(strError.GetBuffer());
		LogEvent(strError);
		return FALSE;
	}

	strError.Format(_T("AppName:%s"), strAppPath);
	LOGGER_WRITE(strError.GetBuffer());

	int iIndex = strAppPath.ReverseFind(_T('\\'));
	ATLASSERT(-1 != iIndex);
	strAppPath = strAppPath.Left(iIndex + 1);

	CParameter Parameter;
	CConfigReader Reader;
	Reader.Read(strAppPath, strFileName, strSection, FileType, Parameter);

	CHAR Buffer[MAX_PATH] = { 0 };
#pragma warning(push)
#pragma warning(disable: 4996)
	strcat(Buffer, Parameter.m_cFixFolder);
	strcat(Buffer, Parameter.m_cCycleFolder);
	strcat(Buffer, Parameter.m_cCycleName);
	strcat(Buffer, Parameter.m_cCreateTime);
	strcat(Buffer, Parameter.m_cSaveTime);
	strcat(Buffer, Parameter.m_cExeName);
#pragma warning(pop)
	strLogName = CString(Buffer);
	strLogName.Remove(_T('\\'));
	strLogName.Remove(_T(':'));
	strLogName.Remove(_T('.'));
	strLogName.Remove(_T(' '));

	LOGGER_WRITE2(_T("LogName:") << strLogName.GetBuffer() << _T(" FileType:") << FileType);

	return TRUE;
}
コード例 #6
0
ファイル: CoolDialogBar.cpp プロジェクト: Liscar/jmc
void CCoolDialogBar::Load()
{
	CString strSection("Docbar");
//vls-begin// multiple output
    if (m_wndCode > 0)
        strSection.Format("Docbar%d", m_wndCode+1);
//vls-end//

	//////////////////////////////////////////////////////////////////////
    m_sizeFloat.cx = ::GetPrivateProfileInt(strSection, "CXFloat", m_sizeFloat.cx, szGLOBAL_PROFILE);
	//////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////
    m_sizeFloat.cy = ::GetPrivateProfileInt(strSection, "CYFloat", m_sizeFloat.cy,szGLOBAL_PROFILE);

	//////////////////////////////////////////////////////////////////////
    m_sizeHorz.cx = ::GetPrivateProfileInt(strSection, "CXHorz", m_sizeHorz.cx,szGLOBAL_PROFILE);
	//////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////
    m_sizeHorz.cy = ::GetPrivateProfileInt(strSection, "CYHorz", m_sizeHorz.cy, szGLOBAL_PROFILE);

	//////////////////////////////////////////////////////////////////////
    m_sizeVert.cx = ::GetPrivateProfileInt(strSection, "CXVert", m_sizeVert.cx, szGLOBAL_PROFILE);
	//////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////
    m_sizeVert.cy = ::GetPrivateProfileInt(strSection, "CYVert", m_sizeVert.cy, szGLOBAL_PROFILE);

//vls-begin// multiple output
    m_bFlag = ::GetPrivateProfileInt(strSection, "Visible", FALSE, szGLOBAL_PROFILE);
    m_Dock = ::GetPrivateProfileInt(strSection, "Docking", 0xF000L, szGLOBAL_PROFILE);
	EnableDocking(m_Dock);
    ShowWindow(m_bFlag ? SW_SHOW : SW_HIDE);
    // ShowWindow(m_bVisible ? SW_SHOW : SW_HIDE);

    CString t, sDefault;
    CHAR sTitle[4096] = "";
    t.LoadString(IDS_OUTPUT);
    sDefault.Format(t, m_wndCode);
    ::GetPrivateProfileString(strSection, "Title", sDefault, sTitle, 4096, szGLOBAL_PROFILE);
    m_sTitle = sTitle;
    SetWindowText(sTitle);
//vls-end//
//* en
	m_mX = ::GetPrivateProfileInt(strSection, "posX", 0, szGLOBAL_PROFILE);
	m_mY = ::GetPrivateProfileInt(strSection, "posY", 0, szGLOBAL_PROFILE);
//*/en
}
コード例 #7
0
ファイル: workerThread.cpp プロジェクト: rungkarn/APM
//------------------------------------------------------
//Name updateParamFromINIFile
//Desc parameter modified need to read up-to-date parameter
//	   unsigned char*	pchkModifyParam  --check for parameter change 11111 = 63
//------------------------------------------------------
void workerThread::updateParamFromINIFile(unsigned char* pchkModifyParam)
{
		unsigned char idxBit;
		string strSection ("Parameter");

		idxBit = 1 & *pchkModifyParam;
		if(idxBit ==1)
		{
			m_iCapEveryNSec=::GetPrivateProfileIntA(strSection.c_str(),"CapEveryNSec",180,m_strIniFileName);
			if(m_iCapEveryNSec == 0)
				return;
		}
		idxBit = 2 & *pchkModifyParam;
		if(idxBit ==2)
		{
			m_iThresDiff=::GetPrivateProfileIntA(strSection.c_str(),"ThresDiff",50,m_strIniFileName);
			if(m_iThresDiff == 0)
				return;
		}
		idxBit = 4 & *pchkModifyParam;
		if(idxBit ==4)
		{
			m_iThresShutdownComputer=::GetPrivateProfileIntA(strSection.c_str(),"ThresShutdownComputer",50,m_strIniFileName);
			if(m_iThresShutdownComputer == 0)
				return;
		}
		idxBit = 8 & *pchkModifyParam;
		if(idxBit ==8)
		{
			m_iThresBootComputer=::GetPrivateProfileIntA(strSection.c_str(),"ThresBootComputer",50,m_strIniFileName);
			if(m_iThresBootComputer == 0)
				return;
		}
		idxBit = 16 & *pchkModifyParam;
		if(idxBit ==16)
		{
			m_iNumberOfDelay=::GetPrivateProfileIntA(strSection.c_str(),"NumberOfDelay",50,m_strIniFileName);
			if(m_iNumberOfDelay == 0)
				return;	
		}

		//read Parameter section data
			
		
			
			

}
コード例 #8
0
/*
Utility function to look up a columns width in the registry.
If it returns -1 then it means that it was not found in the registry
*/
const int CMultiColumnSortListCtrl::GetRegColumnWidth( int iColumn ) const
{
	int nRes = -1;
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl
	
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnWidthSection );
	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );
	AfxExtractSubString(strSubString, strValue, iColumn, ',');
	if( !strSubString.IsEmpty() )
	{
		nRes = atoi( (LPCTSTR)strSubString );
	}

	return nRes;
}
コード例 #9
0
ファイル: workerThread.cpp プロジェクト: rungkarn/APM
//manipulate ini File
//------------------------------------------------------
//Name manipulateAPMINIFile
//Desc get dat from INI file
//     char* pFileName  name and path of ini file
//		 feed data
//------------------------------------------------------
void workerThread::manipulateCPFeedINIFile(char* pFileName)
{
		char* retBuffer;
		string strSection ("Parameter");
		//¤ÇõÃǨÊͺ¡è͹ÇèÒ ÁÕä¿Åì¹ÕéÍÂÙèËÃ×Íà»ÅèÒ
		//set feed type to list
		fstream file;
		file.open( pFileName, ios::in );
		if(file.fail())
		{
			file.close();
			MessageBox::Show("File " + gcnew System::String(pFileName) + " is not exist!!!");
			return ;
		}
		else
		{
			file.close();
			retBuffer = (char*)calloc(MAXSIZE,sizeof(char));
			char* pdest = NULL;
			char* psrc = NULL;

			//read Parameter section data
			m_iCapEveryNSec=::GetPrivateProfileIntA(strSection.c_str(),"CapEveryNSec",180,pFileName);
			if(m_iCapEveryNSec == 0)
				return;

			m_iThresDiff=::GetPrivateProfileIntA(strSection.c_str(),"ThresDiff",50,pFileName);
			if(m_iThresDiff == 0)
				return;


			m_iThresShutdownComputer=::GetPrivateProfileIntA(strSection.c_str(),"ThresShutdownComputer",50,pFileName);
			if(m_iThresShutdownComputer == 0)
				return;
			
			m_iThresBootComputer=::GetPrivateProfileIntA(strSection.c_str(),"ThresBootComputer",50,pFileName);
			if(m_iThresBootComputer == 0)
				return;
			
			m_iNumberOfDelay=::GetPrivateProfileIntA(strSection.c_str(),"NumberOfDelay",50,pFileName);
			if(m_iNumberOfDelay == 0)
				return;	

		}

}
コード例 #10
0
/*
This function loads the columns sort
To apply the changes you have to call SortCombinedColumns()
*/
int CMultiColumnSortListCtrl::LoadColumnSort()
{
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl

	//set the colum order
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnSortSection );

	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );

	if( !strValue.IsEmpty() )
	{
		m_ctlHeaderCtrl.RemoveAllSortImages();
    	EmptyArray(m_aCombinedSortedColumns, -1);
	    m_lColumnSortStates = 0;

		int nIndex = 0;
		while( AfxExtractSubString(strSubString, strValue, nIndex, ',') )
		{
			//get the m_lColumnSortStates first
			if( !nIndex )
			{
				m_lColumnSortStates = atol( (LPCTSTR)strSubString );
				nIndex++;
				continue;
			}
			
			//get the other columns
			if( !strSubString.IsEmpty() )
			{
				m_aCombinedSortedColumns[nIndex-1] = atoi( (LPCTSTR)strSubString );
			}
			else
			{
				break;
			}
			
			//next please
			nIndex++;
		}
	}

	return 1;
}
コード例 #11
0
/**
*
* This function Gets the int32 value in the ini file
*
* @Author Carsten Scholz
* @param _pcSection is the section in the ini file it is located
* @param _pcKey is the key to the string value
* @param _riValue is then filled with the value if it is found
* @return Returns bResult if true the value was found
* 
*/
bool
CINIParser::GetIntValue(const char *_pcSection, const char *_pcKey, int32 &_riValue)
{
	bool bResult = false;

	std::string strSection(_pcSection);
	std::string strKey(strSection);
	strKey += "|";
	strKey += _pcKey;

	if(!m_mapPairs[strKey].empty())
	{
		_riValue = atoi(m_mapPairs[strKey].c_str());
		bResult = true;
	}

	return (bResult);
}
コード例 #12
0
/**
*
* This function Gets the bool value in the ini file
*
* @Author Carsten Scholz
* @param _pcSection is the section in the ini file it is located
* @param _pcKey is the key to the string value
* @param _rbValue is then filled with the value if it is found
* @return Returns bResult if true the value was found
* 
*/
bool
CINIParser::GetBoolValue(const char *_pcSection, const char *_pcKey, bool &_rbValue)
{
 	bool bResult = false;

	std::string strSection(_pcSection);
	std::string strKey(strSection);
	strKey += "|";
	strKey += _pcKey;

	if(!m_mapPairs[strKey].empty())
	{
		_rbValue = (m_mapPairs[strKey] == "true");
		bResult = true;
	}

	return (bResult);
}
コード例 #13
0
/**
*
* This function Gets the float32 value in the ini file
*
* @Author Carsten Scholz
* @param _pcSection is the section in the ini file it is located
* @param _pcKey is the key to the string value
* @param _rfValue is then filled with the value if it is found
* @return Returns bResult if true the value was found
* 
*/
bool
CINIParser::GetFloatValue(const char *_pcSection, const char *_pcKey, float32 &_rfValue)
{
 	bool bResult = false;

	std::string strSection(_pcSection);
	std::string strKey(strSection);
	strKey += "|";
	strKey += _pcKey;

	if(!m_mapPairs[strKey].empty())
	{
		_rfValue = static_cast<float32>(atof(m_mapPairs[strKey].c_str()));
		bResult = true;
	}

	return (bResult);
}
コード例 #14
0
/**
*
* This function Gets the string value in the ini file
*
* @Author Carsten Scholz
* @param _pcSection is the section in the ini file it is located
* @param _pcKey is the key to the string value
* @param _rStrValue is then filled with the value if it is found
* @return Returns bResult if true the value was found
* 
*/
bool
CINIParser::GetStringValue(const char *_pcSection, const char *_pcKey, std::string &_rStrValue)
{
	bool bResult = false;

	std::string strSection(_pcSection);
	std::string strKey(strSection);
	strKey += "|";
	strKey += _pcKey;

	if(!m_mapPairs[strKey].empty())
	{
		_rStrValue = m_mapPairs[strKey];
		bResult = true;
	}

	return (bResult);
}
コード例 #15
0
ファイル: Registry.cpp プロジェクト: lemonxiao0/peerproject
DWORD CRegistry::GetDword(LPCTSTR pszSection, LPCTSTR pszName, DWORD nDefault, LPCTSTR pszSubKey)
{
	CString strSection( pszSubKey ? pszSubKey : _T("Software\\PeerProject\\PeerProject") );
	if ( pszSection && *pszSection )
	{
		if ( pszSection[0] != _T('\\') )
			strSection += _T("\\");
		strSection += pszSection;
	}

	// Read from HKCU then from HKLM
	DWORD nValue = 0;
	DWORD nType = 0, nSize = sizeof( nValue );
	LONG nErrorCode = SHRegGetUSValue( (LPCTSTR)strSection, pszName, &nType,
		(PBYTE)&nValue, &nSize, FALSE, NULL, 0 );
	if ( nErrorCode == ERROR_SUCCESS && nType == REG_DWORD && nSize == sizeof( nValue ) )
		return nValue;

	return nDefault;
}
コード例 #16
0
ファイル: CoolDialogBar.cpp プロジェクト: Liscar/jmc
void CCoolDialogBar::Save()
{
	CString strSection("Docbar");
//vls-begin// multiple output
    if (m_wndCode > 0)
        strSection.Format("Docbar%d", m_wndCode+1);
//vls-end//
//	char bf[BUFFER_SIZE];
//	sprintf(bf,"at %d %d|%d %d|%d %d|%d",m_wndCode, m_sizeFloat.cx,m_sizeFloat.cy,m_sizeHorz.cx,m_sizeHorz.cy,m_sizeVert.cx,m_sizeVert.cy);
//	MessageBox(bf,"jmc",MB_OK|MB_ICONSTOP);

	///////////////////////////////////////////////////////////////////////////
    ::WritePrivateProfileInt(strSection, "CXFloat", m_sizeFloat.cx, szGLOBAL_PROFILE);
	///////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////
    ::WritePrivateProfileInt(strSection, "CYFloat", m_sizeFloat.cy, szGLOBAL_PROFILE);

	///////////////////////////////////////////////////////////////////////////
    ::WritePrivateProfileInt(strSection, "CXHorz", m_sizeHorz.cx, szGLOBAL_PROFILE);
	///////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////
    ::WritePrivateProfileInt(strSection, "CYHorz", m_sizeHorz.cy,szGLOBAL_PROFILE);

	///////////////////////////////////////////////////////////////////////////
    ::WritePrivateProfileInt(strSection, "CXVert", m_sizeVert.cx,szGLOBAL_PROFILE);
	///////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////
    ::WritePrivateProfileInt(strSection, "CYVert", m_sizeVert.cy, szGLOBAL_PROFILE);

//vls-begin// multiple output
    ::WritePrivateProfileInt(strSection, "Visible", m_bFlag, szGLOBAL_PROFILE);
    ::WritePrivateProfileInt(strSection, "Docking", m_Dock, szGLOBAL_PROFILE);
    ::WritePrivateProfileInt(strSection, "posX", m_mX, szGLOBAL_PROFILE);
    ::WritePrivateProfileInt(strSection, "posY", m_mY, szGLOBAL_PROFILE);
    ::WritePrivateProfileString(strSection, "Title", m_sTitle, szGLOBAL_PROFILE);
//vls-end//
}
コード例 #17
0
/*
This function loads the columns order as the columns can be re-arranged with drag & drop
You should call it BEFORE you fill in the contents or it might not redraw properly
*/
int CMultiColumnSortListCtrl::LoadColumnOrder()
{
	ASSERT( m_strUniqueName.GetLength() );	//You must set a unique name for every listctrl

	int iNumColumns = GetColumnCount();

	//set the colum order
	CString strEntry( m_strUniqueName );
	CString strValue, strSubString;
	CString strSection( m_strColumnOrderSection );

	strValue = AfxGetApp()->GetProfileString( strSection, strEntry, "" );

	if( !strValue.IsEmpty() )
	{
		LPINT pnOrder = (LPINT)malloc(iNumColumns*sizeof(int));
		ASSERT(pnOrder != NULL);

		if( pnOrder )
		{
			for( int nIndex = 0; nIndex < iNumColumns; nIndex++ )
			{
				
				AfxExtractSubString(strSubString, strValue, nIndex, ',');
				if( !strSubString.IsEmpty() )
				{
					pnOrder[nIndex] = atoi( (LPCTSTR)strSubString );
				}
			}

			SetColumnOrderArray( iNumColumns, pnOrder );

			free(pnOrder);
		}
	}

	return 1;
}
コード例 #18
0
bool CIniFileBase::DeleteSection ( LPCTSTR lpSectionName )
{
	stdstr_f strSection("[%s]",lpSectionName);

	/*if(m_File.IsOpen())
	{
		m_CurrentSectionFilePos = 0;
		m_File.Seek(m_CurrentSectionFilePos,CFileBase::begin);

		ULONG dwSize = m_File.GetLength();
		if(dwSize)
		{
			char *pData = new char[dwSize+1];
			if(pData)
			{
				ULONG dwRet = m_File.Read(pData, dwSize);
				if(dwRet != 0)
				{
					if(dwRet <= dwSize)
					{
						pData[dwRet] = 0;

						char *pSection = strstr(pData, strSection.c_str());
						if(pSection)
						{
							char tmp = pSection[0];
							pSection[0] = 0;

							std::string strNewData = pData;
							pSection[0] = tmp;

							char *pEndSection = pSection + strlen(strSection.c_str());
							char *pNextSection = strstr(pEndSection, "[");
							if(pNextSection)
							{
								strNewData += pNextSection;
							}

							m_File.Seek(m_CurrentSectionFilePos,CFileBase::begin);
							m_File.Write(strNewData.c_str(), (ULONG)strlen(strNewData.c_str()));
							m_File.Flush();
							m_File.SetEndOfFile();
						}
					}
					else
					{
						delete [] pData;

						return false;
					}
				}

				delete [] pData;
			}
			else
				return false;
		}
	}
	else
		return false;*/

	return true;
}
コード例 #19
0
ファイル: KillerDlg.cpp プロジェクト: caidongyun/PcGuard
void CKillerDlg::LoadUserSet()
{
	#define  TEMP_BUF_SIZE 125//缓冲区长度
	char appPath[256];
	GetCurrentDirectory(256,appPath);	//取得应用程序当前路径
	CString  filePath;					//保存Ini文件名
	filePath.Format("%s",appPath);
	filePath += "\\";
	filePath += "virus.ini";
	
	//从ini文件中获得病毒特征数量
 	int count =::GetPrivateProfileInt("VirusCount", "Count", 0, filePath);
	if(count<=0)
		return;
	int nIndex = 0;
	while (TRUE)
	{
		CString strSection("section");
		CString strIndex;
		strIndex.Format("%d",nIndex);
		strSection += strIndex;
		
		//病毒名称
		CString strSectionKey = "VirusName";					
		CString strValue = _T("");
		char cBuf[TEMP_BUF_SIZE];
		memset(cBuf, 0, TEMP_BUF_SIZE);
		VIRUS_DATA *pVirusInfo = new VIRUS_DATA;//新建VIRUS_DATA对象
		memset(pVirusInfo,0,sizeof(VIRUS_DATA));
		if(GetPrivateProfileString (strSection, strSectionKey, NULL, cBuf, TEMP_BUF_SIZE, filePath))
		{
			strcpy(pVirusInfo->VirusName,cBuf);
		}
		//  特征码长度
		strSectionKey = "DataLen";
		memset(cBuf, 0, TEMP_BUF_SIZE);
		if(GetPrivateProfileString (strSection, strSectionKey, NULL, cBuf, TEMP_BUF_SIZE, filePath))
		{
			pVirusInfo->dataLen = (LONG)atoi(cBuf);
		}
		
		//文件扩展名
		strSectionKey = "ExtName";
		memset(cBuf, 0, TEMP_BUF_SIZE);
		if(GetPrivateProfileString (strSection, strSectionKey, NULL, cBuf, TEMP_BUF_SIZE, filePath))
		{
			strcpy(pVirusInfo->ExtName,cBuf);
		}
		
		//偏移量
		strSectionKey = "OffSet";
		memset(cBuf, 0, TEMP_BUF_SIZE);
		if(GetPrivateProfileString (strSection, strSectionKey, NULL, cBuf, TEMP_BUF_SIZE, filePath))
		{
			pVirusInfo->offset = (LONG)atoi(cBuf);
		}

		//读取特征码
		strSectionKey = "VirusData";
		memset(cBuf, 0, TEMP_BUF_SIZE);
		if(GetPrivateProfileString (strSection, strSectionKey, NULL,  cBuf,TEMP_BUF_SIZE, filePath))
		{
			strcpy(pVirusInfo->VirusData,cBuf);
		}
		m_VirusLibLIst.push_back(*pVirusInfo);		//加入链表
		delete pVirusInfo;
		if(++nIndex>=count) // 判断病毒库加载完毕
			break;
	}	
}
コード例 #20
0
bool CMemoryIniFile::Update( char* szSection, char* szName, std::string& strValue, bool bWrite)
{
	bool bRC = false;

    std::string strSection(szSection); 
    std::string strName(szName);
        
    str::ToLower(strSection);
    str::ToLower(strName);
	
    bool bSectionFound = false;    
    bool bEntryFound = false;
    CIniSectionLst::iterator sectionIter;    
    CIniEntryLst::iterator entryIter;

    sectionIter = m_cIniFile.begin();
    while( sectionIter != m_cIniFile.end() )
    {
        if (sectionIter->getName() == strSection)
        {
            bSectionFound = true;
            break;
        }
        sectionIter++;
    }

    if (bSectionFound)
    {
        entryIter = sectionIter->cEntries.begin();
        while( entryIter != sectionIter->cEntries.end() )
        {
            if (entryIter->getName() == strName)
            {
                bEntryFound = true;
                break;
            }
            entryIter++;
        }       
    }
    // read or write value
    if (true == bWrite)
    {
        if (bSectionFound && bEntryFound) // value exist => overwrite
        {
            entryIter->setValue( strValue );
        }
        else if (bSectionFound) // section exist => create value 
        {
            sectionIter->cEntries.push_back( CMemoryIniFileEntry(strName, strValue) );
        }
        else // create section and value 
        {
            m_cIniFile.push_back( CMemoryIniFileSection(strSection, CMemoryIniFileEntry(strName, strValue) ) );
        }
        bRC = true;
    }
    else // read a existing value
    {
        if (bSectionFound && bEntryFound) // value exist => read
        {
            strValue = entryIter->getValue();
            bRC = true;
        }        
    }

	return bRC;
}