Fixing errors caused by r549.

This commit is contained in:
Birunthan Mohanathas 2010-09-23 08:49:43 +00:00
parent c1fda93526
commit 9da555a187
5 changed files with 344 additions and 334 deletions

View File

@ -53,58 +53,58 @@ CMeasureRegistry::~CMeasureRegistry()
*/ */
bool CMeasureRegistry::Update() bool CMeasureRegistry::Update()
{ {
if (!CMeasure::PreUpdate()) return false; if (!CMeasure::PreUpdate()) return false;
if(m_RegKey != NULL) 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)
{ {
DWORD size = 4096; switch(type)
WCHAR data[4096]; {
DWORD type = 0; case REG_DWORD:
m_Value = *((LPDWORD)&data);
m_StringValue.erase();
break;
if(RegQueryValueEx(m_RegKey, case REG_SZ:
m_RegValueName.c_str(), case REG_EXPAND_SZ:
NULL, case REG_MULTI_SZ:
(LPDWORD)&type, m_Value = 0.0;
(LPBYTE)&data, m_StringValue = data;
(LPDWORD)&size) == ERROR_SUCCESS) break;
{
switch(type)
{
case REG_DWORD:
m_Value = *((LPDWORD)&data);
m_StringValue.erase();
break;
case REG_SZ: case REG_QWORD:
case REG_EXPAND_SZ: m_Value = (double)((LARGE_INTEGER*)&data)->QuadPart;
case REG_MULTI_SZ: m_StringValue.erase();
m_Value = 0.0; break;
m_StringValue = data;
break;
case REG_QWORD: default: // Other types are not supported
m_Value = (double)((LARGE_INTEGER*)&data)->QuadPart; m_Value = 0.0;
m_StringValue.erase(); m_StringValue.erase();
break; }
default: // Other types are not supported
m_Value = 0.0;
m_StringValue.erase();
}
}
else
{
m_Value = 0.0;
m_StringValue.erase();
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
}
} }
else else
{ {
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey); m_Value = 0.0;
m_StringValue.erase();
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
} }
}
else
{
RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey);
}
return PostUpdate(); return PostUpdate();
} }
/* /*

View File

@ -1,288 +1,290 @@
/* /*
Copyright (C) 2005 Kimmo Pekkola, 2009 Greg Schoppe Copyright (C) 2005 Kimmo Pekkola, 2009 Greg Schoppe
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------ ------------
Usage: Usage:
[MeasureBin1] [MeasureBin1]
Measure=Plugin Measure=Plugin
Plugin=RecycleManager.dll Plugin=RecycleManager.dll
Drives=C: (for total system bin, use Drives=ALL :: for multiple drives use | as a delimiter e.g. Drives=A:|C:|D: will give the sum of these drives) Drives=C: (for total system bin, use Drives=ALL :: for multiple drives use | as a delimiter e.g. Drives=A:|C:|D: will give the sum of these drives)
RecycleType=COUNT (type can be COUNT for nomber of items or SIZE, for size in bytes) RecycleType=COUNT (type can be COUNT for nomber of items or SIZE, for size in bytes)
Update=1000 Update=1000
UpdateDivider=10 UpdateDivider=10
*/ */
#pragma warning(disable: 4786) #pragma warning(disable: 4786)
#pragma warning(disable: 4996) #pragma warning(disable: 4996)
#include <windows.h> #include <windows.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <map> #include <map>
#include <vector> #include <vector>
#include <time.h> #include <time.h>
#include "..\..\Library\Export.h" // Rainmeter's exported functions #include "..\..\Library\Export.h" // Rainmeter's exported functions
/* The exported functions */ /* The exported functions */
extern "C" extern "C"
{ {
__declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id); __declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
__declspec( dllexport ) void Finalize(HMODULE instance, UINT id); __declspec( dllexport ) void Finalize(HMODULE instance, UINT id);
__declspec( dllexport ) double Update2(UINT id); __declspec( dllexport ) double Update2(UINT id);
__declspec( dllexport ) UINT GetPluginVersion(); __declspec( dllexport ) UINT GetPluginVersion();
__declspec( dllexport ) LPCTSTR GetPluginAuthor(); __declspec( dllexport ) LPCTSTR GetPluginAuthor();
__declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id); __declspec( dllexport ) void ExecuteBang(LPCTSTR args, UINT id);
} }
//const int NUMRECYCLE = 1; //const int NUMRECYCLE = 1;
//const int SIZERECYCLE = 2; //const int SIZERECYCLE = 2;
//static std::map<UINT, int> g_Values; //static std::map<UINT, int> g_Values;
// system resources that can be counted // system resources that can be counted
enum MEASURETYPE enum MEASURETYPE
{ {
NUMRECYCLE, NUMRECYCLE,
SIZERECYCLE SIZERECYCLE
}; };
// list of counter types corresponding to gauges // list of counter types corresponding to gauges
static std::map<UINT, MEASURETYPE> g_Values; static std::map<UINT, MEASURETYPE> g_Values;
static std::map<UINT, std::wstring> g_DriveList; static std::map<UINT, std::wstring> g_DriveList;
/* /*
This function is called when the measure is initialized. This function is called when the measure is initialized.
The function must return the maximum value that can be measured. The function must return the maximum value that can be measured.
The return value can also be 0, which means that Rainmeter will The return value can also be 0, which means that Rainmeter will
track the maximum value automatically. The parameters for this track the maximum value automatically. The parameters for this
function are: function are:
instance The instance of this DLL instance The instance of this DLL
iniFile The name of the ini-file (usually Rainmeter.ini) iniFile The name of the ini-file (usually Rainmeter.ini)
section The name of the section in the ini-file for this measure section The name of the section in the ini-file for this measure
id The identifier for the measure. This is used to identify the measures that use the same plugin. id The identifier for the measure. This is used to identify the measures that use the same plugin.
*/ */
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
MEASURETYPE dataType = NUMRECYCLE; // 1 for numRecycled, 2 for sizeRecycled MEASURETYPE dataType = NUMRECYCLE; // 1 for numRecycled, 2 for sizeRecycled
/* Read our own settings from the ini-file */ /* Read our own settings from the ini-file */
LPCTSTR type = ReadConfigString(section, L"RecycleType", L"COUNT"); LPCTSTR type = ReadConfigString(section, L"RecycleType", L"COUNT");
if (type) if (type)
{ {
if (_wcsicmp(L"COUNT", type) == 0) if (_wcsicmp(L"COUNT", type) == 0)
{ {
dataType = NUMRECYCLE; dataType = NUMRECYCLE;
} }
else if (_wcsicmp(L"SIZE", type) == 0) else if (_wcsicmp(L"SIZE", type) == 0)
{ {
dataType = SIZERECYCLE; dataType = SIZERECYCLE;
} }
else else
{ {
std::wstring error = L"RecycleType="; std::wstring error = L"RecycleType=";
error += type; error += type;
error += L" is not valid in measure [" + section + L"]."; error += L" is not valid in measure [";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); error += section;
} error += L"].";
} MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
}
g_Values[id] = dataType; }
LPCTSTR drives = ReadConfigString(section, L"Drives", L"ALL"); g_Values[id] = dataType;
if (drives && wcslen(drives) > 0)
{ LPCTSTR drives = ReadConfigString(section, L"Drives", L"ALL");
g_DriveList[id] = drives; if (drives && wcslen(drives) > 0)
} {
else g_DriveList[id] = drives;
{ }
g_DriveList[id] = L"ALL"; else
} {
g_DriveList[id] = L"ALL";
return 0; }
}
return 0;
}
void Tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters = L"|")
{
// Skip delimiters at beginning. void Tokenize(const std::wstring& str, std::vector<std::wstring>& tokens, const std::wstring& delimiters = L"|")
std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0); {
// Find first "non-delimiter". // Skip delimiters at beginning.
std::wstring::size_type pos = str.find_first_of(delimiters, lastPos); std::wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
while (std::wstring::npos != pos || std::wstring::npos != lastPos) std::wstring::size_type pos = str.find_first_of(delimiters, lastPos);
{
// Found a token, add it to the vector. while (std::wstring::npos != pos || std::wstring::npos != lastPos)
tokens.push_back(str.substr(lastPos, pos - lastPos)); {
// Skip delimiters. Note the "not_of" // Found a token, add it to the vector.
lastPos = str.find_first_not_of(delimiters, pos); tokens.push_back(str.substr(lastPos, pos - lastPos));
// Find next "non-delimiter" // Skip delimiters. Note the "not_of"
pos = str.find_first_of(delimiters, lastPos); lastPos = str.find_first_not_of(delimiters, pos);
} // Find next "non-delimiter"
} pos = str.find_first_of(delimiters, lastPos);
}
/* }
This function is called when new value should be measured.
The function returns the new value. /*
*/ This function is called when new value should be measured.
double Update2(UINT id) The function returns the new value.
{ */
MEASURETYPE dataType = g_Values[id]; double Update2(UINT id)
std::wstring driveSet = g_DriveList[id]; {
MEASURETYPE dataType = g_Values[id];
SHQUERYRBINFO RecycleBinInfo = { 0 }; std::wstring driveSet = g_DriveList[id];
RecycleBinInfo.cbSize = sizeof( RecycleBinInfo ); // Tell size of structure
SHQUERYRBINFO RecycleBinInfo = { 0 };
if(_wcsicmp(driveSet.c_str(), L"ALL") == 0) RecycleBinInfo.cbSize = sizeof( RecycleBinInfo ); // Tell size of structure
{
if(SHQueryRecycleBin( NULL, &RecycleBinInfo ) == S_OK) if(_wcsicmp(driveSet.c_str(), L"ALL") == 0)
{ {
if (dataType == SIZERECYCLE) if(SHQueryRecycleBin( NULL, &RecycleBinInfo ) == S_OK)
{ {
return (double)RecycleBinInfo.i64Size; // size in bytes if (dataType == SIZERECYCLE)
} {
else if (dataType == NUMRECYCLE) return (double)RecycleBinInfo.i64Size; // size in bytes
{ }
return (double)RecycleBinInfo.i64NumItems; // number of items in bin else if (dataType == NUMRECYCLE)
} {
return 0; return (double)RecycleBinInfo.i64NumItems; // number of items in bin
} }
else return 0;
{ }
driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"; else
} {
} driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:";
std::vector<std::wstring> tokens; }
std::wstring toSplit(driveSet.begin(), driveSet.end()); }
double retVal = 0; std::vector<std::wstring> tokens;
Tokenize(toSplit, tokens, L"|"); std::wstring toSplit(driveSet.begin(), driveSet.end());
double retVal = 0;
for(int i=0;i < tokens.size(); i++) Tokenize(toSplit, tokens, L"|");
{
double tempVal; for(int i=0;i < tokens.size(); i++)
std::wstring strd = tokens.at(i); {
SHQueryRecycleBin( strd.c_str(), &RecycleBinInfo ); // Get recycle bin info double tempVal;
if (dataType == SIZERECYCLE) std::wstring strd = tokens.at(i);
{ SHQueryRecycleBin( strd.c_str(), &RecycleBinInfo ); // Get recycle bin info
tempVal = (double)RecycleBinInfo.i64Size; // size in bytes if (dataType == SIZERECYCLE)
} {
else if (dataType == NUMRECYCLE) tempVal = (double)RecycleBinInfo.i64Size; // size in bytes
{ }
tempVal = (double)RecycleBinInfo.i64NumItems; // number of items in bin else if (dataType == NUMRECYCLE)
} {
retVal += tempVal; tempVal = (double)RecycleBinInfo.i64NumItems; // number of items in bin
} }
retVal += tempVal;
return (retVal); }
}
return (retVal);
/* }
If the measure needs to free resources before quitting.
The plugin can export Finalize function, which is called /*
when Rainmeter quits (or refreshes). If the measure needs to free resources before quitting.
*/ The plugin can export Finalize function, which is called
void Finalize(HMODULE instance, UINT id) when Rainmeter quits (or refreshes).
{ */
std::map<UINT, MEASURETYPE>::iterator i1 = g_Values.find(id); void Finalize(HMODULE instance, UINT id)
if (i1 != g_Values.end()) {
{ std::map<UINT, MEASURETYPE>::iterator i1 = g_Values.find(id);
g_Values.erase(i1); if (i1 != g_Values.end())
} {
} g_Values.erase(i1);
}
UINT GetPluginVersion() }
{
return 1000; UINT GetPluginVersion()
} {
return 1000;
LPCTSTR GetPluginAuthor() }
{
return L"gschoppe (gschoppe@gmail.com)"; LPCTSTR GetPluginAuthor()
} {
return L"gschoppe (gschoppe@gmail.com)";
void ExecuteBang(LPCTSTR args, UINT id) }
{
std::wstring bang = args; void ExecuteBang(LPCTSTR args, UINT id)
std::wstring driveSet = g_DriveList[id]; {
std::wstring bang = args;
if (_wcsicmp(bang.c_str(), L"EmptyBin") == 0) std::wstring driveSet = g_DriveList[id];
{ //Empty the Recycle Bin
if(_wcsicmp(driveSet.c_str(), L"ALL") == 0) if (_wcsicmp(bang.c_str(), L"EmptyBin") == 0)
{ { //Empty the Recycle Bin
if(SHEmptyRecycleBin( NULL, NULL, NULL ) == S_OK) if(_wcsicmp(driveSet.c_str(), L"ALL") == 0)
{ {
return; if(SHEmptyRecycleBin( NULL, NULL, NULL ) == S_OK)
} {
else return;
{ }
driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"; else
} {
} driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:";
std::vector<std::wstring> tokens; }
std::wstring toSplit(driveSet.begin(), driveSet.end()); }
Tokenize(toSplit, tokens, L"|"); std::vector<std::wstring> tokens;
std::wstring toSplit(driveSet.begin(), driveSet.end());
for(int i=0;i < tokens.size(); i++) Tokenize(toSplit, tokens, L"|");
{
std::wstring strd = tokens.at(i); for(int i=0;i < tokens.size(); i++)
SHEmptyRecycleBin( NULL, strd.c_str(), NULL ); // empty bin {
} std::wstring strd = tokens.at(i);
return; SHEmptyRecycleBin( NULL, strd.c_str(), NULL ); // empty bin
} }
else return;
{ }
if (_wcsicmp(bang.c_str(), L"EmptyBinSilent") == 0) else
{ //Empty the Recycle Bin (no prompt) {
if(_wcsicmp(driveSet.c_str(), L"ALL") == 0) if (_wcsicmp(bang.c_str(), L"EmptyBinSilent") == 0)
{ { //Empty the Recycle Bin (no prompt)
if(SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ) == S_OK) if(_wcsicmp(driveSet.c_str(), L"ALL") == 0)
{ {
return; if(SHEmptyRecycleBin( NULL, NULL, SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ) == S_OK)
} {
else return;
{ }
driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:"; else
} {
} driveSet = L"A:|B:|C:|D:|E:|F:|G:|H:|I:|J:|K:|L:|M:|N:|O:|P:|Q:|R:|S:|T:|U:|V:|W:|X:|Y:|Z:";
std::vector<std::wstring> tokens; }
std::wstring toSplit(driveSet.begin(), driveSet.end()); }
Tokenize(toSplit, tokens, L"|"); std::vector<std::wstring> tokens;
std::wstring toSplit(driveSet.begin(), driveSet.end());
for(int i=0;i < tokens.size(); i++) Tokenize(toSplit, tokens, L"|");
{
std::wstring strd = tokens.at(i); for(int i=0;i < tokens.size(); i++)
SHEmptyRecycleBin( NULL, strd.c_str(), SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); // empty bin {
} std::wstring strd = tokens.at(i);
return; SHEmptyRecycleBin( NULL, strd.c_str(), SHERB_NOCONFIRMATION | SHERB_NOPROGRESSUI | SHERB_NOSOUND ); // empty bin
} }
else if (_wcsicmp(bang.c_str(), L"OpenBin") == 0) return;
{ //Open the Recycle Bin folder }
//system("explorer.exe /N,::{645FF040-5081-101B-9F08-00AA002F954E}"); else if (_wcsicmp(bang.c_str(), L"OpenBin") == 0)
std::wstring szCmd = L"explorer.exe"; { //Open the Recycle Bin folder
std::wstring szParm= L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}"; //system("explorer.exe /N,::{645FF040-5081-101B-9F08-00AA002F954E}");
ShellExecute(NULL,L"open",szCmd.c_str(),szParm.c_str(),NULL,SW_SHOW); std::wstring szCmd = L"explorer.exe";
return; std::wstring szParm= L"/N,::{645FF040-5081-101B-9F08-00AA002F954E}";
} ShellExecute(NULL,L"open",szCmd.c_str(),szParm.c_str(),NULL,SW_SHOW);
} return;
} }
}
}

View File

@ -115,7 +115,9 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
std::wstring error = L"GDICountType="; std::wstring error = L"GDICountType=";
error += type; error += type;
error += L" is not valid in measure [" + section + L"]."; error += L" is not valid in measure [";
error += section;
error += L"].";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
} }
} }

View File

@ -113,7 +113,9 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
std::wstring error = L"SpeedFanScale="; std::wstring error = L"SpeedFanScale=";
error += scale; error += scale;
error += L" is not valid in measure [" + section + L"]." ; error += L" is not valid in measure [";
error += section;
error += L"].";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
} }
} }
@ -130,7 +132,9 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
std::wstring error = L"SpeedFanType="; std::wstring error = L"SpeedFanType=";
error += type; error += type;
error += L" is not valid in measure [" + section + L"]." ; error += L" is not valid in measure [";
error += section;
error += L"].";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
} }
} }

View File

@ -209,7 +209,9 @@ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
std::wstring error = L"SysInfoType="; std::wstring error = L"SysInfoType=";
error += type; error += type;
error += L" is not valid in measure [" + section + L"]." ; error += L" is not valid in measure [";
error += section;
error += L"].";
MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, error.c_str(), L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
} }
} }