From e46b04eeb2636f43d8e9359d9ed002389fb53573 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 22 Jul 2003 03:10:13 +0000 Subject: [PATCH] cleanup --- stepmania/src/smpackage/Registry.cpp | 30 +++++++++++++++++----------- stepmania/src/smpackage/Registry.h | 23 ++++++++++----------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/stepmania/src/smpackage/Registry.cpp b/stepmania/src/smpackage/Registry.cpp index 25b6189eb6..0d8a03ee94 100644 --- a/stepmania/src/smpackage/Registry.cpp +++ b/stepmania/src/smpackage/Registry.cpp @@ -462,21 +462,26 @@ int CRegistry::ReadInt(CString strName, int nDefault) 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; DWORD dwSize = sizeof(b); - HKEY hKey; - - 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; + DWORD dwType = REG_BINARY; + int ret = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, &dwType, (LPBYTE)&b, &dwSize); ::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)) != ERROR_SUCCESS) bSuccess = FALSE; - if (!m_bLazyWrite) ::RegFlushKey(hKey); + if (!m_bLazyWrite) + ::RegFlushKey(hKey); ::RegCloseKey(hKey); return bSuccess; } diff --git a/stepmania/src/smpackage/Registry.h b/stepmania/src/smpackage/Registry.h index 481711478b..21dd72a51e 100644 --- a/stepmania/src/smpackage/Registry.h +++ b/stepmania/src/smpackage/Registry.h @@ -1,7 +1,5 @@ - - -#ifndef __REGISTRY_H__ -#define __REGISTRY_H__ +#ifndef REGISTRY_H +#define REGISTRY_H class CRegistry { @@ -9,7 +7,7 @@ public: CRegistry(); ~CRegistry(); -int m_nLastError; + int m_nLastError; // CRegistry properties protected: @@ -18,15 +16,10 @@ protected: CString m_strCurrentPath; public: - inline BOOL PathIsValid() { - return (m_strCurrentPath.GetLength() > 0); } - inline CString GetCurrentPath() { - return m_strCurrentPath; } - inline HKEY GetRootKey() { - return m_hRootKey; } + inline BOOL PathIsValid() const { return m_strCurrentPath.GetLength() > 0; } + inline CString GetCurrentPath() const { return m_strCurrentPath; } + inline HKEY GetRootKey() const { return m_hRootKey; } - -//CRegistry methods public: BOOL ClearKey(); BOOL SetRootKey(HKEY hRootKey); @@ -55,6 +48,10 @@ public: BOOL ReadRect(CString strName, CRect* pRect); 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 BOOL WriteBool(CString strName, BOOL bValue); BOOL WriteDateTime(CString strName, COleDateTime dtValue);