ROAMap.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:3k
源码类别:
外挂编程
开发平台:
Visual C++
- // ROAMap.cpp: implementation of the CROAMap class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ROA.h"
- #include "ROAMap.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CROAMap::CROAMap()
- {
- m_bInited = false;
- }
- CROAMap::~CROAMap()
- {
- }
- BOOL CROAMap::init(LPCTSTR lpszFilename, LPCTSTR lpszAlias)
- {
- CFile file;
- CString strRead;
- CString strKey, strValue;
- BOOL bRtn = false;
- int nCount = 0;
- m_strAlias = lpszAlias;
- do
- {
- if(!file.Open(lpszFilename, CFile::modeRead))
- {
- break;
- }
- CArchive arc(&file, CArchive::load);
- while(arc.ReadString(strRead))
- {
- strRead.TrimLeft();
- strRead.TrimRight();
- if(strRead.IsEmpty() || strRead[0] == '#')
- continue;
- switch(strRead[0])
- {
- case '*':
- strKey.Format(_T("%d"), nCount);
- strValue = strRead.Mid(1);
- break;
- case '&':
- strKey = strRead.Mid(1);
- strValue = _T("DUMMY");
- break;
- default:
- strKey = strRead.Left(strRead.Find(' '));
- strValue = strRead.Mid(strRead.Find(' ')+1);
- break;
- }
- strKey.MakeLower();
- strValue.MakeLower();
- strValue.TrimLeft();
- strValue.TrimRight();
- SetAt(strKey, strValue);
- bRtn = true;
- m_bInited = true;
- nCount++;
- }
- arc.Close();
- file.Close();
- }while(0);
- return(bRtn);
- }
- CString CROAMap::FindValue(LPCTSTR lpszKey, int nSection, BOOL *pFound)
- {
- CString strRtn = "Not inited!";
- CString strTemp;
- int nPos;
- strTemp.MakeLower();
- if(pFound)
- *pFound = true;
- if(m_bInited)
- {
- if(!Lookup(lpszKey, strRtn))
- {
- strRtn = "δ֪" + m_strAlias;
- if(pFound)
- *pFound = false;
- }
- if(-1 != nSection)
- {
- for(int i=0; i<nSection; i++)
- {
- nPos = strRtn.Find(" ");
- if(-1 != nPos)
- {
- strRtn = strRtn.Mid(nPos+1);
- strRtn.TrimLeft();
- }
- else
- {
- break;
- }
- }
- if(i >= nSection)
- {
- nPos = strRtn.Find(" ");
- if(-1 != nPos)
- {
- strRtn = strRtn.Left(nPos);
- }
- }
- else
- {
- strRtn.Empty();
- }
- }
- }
- strRtn.TrimLeft();
- strRtn.TrimRight();
- return(strRtn);
- }
- CString CROAMap::FindValue(DWORD dwKey, int nSection, BOOL *pFound)
- {
- CString strTemp;
- strTemp.Format("%d", dwKey);
- return(FindValue(strTemp, nSection, pFound));
- }