// Condition.cpp: implementation of the CCondition class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "hookmsg.h" #include "Condition.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////////// // void CCondition::Initialize() { Init_Item_Multi( m_arrTextNot, "°ø½Ã_ºÎÁ¤¹®±¸.txt" ); Init_Item_Multi( m_arrTextAnd, "°ø½Ã_±àÁ¤¹®±¸.txt" ); Init_Item_Multi( m_arrNewsPlusAnd_Special, "´º½ºÇ÷¯½º_Ưº°¿ë_±àÁ¤¹®±¸.txt" ); Init_Item_Multi( m_arrNewsPlusAnd_Normal, "´º½ºÇ÷¯½º_ÀϹݿë_±àÁ¤¹®±¸.txt" ); Init_Item_Multi( m_arrNewsPlusNot, "´º½ºÇ÷¯½º_ºÎÁ¤¹®±¸.txt" ); } void CCondition::Finalize() { m_arrTextNot.RemoveAll(); m_arrTextAnd.RemoveAll(); m_arrNewsPlusAnd_Special.RemoveAll(); m_arrNewsPlusAnd_Normal.RemoveAll(); m_arrNewsPlusNot.RemoveAll(); } BOOL CCondition::Refresh() { if( Init_Item_Multi( m_arrTextNot, "°ø½Ã_ºÎÁ¤¹®±¸.txt" ) ) if( Init_Item_Multi( m_arrTextAnd, "°ø½Ã_±àÁ¤¹®±¸.txt" ) ) if( Init_Item_Multi( m_arrNewsPlusAnd_Special, "´º½ºÇ÷¯½º_Ưº°¿ë_±àÁ¤¹®±¸.txt" ) ) if( Init_Item_Multi( m_arrNewsPlusAnd_Normal, "´º½ºÇ÷¯½º_ÀϹݿë_±àÁ¤¹®±¸.txt" ) ) if( Init_Item_Multi( m_arrNewsPlusNot, "´º½ºÇ÷¯½º_ºÎÁ¤¹®±¸.txt" ) ) { return TRUE; } return FALSE; } ////////////////////////////////////////////////////////////////////////// // BOOL CCondition::SearchAnd( CStringArray &array, CString &strSource ) { int nStart = 0; int nEnd = 0; CString strKeyList1, strKeyList2, strKey; for(int n = 0; n < array.GetSize(); n++) { strKeyList1 = array.GetAt(n); int _nCount=0; if( sscanf( strKeyList1, "%02d", &_nCount ) < 1 ) continue; strKeyList2 = strKeyList1.Mid(3); int j = 0; while(AfxExtractSubString(strKey, strKeyList2, j++, '+')) { if( strSource.Find( strKey ) != -1 ) { if( _nCount <= j ) return TRUE; } else break; } } return FALSE; } BOOL CCondition::SearchNot( CStringArray &array, CString &strSource ) { int nStart = 0; int nEnd = 0; CString strKeyList1, strKeyList2, strKey; for(int n = 0; n < array.GetSize(); n++) { strKeyList1 = array.GetAt(n); int _nCount=0; if( sscanf( strKeyList1, "%02d", &_nCount ) < 1 ) continue; strKeyList2 = strKeyList1.Mid(3); int j = 0; while(AfxExtractSubString(strKey, strKeyList2, j++, '+')) { if( strSource.Find( strKey ) != -1 ) { if( _nCount <= j ) return TRUE; } else break; } } return FALSE; } ////////////////////////////////////////////////////////////////////////// // BOOL CCondition::Init_Item_Single( CStringArray &array, CString strFile ) { TCHAR szFilePath[_MAX_PATH]={0,}; ::GetModuleFileName(NULL, szFilePath, _MAX_PATH); *(strrchr( szFilePath, '\\' ) + 1) = 0; strcat( szFilePath, (LPSTR)(LPCTSTR)strFile ); CStdioFile file; if( !file.Open(szFilePath, CFile::modeRead | CFile::typeText) ) { CString str; str.Format(TEXT("File Open Error : %d\n%s"), GetLastError(), szFilePath); AfxMessageBox(str); return FALSE; } array.RemoveAll(); CString strSourceData; TRY { while( file.ReadString(strSourceData) ) { strSourceData.TrimLeft(" "); strSourceData.TrimRight(" "); if( "'" == strSourceData.Left(1) || strSourceData.GetLength() == 0 ) continue; strSourceData.TrimLeft('"'); strSourceData.TrimRight('"'); array.Add( strSourceData ); } } CATCH(CFileException, e) { #ifdef _DEBUG afxDump << "Error during reading. " << e->m_cause << "\n"; #endif AfxMessageBox("Error during reading file."); file.Close(); return FALSE; } END_CATCH file.Close(); return TRUE; } ////////////////////////////////////////////////////////////////////////// // BOOL CCondition::Init_Item_Multi(CStringArray &array, CString strFile) { BOOL bRet = FALSE; TCHAR szFilePath[_MAX_PATH]={0,}; ::GetModuleFileName(NULL, szFilePath, _MAX_PATH); *(strrchr( szFilePath, '\\' ) + 1) = 0; strcat( szFilePath, (LPSTR)(LPCTSTR)strFile ); CStdioFile file; if( !file.Open(szFilePath, CFile::modeRead | CFile::typeText) ) { CString str; str.Format(TEXT("File Open Error : %d\n%s"), GetLastError(), szFilePath); AfxMessageBox(str); return bRet; } array.RemoveAll(); CString strSourceData; TRY { CString strElement; CString strTemp = ""; CString strTemp2 = ""; while( file.ReadString(strSourceData) ) { strSourceData.TrimLeft(" "); strSourceData.TrimRight(" "); if( "'" == strSourceData.Left(1) || strSourceData.GetLength() == 0 ) continue; strTemp = ""; strTemp2 = ""; int i = 0; while(AfxExtractSubString(strTemp, strSourceData, i++, '+')) { strTemp.TrimLeft('"'); strTemp.TrimRight('"'); strTemp2 += strTemp + "+"; } strElement.Format( "%02d+%s", i-1, strTemp2 ); array.Add( strElement ); } bRet = TRUE; } CATCH(CFileException, e) { #ifdef _DEBUG afxDump << "Error during reading. " << e->m_cause << "\n"; #endif AfxMessageBox("Error during reading file."); } END_CATCH file.Close(); return bRet; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // enum HM_CONDITION_TYPE CCondition::DetectConditionTitle( CString & strTitle, int nSrcType ) { if( nSrcType == UM_HOOKOK_WND2 ) // NewsPlus. { if( ! SearchNot( m_arrNewsPlusNot, strTitle ) ) // [´º½ºÇ÷¯½º_ºÎÁ¤¹®±¸]¸¦ ã´Â´Ù. { if( SearchAnd( m_arrNewsPlusAnd_Special, strTitle ) ) // [´º½ºÇ÷¯½º_Ưº°¿ë_±àÁ¤¹®±¸]¸¦ ã´Â´Ù. return HM_CONDITION_TYPE_SPECIAL; if ( SearchAnd( m_arrNewsPlusAnd_Normal, strTitle ) ) // [´º½ºÇ÷¯½º_ÀϹݿë_±àÁ¤¹®±¸]¸¦ ã´Â´Ù. return HM_CONDITION_TYPE_NORMAL; } } else // TK, IM, 7121 °øÅë. { if( ! SearchNot( m_arrTextNot, strTitle ) ) // [°ø½Ã ºÎÁ¤¹®±¸]¸¦ ã´Â´Ù. { if( SearchAnd( m_arrTextAnd, strTitle ) ) // [°ø½Ã ±àÁ¤¹®±¸]¸¦ ã´Â´Ù. return HM_CONDITION_TYPE_TRUE; } } return HM_CONDITION_TYPE_FALSE; }