From cab258a7e5a350889995b079cfe803fc63e01bcc Mon Sep 17 00:00:00 2001 From: spx Date: Thu, 11 Nov 2010 20:24:59 +0000 Subject: [PATCH] Code optimization and removed unused part for reducing core dll size. --- Library/AboutDialog.cpp | 3 +- Library/Error.cpp | 2 +- Library/Error.h | 12 +-- Library/Measure.cpp | 17 ++-- Library/MeasureCPU.cpp | 167 +++++++++++++----------------------- Library/MeasureCPU.h | 1 - Library/MeasureRegistry.cpp | 3 +- Library/MeasureTime.cpp | 3 +- Library/Meter.cpp | 4 +- Library/MeterBar.cpp | 21 ++--- Library/MeterBitmap.cpp | 24 ++---- Library/MeterHistogram.cpp | 48 ++++++----- Library/MeterImage.cpp | 10 +-- Library/MeterImage.h | 7 +- Library/MeterLine.cpp | 70 ++++++++------- Library/MeterRotator.cpp | 6 +- Library/MeterRoundLine.cpp | 3 +- Library/MeterString.cpp | 62 ++++++------- Library/MeterWindow.cpp | 57 ++++++------ Library/MeterWindow.h | 4 +- Library/Rainmeter.cpp | 42 ++++----- Library/Rainmeter.h | 28 +++--- Library/StdAfx.h | 1 + Library/System.cpp | 2 +- Library/TrayWindow.cpp | 10 +-- 25 files changed, 257 insertions(+), 350 deletions(-) diff --git a/Library/AboutDialog.cpp b/Library/AboutDialog.cpp index 8c4348c2..988b5a7e 100644 --- a/Library/AboutDialog.cpp +++ b/Library/AboutDialog.cpp @@ -201,12 +201,11 @@ void UpdateAboutStatistics(LPCTSTR entryName) const WCHAR* name = (*i)->GetName(); const WCHAR* val = (*i)->GetStats(); - std::wstring range; WCHAR buffer[256]; double minVal = (*i)->GetMinValue(); double maxVal = (*i)->GetMaxValue(); CMeasure::GetScaledValue(1, minVal, buffer); - range = buffer; + std::wstring range = buffer; range += L" - "; CMeasure::GetScaledValue(1, maxVal, buffer); range += buffer; diff --git a/Library/Error.cpp b/Library/Error.cpp index 9e25e1aa..042153d3 100644 --- a/Library/Error.cpp +++ b/Library/Error.cpp @@ -36,7 +36,7 @@ const WCHAR* CError::c_ErrorStrings[] = */ const std::wstring& CError::GetString() { - static WCHAR Buffer[16]; +// static WCHAR Buffer[16]; if (m_Error != ERROR_USER) { diff --git a/Library/Error.h b/Library/Error.h index 15c58a16..68b2956d 100644 --- a/Library/Error.h +++ b/Library/Error.h @@ -35,12 +35,12 @@ public: ERROR_CREATE_WINDOW }; - 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 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(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(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 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(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) {} const std::wstring& GetString(); diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 696a532a..f95cfbd8 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -47,7 +47,7 @@ extern CRainmeter* Rainmeter; ** The constructor ** */ -CMeasure::CMeasure(CMeterWindow* meterWindow) +CMeasure::CMeasure(CMeterWindow* meterWindow) : m_MeterWindow(meterWindow) { m_Invert = false; m_LogMaxValue = false; @@ -68,8 +68,6 @@ CMeasure::CMeasure(CMeterWindow* meterWindow) m_AverageSize = 0; m_DynamicVariables = 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); - std::wstring subs; - subs = parser.ReadString(section, L"Substitute", L""); + std::wstring subs = parser.ReadString(section, L"Substitute", L""); if (!subs.empty() && (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; - std::wstring word1; - std::wstring word2; - std::wstring sep; - while (!buffer.empty()) { - word1 = ExtractWord(buffer); - sep = ExtractWord(buffer); + std::wstring word1 = ExtractWord(buffer); + std::wstring sep = ExtractWord(buffer); if (sep != L":") return false; - word2 = ExtractWord(buffer); + std::wstring word2 = ExtractWord(buffer); if (word1 != word2) { diff --git a/Library/MeasureCPU.cpp b/Library/MeasureCPU.cpp index 0530ec2b..a7314997 100644 --- a/Library/MeasureCPU.cpp +++ b/Library/MeasureCPU.cpp @@ -27,7 +27,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)) // ntdll!NtQuerySystemInformation (NT specific!) @@ -56,7 +57,6 @@ */ CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow) : CMeasure(meterWindow) { - m_CPUFromRegistry = false; m_MaxValue = 100.0; m_MinValue = 0.0; m_FirstTime = true; @@ -85,19 +85,6 @@ CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow) : CMeasure(meterWindow) */ 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 ** -** Updates the current CPU utilization value. On NT the value is taken -** from the performance counters and on 9x we'll use the registry. +** Updates the current CPU utilization value. ** */ bool CMeasureCPU::Update() { 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; - FILETIME ftIdleTime, ftKernelTime, ftUserTime; + ULONG size = 0; - // get new CPU's idle/kernel/user time - status = m_GetSystemTimes(&ftIdleTime, &ftKernelTime, &ftUserTime); - if (status == 0) return false; + status = m_NtQuerySystemInformation(SystemProcessorPerformanceInformation, buf, bufSize, &size); + if (status == STATUS_SUCCESS) break; - CalcUsage(Ft2Double(ftIdleTime), - Ft2Double(ftKernelTime) + Ft2Double(ftUserTime)); - } - else if (m_NtQuerySystemInformation) - { - LONG status; - BYTE* buf = NULL; - ULONG bufSize = 0; - - int loop = 0; - - do + if (status == STATUS_INFO_LENGTH_MISMATCH) { - ULONG size = 0; - - 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 (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; - } - else - { - bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); - } + bufSize = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * m_NumOfProcessors; } else { - if (size != bufSize) - { - bufSize = size; - } - else // ?? - { - bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); - } + bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); } - - if (buf) delete [] buf; - buf = new BYTE[bufSize]; } - else // failed + else { - if (buf) delete [] buf; - return false; + if (size != bufSize) + { + bufSize = size; + } + else // ?? + { + bufSize += sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); + } } - ++loop; - } while (loop < 10); - - if (status != STATUS_SUCCESS) // failed + if (buf) delete [] buf; + buf = new BYTE[bufSize]; + } + else // failed { if (buf) delete [] buf; return false; } - SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)buf; + ++loop; + } while (loop < 10); - if (m_Processor == 0) - { - CalcAverageUsage(systemPerfInfo); - } - else - { - int processor = m_Processor - 1; + if (status != STATUS_SUCCESS) // failed + { + if (buf) delete [] buf; + return false; + } - CalcUsage(Li2Double(systemPerfInfo[processor].IdleTime), - Li2Double(systemPerfInfo[processor].KernelTime) + Li2Double(systemPerfInfo[processor].UserTime)); - } + SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)buf; - delete [] buf; + if (m_Processor == 0) + { + CalcAverageUsage(systemPerfInfo); } else { - return false; + int processor = m_Processor - 1; + + CalcUsage(Li2Double(systemPerfInfo[processor].IdleTime), + Li2Double(systemPerfInfo[processor].KernelTime) + Li2Double(systemPerfInfo[processor].UserTime)); } + + delete [] buf; } else { - // It's a wintendo! - 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 false; } return PostUpdate(); diff --git a/Library/MeasureCPU.h b/Library/MeasureCPU.h index 6bcb4ed5..f61a3880 100644 --- a/Library/MeasureCPU.h +++ b/Library/MeasureCPU.h @@ -45,7 +45,6 @@ protected: void CalcUsage(double idleTime, double systemTime); void CalcAverageUsage(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo); - bool m_CPUFromRegistry; bool m_FirstTime; int m_Processor; diff --git a/Library/MeasureRegistry.cpp b/Library/MeasureRegistry.cpp index 85a6fbf9..d99c9c18 100644 --- a/Library/MeasureRegistry.cpp +++ b/Library/MeasureRegistry.cpp @@ -117,8 +117,7 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section) { CMeasure::ReadConfig(parser, section); - std::wstring keyname; - keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER"); + std::wstring keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER"); if(_wcsicmp(keyname.c_str(), L"HKEY_CLASSES_ROOT") == 0) { diff --git a/Library/MeasureTime.cpp b/Library/MeasureTime.cpp index 452ddce0..3f353e7b 100644 --- a/Library/MeasureTime.cpp +++ b/Library/MeasureTime.cpp @@ -233,8 +233,7 @@ void CMeasureTime::ReadConfig(CConfigParser& parser, const WCHAR* section) m_Format = parser.ReadString(section, L"Format", L""); - std::wstring timezone; - timezone = parser.ReadString(section, L"TimeZone", L"local"); + std::wstring timezone = parser.ReadString(section, L"TimeZone", L"local"); bool dst = 1 == parser.ReadInt(section, L"DaylightSavingTime", 1); SYSTEMTIME sysLocalTime, sysUTCTime; diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 70ab6f65..0ad9f241 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -39,7 +39,7 @@ using namespace Gdiplus; ** The constructor ** */ -CMeter::CMeter(CMeterWindow* meterWindow) +CMeter::CMeter(CMeterWindow* meterWindow) : m_MeterWindow(meterWindow) { m_Measure = NULL; @@ -64,8 +64,6 @@ CMeter::CMeter(CMeterWindow* meterWindow) m_ToolTipHidden = false; m_ToolTipHandle = NULL; - - m_MeterWindow = meterWindow; } /* diff --git a/Library/MeterBar.cpp b/Library/MeterBar.cpp index a2d01965..599a5de7 100644 --- a/Library/MeterBar.cpp +++ b/Library/MeterBar.cpp @@ -34,16 +34,12 @@ extern CRainmeter* Rainmeter; ** 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_Border = 0; 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; - std::wstring orientation; - orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL"); + std::wstring orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL"); if(_wcsicmp(L"VERTICAL", orientation.c_str()) == 0) { @@ -182,8 +177,9 @@ bool CMeterBar::Draw(Graphics& graphics) if(m_Orientation == VERTICAL) { - int size = (int)((m_H - 2 * m_Border) * m_Value); - size = min(m_H - 2 * m_Border, size); + int barSize = m_H - 2 * m_Border; + int size = (int)(barSize * m_Value); + size = min(barSize, size); size = max(0, size); if (drawBitmap) @@ -234,8 +230,9 @@ bool CMeterBar::Draw(Graphics& graphics) } else { - int size = (int)((m_W - 2 * m_Border) * m_Value); - size = min(m_W - 2 * m_Border, size); + int barSize = m_W - 2 * m_Border; + int size = (int)(barSize * m_Value); + size = min(barSize, size); size = max(0, size); if (drawBitmap) diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index 5df75723..d0dd8eff 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -115,11 +115,6 @@ bool CMeterBitmap::HitTest(int x, int y) { 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 int numOfNums = 0; @@ -129,6 +124,9 @@ bool CMeterBitmap::HitTest(int x, int y) } else { + int tmpValue = (int)m_Value; + tmpValue = max(0, tmpValue); // Only positive integers are supported + int realFrames = (m_FrameCount / (m_TransitionFrameCount + 1)); do { @@ -197,8 +195,7 @@ void CMeterBitmap::ReadConfig(const WCHAR* section) m_TransitionFrameCount = parser.ReadInt(section, L"BitmapTransitionFrames", 0); - std::wstring align; - align = parser.ReadString(section, L"BitmapAlign", L"LEFT"); + std::wstring align = parser.ReadString(section, L"BitmapAlign", L"LEFT"); if(_wcsicmp(align.c_str(), L"LEFT") == 0) { @@ -242,15 +239,7 @@ bool CMeterBitmap::Update() { if (CMeter::Update() && m_Measure) { - double value = 0.0; - if (m_Extend) - { - value = m_Measure->GetValue(); - } - else - { - value = m_Measure->GetRelativeValue(); - } + double value = (m_Extend) ? m_Measure->GetValue() : m_Measure->GetRelativeValue(); if (m_TransitionFrameCount > 0) { @@ -314,7 +303,6 @@ bool CMeterBitmap::Draw(Graphics& graphics) int transitionValue = (int)m_TransitionStartValue; transitionValue = max(0, transitionValue); // Only positive integers are supported - int tmpValue = value; // Calc the number of numbers int numOfNums = 0; @@ -324,6 +312,8 @@ bool CMeterBitmap::Draw(Graphics& graphics) } else { + int tmpValue = value; + do { ++numOfNums; diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index 4cc9bfd2..d1c2e8c3 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -32,12 +32,12 @@ extern CRainmeter* Rainmeter; ** 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_PrimaryColor = 0; - m_SecondaryColor = 0; - m_BothColor = 0; m_MeterPos = 0; m_PrimaryBitmap = NULL; m_SecondaryBitmap = NULL; @@ -342,30 +342,44 @@ bool CMeterHistogram::Update() // Go through all values and find the max 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]); } // Scale the value up to nearest power of 2 - m_MaxPrimaryValue = 2; - while(m_MaxPrimaryValue < newValue && m_MaxPrimaryValue != 0) + if (newValue > DBL_MAX / 2.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) { - for (int i = 0; i != m_W; ++i) + for (int i = 0; i < m_W; ++i) { newValue = max(newValue, m_SecondaryValues[i]); } // Scale the value up to nearest power of 2 - m_MaxSecondaryValue = 2; - while(m_MaxSecondaryValue < newValue && m_MaxSecondaryValue != 0) + if (newValue > DBL_MAX / 2.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); // Check which measured value is higher - int bothBarHeight; - if (secondaryBarHeight > primaryBarHeight) - { - bothBarHeight = primaryBarHeight; - } - else - { - bothBarHeight = secondaryBarHeight; - } + int bothBarHeight = min(primaryBarHeight, secondaryBarHeight); // Draw image/color for the both lines if (m_PrimaryBitmap) diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index d398db8b..94dd2806 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -51,7 +51,8 @@ const Gdiplus::ColorMatrix CMeterImage::c_IdentifyMatrix = { ** 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_BitmapTint = NULL; @@ -66,12 +67,8 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow) m_Modified.dwLowDateTime = 0; m_GreyScale = false; - m_ColorMatrix = c_IdentifyMatrix; m_Flip = RotateNoneFlipNone; 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)); - std::wstring flip; - flip = parser.ReadString(section, L"ImageFlip", L"NONE"); + std::wstring flip = parser.ReadString(section, L"ImageFlip", L"NONE"); if(_wcsicmp(flip.c_str(), L"NONE") == 0) { diff --git a/Library/MeterImage.h b/Library/MeterImage.h index 02360147..7bb45d6d 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -30,7 +30,7 @@ namespace Gdiplus class CMeterImage : public CMeter { public: - CMeterImage(CMeterWindow* meterWindow); + CMeterImage(CMeterWindow* meterWindow, WCHAR* wName = L"W", WCHAR* hName = L"H"); virtual ~CMeterImage(); virtual void ReadConfig(const WCHAR* section); @@ -40,14 +40,15 @@ public: virtual void BindMeasure(std::list& measures); protected: - std::wstring m_ImageWidthString; - std::wstring m_ImageHeightString; void LoadImage(bool bLoadAlways); bool CompareColorMatrix(const Gdiplus::ColorMatrix& a, const Gdiplus::ColorMatrix& b); void ApplyTint(); Gdiplus::Bitmap* TurnGreyscale(); void ApplyTransform(); + const std::wstring m_ImageWidthString; + const std::wstring m_ImageHeightString; + Gdiplus::Bitmap* m_Bitmap; // The bitmap Gdiplus::Bitmap* m_BitmapTint; // The bitmap std::wstring m_ImageName; // Name of the image diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index d3f4e03f..abfb9125 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -29,11 +29,11 @@ using namespace Gdiplus; ** The constructor ** */ -CMeterLine::CMeterLine(CMeterWindow* meterWindow) : CMeter(meterWindow) +CMeterLine::CMeterLine(CMeterWindow* meterWindow) : CMeter(meterWindow), + m_HorizontalColor(Color::Black) { m_Autoscale = false; m_HorizontalLines = false; - m_HorizontalColor = 0; m_CurrentPos = 0; m_Flip = false; m_LineWidth = 1.0; @@ -224,19 +224,28 @@ bool CMeterLine::Draw(Graphics& graphics) counter = 0; for (; i != m_AllValues.end(); ++i) { + double scale = m_ScaleValues[counter]; std::vector::const_iterator j = (*i).begin(); for (; j != (*i).end(); ++j) { - newValue = max(newValue, (*j) * m_ScaleValues[counter]); + double val = (*j) * scale; + newValue = max(newValue, val); } ++counter; } // Scale the value up to nearest power of 2 - maxValue = 2; - while(maxValue < newValue && maxValue != 0) + if (newValue > DBL_MAX / 2.0) { - maxValue *= 2; + maxValue = DBL_MAX; + } + else + { + maxValue = 2.0; + while (maxValue < newValue) + { + maxValue *= 2.0; + } } } else @@ -248,14 +257,15 @@ bool CMeterLine::Draw(Graphics& graphics) std::vector::const_iterator i = m_Measures.begin(); for (; i != m_Measures.end(); ++i) { - maxValue = max(maxValue, (*i)->GetMaxValue()); + double val = (*i)->GetMaxValue(); + maxValue = max(maxValue, val); } } - } - if (maxValue == 0.0) - { - maxValue = 1.0; + if (maxValue == 0.0) + { + maxValue = 1.0; + } } int x = GetX(); @@ -294,47 +304,41 @@ bool CMeterLine::Draw(Graphics& graphics) for (; i != m_AllValues.end(); ++i) { // Draw a line - int X = x; - REAL Y = 0; - REAL oldY = 0; - int pos = m_CurrentPos; - if (pos >= m_W) pos = 0; + REAL Y = 0.0f; + REAL oldY = 0.0f; + REAL H = m_H - 1.0f; + double scale = m_ScaleValues[counter] * H / maxValue; + + int pos = m_CurrentPos; int size = (int)(*i).size(); 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) { - Y = (REAL)((*i)[pos] * m_ScaleValues[counter] * (m_H - 1) / maxValue); - Y = min(Y, m_H - 1); - Y = max(Y, 0); + Y = (REAL)((*i)[pos] * scale); + Y = min(Y, H); + Y = max(Y, 0.0f); } else { - Y = 0; + Y = 0.0f; } - if (m_Flip) - { - Y = y + Y; - } - else - { - Y = y + m_H - Y - 1; - } + Y = (m_Flip) ? y + Y : y + H - Y; - 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; - ++X; ++pos; - if (pos >= m_W) pos = 0; } ++counter; diff --git a/Library/MeterRotator.cpp b/Library/MeterRotator.cpp index 120e45dc..7618c69a 100644 --- a/Library/MeterRotator.cpp +++ b/Library/MeterRotator.cpp @@ -33,13 +33,9 @@ extern CRainmeter* Rainmeter; ** 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_ImageWidthString = L"ImageW"; - m_ImageHeightString = L"ImageH"; } /* diff --git a/Library/MeterRoundLine.cpp b/Library/MeterRoundLine.cpp index 91701f69..b59930ba 100644 --- a/Library/MeterRoundLine.cpp +++ b/Library/MeterRoundLine.cpp @@ -30,7 +30,8 @@ using namespace Gdiplus; ** The constructor ** */ -CMeterRoundLine::CMeterRoundLine(CMeterWindow* meterWindow) : CMeter(meterWindow) +CMeterRoundLine::CMeterRoundLine(CMeterWindow* meterWindow) : CMeter(meterWindow), + m_LineColor(Color::Black) { m_LineWidth = 1.0; m_LineLength = 20; diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 00ad3cf7..fd31cef7 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -66,10 +66,10 @@ void StringToProper(std::wstring& str) ** 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_AutoScale = true; 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); - std::wstring scale; - scale = parser.ReadString(section, L"Scale", L"1"); + std::wstring scale = parser.ReadString(section, L"Scale", L"1"); 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"); - std::wstring align; - align = parser.ReadString(section, L"StringAlign", L"LEFT"); + std::wstring align = parser.ReadString(section, L"StringAlign", L"LEFT"); 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__); } - std::wstring stringCase; - stringCase = parser.ReadString(section, L"StringCase", L"NONE"); + std::wstring stringCase = parser.ReadString(section, L"StringCase", L"NONE"); 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__); } - std::wstring style; - style = parser.ReadString(section, L"StringStyle", L"NORMAL"); + std::wstring style = parser.ReadString(section, L"StringStyle", L"NORMAL"); 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__); } - std::wstring effect; - effect = parser.ReadString(section, L"StringEffect", L"NONE"); + std::wstring effect = parser.ReadString(section, L"StringEffect", L"NONE"); 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); } - switch (m_Effect) + if (m_Effect == EFFECT_SHADOW) { - case EFFECT_SHADOW: - { - SolidBrush solidBrush(m_EffectColor); - RectF rcEffect(rc); - rcEffect.Offset(1, 1); - graphics.DrawString(m_String.c_str(), (int)m_String.length(), m_Font, rcEffect, &stringFormat, &solidBrush); - break; - } - case EFFECT_BORDER: - { - SolidBrush solidBrush(m_EffectColor); - RectF rcEffect(rc); - rcEffect.Offset(0, 1); - 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); - rcEffect.Offset(-1, -1); - 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_EffectColor); + RectF rcEffect(rc); + 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) + { + SolidBrush solidBrush(m_EffectColor); + RectF rcEffect(rc); + rcEffect.Offset(0, 1); + 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); + rcEffect.Offset(-1, -1); + 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); } SolidBrush solidBrush(m_Color); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 0362d291..14fb3bce 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -33,9 +33,6 @@ using namespace Gdiplus; -#define ULW_ALPHA 0x00000002 -#define WS_EX_LAYERED 0x00080000 - #define METERTIMER 1 #define MOUSETIMER 2 #define FADETIMER 3 @@ -53,16 +50,18 @@ extern CRainmeter* Rainmeter; ** 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_Window = NULL; m_ChildWindow = false; m_DoubleBuffer = NULL; - m_WindowX = L"0"; - m_WindowY = L"0"; m_ScreenX = 0; m_ScreenY = 0; m_WindowW = 0; @@ -91,7 +90,6 @@ CMeterWindow::CMeterWindow(std::wstring& path, std::wstring& config, std::wstrin m_WindowHide = HIDEMODE_NONE; m_WindowStartHidden = false; m_SnapEdges = true; - m_Rainmeter = NULL; m_Hidden = false; m_ResetRegion = false; m_Refreshing = false; @@ -120,10 +118,6 @@ CMeterWindow::CMeterWindow(std::wstring& path, std::wstring& config, std::wstrin m_BackgroundMode = BGMODE_IMAGE; m_SolidBevel = BEVELTYPE_NONE; - m_SkinPath = path; - m_SkinName = config; - m_SkinIniFile = iniFile; - m_UpdateCounter = 0; m_FontCollection = NULL; @@ -819,9 +813,9 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg) case BANG_SETTRANSPARENCY: if (arg != NULL) { - int alpha = (int)CConfigParser::ParseDouble(arg, 255, true); - alpha = max(alpha, 0); - m_AlphaValue = min(alpha, 255); + m_AlphaValue = (int)CConfigParser::ParseDouble(arg, 255, true); + m_AlphaValue = max(m_AlphaValue, 0); + m_AlphaValue = min(m_AlphaValue, 255); UpdateTransparency(m_AlphaValue, false); } break; @@ -1623,8 +1617,8 @@ void CMeterWindow::ReadConfig() m_AutoSelectScreen = 0!=parser.ReadInt(section, L"AutoSelectScreen", m_AutoSelectScreen); m_AlphaValue = parser.ReadInt(section, L"AlphaValue", m_AlphaValue); - m_AlphaValue = min(255, m_AlphaValue); - m_AlphaValue = max(0, m_AlphaValue); + m_AlphaValue = max(m_AlphaValue, 0); + m_AlphaValue = min(m_AlphaValue, 255); m_FadeDuration = parser.ReadInt(section, L"FadeDuration", m_FadeDuration); @@ -1729,7 +1723,6 @@ bool CMeterWindow::ReadSkin() if (appVersion > RAINMETER_VERSION) { WCHAR buffer[128]; - std::wstring text; if (appVersion % 1000 != 0) { 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); } - text = L"The skin \""; + std::wstring text = L"The skin \""; text += m_SkinName; text += L"\\"; text += m_SkinIniFile; @@ -1809,7 +1802,7 @@ bool CMeterWindow::ReadSkin() // We want to check the fonts folder first // !!!!!!! - We may want to fix the method in which I get the path to // Rainmeter/fonts - std::wstring szFontFile = m_Rainmeter->GetPath().c_str(); + std::wstring szFontFile = m_Rainmeter->GetPath(); m_FontCollection = new Gdiplus::PrivateFontCollection(); @@ -1828,7 +1821,7 @@ bool CMeterWindow::ReadSkin() // The font wasn't found, check full path. if(nResults != Ok) { - szFontFile = localFont.c_str(); + szFontFile = localFont; nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); if(nResults != Ok) { @@ -1854,7 +1847,7 @@ bool CMeterWindow::ReadSkin() // We want to check the fonts folder first // !!!!!!! - We may want to fix the method in which I get the path to // Rainmeter/fonts - std::wstring szFontFile = m_Rainmeter->GetPath().c_str(); + std::wstring szFontFile = m_Rainmeter->GetPath(); szFontFile += L"Fonts\\"; szFontFile += localFont; @@ -1871,7 +1864,7 @@ bool CMeterWindow::ReadSkin() // The font wasn't found, check full path. if(nResults != Ok) { - szFontFile = localFont.c_str(); + szFontFile = localFont; nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); // The font file wasn't found anywhere, log the error if(nResults != Ok) @@ -1908,11 +1901,9 @@ bool CMeterWindow::ReadSkin() _wcsicmp(L"Variables", 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) - measureName = m_Parser.ReadString(strSection.c_str(), L"Measure", L""); - meterName = m_Parser.ReadString(strSection.c_str(), L"Meter", L""); + std::wstring measureName = m_Parser.ReadString(strSection.c_str(), L"Measure", L""); + std::wstring meterName = m_Parser.ReadString(strSection.c_str(), L"Meter", L""); if (measureName.length() > 0) { // It's a measure @@ -1996,8 +1987,7 @@ bool CMeterWindow::ReadSkin() if (m_Meters.empty()) { - std::wstring text; - text = L"The skin \""; + std::wstring text = L"The skin \""; text += m_SkinName; text += L"\\"; text += m_SkinIniFile; @@ -2104,8 +2094,10 @@ bool CMeterWindow::ResizeWindow(bool reset) std::list::const_iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) { - w = max(w, (*j)->GetX() + (*j)->GetW()); - h = max(h, (*j)->GetY() + (*j)->GetH()); + int mr = (*j)->GetX() + (*j)->GetW(); + w = max(w, mr); + int mb = (*j)->GetY() + (*j)->GetH(); + h = max(h, mb); } w += m_BackgroundMargins.GetRight(); @@ -3120,8 +3112,7 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam) } else if(wParam == ID_CONTEXT_SKINMENU_OPENSKINSFOLDER) { - std::wstring command; - command += L"\""; + std::wstring command = L"\""; command += m_SkinPath + L"\\" + m_SkinName; command += L"\""; 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). ** */ -std::wstring CMeterWindow::MakePathAbsolute(std::wstring path) +std::wstring CMeterWindow::MakePathAbsolute(const std::wstring& path) { if (path.empty() || path.find(L":\\") != std::wstring::npos || path.find(L":/") != std::wstring::npos || diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index 70b01249..6bc34fe5 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -139,7 +139,7 @@ class CMeter; class CMeterWindow : public CGroup { 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(); int Initialize(CRainmeter& Rainmeter); @@ -203,7 +203,7 @@ public: 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; } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 734dbe55..a9695c0e 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -230,8 +230,7 @@ void BangWithArgs(BANGCOMMAND bang, const WCHAR* arg, size_t numOfArgs) } else { - std::wstring dbg; - dbg = L"Unknown config name: " + config; + std::wstring dbg = L"Unknown config name: " + config; 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; /* @@ -1185,11 +1184,6 @@ bool CRainmeter::c_Debug = false; */ CRainmeter::CRainmeter() { - c_GlobalConfig.netInSpeed = 0; - c_GlobalConfig.netOutSpeed = 0; - - c_Debug = false; - m_MenuActive = 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. ** */ -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()) return -1; @@ -1773,7 +1767,7 @@ int CRainmeter::CompareVersions(std::wstring strA, std::wstring strB) ** 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'\\'); if (pos != std::wstring::npos) @@ -1839,9 +1833,9 @@ void CRainmeter::ActivateConfig(int configIndex, int iniIndex) if (_waccess(skinIniPath.c_str(), 0) == -1) { std::wstring message = L"Unable to activate skin \""; - message += skinConfig.c_str(); + message += skinConfig; message += L"\\"; - message += skinIniFile.c_str(); + message += skinIniFile; message += L"\": Ini-file not found."; LSLog(LOG_DEBUG, APPNAME, message.c_str()); 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()); } -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); @@ -2164,7 +2158,7 @@ void CRainmeter::Quit(HINSTANCE dllInst) ** ** 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_ConfigMenu.clear(); @@ -2173,7 +2167,7 @@ void CRainmeter::ScanForConfigs(std::wstring& path) ScanForConfigsRecursive(path, L"", 0, m_ConfigMenu, false); } -int CRainmeter::ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector& menu, bool DontRecurse) +int CRainmeter::ScanForConfigsRecursive(const std::wstring& path, std::wstring base, int index, std::vector& menu, bool DontRecurse) { WIN32_FIND_DATA fileData; // 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 */ -void CRainmeter::ScanForThemes(std::wstring& path) +void CRainmeter::ScanForThemes(const std::wstring& path) { m_Themes.clear(); @@ -2726,7 +2720,7 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow) ** 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 m_DesktopWorkAreas.clear(); @@ -2859,8 +2853,7 @@ void CRainmeter::ReadGeneralSettings(std::wstring& iniFile) { if (!SetActiveConfig(skinName, skinIni)) { - std::wstring error; - error = L"The selected skin (L" + skinName + L"\\" + skinIni + L") cannot be found."; + std::wstring 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); } 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. */ -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) { @@ -2969,9 +2962,9 @@ void CRainmeter::RefreshAll() DeactivateConfig(mw, i); std::wstring message = L"Unable to refresh skin \""; - message += skinConfig.c_str(); + message += skinConfig; message += L"\\"; - message += skinIniFile.c_str(); + message += skinIniFile; message += L"\": Ini-file not found."; LSLog(LOG_DEBUG, APPNAME, message.c_str()); 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 std::wstring message = L"Unable to refresh config \""; - message += skinConfig.c_str(); + message += skinConfig; message += L"\": Config not found."; LSLog(LOG_DEBUG, APPNAME, message.c_str()); 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."); - std::wstring error; - error += L"The Rainmeter.ini file is not writable. This means that the\n"; + std::wstring 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"; if (!bDefaultIniLocation) diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index c94b3188..6e7324a6 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -204,12 +204,12 @@ public: bool IsMenuActive() { return m_MenuActive; } void ShowContextMenu(POINT pos, CMeterWindow* meterWindow); - std::wstring GetTrayExecuteL() { return m_TrayExecuteL; } - std::wstring GetTrayExecuteR() { return m_TrayExecuteR; } - std::wstring GetTrayExecuteM() { return m_TrayExecuteM; } - std::wstring GetTrayExecuteDR() { return m_TrayExecuteDR; } - std::wstring GetTrayExecuteDL() { return m_TrayExecuteDL; } - std::wstring GetTrayExecuteDM() { return m_TrayExecuteDM; } + const std::wstring& GetTrayExecuteL() { return m_TrayExecuteL; } + const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; } + const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; } + const std::wstring& GetTrayExecuteDR() { return m_TrayExecuteDR; } + const std::wstring& GetTrayExecuteDL() { return m_TrayExecuteDL; } + const std::wstring& GetTrayExecuteDM() { return m_TrayExecuteDM; } BOOL ExecuteBang(const std::wstring& bang, const std::wstring& arg, CMeterWindow* meterWindow); std::wstring ParseCommand(const WCHAR* command, CMeterWindow* meterWindow); @@ -224,27 +224,27 @@ public: static void ExpandEnvironmentVariables(std::wstring& strPath); 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); void WriteActive(const std::wstring& config, int iniIndex); - void ScanForConfigs(std::wstring& path); - void ScanForThemes(std::wstring& path); - void ReadGeneralSettings(std::wstring& path); + void ScanForConfigs(const std::wstring& path); + void ScanForThemes(const std::wstring& path); + void ReadGeneralSettings(const std::wstring& iniFile); void SetConfigOrder(int configIndex); 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); HMENU CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU configMenu); void ChangeSkinIndex(HMENU subMenu, int index); - int ScanForConfigsRecursive(std::wstring& path, std::wstring base, int index, std::vector& menu, bool DontRecurse); + int ScanForConfigsRecursive(const std::wstring& path, std::wstring base, int index, std::vector& menu, bool DontRecurse); HMENU CreateConfigMenu(std::vector& configMenuData); HMENU CreateThemeMenu(); void CreateMonitorMenu(HMENU monitorMenu, CMeterWindow* meterWindow); - void CreateDefaultConfigFile(std::wstring strFile); + void CreateDefaultConfigFile(const std::wstring& strFile); void SetLogging(bool logging); void TestSettingsFile(bool bDefaultIniLocation); void CheckSkinVersions(); - int CompareVersions(std::wstring strA, std::wstring strB); + int CompareVersions(const std::wstring& strA, const std::wstring& strB); CTrayWindow* m_TrayWindow; diff --git a/Library/StdAfx.h b/Library/StdAfx.h index bda2ece6..27ed1089 100644 --- a/Library/StdAfx.h +++ b/Library/StdAfx.h @@ -69,5 +69,6 @@ #include #include #include +#include #endif diff --git a/Library/System.cpp b/Library/System.cpp index 2b59f45b..07d4b9bb 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -1242,7 +1242,7 @@ void CSystem::GetIniFileMappingList(std::vector& iniFileMappings) ** Note that a temporary file must be deleted by caller. ** */ -std::wstring CSystem::GetTemporaryFile(const std::vector& iniFileMappings, const std::wstring &iniFile) +std::wstring CSystem::GetTemporaryFile(const std::vector& iniFileMappings, const std::wstring& iniFile) { std::wstring temporary; diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index b58d2f5f..d1f74ddf 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -37,7 +37,9 @@ extern CRainmeter* Rainmeter; 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; @@ -68,13 +70,10 @@ CTrayWindow::CTrayWindow(HINSTANCE instance) instance, this); - m_Instance = instance; m_Measure = NULL; m_TrayIcon = NULL; m_MeterType = TRAY_METER_TYPE_HISTOGRAM; - m_TrayColor1 = Color(0, 100, 0); - m_TrayColor2 = Color(0, 255, 0); m_Bitmap = NULL; @@ -477,8 +476,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } else if(wParam == ID_CONTEXT_OPENSKINSFOLDER) { - std::wstring command; - command += L"\""; + std::wstring command = L"\""; command += Rainmeter->GetSkinPath(); command += L"\""; LSExecute(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL);