#include "StdAfx.h" #include "MBCfgInfo.h" CMBCfgInfo::CMBCfgInfo(CString strCfgName) { m_pStrFileUtils = NULL; if( m_pStrFileUtils->IsExist(strCfgName) ) { m_pStrFileUtils = new CStrFileUtils(); m_iniFile.SetFileName(strCfgName); ReInit(); } } CMBCfgInfo::CMBCfgInfo() { } CMBCfgInfo::~CMBCfgInfo(void) { if(m_pStrFileUtils == NULL){ delete m_pStrFileUtils; m_pStrFileUtils = NULL; } } void CMBCfgInfo::ReInit(CString strCfgName) { m_pStrFileUtils = NULL; if( m_pStrFileUtils->IsExist(strCfgName) ) { m_pStrFileUtils = new CStrFileUtils(); m_iniFile.SetFileName(strCfgName); ReInit(); } } void CMBCfgInfo::ReInit() { m_arServerLst.RemoveAll(); m_arServerLoginLst.RemoveAll(); m_arServerIDLst.RemoveAll(); m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("ServerName"), m_strServerName ); //µÇ¼µÄ·þÎñ m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("Port"), m_strPort ); //µÇ¼µÄ·þÎñ¶Ë¿Ú m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("LoginName"), m_strLoginName ); //µÇ¼µÄÓû§µÇ¼Ãû m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("AutoLogin"), m_strAutoLogin ); //ÊÇ·ñ×Ô¶¯µÇ¼ 1 ×Ô¶¯µÇ¼ 0 ²»ÊÇ m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("SavePwd"), m_strSavePwd ); //ÊÇ·ñ±£´æÃÜÂë 1 ÊDZ£´æ 0 ÊDz»±£´æ //m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("Password"), m_strPwd ); //ÃÜÂ룬¼ÓÃܺóµÄ m_iniFile.GetProfileSection(_T("SERVERLIST"),m_arServerLst); //·þÎñÆ÷Áбí m_iniFile.GetProfileSection(_T("SERVERLOGINLIST"),m_arServerLoginLst); //µÇ¼µÄ·þÎñ¶ÔÓ¦µÇ¼µÄһЩÓû§Áбí m_iniFile.GetProfileSection(_T("SERVERIDLIST"),m_arServerIDLst); //µÇ½¹ýµÄ·þÎñ¶ÔÓ¦µÄServerID£¬Ã¿¸ö·þÎñ¶¼ÓÐÒ»¸öΨһµÄID m_iniFile.GetProfileString(_T("MOBOX_APPSET"),_T("Offline"),m_strOffline); // ÀëÏß 1 ÊÇÀëÏß 0 ²»ÀëÏß } void CMBCfgInfo::GetServerLst( CStringArray &strArray ) { strArray.RemoveAll(); for( int i = 0;i < m_arServerLst.GetCount();i++ ) { CString strTmp = m_arServerLst[i]; int npos = strTmp.Find(_T('=')); CString strKey = strTmp.Left(npos); CString strValue = strTmp.Mid(npos + 1); strArray.Add(strValue); } } CString CMBCfgInfo::GetServerSection( CString strServer ) { for( int i = 0;i < m_arServerLst.GetCount();i++ ) { CString strTmp = m_arServerLst[i]; int npos = strTmp.Find(_T('=')); CString strKey = strTmp.Left(npos); CString strValue = strTmp.Mid(npos + 1); if( strValue == strServer ) { return strKey; } } return GetMaxServerSection(); } CString CMBCfgInfo::GetMaxServerSection() { CString strMaxSection; int nMax = 1; for( int i = 0;i < m_arServerLst.GetCount();i++ ) { CString strTmp = m_arServerLst[i]; int npos = strTmp.Find(_T('=')); CString strKey = strTmp.Left(npos); strKey.Replace(_T("server"),_T("")); if( _ttoi(strKey) > nMax ) { nMax = _ttoi(strKey) ; } } nMax++; strMaxSection.Format(_T("server%d"),nMax); return strMaxSection; } void CMBCfgInfo::GetLoginLst( CString strServerName,CStringArray &strArray ) { strArray.RemoveAll(); CString strTmpLogins; for( int i = 0;i < m_arServerLoginLst.GetCount();i++ ) { CString strTmp = m_arServerLoginLst[i]; int npos = strTmp.Find(_T('=')); CString strKey = strTmp.Left(npos); CString strValue = strTmp.Mid(npos + 1); if( strKey == strServerName ){ strTmpLogins = strValue; break; } } CMBStrOper::SplitString(strTmpLogins, _T(';'), strArray); } CString CMBCfgInfo::GetServerID( CString strServerName ) { for( int i = 0;i < m_arServerIDLst.GetCount();i++ ) { CString strTmp = m_arServerIDLst[i]; int npos = strTmp.Find(_T('=')); CString strKey = strTmp.Left(npos); CString strValue = strTmp.Mid(npos + 1); if( strKey == strServerName ){ return strValue; } } return _T(""); } CString CMBCfgInfo::GetLoginLstStr( CString strServerName,CString strLogin ) { CString strTmpLogins,strTmpLogin; CStringArray strArray; bool bExist = false; for( int i = 0;i < m_arServerLoginLst.GetCount();i++ ) { CString strTmp = m_arServerLoginLst[i]; int npos = strTmp.Find(_T('=')); CString strKey = strTmp.Left(npos); CString strValue = strTmp.Mid(npos + 1); if( strKey == strServerName ){ strTmpLogins = strValue; break; } } if( !strTmpLogins.IsEmpty() ) { CMBStrOper::SplitString(strTmpLogins, _T(';'), strArray); for( int i = 0;i < strArray.GetCount();i++ ) { strTmpLogin = strArray[i]; if( strTmpLogin == strLogin ) { bExist = true; return strTmpLogins; } } if( !bExist ) { return (strTmpLogins + _T(";") + strLogin); } } return strLogin; }