From 3c1338b4c5972ced898825b7c0aec72b8a773320 Mon Sep 17 00:00:00 2001 From: spx Date: Sat, 26 Nov 2011 02:49:52 +0000 Subject: [PATCH] - Renamed bool ReadFormula() to ParseFormula. - Changed ReadConfig() in Measure/Meter to protected. - Other code tweaks and cleanups. --- Library/ConfigParser.cpp | 145 +++++++++++++++++++------------- Library/ConfigParser.h | 9 +- Library/Measure.cpp | 24 +++--- Library/Measure.h | 3 +- Library/MeasureCPU.h | 4 +- Library/MeasureCalc.h | 6 +- Library/MeasureDiskSpace.h | 4 +- Library/MeasureMemory.h | 2 + Library/MeasureNetIn.h | 4 +- Library/MeasureNetOut.h | 4 +- Library/MeasureNetTotal.h | 4 +- Library/MeasurePhysicalMemory.h | 2 + Library/MeasurePlugin.h | 4 +- Library/MeasureRegistry.h | 4 +- Library/MeasureScript.h | 4 +- Library/MeasureTime.h | 6 +- Library/MeasureUptime.h | 2 + Library/MeasureVirtualMemory.h | 2 + Library/Meter.cpp | 10 +-- Library/Meter.h | 3 +- Library/MeterBar.h | 4 +- Library/MeterBitmap.h | 4 +- Library/MeterButton.h | 4 +- Library/MeterHistogram.h | 4 +- Library/MeterImage.h | 4 +- Library/MeterLine.h | 4 +- Library/MeterRotator.h | 4 +- Library/MeterRoundLine.h | 4 +- Library/MeterString.h | 9 +- Library/MeterWindow.cpp | 20 ++--- Library/Rainmeter.cpp | 9 +- 31 files changed, 198 insertions(+), 118 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 4f1b3fe3..9f1bc707 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -40,7 +40,8 @@ CConfigParser::CConfigParser() : m_Parser(MathParser_Create(NULL)), m_LastReplaced(false), m_LastDefaultUsed(false), - m_LastValueDefined(false) + m_LastValueDefined(false), + m_CurrentSection() { } @@ -76,6 +77,8 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterW m_LastDefaultUsed = false; m_LastValueDefined = false; + m_CurrentSection = NULL; + // Set the built-in variables. Do this before the ini file is read so that the paths can be used with @include SetBuiltInVariables(pRainmeter, meterWindow); ResetMonitorVariables(meterWindow); @@ -106,7 +109,6 @@ void CConfigParser::SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* me SetBuiltInVariable(L"PLUGINSPATH", pRainmeter->GetPluginPath()); SetBuiltInVariable(L"CURRENTPATH", CRainmeter::ExtractPath(m_Filename)); SetBuiltInVariable(L"ADDONSPATH", pRainmeter->GetAddonPath()); - SetBuiltInVariable(L"CRLF", L"\n"); } if (meterWindow) { @@ -114,6 +116,12 @@ void CConfigParser::SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* me SetBuiltInVariable(L"CURRENTCONFIG", meterWindow->GetSkinName()); SetBuiltInVariable(L"ROOTCONFIGPATH", meterWindow->GetSkinRootPath()); } + + SetBuiltInVariable(L"CRLF", L"\n"); + + static const std::wstring CURRENTSECTION = L"CURRENTSECTION"; + SetBuiltInVariable(CURRENTSECTION, L""); + m_CurrentSection = &((*m_BuiltInVariables.find(StrToLower(CURRENTSECTION))).second); // shortcut } /* @@ -461,7 +469,7 @@ bool CConfigParser::ReplaceVariables(std::wstring& result) if (end != std::wstring::npos) { size_t ei = end - 1; - if (result[si] == L'*' && result[ei] == L'*') + if (si != ei && result[si] == L'*' && result[ei] == L'*') { result.erase(ei, 1); result.erase(si, 1); @@ -528,7 +536,7 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result) if (next == std::wstring::npos || end < next) { size_t ei = end - 1; - if (result[si] == L'*' && result[ei] == L'*') + if (si != ei && result[si] == L'*' && result[ei] == L'*') { result.erase(ei, 1); result.erase(si, 1); @@ -633,26 +641,28 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT { m_LastValueDefined = true; - if (result.find(L'#') != std::wstring::npos) + if (result.size() >= 3) { - static const std::wstring CURRENTSECTION = L"CURRENTSECTION"; - SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily + if (result.find(L'#') != std::wstring::npos) + { + m_CurrentSection->assign(strSection); // Set temporarily - if (ReplaceVariables(result)) + if (ReplaceVariables(result)) + { + m_LastReplaced = true; + } + + m_CurrentSection->clear(); // Reset + } + else + { + CRainmeter::ExpandEnvironmentVariables(result); + } + + if (bReplaceMeasures && ReplaceMeasures(result)) { m_LastReplaced = true; } - - SetBuiltInVariable(CURRENTSECTION, L""); // Reset - } - else - { - CRainmeter::ExpandEnvironmentVariables(result); - } - - if (bReplaceMeasures && ReplaceMeasures(result)) - { - m_LastReplaced = true; } } @@ -667,8 +677,8 @@ bool CConfigParser::IsKeyDefined(LPCTSTR section, LPCTSTR key) bool CConfigParser::IsValueDefined(LPCTSTR section, LPCTSTR key) { - const std::wstring& result = ReadString(section, key, L"", false); - return (!m_LastDefaultUsed && !result.empty()); + ReadString(section, key, L"", false); + return m_LastValueDefined; } void CConfigParser::AddMeasure(CMeasure* pMeasure) @@ -694,7 +704,7 @@ double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue) { const std::wstring& result = ReadString(section, key, L""); - return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue); + return (m_LastDefaultUsed) ? defValue : ParseDouble(result.c_str(), defValue); } std::vector CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key) @@ -708,7 +718,7 @@ std::vector CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR ke std::vector::const_iterator iter = tokens.begin(); for ( ; iter != tokens.end(); ++iter) { - result.push_back((Gdiplus::REAL)ParseDouble((*iter), 0)); + result.push_back((Gdiplus::REAL)ParseDouble((*iter).c_str(), 0.0)); } } return result; @@ -718,14 +728,14 @@ int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue) { const std::wstring& result = ReadString(section, key, L""); - return (m_LastDefaultUsed) ? defValue : (int)ParseDouble(result, defValue, true); + return (m_LastDefaultUsed) ? defValue : ParseInt(result.c_str(), defValue); } unsigned int CConfigParser::ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue) { const std::wstring& result = ReadString(section, key, L""); - return (m_LastDefaultUsed) ? defValue : (unsigned int)ParseDouble(result, defValue, true); + return (m_LastDefaultUsed) ? defValue : ParseUInt(result.c_str(), defValue); } // Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula @@ -743,9 +753,9 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) std::wstring error = L"ReadFormula: "; error += ConvertToWide(errMsg); error += L" in key \""; - error += key ? key : L""; + error += key; error += L"\" in ["; - error += section ? section : L""; + error += section; error += L"]"; Log(LOG_ERROR, error.c_str()); } @@ -753,12 +763,12 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) return resultValue; } - return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue); + return (m_LastDefaultUsed) ? defValue : ParseDouble(result.c_str(), defValue); } // Returns true if the formula was read successfully, false for failure. // Pass a pointer to a double. -bool CConfigParser::ReadFormula(const std::wstring& result, double* resultValue) +bool CConfigParser::ParseFormula(const std::wstring& result, double* resultValue) { // Formulas must be surrounded by parenthesis if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') @@ -766,7 +776,7 @@ bool CConfigParser::ReadFormula(const std::wstring& result, double* resultValue) char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), resultValue); if (errMsg != NULL) { - std::wstring error = L"ReadFormula: "; + std::wstring error = L"ParseFormula: "; error += ConvertToWide(errMsg); error += L": "; error += result; @@ -874,40 +884,59 @@ void CConfigParser::Shrink(std::vector& vec) ** If the given string is invalid format or causes overflow/underflow, returns given default value. ** */ -double CConfigParser::ParseDouble(const std::wstring& string, double defValue, bool rejectExp) +double CConfigParser::ParseDouble(LPCTSTR string, double defValue) { - std::wstring::size_type pos; - - // Ignore inline comments which start with ';' - if ((pos = string.find_first_of(L';')) != std::wstring::npos) + if (string && *string) { - std::wstring temp(string, 0, pos); - return ParseDouble(temp, defValue, rejectExp); - } - - if (rejectExp) - { - // Reject if the given string includes the exponential part - if (string.find_last_of(L"dDeE") != std::wstring::npos) - { - return defValue; - } - } - - if ((pos = string.find_first_not_of(L" \t\r\n")) != std::wstring::npos) - { - // Trim white-space - std::wstring temp(string, pos, string.find_last_not_of(L" \t\r\n") - pos + 1); - - WCHAR* end = NULL; errno = 0; - double resultValue = wcstod(temp.c_str(), &end); - if (end && *end == L'\0' && errno != ERANGE) + double resultValue = wcstod(string, NULL); + if (errno != ERANGE) { return resultValue; } } + return defValue; +} +/* +** ParseInt +** +** This is a helper method that parses the integer value from the given string. +** If the given string is invalid format or causes overflow/underflow, returns given default value. +** +*/ +int CConfigParser::ParseInt(LPCTSTR string, int defValue) +{ + if (string && *string) + { + errno = 0; + int resultValue = wcstol(string, NULL, 10); + if (errno != ERANGE) + { + return resultValue; + } + } + return defValue; +} + +/* +** ParseUInt +** +** This is a helper method that parses the unsigned integer value from the given string. +** If the given string is invalid format or causes overflow/underflow, returns given default value. +** +*/ +unsigned int CConfigParser::ParseUInt(LPCTSTR string, unsigned int defValue) +{ + if (string && *string) + { + errno = 0; + unsigned int resultValue = wcstoul(string, NULL, 10); + if (errno != ERANGE) + { + return resultValue; + } + } return defValue; } @@ -1198,9 +1227,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int clen = len - (clen + 1); // value's length // Trim surrounded quotes from value - if (clen >= 2 && ( - (sep[0] == L'\"' && sep[clen - 1] == L'\"') || - (sep[0] == L'\'' && sep[clen - 1] == L'\''))) + if (clen >= 2 && (sep[0] == L'\"' || sep[0] == L'\'') && sep[clen - 1] == sep[0]) { clen -= 2; ++sep; diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index c94eeb79..4c41a0bd 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -74,7 +74,7 @@ public: RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue); std::vector ReadFloats(LPCTSTR section, LPCTSTR key); - bool ReadFormula(const std::wstring& result, double* resultValue); + bool ParseFormula(const std::wstring& result, double* resultValue); const std::wstring& GetFilename() { return m_Filename; } const std::list& GetSections() { return m_Sections; } @@ -84,7 +84,9 @@ public: static std::vector Tokenize(const std::wstring& str, const std::wstring& delimiters); static void Shrink(std::vector& vec); - static double ParseDouble(const std::wstring& string, double defValue, bool rejectExp = false); + static double ParseDouble(LPCTSTR string, double defValue); + static int ParseInt(LPCTSTR string, int defValue); + static unsigned int ParseUInt(LPCTSTR string, unsigned int defValue); static Gdiplus::ARGB ParseColor(LPCTSTR string); static Gdiplus::Rect ParseRect(LPCTSTR string); static RECT ParseRECT(LPCTSTR string); @@ -107,6 +109,7 @@ private: static void SetMultiMonitorVariables(bool reset); static void SetMonitorVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); } + static void SetMonitorVariable(const WCHAR* strVariable, const WCHAR* strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); } static std::wstring StrToLower(const std::wstring& str) { std::wstring strTmp(str); StrToLowerC(strTmp); return strTmp; } static std::wstring StrToLower(const WCHAR* str) { std::wstring strTmp(str); StrToLowerC(strTmp); return strTmp; } @@ -124,6 +127,8 @@ private: bool m_LastDefaultUsed; bool m_LastValueDefined; + std::wstring* m_CurrentSection; + std::list m_Sections; // The sections must be an ordered array std::unordered_map m_Values; diff --git a/Library/Measure.cpp b/Library/Measure.cpp index aa1dbd1f..acc1f434 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -142,7 +142,7 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section) const std::wstring& result = parser.ReadString(section, L"Disabled", L"0"); if (parser.GetLastReplaced()) { - m_Disabled = 0!=(int)parser.ParseDouble(result, 0.0, true); + m_Disabled = 0!=parser.ParseInt(result.c_str(), 0); } } @@ -172,17 +172,19 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section) m_RegExpSubstitute = 0!=parser.ReadInt(section, L"RegExpSubstitute", 0); 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'\"')) + if (!subs.empty()) { - // Add quotes since they are removed by the GetProfileString - subs.insert(0, L"\""); - subs.append(L"\""); - } - if (!ParseSubstitute(subs)) - { - LogWithArgs(LOG_ERROR, L"Measure: Invalid Substitute=%s", subs.c_str()); + if ((subs[0] != L'\"' || subs[subs.length() - 1] != L'\'') && + (subs[0] != L'\'' || subs[subs.length() - 1] != L'\"')) + { + // Add quotes since they are removed by the GetProfileString + subs.insert(0, L"\""); + subs.append(L"\""); + } + if (!ParseSubstitute(subs)) + { + LogWithArgs(LOG_ERROR, L"Measure: Invalid Substitute=%s", subs.c_str()); + } } const std::wstring& group = parser.ReadString(section, L"Group", L""); diff --git a/Library/Measure.h b/Library/Measure.h index 6b3f25bd..240d505b 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -49,7 +49,6 @@ public: void ReadConfig(CConfigParser& parser) { ReadConfig(parser, GetName()); } - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update() = 0; @@ -87,6 +86,8 @@ public: static CMeasure* Create(const WCHAR* measure, CMeterWindow* meterWindow, const WCHAR* name); protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + virtual bool PreUpdate(); virtual bool PostUpdate(); diff --git a/Library/MeasureCPU.h b/Library/MeasureCPU.h index 8e445484..cb097294 100644 --- a/Library/MeasureCPU.h +++ b/Library/MeasureCPU.h @@ -37,10 +37,12 @@ public: CMeasureCPU(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureCPU(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + +private: void CalcUsage(double idleTime, double systemTime); void CalcAverageUsage(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo); diff --git a/Library/MeasureCalc.h b/Library/MeasureCalc.h index 349b88fb..9ab42fae 100644 --- a/Library/MeasureCalc.h +++ b/Library/MeasureCalc.h @@ -28,11 +28,13 @@ public: CMeasureCalc(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureCalc(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); static void UpdateVariableMap(CMeterWindow& meterWindow); - + +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: void FormulaReplace(); bool IsDelimiter(WCHAR ch); diff --git a/Library/MeasureDiskSpace.h b/Library/MeasureDiskSpace.h index edd7707b..843923ab 100644 --- a/Library/MeasureDiskSpace.h +++ b/Library/MeasureDiskSpace.h @@ -27,10 +27,12 @@ public: CMeasureDiskSpace(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureDiskSpace(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: std::wstring m_Drive; std::wstring m_LabelName; diff --git a/Library/MeasureMemory.h b/Library/MeasureMemory.h index 864f0bb3..86b4e6e5 100644 --- a/Library/MeasureMemory.h +++ b/Library/MeasureMemory.h @@ -28,6 +28,8 @@ public: virtual ~CMeasureMemory(); virtual bool Update(); + +protected: virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); private: diff --git a/Library/MeasureNetIn.h b/Library/MeasureNetIn.h index eaefd0cf..7a55e54b 100644 --- a/Library/MeasureNetIn.h +++ b/Library/MeasureNetIn.h @@ -27,9 +27,11 @@ public: CMeasureNetIn(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureNetIn(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: bool m_FirstTime; ULONG64 m_InOctets; diff --git a/Library/MeasureNetOut.h b/Library/MeasureNetOut.h index 83de7b67..e1a080cb 100644 --- a/Library/MeasureNetOut.h +++ b/Library/MeasureNetOut.h @@ -27,9 +27,11 @@ public: CMeasureNetOut(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureNetOut(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: bool m_FirstTime; ULONG64 m_OutOctets; diff --git a/Library/MeasureNetTotal.h b/Library/MeasureNetTotal.h index 10e4aaa9..c596e5f5 100644 --- a/Library/MeasureNetTotal.h +++ b/Library/MeasureNetTotal.h @@ -27,9 +27,11 @@ public: CMeasureNetTotal(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureNetTotal(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: bool m_FirstTime; ULONG64 m_TotalOctets; diff --git a/Library/MeasurePhysicalMemory.h b/Library/MeasurePhysicalMemory.h index 42aa3698..639db0b7 100644 --- a/Library/MeasurePhysicalMemory.h +++ b/Library/MeasurePhysicalMemory.h @@ -28,6 +28,8 @@ public: virtual ~CMeasurePhysicalMemory(); virtual bool Update(); + +protected: virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); private: diff --git a/Library/MeasurePlugin.h b/Library/MeasurePlugin.h index b70e0d52..cfddafd9 100644 --- a/Library/MeasurePlugin.h +++ b/Library/MeasurePlugin.h @@ -34,11 +34,13 @@ public: CMeasurePlugin(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasurePlugin(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); virtual void ExecuteBang(const WCHAR* args); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: std::wstring m_PluginName; HMODULE m_Plugin; diff --git a/Library/MeasureRegistry.h b/Library/MeasureRegistry.h index 8671b66d..8a6eb17c 100644 --- a/Library/MeasureRegistry.h +++ b/Library/MeasureRegistry.h @@ -27,10 +27,12 @@ public: CMeasureRegistry(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureRegistry(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: std::wstring m_RegKeyName; std::wstring m_RegValueName; diff --git a/Library/MeasureScript.h b/Library/MeasureScript.h index 8c18d805..963f1fc9 100644 --- a/Library/MeasureScript.h +++ b/Library/MeasureScript.h @@ -27,7 +27,6 @@ public: CMeasureScript(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureScript(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); @@ -36,6 +35,9 @@ public: void DeleteLuaScript(); protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + +private: LuaScript* m_LuaScript; bool m_HasInitializeFunction; diff --git a/Library/MeasureTime.h b/Library/MeasureTime.h index a8143594..9edcbce4 100644 --- a/Library/MeasureTime.h +++ b/Library/MeasureTime.h @@ -27,10 +27,12 @@ public: CMeasureTime(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeasureTime(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); - + +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: void TimeToString(WCHAR* buf, size_t bufLen, const WCHAR* format, const struct tm* time); diff --git a/Library/MeasureUptime.h b/Library/MeasureUptime.h index 7d1f4888..ea67ef97 100644 --- a/Library/MeasureUptime.h +++ b/Library/MeasureUptime.h @@ -29,6 +29,8 @@ public: virtual bool Update(); virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual); + +protected: virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); private: diff --git a/Library/MeasureVirtualMemory.h b/Library/MeasureVirtualMemory.h index f23d3d05..10be4e07 100644 --- a/Library/MeasureVirtualMemory.h +++ b/Library/MeasureVirtualMemory.h @@ -28,6 +28,8 @@ public: virtual ~CMeasureVirtualMemory(); virtual bool Update(); + +protected: virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); private: diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 6146d495..925e8d95 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -307,13 +307,13 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section) } double val; - if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ReadFormula(coord, &val)) + if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ParseFormula(coord, &val)) { m_X = (int)val; } else { - m_X = (int)parser.ParseDouble(coord, 0.0); + m_X = (int)parser.ParseDouble(coord.c_str(), 0.0); } } else @@ -346,13 +346,13 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section) } double val; - if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ReadFormula(coord, &val)) + if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ParseFormula(coord, &val)) { m_Y = (int)val; } else { - m_Y = (int)parser.ParseDouble(coord, 0.0); + m_Y = (int)parser.ParseDouble(coord.c_str(), 0.0); } } else @@ -380,7 +380,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section) m_StyleHidden = parser.GetLastUsedStyle(); if (parser.GetLastReplaced() || !parser.GetLastDefaultUsed() && m_StyleHidden != oldStyleHidden) { - m_Hidden = 0!=(int)parser.ParseDouble(result, 0.0, true); + m_Hidden = 0!=parser.ParseInt(result.c_str(), 0); } } diff --git a/Library/Meter.h b/Library/Meter.h index c09c64c1..49f5b425 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -38,7 +38,6 @@ public: void ReadConfig(CConfigParser& parser) { ReadConfig(parser, GetName()); parser.ClearStyleTemplate(); } - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); @@ -120,6 +119,8 @@ protected: POSITION_RELATIVE_BR }; + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + void SetAllMeasures(CMeasure* measure); void SetAllMeasures(const std::vector& measures); void ReplaceToolTipMeasures(std::wstring& str); diff --git a/Library/MeterBar.h b/Library/MeterBar.h index 33eb5549..b71ea938 100644 --- a/Library/MeterBar.h +++ b/Library/MeterBar.h @@ -28,11 +28,13 @@ public: CMeterBar(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterBar(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: enum ORIENTATION { diff --git a/Library/MeterBitmap.h b/Library/MeterBitmap.h index 22c7f7f1..d0859c42 100644 --- a/Library/MeterBitmap.h +++ b/Library/MeterBitmap.h @@ -30,12 +30,14 @@ public: virtual bool HitTest(int x, int y); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); virtual bool HasActiveTransition(); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: CTintedImage m_Image; std::wstring m_ImageName; // Name of the image diff --git a/Library/MeterButton.h b/Library/MeterButton.h index 7fbd6572..c8a89542 100644 --- a/Library/MeterButton.h +++ b/Library/MeterButton.h @@ -30,7 +30,6 @@ public: CMeterButton(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterButton(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); @@ -42,6 +41,9 @@ public: void SetFocus(bool f) { m_Focus = f; } +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: bool HitTest2(int px, int py, bool checkAlpha); diff --git a/Library/MeterHistogram.h b/Library/MeterHistogram.h index 1e8f263f..1c6e027c 100644 --- a/Library/MeterHistogram.h +++ b/Library/MeterHistogram.h @@ -28,12 +28,14 @@ public: CMeterHistogram(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterHistogram(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); virtual void BindMeasure(const std::list& measures); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: void DisposeBuffer(); diff --git a/Library/MeterImage.h b/Library/MeterImage.h index 0e79a0b6..cae4b115 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -28,13 +28,15 @@ public: CMeterImage(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterImage(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); virtual void BindMeasure(const std::list& measures); protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + +private: void LoadImage(const std::wstring& imageName, bool bLoadAlways); CTintedImage m_Image; diff --git a/Library/MeterLine.h b/Library/MeterLine.h index cb223570..6b98be92 100644 --- a/Library/MeterLine.h +++ b/Library/MeterLine.h @@ -27,12 +27,14 @@ public: CMeterLine(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterLine(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); virtual void BindMeasure(const std::list& measures); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: std::vector m_MeasureNames; // Name of the other measures std::vector m_Measures; // Pointer ot the other measures diff --git a/Library/MeterRotator.h b/Library/MeterRotator.h index 841159a8..e4b16de0 100644 --- a/Library/MeterRotator.h +++ b/Library/MeterRotator.h @@ -28,11 +28,13 @@ public: CMeterRotator(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterRotator(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: CTintedImage m_Image; std::wstring m_ImageName; // Name of the image diff --git a/Library/MeterRoundLine.h b/Library/MeterRoundLine.h index 144065d9..52a23162 100644 --- a/Library/MeterRoundLine.h +++ b/Library/MeterRoundLine.h @@ -27,10 +27,12 @@ public: CMeterRoundLine(CMeterWindow* meterWindow, const WCHAR* name); virtual ~CMeterRoundLine(); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual bool Update(); virtual bool Draw(Gdiplus::Graphics& graphics); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: bool m_Solid; double m_LineWidth; diff --git a/Library/MeterString.h b/Library/MeterString.h index 28e11cf4..d076b2cb 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -23,11 +23,6 @@ #include "Measure.h" #include -namespace Gdiplus -{ -class Font; -} - class CMeterString : public CMeter { public: @@ -36,7 +31,6 @@ public: virtual int GetX(bool abs = false); - virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); virtual void Initialize(); virtual bool Update(); void SetText(const WCHAR* text) { m_Text = text; } @@ -47,6 +41,9 @@ public: static void FreeFontCache(Gdiplus::PrivateFontCollection* collection = NULL); static void EnumerateInstalledFontFamilies(); +protected: + virtual void ReadConfig(CConfigParser& parser, const WCHAR* section); + private: enum TEXTSTYLE { diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 1b4f842c..b3c53e46 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -900,7 +900,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg) case BANG_SETTRANSPARENCY: if (arg != NULL) { - m_AlphaValue = (int)CConfigParser::ParseDouble(arg, 255, true); + m_AlphaValue = CConfigParser::ParseInt(arg, 255); m_AlphaValue = max(m_AlphaValue, 0); m_AlphaValue = min(m_AlphaValue, 255); UpdateTransparency(m_AlphaValue, false); @@ -1003,7 +1003,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg) double value; // Formula read fine - if (m_Parser.ReadFormula(strValue, &value)) + if (m_Parser.ParseFormula(strValue, &value)) { WCHAR buffer[256]; int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", value); @@ -1115,31 +1115,31 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode) if (token) { while (token[0] == L' ') ++token; - type = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + type = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token); token = wcstok(NULL, L","); if (token) { while (token[0] == L' ') ++token; - x = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + x = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token); token = wcstok(NULL, L","); if (token) { while (token[0] == L' ') ++token; - y = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + y = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token); token = wcstok(NULL, L","); if (token) { while (token[0] == L' ') ++token; - w = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + w = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token); token = wcstok(NULL, L","); if (token) { while (token[0] == L' ') ++token; - h = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + h = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token); } } } @@ -1161,7 +1161,7 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode) if (token) { while (token[0] == L' ') ++token; - int r = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + int r = (m_Parser.ParseFormula(token, &val)) ? (int)val : _wtoi(token); tempRegion = CreateRoundRectRgn(x, y, w, h, r, r); } break; @@ -1924,7 +1924,7 @@ void CMeterWindow::ReadConfig() double value; if (!m_WindowX.empty() && m_WindowX[0] == L'(' && m_WindowX[m_WindowX.size() - 1] == L')') { - if (!parser.ReadFormula(m_WindowX, &value)) + if (!parser.ParseFormula(m_WindowX, &value)) { value = 0.0; } @@ -1933,7 +1933,7 @@ void CMeterWindow::ReadConfig() } if (!m_WindowY.empty() && m_WindowY[0] == L'(' && m_WindowY[m_WindowY.size() - 1] == L')') { - if (!parser.ReadFormula(m_WindowY, &value)) + if (!parser.ParseFormula(m_WindowY, &value)) { value = 0.0; } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index c3bdbed7..e8845d5e 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -668,7 +668,7 @@ void CRainmeter::RainmeterWriteKeyValue(const WCHAR* arg) if (mw) { double value; - formula = mw->GetParser().ReadFormula(strValue, &value); + formula = mw->GetParser().ParseFormula(strValue, &value); // Formula read fine if (formula) @@ -3170,13 +3170,16 @@ std::wstring CRainmeter::ExtractPath(const std::wstring& strFilePath) void CRainmeter::ExpandEnvironmentVariables(std::wstring& strPath) { - if (strPath.find(L'%') != std::wstring::npos) + std::wstring::size_type pos; + + if ((pos = strPath.find(L'%')) != std::wstring::npos && + strPath.find(L'%', pos + 2) != std::wstring::npos) { DWORD bufSize = 4096; WCHAR* buffer = new WCHAR[bufSize]; // lets hope the buffer is large enough... // %APPDATA% is a special case - std::wstring::size_type pos = strPath.find(L"%APPDATA%"); + pos = strPath.find(L"%APPDATA%", pos); if (pos != std::wstring::npos) { HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer);