diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index f0f0d4e4..d6fe32c1 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -149,7 +149,15 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT defValue = L""; } - result = GetValue(section, key, defValue); + std::wstring strDefault = defValue; + + // If the template is defined read the value first from there. + if (!m_StyleTemplate.empty()) + { + strDefault = GetValue(m_StyleTemplate, key, strDefault); + } + + result = GetValue(section, key, strDefault); if (result == defValue) { return result; diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 777120ec..5bfa540a 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -39,6 +39,7 @@ public: void Initialize(LPCTSTR filename, CRainmeter* pRainmeter); void AddMeasure(CMeasure* pMeasure); void SetVariable(const std::wstring& strVariable, const std::wstring& strValue); + void SetStyleTemplate(const std::wstring& strStyle) { m_StyleTemplate = strStyle; } const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true); double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue); @@ -66,6 +67,8 @@ private: hqMathParser* m_Parser; std::map m_Measures; + std::wstring m_StyleTemplate; + stdext::hash_map > m_Keys; stdext::hash_map m_Values; }; diff --git a/Library/MeasureCalc.h b/Library/MeasureCalc.h index c9bffc1d..aac74ac3 100644 --- a/Library/MeasureCalc.h +++ b/Library/MeasureCalc.h @@ -44,7 +44,6 @@ private: int m_UpdateRandom; int m_LowBound; int m_HighBound; - }; #endif diff --git a/Library/Meter.cpp b/Library/Meter.cpp index cf54611c..3f32307e 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -212,6 +212,10 @@ void CMeter::ReadConfig(const WCHAR* section) { CConfigParser& parser = m_MeterWindow->GetParser(); + // The MeterStyle defines a template where the values are read if the meter doesn't have it itself + const std::wstring& style = parser.ReadString(section, L"MeterStyle", L""); + parser.SetStyleTemplate(style); + const std::wstring& x = parser.ReadString(section, L"X", L"0"); if (x.size() > 0) { diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index cb2e1e8d..d1ab1a27 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1563,12 +1563,8 @@ void CMeterWindow::ReadSkin() { MessageBox(m_Window, error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); } - } - else - { - // It's something else - throw CError(std::wstring(L"Section [") + pos + L"] is not a meter or a measure!", __LINE__, __FILE__); - } + } + // If it's not a meter or measure it will be ignored } pos = pos + wcslen(pos) + 1; }