www.pudn.com > CP_IVR.zip > HSettings.cpp


// HSettings.cpp: implementation of the CHSettings class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "HSettings.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CHSettings::CHSettings() 
{ 
	m_deviceId = 0; 
	m_ringCount = 0; 
} 
 
CHSettings::~CHSettings() 
{ 
 
} 
 
void CHSettings::Save() 
{ 
	if (!File.Open(_T("Settings.ini"), CFile::modeWrite | CFile::modeCreate|  
		CFile::modeNoTruncate | CFile::typeText, 0)) { 
 
        ex.ReportError(); 
        return ;//FALSE; 
    } ; 
	 
	TRY { 
		CString str; 
		str.Format(_T("m_deviceId=%d\n"),m_deviceId); 
		File.WriteString(str); 
 
		str.Format(_T("m_ringCount=%d\n"),m_ringCount); 
		File.WriteString(str); 
		File.Close(); 
 
	} CATCH (CFileException, e) { 
        AfxMessageBox(_T("There's a file problem.")); 
    } END_CATCH 
} 
 
void CHSettings::Load() 
{ 
 
	if (!File.Open(_T("Settings.ini"), CFile::modeRead |  
		CFile::modeNoTruncate | CFile::typeText, 0)) { 
 
//		ex.ReportError(); 
 
		// Unable to open the file! 
		// Load default settings (In TAPI.Cpp)!  
		m_deviceId = -1; 
		m_ringCount = 2; 
		return; 
	} 
	 
	TRY { 
		m_deviceId = GetNextValue(); 
		m_ringCount = GetNextValue(); 
		File.Close(); 
	} CATCH (CFileException, e) { 
		// If file doe's not exsists 
		if (e->m_cause==CFileException::fileNotFound) { 
			// Load default settings (In TAPI.Cpp)!  
			m_deviceId = -1; 
			m_ringCount = 2; 
		} 
		else AfxMessageBox(_T("Unable to save error.")); 
    } END_CATCH 
 
} 
 
int CHSettings::GetValue(CString str) 
{ 
	// UNDONE: All Impelementation!! 
	return -1; 
} 
 
int CHSettings::GetNextValue() 
{ 
	CString str = _T(""); 
	int nmbr = 0; 
 
	File.ReadString(str); 
	int res = str.Find(_T("="),0); 
	if (res!=-1) { 
		str.Delete(0,res+1); 
		nmbr = _wtoi(str); 
	} 
	return nmbr; 
}