You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.0 KiB
C++

#include "StdAfx.h"
#include "Propertie.h"
#include "LogMgr.h"
#include "FileMgr.h"
#include "CStringFuc.h"
CPropertie::CPropertie()
{
m_pVal = NULL;
m_pModule = NULL;
}
CPropertie::~CPropertie()
{
}
//<2F>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>Ե<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD>Զ<EFBFBD>Ӧ<EFBFBD><D3A6>ģ<EFBFBD><C4A3>
void CPropertie::PropertyChangeVal(const COleVariant &OleVar)
{
//if(m_Name.GetLength()<=0)
//return;
CString Log;
switch(m_Type)
{
case _PROP_TYPE_BOOL:
Log.Format("[%s]---->[%s]",Bool2Str(*((bool *)m_pVal)),Bool2Str(OleVar.boolVal));
*((bool *)m_pVal) = OleVar.boolVal;
break;
case _PROP_TYPE_COLOR:
*((COLORREF *)m_pVal) = (COLORREF)OleVar.lVal;
break;
case _PROP_TYPE_DOUBLE:
Log.Format("[%lf]---->[%lf]",(*((double *)m_pVal)),(OleVar.dblVal));
*((double *)m_pVal) = OleVar.dblVal;
break;
case _PROP_TYPE_INT:
Log.Format("[%ld]---->[%ld]",(*((int *)m_pVal)),(OleVar.lVal));
*((int *)m_pVal) = OleVar.lVal;
break;
case _PROP_TYPE_STRING:
Log.Format("[%s]---->[%s]",(*((CString *)m_pVal)),(OleVar.bstrVal));
*((CString *)m_pVal) = OleVar.bstrVal;
break;
default:
break;
}
CString str("PropertyChange :");
Log = m_Name + Log;
Log = str + Log;
gLogMgr->WriteDebugLog(Log);
//д<><D0B4><EFBFBD>ļ<EFBFBD>
WriteRead(false);
//֪ͨ<CDA8><D6AA>Ӧģ<D3A6><C4A3><EFBFBD><EFBFBD><EFBFBD>Ա仯<D4B1><E4BBAF>
if(m_pModule)
{
m_pModule->OnPropertyChanged();
}
}
void CPropertie::WriteRead(bool bRead)
{
CString FileName = _T("\\Parameter\\") + m_Path + _T("\\")+m_Name+_T(".var");
if(bRead)
ReadFromFile(FileName);
else
WriteToFile(FileName);
}
//<2F><><EFBFBD><EFBFBD>ļ<EFBFBD>
void CPropertie::WriteToFile(CString &FileName)
{
CFileMgr FileMgr;
char filepath[1024];
FileMgr.GetFullFilePath(filepath,FileName);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
CFile file(filepath,CFile::modeReadWrite|CFile::modeCreate);
CArchive ar(&file,CArchive::store);
switch(m_Type)
{
case _PROP_TYPE_BOOL:
ar<<(*((bool *)m_pVal));
break;
case _PROP_TYPE_DOUBLE:
ar<<(*((double *)m_pVal));
break;
case _PROP_TYPE_INT:
ar<<(*((int *)m_pVal));
break;
case _PROP_TYPE_COLOR:
ar<<(*((int *)m_pVal));
break;
case _PROP_TYPE_STRING:
ar<<(*((CString *)m_pVal));
break;
default:
break;
}
}
void CPropertie::WriteToStream(ofstream &FileStream)
{
bool b;
switch(m_Type)
{
case _PROP_TYPE_BOOL:
b = (*((bool *)m_pVal));
FileStream<<Bool2Str(b);
break;
case _PROP_TYPE_DOUBLE:
FileStream<<(*((double *)m_pVal));
break;
case _PROP_TYPE_INT:
FileStream<<(*((int *)m_pVal));
break;
case _PROP_TYPE_COLOR:
FileStream<<(*((int *)m_pVal));
break;
case _PROP_TYPE_STRING:
FileStream<<(*((CString *)m_pVal));
break;
default:
break;
}
}
//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ
void CPropertie::ReadFromFile(CString &FileName)
{
CFileMgr FileMgr;
char filepath[1024];
FileMgr.GetFullFilePath(filepath,FileName);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
CFile file;
if(file.Open(filepath,CFile::modeRead))
{
CArchive ar(&file,CArchive::load);
switch(m_Type)
{
case _PROP_TYPE_BOOL:
ar>>(*((bool *)m_pVal));
break;
case _PROP_TYPE_DOUBLE:
ar>>(*((double *)m_pVal));
break;
case _PROP_TYPE_INT:
ar>>(*((int *)m_pVal));
break;
case _PROP_TYPE_COLOR:
ar>>(*((int *)m_pVal));
break;
case _PROP_TYPE_STRING:
ar>>(*((CString *)m_pVal));
break;
default:
break;
}
}
}