cleanup
This commit is contained in:
@@ -462,21 +462,26 @@ int CRegistry::ReadInt(CString strName, int nDefault)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CRegistry::ReadBool(CString strName, BOOL bDefault)
|
bool CRegistry::Read(CString strName, bool &result)
|
||||||
{
|
{
|
||||||
DWORD dwType = REG_BINARY;
|
ASSERT(m_strCurrentPath.GetLength() > 0);
|
||||||
|
HKEY hKey;
|
||||||
|
if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0,
|
||||||
|
KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||||
|
return false;
|
||||||
|
|
||||||
BOOL b;
|
BOOL b;
|
||||||
DWORD dwSize = sizeof(b);
|
DWORD dwSize = sizeof(b);
|
||||||
HKEY hKey;
|
DWORD dwType = REG_BINARY;
|
||||||
|
int ret = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, &dwType, (LPBYTE)&b, &dwSize);
|
||||||
ASSERT(m_strCurrentPath.GetLength() > 0);
|
|
||||||
if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0,
|
|
||||||
KEY_READ, &hKey) != ERROR_SUCCESS) return bDefault;
|
|
||||||
|
|
||||||
if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL,
|
|
||||||
&dwType, (LPBYTE)&b, &dwSize) != ERROR_SUCCESS) b = bDefault;
|
|
||||||
::RegCloseKey(hKey);
|
::RegCloseKey(hKey);
|
||||||
return b;
|
|
||||||
|
if ( ret != ERROR_SUCCESS )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
result = !!b;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -588,7 +593,8 @@ BOOL CRegistry::WriteBool(CString strName, BOOL bValue)
|
|||||||
REG_BINARY, (LPBYTE)&bValue, sizeof(bValue))
|
REG_BINARY, (LPBYTE)&bValue, sizeof(bValue))
|
||||||
!= ERROR_SUCCESS) bSuccess = FALSE;
|
!= ERROR_SUCCESS) bSuccess = FALSE;
|
||||||
|
|
||||||
if (!m_bLazyWrite) ::RegFlushKey(hKey);
|
if (!m_bLazyWrite)
|
||||||
|
::RegFlushKey(hKey);
|
||||||
::RegCloseKey(hKey);
|
::RegCloseKey(hKey);
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
|
#ifndef REGISTRY_H
|
||||||
|
#define REGISTRY_H
|
||||||
#ifndef __REGISTRY_H__
|
|
||||||
#define __REGISTRY_H__
|
|
||||||
|
|
||||||
class CRegistry
|
class CRegistry
|
||||||
{
|
{
|
||||||
@@ -18,15 +16,10 @@ protected:
|
|||||||
CString m_strCurrentPath;
|
CString m_strCurrentPath;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline BOOL PathIsValid() {
|
inline BOOL PathIsValid() const { return m_strCurrentPath.GetLength() > 0; }
|
||||||
return (m_strCurrentPath.GetLength() > 0); }
|
inline CString GetCurrentPath() const { return m_strCurrentPath; }
|
||||||
inline CString GetCurrentPath() {
|
inline HKEY GetRootKey() const { return m_hRootKey; }
|
||||||
return m_strCurrentPath; }
|
|
||||||
inline HKEY GetRootKey() {
|
|
||||||
return m_hRootKey; }
|
|
||||||
|
|
||||||
|
|
||||||
//CRegistry methods
|
|
||||||
public:
|
public:
|
||||||
BOOL ClearKey();
|
BOOL ClearKey();
|
||||||
BOOL SetRootKey(HKEY hRootKey);
|
BOOL SetRootKey(HKEY hRootKey);
|
||||||
@@ -55,6 +48,10 @@ public:
|
|||||||
BOOL ReadRect(CString strName, CRect* pRect);
|
BOOL ReadRect(CString strName, CRect* pRect);
|
||||||
DWORD ReadDword(CString strName, DWORD dwDefault);
|
DWORD ReadDword(CString strName, DWORD dwDefault);
|
||||||
|
|
||||||
|
/* Readers converted to a less silly mechanism below (do these as needed):
|
||||||
|
* return the value in result if found, otherwise return false. */
|
||||||
|
bool Read(CString strName, bool &result);
|
||||||
|
|
||||||
// data writing functions
|
// data writing functions
|
||||||
BOOL WriteBool(CString strName, BOOL bValue);
|
BOOL WriteBool(CString strName, BOOL bValue);
|
||||||
BOOL WriteDateTime(CString strName, COleDateTime dtValue);
|
BOOL WriteDateTime(CString strName, COleDateTime dtValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user