Code optimization and removed unused part for reducing core dll size.

This commit is contained in:
spx 2010-11-11 20:24:59 +00:00
parent 2bf3299ded
commit cab258a7e5
25 changed files with 257 additions and 350 deletions

View File

@ -201,12 +201,11 @@ void UpdateAboutStatistics(LPCTSTR entryName)
const WCHAR* name = (*i)->GetName(); const WCHAR* name = (*i)->GetName();
const WCHAR* val = (*i)->GetStats(); const WCHAR* val = (*i)->GetStats();
std::wstring range;
WCHAR buffer[256]; WCHAR buffer[256];
double minVal = (*i)->GetMinValue(); double minVal = (*i)->GetMinValue();
double maxVal = (*i)->GetMaxValue(); double maxVal = (*i)->GetMaxValue();
CMeasure::GetScaledValue(1, minVal, buffer); CMeasure::GetScaledValue(1, minVal, buffer);
range = buffer; std::wstring range = buffer;
range += L" - "; range += L" - ";
CMeasure::GetScaledValue(1, maxVal, buffer); CMeasure::GetScaledValue(1, maxVal, buffer);
range += buffer; range += buffer;

View File

@ -36,7 +36,7 @@ const WCHAR* CError::c_ErrorStrings[] =
*/ */
const std::wstring& CError::GetString() const std::wstring& CError::GetString()
{ {
static WCHAR Buffer[16]; // static WCHAR Buffer[16];
if (m_Error != ERROR_USER) if (m_Error != ERROR_USER)
{ {

View File

@ -35,12 +35,12 @@ public:
ERROR_CREATE_WINDOW ERROR_CREATE_WINDOW
}; };
CError(const std::wstring& String) { m_Error = ERROR_USER; m_String = String; m_File = NULL; }; CError(const std::wstring& String) : m_Error(ERROR_USER), m_String(String), m_File(NULL) {}
CError(const WCHAR* String ) { m_Error = ERROR_USER; m_String = String; m_File = NULL; }; CError(const WCHAR* String ) : m_Error(ERROR_USER), m_String(String), m_File(NULL) {}
CError(const std::wstring& String, int Line, const char* File) { m_Error = ERROR_USER; m_String = String; m_Line = Line; m_File = File; }; CError(const std::wstring& String, int Line, const char* File) : m_Error(ERROR_USER), m_String(String), m_Line(Line), m_File(File) {}
CError(const WCHAR* String, int Line, const char* File) { m_Error = ERROR_USER; m_String = String; m_Line = Line; m_File = File; }; CError(const WCHAR* String, int Line, const char* File) : m_Error(ERROR_USER), m_String(String), m_Line(Line), m_File(File) {}
CError(RAINERROR Error) { m_Error = Error; m_File = NULL; }; CError(RAINERROR Error) : m_Error(Error), m_File(NULL) {}
CError(RAINERROR Error, int Line, const char* File) { m_Error = Error; m_Line = Line; m_File = File; }; CError(RAINERROR Error, int Line, const char* File) : m_Error(Error), m_Line(Line), m_File(File) {}
const std::wstring& GetString(); const std::wstring& GetString();

View File

@ -47,7 +47,7 @@ extern CRainmeter* Rainmeter;
** The constructor ** The constructor
** **
*/ */
CMeasure::CMeasure(CMeterWindow* meterWindow) CMeasure::CMeasure(CMeterWindow* meterWindow) : m_MeterWindow(meterWindow)
{ {
m_Invert = false; m_Invert = false;
m_LogMaxValue = false; m_LogMaxValue = false;
@ -68,8 +68,6 @@ CMeasure::CMeasure(CMeterWindow* meterWindow)
m_AverageSize = 0; m_AverageSize = 0;
m_DynamicVariables = false; m_DynamicVariables = false;
m_Initialized = false; m_Initialized = false;
m_MeterWindow = meterWindow;
} }
/* /*
@ -147,8 +145,7 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0); m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
std::wstring subs; std::wstring subs = parser.ReadString(section, L"Substitute", L"");
subs = parser.ReadString(section, L"Substitute", L"");
if (!subs.empty() && if (!subs.empty() &&
(subs[0] != L'\"' || subs[subs.length() - 1] != L'\'') && (subs[0] != L'\"' || subs[subs.length() - 1] != L'\'') &&
(subs[0] != L'\'' || subs[subs.length() - 1] != L'\"')) (subs[0] != L'\'' || subs[subs.length() - 1] != L'\"'))
@ -220,16 +217,12 @@ bool CMeasure::ParseSubstitute(std::wstring buffer)
{ {
if (buffer.empty()) return true; if (buffer.empty()) return true;
std::wstring word1;
std::wstring word2;
std::wstring sep;
while (!buffer.empty()) while (!buffer.empty())
{ {
word1 = ExtractWord(buffer); std::wstring word1 = ExtractWord(buffer);
sep = ExtractWord(buffer); std::wstring sep = ExtractWord(buffer);
if (sep != L":") return false; if (sep != L":") return false;
word2 = ExtractWord(buffer); std::wstring word2 = ExtractWord(buffer);
if (word1 != word2) if (word1 != word2)
{ {

View File

@ -27,7 +27,8 @@
#define SystemProcessorPerformanceInformation 8 #define SystemProcessorPerformanceInformation 8
#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart)) //#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
#define Li2Double(x) ((double)((x).QuadPart))
#define Ft2Double(x) ((double)((x).dwHighDateTime) * 4.294967296E9 + (double)((x).dwLowDateTime)) #define Ft2Double(x) ((double)((x).dwHighDateTime) * 4.294967296E9 + (double)((x).dwLowDateTime))
// ntdll!NtQuerySystemInformation (NT specific!) // ntdll!NtQuerySystemInformation (NT specific!)
@ -56,7 +57,6 @@
*/ */
CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow) : CMeasure(meterWindow) CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow) : CMeasure(meterWindow)
{ {
m_CPUFromRegistry = false;
m_MaxValue = 100.0; m_MaxValue = 100.0;
m_MinValue = 0.0; m_MinValue = 0.0;
m_FirstTime = true; m_FirstTime = true;
@ -85,19 +85,6 @@ CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow) : CMeasure(meterWindow)
*/ */
CMeasureCPU::~CMeasureCPU() CMeasureCPU::~CMeasureCPU()
{ {
if(m_CPUFromRegistry)
{
// Stop the counter if it was started
HKEY hkey;
DWORD dwDataSize;
DWORD dwType;
DWORD dwDummy;
RegOpenKeyEx(HKEY_DYN_DATA, L"PerfStats\\StopStat", 0, KEY_ALL_ACCESS, &hkey);
dwDataSize = sizeof(dwDummy);
RegQueryValueEx(hkey, L"KERNEL\\CPUUsage", NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize);
RegCloseKey(hkey);
}
} }
/* /*
@ -141,132 +128,102 @@ void CMeasureCPU::ReadConfig(CConfigParser& parser, const WCHAR* section)
/* /*
** Update ** Update
** **
** Updates the current CPU utilization value. On NT the value is taken ** Updates the current CPU utilization value.
** from the performance counters and on 9x we'll use the registry.
** **
*/ */
bool CMeasureCPU::Update() bool CMeasureCPU::Update()
{ {
if (!CMeasure::PreUpdate()) return false; if (!CMeasure::PreUpdate()) return false;
if (CSystem::IsNT()) if (m_Processor == 0 && m_GetSystemTimes)
{ {
if (m_Processor == 0 && m_GetSystemTimes) BOOL status;
FILETIME ftIdleTime, ftKernelTime, ftUserTime;
// get new CPU's idle/kernel/user time
status = m_GetSystemTimes(&ftIdleTime, &ftKernelTime, &ftUserTime);
if (status == 0) return false;
CalcUsage(Ft2Double(ftIdleTime),
Ft2Double(ftKernelTime) + Ft2Double(ftUserTime));
}
else if (m_NtQuerySystemInformation)
{
LONG status;
BYTE* buf = NULL;
ULONG bufSize = 0;
int loop = 0;
do
{ {
BOOL status; ULONG size = 0;
FILETIME ftIdleTime, ftKernelTime, ftUserTime;
// get new CPU's idle/kernel/user time status = m_NtQuerySystemInformation(SystemProcessorPerformanceInformation, buf, bufSize, &size);
status = m_GetSystemTimes(&ftIdleTime, &ftKernelTime, &ftUserTime); if (status == STATUS_SUCCESS) break;
if (status == 0) return false;
CalcUsage(Ft2Double(ftIdleTime), if (status == STATUS_INFO_LENGTH_MISMATCH)
Ft2Double(ftKernelTime) + Ft2Double(ftUserTime));
}
else if (m_NtQuerySystemInformation)
{
LONG status;
BYTE* buf = NULL;
ULONG bufSize = 0;
int loop = 0;
do
{ {
ULONG size = 0; if (size == 0) // Returned required buffer size is always 0 on Windows 2000/XP.
status = m_NtQuerySystemInformation(SystemProcessorPerformanceInformation, buf, bufSize, &size);
if (status == STATUS_SUCCESS) break;
if (status == STATUS_INFO_LENGTH_MISMATCH)
{ {
if (size == 0) // Returned required buffer size is always 0 on Windows 2000/XP. if (bufSize == 0)
{ {
if (bufSize == 0) bufSize = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * m_NumOfProcessors;
{
bufSize = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * m_NumOfProcessors;
}
else
{
bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
}
} }
else else
{ {
if (size != bufSize) bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
{
bufSize = size;
}
else // ??
{
bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
}
} }
if (buf) delete [] buf;
buf = new BYTE[bufSize];
} }
else // failed else
{ {
if (buf) delete [] buf; if (size != bufSize)
return false; {
bufSize = size;
}
else // ??
{
bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
}
} }
++loop; if (buf) delete [] buf;
} while (loop < 10); buf = new BYTE[bufSize];
}
if (status != STATUS_SUCCESS) // failed else // failed
{ {
if (buf) delete [] buf; if (buf) delete [] buf;
return false; return false;
} }
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)buf; ++loop;
} while (loop < 10);
if (m_Processor == 0) if (status != STATUS_SUCCESS) // failed
{ {
CalcAverageUsage(systemPerfInfo); if (buf) delete [] buf;
} return false;
else }
{
int processor = m_Processor - 1;
CalcUsage(Li2Double(systemPerfInfo[processor].IdleTime), SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)buf;
Li2Double(systemPerfInfo[processor].KernelTime) + Li2Double(systemPerfInfo[processor].UserTime));
}
delete [] buf; if (m_Processor == 0)
{
CalcAverageUsage(systemPerfInfo);
} }
else else
{ {
return false; int processor = m_Processor - 1;
CalcUsage(Li2Double(systemPerfInfo[processor].IdleTime),
Li2Double(systemPerfInfo[processor].KernelTime) + Li2Double(systemPerfInfo[processor].UserTime));
} }
delete [] buf;
} }
else else
{ {
// It's a wintendo! return false;
HKEY hkey;
DWORD dwDataSize;
DWORD dwType;
DWORD dwCpuUsage;
if(m_FirstTime)
{
RegOpenKeyEx(HKEY_DYN_DATA, L"PerfStats\\StartStat", 0, KEY_ALL_ACCESS, &hkey);
dwDataSize = sizeof(dwCpuUsage);
RegQueryValueEx(hkey, L"KERNEL\\CPUUsage", NULL, &dwType, (LPBYTE)&dwCpuUsage, &dwDataSize);
RegCloseKey(hkey);
m_FirstTime = false;
}
RegOpenKeyEx(HKEY_DYN_DATA, L"PerfStats\\StatData", 0, KEY_ALL_ACCESS, &hkey);
dwDataSize = sizeof(dwCpuUsage);
RegQueryValueEx(hkey, L"KERNEL\\CPUUsage", NULL, &dwType, (LPBYTE)&dwCpuUsage, &dwDataSize);
RegCloseKey(hkey);
m_Value = dwCpuUsage;
m_CPUFromRegistry = true;
} }
return PostUpdate(); return PostUpdate();

View File

@ -45,7 +45,6 @@ protected:
void CalcUsage(double idleTime, double systemTime); void CalcUsage(double idleTime, double systemTime);
void CalcAverageUsage(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo); void CalcAverageUsage(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo);
bool m_CPUFromRegistry;
bool m_FirstTime; bool m_FirstTime;
int m_Processor; int m_Processor;

View File

@ -117,8 +117,7 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
{ {
CMeasure::ReadConfig(parser, section); CMeasure::ReadConfig(parser, section);
std::wstring keyname; std::wstring keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER");
keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER");
if(_wcsicmp(keyname.c_str(), L"HKEY_CLASSES_ROOT") == 0) if(_wcsicmp(keyname.c_str(), L"HKEY_CLASSES_ROOT") == 0)
{ {

View File

@ -233,8 +233,7 @@ void CMeasureTime::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_Format = parser.ReadString(section, L"Format", L""); m_Format = parser.ReadString(section, L"Format", L"");
std::wstring timezone; std::wstring timezone = parser.ReadString(section, L"TimeZone", L"local");
timezone = parser.ReadString(section, L"TimeZone", L"local");
bool dst = 1 == parser.ReadInt(section, L"DaylightSavingTime", 1); bool dst = 1 == parser.ReadInt(section, L"DaylightSavingTime", 1);
SYSTEMTIME sysLocalTime, sysUTCTime; SYSTEMTIME sysLocalTime, sysUTCTime;

View File

@ -39,7 +39,7 @@ using namespace Gdiplus;
** The constructor ** The constructor
** **
*/ */
CMeter::CMeter(CMeterWindow* meterWindow) CMeter::CMeter(CMeterWindow* meterWindow) : m_MeterWindow(meterWindow)
{ {
m_Measure = NULL; m_Measure = NULL;
@ -64,8 +64,6 @@ CMeter::CMeter(CMeterWindow* meterWindow)
m_ToolTipHidden = false; m_ToolTipHidden = false;
m_ToolTipHandle = NULL; m_ToolTipHandle = NULL;
m_MeterWindow = meterWindow;
} }
/* /*

View File

@ -34,16 +34,12 @@ extern CRainmeter* Rainmeter;
** The constructor ** The constructor
** **
*/ */
CMeterBar::CMeterBar(CMeterWindow* meterWindow) : CMeterImage(meterWindow) CMeterBar::CMeterBar(CMeterWindow* meterWindow) : CMeterImage(meterWindow, L"ImageW", L"ImageH"),
m_Color(Color::Green)
{ {
m_Color = 0;
m_Bitmap = NULL;
m_Value = 0.0; m_Value = 0.0;
m_Border = 0; m_Border = 0;
m_Flip = false; m_Flip = false;
m_ImageWidthString = L"ImageW";
m_ImageHeightString = L"ImageH";
} }
/* /*
@ -118,8 +114,7 @@ void CMeterBar::ReadConfig(const WCHAR* section)
m_Flip = parser.ReadInt(section, L"Flip", 0) == 1; m_Flip = parser.ReadInt(section, L"Flip", 0) == 1;
std::wstring orientation; std::wstring orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL");
orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL");
if(_wcsicmp(L"VERTICAL", orientation.c_str()) == 0) if(_wcsicmp(L"VERTICAL", orientation.c_str()) == 0)
{ {
@ -182,8 +177,9 @@ bool CMeterBar::Draw(Graphics& graphics)
if(m_Orientation == VERTICAL) if(m_Orientation == VERTICAL)
{ {
int size = (int)((m_H - 2 * m_Border) * m_Value); int barSize = m_H - 2 * m_Border;
size = min(m_H - 2 * m_Border, size); int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size); size = max(0, size);
if (drawBitmap) if (drawBitmap)
@ -234,8 +230,9 @@ bool CMeterBar::Draw(Graphics& graphics)
} }
else else
{ {
int size = (int)((m_W - 2 * m_Border) * m_Value); int barSize = m_W - 2 * m_Border;
size = min(m_W - 2 * m_Border, size); int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size); size = max(0, size);
if (drawBitmap) if (drawBitmap)

View File

@ -115,11 +115,6 @@ bool CMeterBitmap::HitTest(int x, int y)
{ {
if (m_Extend) if (m_Extend)
{ {
int value = (int)m_Value;
value = max(0, value); // Only positive integers are supported
int tmpValue = value;
// Calc the number of numbers // Calc the number of numbers
int numOfNums = 0; int numOfNums = 0;
@ -129,6 +124,9 @@ bool CMeterBitmap::HitTest(int x, int y)
} }
else else
{ {
int tmpValue = (int)m_Value;
tmpValue = max(0, tmpValue); // Only positive integers are supported
int realFrames = (m_FrameCount / (m_TransitionFrameCount + 1)); int realFrames = (m_FrameCount / (m_TransitionFrameCount + 1));
do do
{ {
@ -197,8 +195,7 @@ void CMeterBitmap::ReadConfig(const WCHAR* section)
m_TransitionFrameCount = parser.ReadInt(section, L"BitmapTransitionFrames", 0); m_TransitionFrameCount = parser.ReadInt(section, L"BitmapTransitionFrames", 0);
std::wstring align; std::wstring align = parser.ReadString(section, L"BitmapAlign", L"LEFT");
align = parser.ReadString(section, L"BitmapAlign", L"LEFT");
if(_wcsicmp(align.c_str(), L"LEFT") == 0) if(_wcsicmp(align.c_str(), L"LEFT") == 0)
{ {
@ -242,15 +239,7 @@ bool CMeterBitmap::Update()
{ {
if (CMeter::Update() && m_Measure) if (CMeter::Update() && m_Measure)
{ {
double value = 0.0; double value = (m_Extend) ? m_Measure->GetValue() : m_Measure->GetRelativeValue();
if (m_Extend)
{
value = m_Measure->GetValue();
}
else
{
value = m_Measure->GetRelativeValue();
}
if (m_TransitionFrameCount > 0) if (m_TransitionFrameCount > 0)
{ {
@ -314,7 +303,6 @@ bool CMeterBitmap::Draw(Graphics& graphics)
int transitionValue = (int)m_TransitionStartValue; int transitionValue = (int)m_TransitionStartValue;
transitionValue = max(0, transitionValue); // Only positive integers are supported transitionValue = max(0, transitionValue); // Only positive integers are supported
int tmpValue = value;
// Calc the number of numbers // Calc the number of numbers
int numOfNums = 0; int numOfNums = 0;
@ -324,6 +312,8 @@ bool CMeterBitmap::Draw(Graphics& graphics)
} }
else else
{ {
int tmpValue = value;
do do
{ {
++numOfNums; ++numOfNums;

View File

@ -32,12 +32,12 @@ extern CRainmeter* Rainmeter;
** The constructor ** The constructor
** **
*/ */
CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow) : CMeter(meterWindow),
m_PrimaryColor(Color::Green),
m_SecondaryColor(Color::Red),
m_BothColor(Color::Yellow)
{ {
m_SecondaryMeasure = NULL; m_SecondaryMeasure = NULL;
m_PrimaryColor = 0;
m_SecondaryColor = 0;
m_BothColor = 0;
m_MeterPos = 0; m_MeterPos = 0;
m_PrimaryBitmap = NULL; m_PrimaryBitmap = NULL;
m_SecondaryBitmap = NULL; m_SecondaryBitmap = NULL;
@ -342,30 +342,44 @@ bool CMeterHistogram::Update()
// Go through all values and find the max // Go through all values and find the max
double newValue = 0; double newValue = 0;
for (int i = 0; i != m_W; ++i) for (int i = 0; i < m_W; ++i)
{ {
newValue = max(newValue, m_PrimaryValues[i]); newValue = max(newValue, m_PrimaryValues[i]);
} }
// Scale the value up to nearest power of 2 // Scale the value up to nearest power of 2
m_MaxPrimaryValue = 2; if (newValue > DBL_MAX / 2.0)
while(m_MaxPrimaryValue < newValue && m_MaxPrimaryValue != 0)
{ {
m_MaxPrimaryValue *= 2; m_MaxPrimaryValue = DBL_MAX;
}
else
{
m_MaxPrimaryValue = 2.0;
while (m_MaxPrimaryValue < newValue)
{
m_MaxPrimaryValue *= 2.0;
}
} }
if (m_SecondaryMeasure && m_SecondaryValues) if (m_SecondaryMeasure && m_SecondaryValues)
{ {
for (int i = 0; i != m_W; ++i) for (int i = 0; i < m_W; ++i)
{ {
newValue = max(newValue, m_SecondaryValues[i]); newValue = max(newValue, m_SecondaryValues[i]);
} }
// Scale the value up to nearest power of 2 // Scale the value up to nearest power of 2
m_MaxSecondaryValue = 2; if (newValue > DBL_MAX / 2.0)
while(m_MaxSecondaryValue < newValue && m_MaxSecondaryValue != 0)
{ {
m_MaxSecondaryValue *= 2; m_MaxSecondaryValue = DBL_MAX;
}
else
{
m_MaxSecondaryValue = 2.0;
while (m_MaxSecondaryValue < newValue)
{
m_MaxSecondaryValue *= 2.0;
}
} }
} }
} }
@ -426,15 +440,7 @@ bool CMeterHistogram::Draw(Graphics& graphics)
secondaryBarHeight = max(0, secondaryBarHeight); secondaryBarHeight = max(0, secondaryBarHeight);
// Check which measured value is higher // Check which measured value is higher
int bothBarHeight; int bothBarHeight = min(primaryBarHeight, secondaryBarHeight);
if (secondaryBarHeight > primaryBarHeight)
{
bothBarHeight = primaryBarHeight;
}
else
{
bothBarHeight = secondaryBarHeight;
}
// Draw image/color for the both lines // Draw image/color for the both lines
if (m_PrimaryBitmap) if (m_PrimaryBitmap)

View File

@ -51,7 +51,8 @@ const Gdiplus::ColorMatrix CMeterImage::c_IdentifyMatrix = {
** The constructor ** The constructor
** **
*/ */
CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterImage::CMeterImage(CMeterWindow* meterWindow, WCHAR* wName, WCHAR* hName) : CMeter(meterWindow), m_ImageWidthString(wName), m_ImageHeightString(hName),
m_ColorMatrix(c_IdentifyMatrix)
{ {
m_Bitmap = NULL; m_Bitmap = NULL;
m_BitmapTint = NULL; m_BitmapTint = NULL;
@ -66,12 +67,8 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow)
m_Modified.dwLowDateTime = 0; m_Modified.dwLowDateTime = 0;
m_GreyScale = false; m_GreyScale = false;
m_ColorMatrix = c_IdentifyMatrix;
m_Flip = RotateNoneFlipNone; m_Flip = RotateNoneFlipNone;
m_Rotate = 0.0f; m_Rotate = 0.0f;
m_ImageWidthString = L"W";
m_ImageHeightString = L"H";
} }
/* /*
@ -522,8 +519,7 @@ void CMeterImage::ReadConfig(const WCHAR* section)
m_NeedsTinting = (oldGreyScale != m_GreyScale || !CompareColorMatrix(oldColorMatrix, m_ColorMatrix)); m_NeedsTinting = (oldGreyScale != m_GreyScale || !CompareColorMatrix(oldColorMatrix, m_ColorMatrix));
std::wstring flip; std::wstring flip = parser.ReadString(section, L"ImageFlip", L"NONE");
flip = parser.ReadString(section, L"ImageFlip", L"NONE");
if(_wcsicmp(flip.c_str(), L"NONE") == 0) if(_wcsicmp(flip.c_str(), L"NONE") == 0)
{ {

View File

@ -30,7 +30,7 @@ namespace Gdiplus
class CMeterImage : public CMeter class CMeterImage : public CMeter
{ {
public: public:
CMeterImage(CMeterWindow* meterWindow); CMeterImage(CMeterWindow* meterWindow, WCHAR* wName = L"W", WCHAR* hName = L"H");
virtual ~CMeterImage(); virtual ~CMeterImage();
virtual void ReadConfig(const WCHAR* section); virtual void ReadConfig(const WCHAR* section);
@ -40,14 +40,15 @@ public:
virtual void BindMeasure(std::list<CMeasure*>& measures); virtual void BindMeasure(std::list<CMeasure*>& measures);
protected: protected:
std::wstring m_ImageWidthString;
std::wstring m_ImageHeightString;
void LoadImage(bool bLoadAlways); void LoadImage(bool bLoadAlways);
bool CompareColorMatrix(const Gdiplus::ColorMatrix& a, const Gdiplus::ColorMatrix& b); bool CompareColorMatrix(const Gdiplus::ColorMatrix& a, const Gdiplus::ColorMatrix& b);
void ApplyTint(); void ApplyTint();
Gdiplus::Bitmap* TurnGreyscale(); Gdiplus::Bitmap* TurnGreyscale();
void ApplyTransform(); void ApplyTransform();
const std::wstring m_ImageWidthString;
const std::wstring m_ImageHeightString;
Gdiplus::Bitmap* m_Bitmap; // The bitmap Gdiplus::Bitmap* m_Bitmap; // The bitmap
Gdiplus::Bitmap* m_BitmapTint; // The bitmap Gdiplus::Bitmap* m_BitmapTint; // The bitmap
std::wstring m_ImageName; // Name of the image std::wstring m_ImageName; // Name of the image

View File

@ -29,11 +29,11 @@ using namespace Gdiplus;
** The constructor ** The constructor
** **
*/ */
CMeterLine::CMeterLine(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterLine::CMeterLine(CMeterWindow* meterWindow) : CMeter(meterWindow),
m_HorizontalColor(Color::Black)
{ {
m_Autoscale = false; m_Autoscale = false;
m_HorizontalLines = false; m_HorizontalLines = false;
m_HorizontalColor = 0;
m_CurrentPos = 0; m_CurrentPos = 0;
m_Flip = false; m_Flip = false;
m_LineWidth = 1.0; m_LineWidth = 1.0;
@ -224,19 +224,28 @@ bool CMeterLine::Draw(Graphics& graphics)
counter = 0; counter = 0;
for (; i != m_AllValues.end(); ++i) for (; i != m_AllValues.end(); ++i)
{ {
double scale = m_ScaleValues[counter];
std::vector<double>::const_iterator j = (*i).begin(); std::vector<double>::const_iterator j = (*i).begin();
for (; j != (*i).end(); ++j) for (; j != (*i).end(); ++j)
{ {
newValue = max(newValue, (*j) * m_ScaleValues[counter]); double val = (*j) * scale;
newValue = max(newValue, val);
} }
++counter; ++counter;
} }
// Scale the value up to nearest power of 2 // Scale the value up to nearest power of 2
maxValue = 2; if (newValue > DBL_MAX / 2.0)
while(maxValue < newValue && maxValue != 0)
{ {
maxValue *= 2; maxValue = DBL_MAX;
}
else
{
maxValue = 2.0;
while (maxValue < newValue)
{
maxValue *= 2.0;
}
} }
} }
else else
@ -248,14 +257,15 @@ bool CMeterLine::Draw(Graphics& graphics)
std::vector<CMeasure*>::const_iterator i = m_Measures.begin(); std::vector<CMeasure*>::const_iterator i = m_Measures.begin();
for (; i != m_Measures.end(); ++i) for (; i != m_Measures.end(); ++i)
{ {
maxValue = max(maxValue, (*i)->GetMaxValue()); double val = (*i)->GetMaxValue();
maxValue = max(maxValue, val);
} }
} }
}
if (maxValue == 0.0) if (maxValue == 0.0)
{ {
maxValue = 1.0; maxValue = 1.0;
}
} }
int x = GetX(); int x = GetX();
@ -294,47 +304,41 @@ bool CMeterLine::Draw(Graphics& graphics)
for (; i != m_AllValues.end(); ++i) for (; i != m_AllValues.end(); ++i)
{ {
// Draw a line // Draw a line
int X = x; REAL Y = 0.0f;
REAL Y = 0; REAL oldY = 0.0f;
REAL oldY = 0; REAL H = m_H - 1.0f;
int pos = m_CurrentPos;
if (pos >= m_W) pos = 0;
double scale = m_ScaleValues[counter] * H / maxValue;
int pos = m_CurrentPos;
int size = (int)(*i).size(); int size = (int)(*i).size();
Pen pen(m_Colors[counter], (REAL)m_LineWidth); Pen pen(m_Colors[counter], (REAL)m_LineWidth);
for (int j = 0; j < m_W; ++j) for (int j = x, R = x + m_W; j < R; ++j)
{ {
if (pos >= m_W) pos = 0;
if (pos < size) if (pos < size)
{ {
Y = (REAL)((*i)[pos] * m_ScaleValues[counter] * (m_H - 1) / maxValue); Y = (REAL)((*i)[pos] * scale);
Y = min(Y, m_H - 1); Y = min(Y, H);
Y = max(Y, 0); Y = max(Y, 0.0f);
} }
else else
{ {
Y = 0; Y = 0.0f;
} }
if (m_Flip) Y = (m_Flip) ? y + Y : y + H - Y;
{
Y = y + Y;
}
else
{
Y = y + m_H - Y - 1;
}
if (j != 0) if (j != x)
{ {
graphics.DrawLine(&pen, (REAL)X - 1, oldY, (REAL)X, Y); // GDI+ graphics.DrawLine(&pen, (REAL)(j - 1), oldY, (REAL)j, Y); // GDI+
} }
oldY = Y; oldY = Y;
++X;
++pos; ++pos;
if (pos >= m_W) pos = 0;
} }
++counter; ++counter;

View File

@ -33,13 +33,9 @@ extern CRainmeter* Rainmeter;
** The constructor ** The constructor
** **
*/ */
CMeterRotator::CMeterRotator(CMeterWindow* meterWindow) : CMeterImage(meterWindow) CMeterRotator::CMeterRotator(CMeterWindow* meterWindow) : CMeterImage(meterWindow, L"ImageW", L"ImageH")
{ {
m_Bitmap = NULL;
m_Value = 0.0; m_Value = 0.0;
m_ImageWidthString = L"ImageW";
m_ImageHeightString = L"ImageH";
} }
/* /*

View File

@ -30,7 +30,8 @@ using namespace Gdiplus;
** The constructor ** The constructor
** **
*/ */
CMeterRoundLine::CMeterRoundLine(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterRoundLine::CMeterRoundLine(CMeterWindow* meterWindow) : CMeter(meterWindow),
m_LineColor(Color::Black)
{ {
m_LineWidth = 1.0; m_LineWidth = 1.0;
m_LineLength = 20; m_LineLength = 20;

View File

@ -66,10 +66,10 @@ void StringToProper(std::wstring& str)
** The constructor ** The constructor
** **
*/ */
CMeterString::CMeterString(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterString::CMeterString(CMeterWindow* meterWindow) : CMeter(meterWindow),
m_Color(Color::White),
m_EffectColor(Color::Black)
{ {
m_Color = RGB(255, 255, 255);
m_EffectColor = RGB(0, 0, 0);
m_Effect = EFFECT_NONE; m_Effect = EFFECT_NONE;
m_AutoScale = true; m_AutoScale = true;
m_Align = ALIGN_LEFT; m_Align = ALIGN_LEFT;
@ -298,8 +298,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0); m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0);
std::wstring scale; std::wstring scale = parser.ReadString(section, L"Scale", L"1");
scale = parser.ReadString(section, L"Scale", L"1");
if (scale.find(L'.') == std::wstring::npos) if (scale.find(L'.') == std::wstring::npos)
{ {
@ -313,8 +312,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
m_FontFace = parser.ReadString(section, L"FontFace", L"Arial"); m_FontFace = parser.ReadString(section, L"FontFace", L"Arial");
std::wstring align; std::wstring align = parser.ReadString(section, L"StringAlign", L"LEFT");
align = parser.ReadString(section, L"StringAlign", L"LEFT");
if(_wcsicmp(align.c_str(), L"LEFT") == 0) if(_wcsicmp(align.c_str(), L"LEFT") == 0)
{ {
@ -333,8 +331,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
throw CError(std::wstring(L"StringAlign=") + align + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); throw CError(std::wstring(L"StringAlign=") + align + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
} }
std::wstring stringCase; std::wstring stringCase = parser.ReadString(section, L"StringCase", L"NONE");
stringCase = parser.ReadString(section, L"StringCase", L"NONE");
if(_wcsicmp(stringCase.c_str(), L"NONE") == 0) if(_wcsicmp(stringCase.c_str(), L"NONE") == 0)
{ {
@ -357,8 +354,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
throw CError(std::wstring(L"StringCase=") + stringCase + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); throw CError(std::wstring(L"StringCase=") + stringCase + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
} }
std::wstring style; std::wstring style = parser.ReadString(section, L"StringStyle", L"NORMAL");
style = parser.ReadString(section, L"StringStyle", L"NORMAL");
if(_wcsicmp(style.c_str(), L"NORMAL") == 0) if(_wcsicmp(style.c_str(), L"NORMAL") == 0)
{ {
@ -381,8 +377,7 @@ void CMeterString::ReadConfig(const WCHAR* section)
throw CError(std::wstring(L"StringStyle=") + style + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); throw CError(std::wstring(L"StringStyle=") + style + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
} }
std::wstring effect; std::wstring effect = parser.ReadString(section, L"StringEffect", L"NONE");
effect = parser.ReadString(section, L"StringEffect", L"NONE");
if(_wcsicmp(effect.c_str(), L"NONE") == 0) if(_wcsicmp(effect.c_str(), L"NONE") == 0)
{ {
@ -591,30 +586,25 @@ bool CMeterString::DrawString(Graphics& graphics, RectF* rect)
graphics.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y); graphics.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y);
} }
switch (m_Effect) if (m_Effect == EFFECT_SHADOW)
{ {
case EFFECT_SHADOW: SolidBrush solidBrush(m_EffectColor);
{ RectF rcEffect(rc);
SolidBrush solidBrush(m_EffectColor); rcEffect.Offset(1, 1);
RectF rcEffect(rc); graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
rcEffect.Offset(1, 1); }
graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush); else if (m_Effect == EFFECT_BORDER)
break; {
} SolidBrush solidBrush(m_EffectColor);
case EFFECT_BORDER: RectF rcEffect(rc);
{ rcEffect.Offset(0, 1);
SolidBrush solidBrush(m_EffectColor); graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
RectF rcEffect(rc); rcEffect.Offset(1, -1);
rcEffect.Offset(0, 1); graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush); rcEffect.Offset(-1, -1);
rcEffect.Offset(1, -1); graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush); rcEffect.Offset(-1, 1);
rcEffect.Offset(-1, -1); graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
rcEffect.Offset(-1, 1);
graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush);
break;
}
} }
SolidBrush solidBrush(m_Color); SolidBrush solidBrush(m_Color);

View File

@ -33,9 +33,6 @@
using namespace Gdiplus; using namespace Gdiplus;
#define ULW_ALPHA 0x00000002
#define WS_EX_LAYERED 0x00080000
#define METERTIMER 1 #define METERTIMER 1
#define MOUSETIMER 2 #define MOUSETIMER 2
#define FADETIMER 3 #define FADETIMER 3
@ -53,16 +50,18 @@ extern CRainmeter* Rainmeter;
** Constructor ** Constructor
** **
*/ */
CMeterWindow::CMeterWindow(std::wstring& path, std::wstring& config, std::wstring& iniFile) CMeterWindow::CMeterWindow(const std::wstring& path, const std::wstring& config, const std::wstring& iniFile) : m_SkinPath(path), m_SkinName(config), m_SkinIniFile(iniFile),
m_WindowX(L"0"),
m_WindowY(L"0")
{ {
m_Rainmeter = NULL;
m_Background = NULL; m_Background = NULL;
m_Window = NULL; m_Window = NULL;
m_ChildWindow = false; m_ChildWindow = false;
m_DoubleBuffer = NULL; m_DoubleBuffer = NULL;
m_WindowX = L"0";
m_WindowY = L"0";
m_ScreenX = 0; m_ScreenX = 0;
m_ScreenY = 0; m_ScreenY = 0;
m_WindowW = 0; m_WindowW = 0;
@ -91,7 +90,6 @@ CMeterWindow::CMeterWindow(std::wstring& path, std::wstring& config, std::wstrin
m_WindowHide = HIDEMODE_NONE; m_WindowHide = HIDEMODE_NONE;
m_WindowStartHidden = false; m_WindowStartHidden = false;
m_SnapEdges = true; m_SnapEdges = true;
m_Rainmeter = NULL;
m_Hidden = false; m_Hidden = false;
m_ResetRegion = false; m_ResetRegion = false;
m_Refreshing = false; m_Refreshing = false;
@ -120,10 +118,6 @@ CMeterWindow::CMeterWindow(std::wstring& path, std::wstring& config, std::wstrin
m_BackgroundMode = BGMODE_IMAGE; m_BackgroundMode = BGMODE_IMAGE;
m_SolidBevel = BEVELTYPE_NONE; m_SolidBevel = BEVELTYPE_NONE;
m_SkinPath = path;
m_SkinName = config;
m_SkinIniFile = iniFile;
m_UpdateCounter = 0; m_UpdateCounter = 0;
m_FontCollection = NULL; m_FontCollection = NULL;
@ -819,9 +813,9 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
case BANG_SETTRANSPARENCY: case BANG_SETTRANSPARENCY:
if (arg != NULL) if (arg != NULL)
{ {
int alpha = (int)CConfigParser::ParseDouble(arg, 255, true); m_AlphaValue = (int)CConfigParser::ParseDouble(arg, 255, true);
alpha = max(alpha, 0); m_AlphaValue = max(m_AlphaValue, 0);
m_AlphaValue = min(alpha, 255); m_AlphaValue = min(m_AlphaValue, 255);
UpdateTransparency(m_AlphaValue, false); UpdateTransparency(m_AlphaValue, false);
} }
break; break;
@ -1623,8 +1617,8 @@ void CMeterWindow::ReadConfig()
m_AutoSelectScreen = 0!=parser.ReadInt(section, L"AutoSelectScreen", m_AutoSelectScreen); m_AutoSelectScreen = 0!=parser.ReadInt(section, L"AutoSelectScreen", m_AutoSelectScreen);
m_AlphaValue = parser.ReadInt(section, L"AlphaValue", m_AlphaValue); m_AlphaValue = parser.ReadInt(section, L"AlphaValue", m_AlphaValue);
m_AlphaValue = min(255, m_AlphaValue); m_AlphaValue = max(m_AlphaValue, 0);
m_AlphaValue = max(0, m_AlphaValue); m_AlphaValue = min(m_AlphaValue, 255);
m_FadeDuration = parser.ReadInt(section, L"FadeDuration", m_FadeDuration); m_FadeDuration = parser.ReadInt(section, L"FadeDuration", m_FadeDuration);
@ -1729,7 +1723,6 @@ bool CMeterWindow::ReadSkin()
if (appVersion > RAINMETER_VERSION) if (appVersion > RAINMETER_VERSION)
{ {
WCHAR buffer[128]; WCHAR buffer[128];
std::wstring text;
if (appVersion % 1000 != 0) if (appVersion % 1000 != 0)
{ {
wsprintf(buffer, L"%i.%i.%i", appVersion / 1000000, (appVersion / 1000) % 1000, appVersion % 1000); wsprintf(buffer, L"%i.%i.%i", appVersion / 1000000, (appVersion / 1000) % 1000, appVersion % 1000);
@ -1739,7 +1732,7 @@ bool CMeterWindow::ReadSkin()
wsprintf(buffer, L"%i.%i", appVersion / 1000000, (appVersion / 1000) % 1000); wsprintf(buffer, L"%i.%i", appVersion / 1000000, (appVersion / 1000) % 1000);
} }
text = L"The skin \""; std::wstring text = L"The skin \"";
text += m_SkinName; text += m_SkinName;
text += L"\\"; text += L"\\";
text += m_SkinIniFile; text += m_SkinIniFile;
@ -1809,7 +1802,7 @@ bool CMeterWindow::ReadSkin()
// We want to check the fonts folder first // We want to check the fonts folder first
// !!!!!!! - We may want to fix the method in which I get the path to // !!!!!!! - We may want to fix the method in which I get the path to
// Rainmeter/fonts // Rainmeter/fonts
std::wstring szFontFile = m_Rainmeter->GetPath().c_str(); std::wstring szFontFile = m_Rainmeter->GetPath();
m_FontCollection = new Gdiplus::PrivateFontCollection(); m_FontCollection = new Gdiplus::PrivateFontCollection();
@ -1828,7 +1821,7 @@ bool CMeterWindow::ReadSkin()
// The font wasn't found, check full path. // The font wasn't found, check full path.
if(nResults != Ok) if(nResults != Ok)
{ {
szFontFile = localFont.c_str(); szFontFile = localFont;
nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); nResults = m_FontCollection->AddFontFile(szFontFile.c_str());
if(nResults != Ok) if(nResults != Ok)
{ {
@ -1854,7 +1847,7 @@ bool CMeterWindow::ReadSkin()
// We want to check the fonts folder first // We want to check the fonts folder first
// !!!!!!! - We may want to fix the method in which I get the path to // !!!!!!! - We may want to fix the method in which I get the path to
// Rainmeter/fonts // Rainmeter/fonts
std::wstring szFontFile = m_Rainmeter->GetPath().c_str(); std::wstring szFontFile = m_Rainmeter->GetPath();
szFontFile += L"Fonts\\"; szFontFile += L"Fonts\\";
szFontFile += localFont; szFontFile += localFont;
@ -1871,7 +1864,7 @@ bool CMeterWindow::ReadSkin()
// The font wasn't found, check full path. // The font wasn't found, check full path.
if(nResults != Ok) if(nResults != Ok)
{ {
szFontFile = localFont.c_str(); szFontFile = localFont;
nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); nResults = m_FontCollection->AddFontFile(szFontFile.c_str());
// The font file wasn't found anywhere, log the error // The font file wasn't found anywhere, log the error
if(nResults != Ok) if(nResults != Ok)
@ -1908,11 +1901,9 @@ bool CMeterWindow::ReadSkin()
_wcsicmp(L"Variables", strSection.c_str()) != 0 && _wcsicmp(L"Variables", strSection.c_str()) != 0 &&
_wcsicmp(L"Metadata", strSection.c_str()) != 0) _wcsicmp(L"Metadata", strSection.c_str()) != 0)
{ {
std::wstring meterName, measureName;
// Check if the item is a meter or a measure (or perhaps something else) // Check if the item is a meter or a measure (or perhaps something else)
measureName = m_Parser.ReadString(strSection.c_str(), L"Measure", L""); std::wstring measureName = m_Parser.ReadString(strSection.c_str(), L"Measure", L"");
meterName = m_Parser.ReadString(strSection.c_str(), L"Meter", L""); std::wstring meterName = m_Parser.ReadString(strSection.c_str(), L"Meter", L"");
if (measureName.length() > 0) if (measureName.length() > 0)
{ {
// It's a measure // It's a measure
@ -1996,8 +1987,7 @@ bool CMeterWindow::ReadSkin()
if (m_Meters.empty()) if (m_Meters.empty())
{ {
std::wstring text; std::wstring text = L"The skin \"";
text = L"The skin \"";
text += m_SkinName; text += m_SkinName;
text += L"\\"; text += L"\\";
text += m_SkinIniFile; text += m_SkinIniFile;
@ -2104,8 +2094,10 @@ bool CMeterWindow::ResizeWindow(bool reset)
std::list<CMeter*>::const_iterator j = m_Meters.begin(); std::list<CMeter*>::const_iterator j = m_Meters.begin();
for( ; j != m_Meters.end(); ++j) for( ; j != m_Meters.end(); ++j)
{ {
w = max(w, (*j)->GetX() + (*j)->GetW()); int mr = (*j)->GetX() + (*j)->GetW();
h = max(h, (*j)->GetY() + (*j)->GetH()); w = max(w, mr);
int mb = (*j)->GetY() + (*j)->GetH();
h = max(h, mb);
} }
w += m_BackgroundMargins.GetRight(); w += m_BackgroundMargins.GetRight();
@ -3120,8 +3112,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
else if(wParam == ID_CONTEXT_SKINMENU_OPENSKINSFOLDER) else if(wParam == ID_CONTEXT_SKINMENU_OPENSKINSFOLDER)
{ {
std::wstring command; std::wstring command = L"\"";
command += L"\"";
command += m_SkinPath + L"\\" + m_SkinName; command += m_SkinPath + L"\\" + m_SkinName;
command += L"\""; command += L"\"";
LSExecute(NULL, command.c_str(), SW_SHOWNORMAL); LSExecute(NULL, command.c_str(), SW_SHOWNORMAL);
@ -4570,7 +4561,7 @@ LRESULT CMeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam)
** Converts the path to absolute by adding the skin's path to it (unless it already is absolute). ** Converts the path to absolute by adding the skin's path to it (unless it already is absolute).
** **
*/ */
std::wstring CMeterWindow::MakePathAbsolute(std::wstring path) std::wstring CMeterWindow::MakePathAbsolute(const std::wstring& path)
{ {
if (path.empty() || if (path.empty() ||
path.find(L":\\") != std::wstring::npos || path.find(L":/") != std::wstring::npos || path.find(L":\\") != std::wstring::npos || path.find(L":/") != std::wstring::npos ||

View File

@ -139,7 +139,7 @@ class CMeter;
class CMeterWindow : public CGroup class CMeterWindow : public CGroup
{ {
public: public:
CMeterWindow(std::wstring& path, std::wstring& config, std::wstring& iniFile); CMeterWindow(const std::wstring& path, const std::wstring& config, const std::wstring& iniFile);
~CMeterWindow(); ~CMeterWindow();
int Initialize(CRainmeter& Rainmeter); int Initialize(CRainmeter& Rainmeter);
@ -203,7 +203,7 @@ public:
LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam);
std::wstring MakePathAbsolute(std::wstring path); std::wstring MakePathAbsolute(const std::wstring& path);
Gdiplus::PrivateFontCollection* GetPrivateFontCollection() { return m_FontCollection; } Gdiplus::PrivateFontCollection* GetPrivateFontCollection() { return m_FontCollection; }

View File

@ -230,8 +230,7 @@ void BangWithArgs(BANGCOMMAND bang, const WCHAR* arg, size_t numOfArgs)
} }
else else
{ {
std::wstring dbg; std::wstring dbg = L"Unknown config name: " + config;
dbg = L"Unknown config name: " + config;
LSLog(LOG_DEBUG, APPNAME, dbg.c_str()); LSLog(LOG_DEBUG, APPNAME, dbg.c_str());
} }
} }
@ -1174,7 +1173,7 @@ void RainmeterQuit(HWND, const char* arg)
// //
// ----------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------
GlobalConfig CRainmeter::c_GlobalConfig; GlobalConfig CRainmeter::c_GlobalConfig = {0};
bool CRainmeter::c_Debug = false; bool CRainmeter::c_Debug = false;
/* /*
@ -1185,11 +1184,6 @@ bool CRainmeter::c_Debug = false;
*/ */
CRainmeter::CRainmeter() CRainmeter::CRainmeter()
{ {
c_GlobalConfig.netInSpeed = 0;
c_GlobalConfig.netOutSpeed = 0;
c_Debug = false;
m_MenuActive = false; m_MenuActive = false;
m_Logging = false; m_Logging = false;
@ -1736,7 +1730,7 @@ void CRainmeter::CheckSkinVersions()
** Compares two version strings. Returns 0 if they are equal, 1 if A > B and -1 if A < B. ** Compares two version strings. Returns 0 if they are equal, 1 if A > B and -1 if A < B.
** **
*/ */
int CRainmeter::CompareVersions(std::wstring strA, std::wstring strB) int CRainmeter::CompareVersions(const std::wstring& strA, const std::wstring& strB)
{ {
if (strA.empty() && strB.empty()) return 0; if (strA.empty() && strB.empty()) return 0;
if (strA.empty()) return -1; if (strA.empty()) return -1;
@ -1773,7 +1767,7 @@ int CRainmeter::CompareVersions(std::wstring strA, std::wstring strB)
** illustro\System is enabled. ** illustro\System is enabled.
** **
*/ */
void CRainmeter::CreateDefaultConfigFile(std::wstring strFile) void CRainmeter::CreateDefaultConfigFile(const std::wstring& strFile)
{ {
size_t pos = strFile.find_last_of(L'\\'); size_t pos = strFile.find_last_of(L'\\');
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
@ -1839,9 +1833,9 @@ void CRainmeter::ActivateConfig(int configIndex, int iniIndex)
if (_waccess(skinIniPath.c_str(), 0) == -1) if (_waccess(skinIniPath.c_str(), 0) == -1)
{ {
std::wstring message = L"Unable to activate skin \""; std::wstring message = L"Unable to activate skin \"";
message += skinConfig.c_str(); message += skinConfig;
message += L"\\"; message += L"\\";
message += skinIniFile.c_str(); message += skinIniFile;
message += L"\": Ini-file not found."; message += L"\": Ini-file not found.";
LSLog(LOG_DEBUG, APPNAME, message.c_str()); LSLog(LOG_DEBUG, APPNAME, message.c_str());
MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
@ -1899,7 +1893,7 @@ void CRainmeter::WriteActive(const std::wstring& config, int iniIndex)
WritePrivateProfileString(config.c_str(), L"Active", buffer, m_IniFile.c_str()); WritePrivateProfileString(config.c_str(), L"Active", buffer, m_IniFile.c_str());
} }
void CRainmeter::CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile) void CRainmeter::CreateMeterWindow(const std::wstring& path, const std::wstring& config, const std::wstring& iniFile)
{ {
CMeterWindow* mw = new CMeterWindow(path, config, iniFile); CMeterWindow* mw = new CMeterWindow(path, config, iniFile);
@ -2164,7 +2158,7 @@ void CRainmeter::Quit(HINSTANCE dllInst)
** **
** Scans all the subfolders and locates the ini-files. ** Scans all the subfolders and locates the ini-files.
*/ */
void CRainmeter::ScanForConfigs(std::wstring& path) void CRainmeter::ScanForConfigs(const std::wstring& path)
{ {
m_ConfigStrings.clear(); m_ConfigStrings.clear();
m_ConfigMenu.clear(); m_ConfigMenu.clear();
@ -2173,7 +2167,7 @@ void CRainmeter::ScanForConfigs(std::wstring& path)
ScanForConfigsRecursive(path, L"", 0, m_ConfigMenu, false); ScanForConfigsRecursive(path, L"", 0, m_ConfigMenu, false);
} }
int CRainmeter::ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector<CONFIGMENU>& menu, bool DontRecurse) int CRainmeter::ScanForConfigsRecursive(const std::wstring& path, std::wstring base, int index, std::vector<CONFIGMENU>& menu, bool DontRecurse)
{ {
WIN32_FIND_DATA fileData; // Data structure describes the file found WIN32_FIND_DATA fileData; // Data structure describes the file found
WIN32_FIND_DATA fileDataIni; // Data structure describes the file found WIN32_FIND_DATA fileDataIni; // Data structure describes the file found
@ -2263,7 +2257,7 @@ int CRainmeter::ScanForConfigsRecursive(std::wstring& path, std::wstring base, i
** **
** Scans the given folder for themes ** Scans the given folder for themes
*/ */
void CRainmeter::ScanForThemes(std::wstring& path) void CRainmeter::ScanForThemes(const std::wstring& path)
{ {
m_Themes.clear(); m_Themes.clear();
@ -2726,7 +2720,7 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
** Reads the general settings from the Rainmeter.ini file ** Reads the general settings from the Rainmeter.ini file
** **
*/ */
void CRainmeter::ReadGeneralSettings(std::wstring& iniFile) void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
{ {
// Clear old settings // Clear old settings
m_DesktopWorkAreas.clear(); m_DesktopWorkAreas.clear();
@ -2859,8 +2853,7 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile)
{ {
if (!SetActiveConfig(skinName, skinIni)) if (!SetActiveConfig(skinName, skinIni))
{ {
std::wstring error; std::wstring error = L"The selected skin (L" + skinName + L"\\" + skinIni + L") cannot be found.";
error = L"The selected skin (L" + skinName + L"\\" + skinIni + L") cannot be found.";
MessageBox(NULL, error.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, error.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
} }
return; return;
@ -2886,7 +2879,7 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile)
** **
** Makes the given config active. If the config cannot be found this returns false. ** Makes the given config active. If the config cannot be found this returns false.
*/ */
bool CRainmeter::SetActiveConfig(std::wstring& skinName, std::wstring& skinIni) bool CRainmeter::SetActiveConfig(const std::wstring& skinName, const std::wstring& skinIni)
{ {
for (size_t i = 0; i < m_ConfigStrings.size(); ++i) for (size_t i = 0; i < m_ConfigStrings.size(); ++i)
{ {
@ -2969,9 +2962,9 @@ void CRainmeter::RefreshAll()
DeactivateConfig(mw, i); DeactivateConfig(mw, i);
std::wstring message = L"Unable to refresh skin \""; std::wstring message = L"Unable to refresh skin \"";
message += skinConfig.c_str(); message += skinConfig;
message += L"\\"; message += L"\\";
message += skinIniFile.c_str(); message += skinIniFile;
message += L"\": Ini-file not found."; message += L"\": Ini-file not found.";
LSLog(LOG_DEBUG, APPNAME, message.c_str()); LSLog(LOG_DEBUG, APPNAME, message.c_str());
MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
@ -2987,7 +2980,7 @@ void CRainmeter::RefreshAll()
DeactivateConfig(mw, -2); // -2 = Deactivate the config forcibly DeactivateConfig(mw, -2); // -2 = Deactivate the config forcibly
std::wstring message = L"Unable to refresh config \""; std::wstring message = L"Unable to refresh config \"";
message += skinConfig.c_str(); message += skinConfig;
message += L"\": Config not found."; message += L"\": Config not found.";
LSLog(LOG_DEBUG, APPNAME, message.c_str()); LSLog(LOG_DEBUG, APPNAME, message.c_str());
MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); MessageBox(NULL, message.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
@ -3770,8 +3763,7 @@ void CRainmeter::TestSettingsFile(bool bDefaultIniLocation)
{ {
LSLog(LOG_DEBUG, APPNAME, L"The Rainmeter.ini file is NOT writable."); LSLog(LOG_DEBUG, APPNAME, L"The Rainmeter.ini file is NOT writable.");
std::wstring error; std::wstring error = L"The Rainmeter.ini file is not writable. This means that the\n";
error += L"The Rainmeter.ini file is not writable. This means that the\n";
error += L"application will not be able to save any settings permanently.\n\n"; error += L"application will not be able to save any settings permanently.\n\n";
if (!bDefaultIniLocation) if (!bDefaultIniLocation)

View File

@ -204,12 +204,12 @@ public:
bool IsMenuActive() { return m_MenuActive; } bool IsMenuActive() { return m_MenuActive; }
void ShowContextMenu(POINT pos, CMeterWindow* meterWindow); void ShowContextMenu(POINT pos, CMeterWindow* meterWindow);
std::wstring GetTrayExecuteL() { return m_TrayExecuteL; } const std::wstring& GetTrayExecuteL() { return m_TrayExecuteL; }
std::wstring GetTrayExecuteR() { return m_TrayExecuteR; } const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; }
std::wstring GetTrayExecuteM() { return m_TrayExecuteM; } const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; }
std::wstring GetTrayExecuteDR() { return m_TrayExecuteDR; } const std::wstring& GetTrayExecuteDR() { return m_TrayExecuteDR; }
std::wstring GetTrayExecuteDL() { return m_TrayExecuteDL; } const std::wstring& GetTrayExecuteDL() { return m_TrayExecuteDL; }
std::wstring GetTrayExecuteDM() { return m_TrayExecuteDM; } const std::wstring& GetTrayExecuteDM() { return m_TrayExecuteDM; }
BOOL ExecuteBang(const std::wstring& bang, const std::wstring& arg, CMeterWindow* meterWindow); BOOL ExecuteBang(const std::wstring& bang, const std::wstring& arg, CMeterWindow* meterWindow);
std::wstring ParseCommand(const WCHAR* command, CMeterWindow* meterWindow); std::wstring ParseCommand(const WCHAR* command, CMeterWindow* meterWindow);
@ -224,27 +224,27 @@ public:
static void ExpandEnvironmentVariables(std::wstring& strPath); static void ExpandEnvironmentVariables(std::wstring& strPath);
private: private:
void CreateMeterWindow(std::wstring path, std::wstring config, std::wstring iniFile); void CreateMeterWindow(const std::wstring& path, const std::wstring& config, const std::wstring& iniFile);
bool DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater); bool DeleteMeterWindow(CMeterWindow* meterWindow, bool bLater);
void WriteActive(const std::wstring& config, int iniIndex); void WriteActive(const std::wstring& config, int iniIndex);
void ScanForConfigs(std::wstring& path); void ScanForConfigs(const std::wstring& path);
void ScanForThemes(std::wstring& path); void ScanForThemes(const std::wstring& path);
void ReadGeneralSettings(std::wstring& path); void ReadGeneralSettings(const std::wstring& iniFile);
void SetConfigOrder(int configIndex); void SetConfigOrder(int configIndex);
int GetLoadOrder(const std::wstring& config); int GetLoadOrder(const std::wstring& config);
bool SetActiveConfig(std::wstring& skinName, std::wstring& skinIni); bool SetActiveConfig(const std::wstring& skinName, const std::wstring& skinIni);
void UpdateDesktopWorkArea(bool reset); void UpdateDesktopWorkArea(bool reset);
HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu); HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu);
void ChangeSkinIndex(HMENU subMenu, int index); void ChangeSkinIndex(HMENU subMenu, int index);
int ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector<CONFIGMENU>& menu, bool DontRecurse); int ScanForConfigsRecursive(const std::wstring& path, std::wstring base, int index, std::vector<CONFIGMENU>& menu, bool DontRecurse);
HMENU CreateConfigMenu(std::vector<CONFIGMENU>& configMenuData); HMENU CreateConfigMenu(std::vector<CONFIGMENU>& configMenuData);
HMENU CreateThemeMenu(); HMENU CreateThemeMenu();
void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow); void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow);
void CreateDefaultConfigFile(std::wstring strFile); void CreateDefaultConfigFile(const std::wstring& strFile);
void SetLogging(bool logging); void SetLogging(bool logging);
void TestSettingsFile(bool bDefaultIniLocation); void TestSettingsFile(bool bDefaultIniLocation);
void CheckSkinVersions(); void CheckSkinVersions();
int CompareVersions(std::wstring strA, std::wstring strB); int CompareVersions(const std::wstring& strA, const std::wstring& strB);
CTrayWindow* m_TrayWindow; CTrayWindow* m_TrayWindow;

View File

@ -69,5 +69,6 @@
#include <io.h> #include <io.h>
#include <stdarg.h> #include <stdarg.h>
#include <process.h> #include <process.h>
#include <float.h>
#endif #endif

View File

@ -1242,7 +1242,7 @@ void CSystem::GetIniFileMappingList(std::vector<std::wstring>& iniFileMappings)
** Note that a temporary file must be deleted by caller. ** Note that a temporary file must be deleted by caller.
** **
*/ */
std::wstring CSystem::GetTemporaryFile(const std::vector<std::wstring>& iniFileMappings, const std::wstring &iniFile) std::wstring CSystem::GetTemporaryFile(const std::vector<std::wstring>& iniFileMappings, const std::wstring& iniFile)
{ {
std::wstring temporary; std::wstring temporary;

View File

@ -37,7 +37,9 @@ extern CRainmeter* Rainmeter;
using namespace Gdiplus; using namespace Gdiplus;
CTrayWindow::CTrayWindow(HINSTANCE instance) CTrayWindow::CTrayWindow(HINSTANCE instance) : m_Instance(instance),
m_TrayColor1(0, 100, 0),
m_TrayColor2(0, 255, 0)
{ {
WNDCLASS wc; WNDCLASS wc;
@ -68,13 +70,10 @@ CTrayWindow::CTrayWindow(HINSTANCE instance)
instance, instance,
this); this);
m_Instance = instance;
m_Measure = NULL; m_Measure = NULL;
m_TrayIcon = NULL; m_TrayIcon = NULL;
m_MeterType = TRAY_METER_TYPE_HISTOGRAM; m_MeterType = TRAY_METER_TYPE_HISTOGRAM;
m_TrayColor1 = Color(0, 100, 0);
m_TrayColor2 = Color(0, 255, 0);
m_Bitmap = NULL; m_Bitmap = NULL;
@ -477,8 +476,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} }
else if(wParam == ID_CONTEXT_OPENSKINSFOLDER) else if(wParam == ID_CONTEXT_OPENSKINSFOLDER)
{ {
std::wstring command; std::wstring command = L"\"";
command += L"\"";
command += Rainmeter->GetSkinPath(); command += Rainmeter->GetSkinPath();
command += L"\""; command += L"\"";
LSExecute(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL); LSExecute(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL);