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
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
/*
|
|
|
|
** CMeasureRegistry
|
|
|
|
**
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
CMeasureRegistry::CMeasureRegistry(CMeterWindow* meterWindow) : CMeasure(meterWindow)
|
|
|
|
{
|
|
|
|
m_RegKey = NULL;
|
|
|
|
m_HKey = NULL;
|
|
|
|
m_MaxValue = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ~CMeasureRegistry
|
|
|
|
**
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
CMeasureRegistry::~CMeasureRegistry()
|
|
|
|
{
|
|
|
|
if(m_RegKey) RegCloseKey(m_RegKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Update
|
|
|
|
**
|
|
|
|
** Gets the current value from the registry
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CMeasureRegistry::Update()
|
|
|
|
{
|
2010-09-23 08:49:43 +00:00
|
|
|
if (!CMeasure::PreUpdate()) return false;
|
2010-09-21 16:45:29 +00:00
|
|
|
|
2010-09-23 08:49:43 +00:00
|
|
|
if(m_RegKey != NULL)
|
|
|
|
{
|
|
|
|
DWORD size = 4096;
|
|
|
|
WCHAR data[4096];
|
|
|
|
DWORD type = 0;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-09-23 08:49:43 +00:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case REG_DWORD:
|
|
|
|
m_Value = *((LPDWORD)&data);
|
|
|
|
m_StringValue.erase();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REG_SZ:
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
case REG_MULTI_SZ:
|
|
|
|
m_Value = 0.0;
|
|
|
|
m_StringValue = data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REG_QWORD:
|
|
|
|
m_Value = (double)((LARGE_INTEGER*)&data)->QuadPart;
|
|
|
|
m_StringValue.erase();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // Other types are not supported
|
|
|
|
m_Value = 0.0;
|
|
|
|
m_StringValue.erase();
|
|
|
|
}
|
2010-09-21 16:45:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-23 08:49:43 +00:00
|
|
|
m_Value = 0.0;
|
|
|
|
m_StringValue.erase();
|
|
|
|
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
|
2010-09-21 16:45:29 +00:00
|
|
|
}
|
2010-09-23 08:49:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
|
|
|
|
}
|
2010-09-21 16:45:29 +00:00
|
|
|
|
2010-09-23 08:49:43 +00:00
|
|
|
return PostUpdate();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ReadConfig
|
|
|
|
**
|
|
|
|
** Reads the measure specific configs.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|
|
|
{
|
|
|
|
CMeasure::ReadConfig(parser, section);
|
|
|
|
|
2010-11-11 20:24:59 +00:00
|
|
|
std::wstring keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER");
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
if(_wcsicmp(keyname.c_str(), L"HKEY_CLASSES_ROOT") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_CLASSES_ROOT;
|
|
|
|
}
|
|
|
|
else if(_wcsicmp(keyname.c_str(), L"HKEY_CURRENT_CONFIG") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_CURRENT_CONFIG;
|
|
|
|
}
|
|
|
|
else if(_wcsicmp(keyname.c_str(), L"HKEY_CURRENT_USER") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_CURRENT_USER;
|
|
|
|
}
|
|
|
|
else if(_wcsicmp(keyname.c_str(), L"HKEY_LOCAL_MACHINE") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_LOCAL_MACHINE;
|
|
|
|
}
|
|
|
|
else if(_wcsicmp(keyname.c_str(), L"HKEY_CLASSES_ROOT") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_CLASSES_ROOT;
|
|
|
|
}
|
|
|
|
else if(_wcsicmp(keyname.c_str(), L"HKEY_PERFORMANCE_DATA") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_PERFORMANCE_DATA;
|
|
|
|
}
|
|
|
|
else if(_wcsicmp(keyname.c_str(), L"HKEY_DYN_DATA") == 0)
|
|
|
|
{
|
|
|
|
m_HKey = HKEY_DYN_DATA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-25 22:00:34 +00:00
|
|
|
std::wstring error = L"HKEY=" + keyname;
|
2010-11-25 15:34:49 +00:00
|
|
|
error += L" is not valid in measure [";
|
|
|
|
error += m_Name;
|
|
|
|
error += L"].";
|
|
|
|
throw CError(error, __LINE__, __FILE__);
|
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
|
2009-09-02 17:04:47 +00:00
|
|
|
if(m_RegKey) RegCloseKey(m_RegKey);
|
2010-09-21 16:45:29 +00:00
|
|
|
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** GetStringValue
|
|
|
|
**
|
|
|
|
** If the measured registry value is a string display it. Otherwise convert the
|
|
|
|
** value to string as normal.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
const WCHAR* CMeasureRegistry::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
|
|
|
|
{
|
2010-09-21 16:45:29 +00:00
|
|
|
if (m_StringValue.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
return CMeasure::GetStringValue(autoScale, scale, decimals, percentual);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CheckSubstitute(m_StringValue.c_str());
|
|
|
|
}
|
|
|
|
|