123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /** *************************************************************** **
- ** Implementation of the GIniFile class. **
- ** by S.B. **
- ** *************************************************************** **/
- #include "stdafx.h"
- #include "GIniFile.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- void GIniFile::SetFileName( const TCHAR *AFileName )
- {
- _tcscpy( rFName, AFileName );
- }
- void GIniFile::SetSectName( const TCHAR *ASectName )
- {
- _tcscpy( rSName, ASectName );
- }
- #define mc_GINIFILE_CheckDeflt()\
- const TCHAR *qDeflt;\
- if (ADeflt) qDeflt = ADeflt;\
- else qDeflt = AKeyName;
- int GIniFile::GetIniStr( const TCHAR *AKeyName, TCHAR *AResult, const TCHAR *ADeflt )
- {
- int qOk = GetPrivateProfileString( rSName, AKeyName, _T(""), AResult, 512, rFName );
- if (qOk) {
- rLastResult = TRUE;
- if (AResult[0]==_T('\\')) { // it allows to specify empty lines using back slash
- _tcscpy( AResult, &(AResult[1]) );
- qOk--;
- };
- }
- else {
- mc_GINIFILE_CheckDeflt();
- _tcscpy( AResult, qDeflt );
- rLastResult = FALSE;
- qOk = (int)_tcslen( ADeflt );
- };
- return qOk;
- }
- int GIniFile::SGetIniStr( const TCHAR *AKeyName, TCHAR *AResult, const TCHAR *ADeflt )
- {
- int qOk;
- mc_GINIFILE_CheckDeflt();
- qOk = GetIniStr( AKeyName, AResult, qDeflt );
- if (!rLastResult) SetIniStr( AKeyName, qDeflt );
- return qOk;
- }
- BOOL GIniFile::SetIniStr( const TCHAR *AKeyName, const TCHAR *AStr )
- {
- if (!AStr || !AStr[0]) AStr = _T("\\");
- return WritePrivateProfileString( rSName, AKeyName, AStr, rFName );
- }
- long GIniFile::GetIniInt( const TCHAR *AKeyName, long ADeflt )
- {
- TCHAR qS[32], qSD[32];
- _ltot( ADeflt, qSD, 0xA );
- GetIniStr( AKeyName, qS, qSD );
- if (!rLastResult) return ADeflt;
- else return _tcstol( qS, NULL, 0xA );
- }
- long GIniFile::SGetIniInt( const TCHAR *AKeyName, long ADeflt )
- {
- long qRes = GetIniInt( AKeyName, ADeflt );
- if (!rLastResult)
- SetIniInt( AKeyName, ADeflt );
- return qRes;
- }
- BOOL GIniFile::SetIniInt( const TCHAR *AKeyName, long AVal )
- {
- TCHAR qS[32];
- _stprintf( qS, _T("%d"), AVal );
- return SetIniStr( AKeyName, qS );
- }
- double GIniFile::GetIniFloat( const TCHAR *AKeyName, double ADeflt )
- {
- TCHAR qS[48], qSD[48];
- _stprintf( qSD, _T("%.4f"), ADeflt );
- GetIniStr( AKeyName, qS, qSD );
- if (!rLastResult) return ADeflt;
- else return _tcstod( qS, NULL );
- }
- double GIniFile::SGetIniFloat( const TCHAR *AKeyName, double ADeflt )
- {
- double qRes = GetIniFloat( AKeyName, ADeflt );
- if (!rLastResult)
- SetIniFloat( AKeyName, ADeflt );
- return qRes;
- }
- BOOL GIniFile::SetIniFloat( const TCHAR *AKeyName, double AVal )
- {
- TCHAR qS[32];
- _stprintf( qS, _T("%f"), AVal );
- return SetIniStr( AKeyName, qS );
- }
|