2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001 Kimmo Pekkola
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "MeasureRegistry.h"
|
|
|
|
#include "Rainmeter.h"
|
|
|
|
#include "Error.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2011-02-15 16:26:54 +00:00
|
|
|
CMeasureRegistry::CMeasureRegistry(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_RegKey(),
|
2012-04-06 16:54:20 +00:00
|
|
|
m_HKey(HKEY_CURRENT_USER)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_MaxValue = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
CMeasureRegistry::~CMeasureRegistry()
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
if (m_RegKey) RegCloseKey(m_RegKey);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Gets the current value from the registry
|
|
|
|
**
|
|
|
|
*/
|
2012-05-30 06:46:11 +00:00
|
|
|
void CMeasureRegistry::UpdateValue()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
if (m_RegKey != NULL)
|
2010-09-23 08:49:43 +00:00
|
|
|
{
|
|
|
|
DWORD size = 4096;
|
2011-02-15 13:22:19 +00:00
|
|
|
WCHAR* data = new WCHAR[size];
|
2010-09-23 08:49:43 +00:00
|
|
|
DWORD type = 0;
|
|
|
|
|
2012-05-30 06:56:20 +00:00
|
|
|
if (RegQueryValueEx(
|
|
|
|
m_RegKey,
|
|
|
|
m_RegValueName.c_str(),
|
|
|
|
NULL,
|
|
|
|
(LPDWORD)&type,
|
|
|
|
(LPBYTE)data,
|
|
|
|
(LPDWORD)&size) == ERROR_SUCCESS)
|
2010-09-21 16:45:29 +00:00
|
|
|
{
|
2011-09-08 14:39:25 +00:00
|
|
|
switch (type)
|
2010-09-23 08:49:43 +00:00
|
|
|
{
|
|
|
|
case REG_DWORD:
|
2011-05-02 07:43:42 +00:00
|
|
|
m_Value = *((LPDWORD)data);
|
2012-05-30 06:56:20 +00:00
|
|
|
m_StringValue.clear();
|
2010-09-23 08:49:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
case REG_MULTI_SZ:
|
2012-08-23 16:20:45 +00:00
|
|
|
m_Value = wcstod(data, NULL);
|
2010-09-23 08:49:43 +00:00
|
|
|
m_StringValue = data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REG_QWORD:
|
2011-05-02 07:43:42 +00:00
|
|
|
m_Value = (double)((LARGE_INTEGER*)data)->QuadPart;
|
2012-05-30 06:56:20 +00:00
|
|
|
m_StringValue.clear();
|
2010-09-23 08:49:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: // Other types are not supported
|
|
|
|
m_Value = 0.0;
|
2012-05-30 06:56:20 +00:00
|
|
|
m_StringValue.clear();
|
2010-09-23 08:49:43 +00:00
|
|
|
}
|
2010-09-21 16:45:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-23 08:49:43 +00:00
|
|
|
m_Value = 0.0;
|
2012-05-30 06:56:20 +00:00
|
|
|
m_StringValue.clear();
|
2010-09-23 08:49:43 +00:00
|
|
|
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
|
2010-09-21 16:45:29 +00:00
|
|
|
}
|
2011-02-15 13:22:19 +00:00
|
|
|
|
|
|
|
delete [] data;
|
2010-09-23 08:49:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-01 13:06:36 +00:00
|
|
|
** Read the options specified in the ini file.
|
2009-02-10 18:37:48 +00:00
|
|
|
**
|
|
|
|
*/
|
2012-05-30 18:53:44 +00:00
|
|
|
void CMeasureRegistry::ReadOptions(CConfigParser& parser, const WCHAR* section)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-30 18:53:44 +00:00
|
|
|
CMeasure::ReadOptions(parser, section);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER").c_str();
|
2011-11-21 12:53:55 +00:00
|
|
|
if (_wcsicmp(keyname, L"HKEY_CURRENT_USER") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_HKey = HKEY_CURRENT_USER;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(keyname, L"HKEY_LOCAL_MACHINE") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_HKey = HKEY_LOCAL_MACHINE;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(keyname, L"HKEY_CLASSES_ROOT") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_HKey = HKEY_CLASSES_ROOT;
|
|
|
|
}
|
2011-11-21 12:53:55 +00:00
|
|
|
else if (_wcsicmp(keyname, L"HKEY_CURRENT_CONFIG") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_CURRENT_CONFIG;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(keyname, L"HKEY_PERFORMANCE_DATA") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_HKey = HKEY_PERFORMANCE_DATA;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(keyname, L"HKEY_DYN_DATA") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_HKey = HKEY_DYN_DATA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-29 19:05:41 +00:00
|
|
|
CLogger_ErrorF(L"RegHKey=%s is not valid in [%s]", keyname, m_Name.c_str());
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_RegKeyName = parser.ReadString(section, L"RegKey", L"");
|
|
|
|
m_RegValueName = parser.ReadString(section, L"RegValue", L"");
|
|
|
|
|
|
|
|
if (m_MaxValue == 0.0)
|
|
|
|
{
|
|
|
|
m_MaxValue = 1.0;
|
|
|
|
m_LogMaxValue = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to open the key
|
2011-03-29 19:21:57 +00:00
|
|
|
if (m_RegKey) RegCloseKey(m_RegKey);
|
|
|
|
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** If the measured registry value is a string display it. Otherwise convert the
|
|
|
|
** value to string as normal.
|
|
|
|
**
|
|
|
|
*/
|
2013-04-10 15:59:41 +00:00
|
|
|
const WCHAR* CMeasureRegistry::GetStringValue()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-04-10 15:59:41 +00:00
|
|
|
return !m_StringValue.empty() ? CheckSubstitute(m_StringValue.c_str()) : NULL;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|