Files
HLStock/HookMsg/Condition.cpp
2013-07-20 23:23:03 +00:00

260 lines
6.2 KiB
C++

// 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;
}