From fb004083d2c33355884e49fb3244ba49dc23ac9f Mon Sep 17 00:00:00 2001 From: spx Date: Wed, 27 Jul 2011 14:18:02 +0000 Subject: [PATCH] - SetOption: Fixed that new image isn't loaded if DynamicVariables=0. - SetOption: Fixed that Rainmeter crashes if !SetOption is executed to Measure=Plugin. - Code cleanup and cosmetic changes. --- Library/ConfigParser.cpp | 6 +++--- Library/MeasureScript.cpp | 15 +++++++-------- Library/MeasureScript.h | 1 - Library/MeterImage.cpp | 14 +++++++++++++- Library/MeterImage.h | 2 +- Library/MeterWindow.cpp | 17 ++++++++++------- 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 89b50c2a..8d92f860 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -1208,10 +1208,10 @@ void CConfigParser::DeleteValue(const std::wstring& strSection, const std::wstri std::wstring strTmp = strSection + L"::"; strTmp += strKey; - std::unordered_map::iterator i = m_Values.find(StrToLower(strTmp)); - if (i != m_Values.end()) + std::unordered_map::iterator iter = m_Values.find(StrToLower(strTmp)); + if (iter != m_Values.end()) { - m_Values.erase(i); + m_Values.erase(iter); } } diff --git a/Library/MeasureScript.cpp b/Library/MeasureScript.cpp index ec566362..bcf74f38 100644 --- a/Library/MeasureScript.cpp +++ b/Library/MeasureScript.cpp @@ -62,6 +62,8 @@ void CMeasureScript::DeleteLuaScript() m_HasInitializeFunction = false; m_HasUpdateFunction = false; m_HasGetStringFunction = false; + + m_ScriptFile.clear(); } /* @@ -125,9 +127,6 @@ const WCHAR* CMeasureScript::GetStringValue(AUTOSCALE autoScale, double scale, i */ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section) { - // Store the current values - std::string oldScriptFile = m_ScriptFile; - // Read common configs CMeasure::ReadConfig(parser, section); @@ -135,15 +134,15 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section) if (!file.empty()) { - file = m_MeterWindow->MakePathAbsolute(file); - m_ScriptFile = ConvertToAscii(file.c_str()); + std::string scriptFile = ConvertToAscii(m_MeterWindow->MakePathAbsolute(file).c_str()); if (!m_Initialized || - oldScriptFile != m_ScriptFile) + scriptFile != m_ScriptFile) { - lua_State* L = LuaManager::GetState(); - DeleteLuaScript(); + + lua_State* L = LuaManager::GetState(); + m_ScriptFile = scriptFile; m_LuaScript = new LuaScript(LuaManager::GetState(), m_ScriptFile.c_str()); if (m_LuaScript->IsInitialized()) diff --git a/Library/MeasureScript.h b/Library/MeasureScript.h index 0955bd15..0c0792c8 100644 --- a/Library/MeasureScript.h +++ b/Library/MeasureScript.h @@ -45,7 +45,6 @@ protected: std::wstring m_StringValue; std::string m_ScriptFile; - std::string m_TableName; }; #endif \ No newline at end of file diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index 5fc52e8f..c2c0f6a4 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -33,7 +33,7 @@ using namespace Gdiplus; ** */ CMeterImage::CMeterImage(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name), - m_NeedsReload(false), + m_NeedsRedraw(false), m_WidthDefined(false), m_HeightDefined(false), m_PreserveAspectRatio(false), @@ -157,6 +157,13 @@ void CMeterImage::ReadConfig(CConfigParser& parser, const WCHAR* section) // Read tinting configs m_Image.ReadConfig(parser, section); + + if (m_Initialized && + !m_Measure && !m_DynamicVariables) + { + Initialize(); + m_NeedsRedraw = true; + } } /* @@ -216,6 +223,11 @@ bool CMeterImage::Update() LoadImage(m_ImageNameResult, oldResult != m_ImageNameResult); return true; } + else if (m_NeedsRedraw) + { + m_NeedsRedraw = false; + return true; + } } return false; } diff --git a/Library/MeterImage.h b/Library/MeterImage.h index 81f4c21b..3d0d38a8 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -42,7 +42,7 @@ protected: std::wstring m_ImageNameResult; // Name of the image (as absolute path) std::wstring m_Path; - bool m_NeedsReload; + bool m_NeedsRedraw; bool m_WidthDefined; bool m_HeightDefined; bool m_PreserveAspectRatio; // If true, aspect ratio of the image is preserved when the image is scaled diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index d4c381ff..b124d157 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1461,27 +1461,29 @@ void CMeterWindow::SetOption(const WCHAR* arg, bool group) if (group) { - for (std::list::const_iterator i = m_Meters.begin(); i != m_Meters.end(); ++i) + for (std::list::const_iterator j = m_Meters.begin(); j != m_Meters.end(); ++j) { - if ((*i)->BelongsToGroup(section)) + if ((*j)->BelongsToGroup(section)) { - (*i)->SetDynamicVariables(true); + // Force DynamicVariables temporarily (it will reset back to original setting in ReadConfig()) + (*j)->SetDynamicVariables(true); if (value.empty()) { - GetParser().DeleteValue((*i)->GetName(), option); + GetParser().DeleteValue((*j)->GetName(), option); } else { - GetParser().SetValue((*i)->GetName(), option, value); + GetParser().SetValue((*j)->GetName(), option, value); } } } for (std::list::const_iterator i = m_Measures.begin(); i != m_Measures.end(); ++i) { - if ((*i)->BelongsToGroup(section)) + if ((*i)->BelongsToGroup(section) && dynamic_cast(*i) == NULL) { + // Force DynamicVariables temporarily (it will reset back to original setting in ReadConfig()) (*i)->SetDynamicVariables(true); if (value.empty()) @@ -1516,8 +1518,9 @@ void CMeterWindow::SetOption(const WCHAR* arg, bool group) } CMeasure* measure = GetMeasure(section); - if (measure) + if (measure && dynamic_cast(measure) == NULL) { + // Force DynamicVariables temporarily (it will reset back to original setting in ReadConfig()) measure->SetDynamicVariables(true); if (value.empty())