From e74d6f4619a5346430fb3ee2074db6da529ce65a Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 29 Jul 2011 17:18:21 +0000 Subject: [PATCH] - Added ability to escape real variables and measures as follows: #*RealVar*# [*RealMeasure*] - NowPlayingPlugin: Addition change to r880 OpenPlayer fix - Removing tolua++ generation package files --- Library/ConfigParser.cpp | 58 +++++++---- Library/Library.vcxproj | 8 -- Library/Library.vcxproj.filters | 3 - Library/MeasureScript.cpp | 7 +- Library/Rainmeter.cpp | 35 ++++--- Library/lua/LuaManager.cpp | 1 - Library/lua/LuaManager.h | 1 - Library/lua/LuaScript.cpp | 2 +- Library/lua/glue/LuaGroup.cpp | 23 ----- Library/lua/glue/LuaMeasure.cpp | 8 +- Library/lua/glue/LuaMeter.cpp | 8 +- Library/lua/glue/LuaMeterWindow.cpp | 132 +----------------------- Plugins/PluginNowPlaying/NowPlaying.cpp | 15 +-- 13 files changed, 77 insertions(+), 224 deletions(-) delete mode 100644 Library/lua/glue/LuaGroup.cpp diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 8d92f860..942cc3ae 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -453,19 +453,28 @@ bool CConfigParser::ReplaceVariables(std::wstring& result) end = result.find(L'#', pos + 1); if (end != std::wstring::npos) { - std::wstring strVariable = result.substr(pos + 1, end - (pos + 1)); - std::wstring strValue; - - if (GetVariable(strVariable, strValue)) + if (result[pos + 1] == L'*' && result[end - 1] == L'*') { - // Variable found, replace it with the value - result.replace(pos, end - pos + 1, strValue); - start = pos + strValue.length(); - replaced = true; + result.erase(pos + 1, 1); + result.erase(end - 2, 1); + start = end - 1; } else { - start = end; + std::wstring strVariable = result.substr(pos + 1, end - (pos + 1)); + std::wstring strValue; + + if (GetVariable(strVariable, strValue)) + { + // Variable found, replace it with the value + result.replace(pos, end - pos + 1, strValue); + start = pos + strValue.length(); + replaced = true; + } + else + { + start = end; + } } } else @@ -510,21 +519,30 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result) pos2 = result.find(L'[', pos + 1); if (pos2 == std::wstring::npos || end < pos2) { - std::wstring var = result.substr(pos + 1, end - (pos + 1)); - - CMeasure* measure = GetMeasure(var); - if (measure) + if (result[pos + 1] == L'*' && result[end - 1] == L'*') { - std::wstring value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false); - - // Measure found, replace it with the value - result.replace(pos, end - pos + 1, value); - start = pos + value.length(); - replaced = true; + result.erase(pos + 1, 1); + result.erase(end - 2, 1); + start = end - 1; } else { - start = end; + std::wstring var = result.substr(pos + 1, end - (pos + 1)); + + CMeasure* measure = GetMeasure(var); + if (measure) + { + std::wstring value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false); + + // Measure found, replace it with the value + result.replace(pos, end - pos + 1, value); + start = pos + value.length(); + replaced = true; + } + else + { + start = end; + } } } else diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index 580132ee..109f8bc6 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -747,14 +747,6 @@ Use ../StdAfx.h - - Use - ../../StdAfx.h - Use - ../../StdAfx.h - Use - ../../StdAfx.h - Use ../../StdAfx.h diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index abf2c2d2..8ca45976 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -171,9 +171,6 @@ Lua - - Lua\glue - Lua\glue diff --git a/Library/MeasureScript.cpp b/Library/MeasureScript.cpp index bcf74f38..2522a45e 100644 --- a/Library/MeasureScript.cpp +++ b/Library/MeasureScript.cpp @@ -197,11 +197,8 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section) } } - // Pop PROPERTIES table - lua_pop(L, 1); - - // Pop the table - lua_pop(L, 1); + // Pop PROPERTIES table and our table + lua_pop(L, 2); } else { diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index c40cf61f..6eba24ed 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -3182,22 +3182,31 @@ std::wstring CRainmeter::ParseCommand(const WCHAR* command, CMeterWindow* meterW { if (meterWindow) { - const std::list& measures = meterWindow->GetMeasures(); - std::list::const_iterator iter = measures.begin(); - for ( ; iter != measures.end(); ++iter) + if (strCommand[start + 1] == L'*' && strCommand[end - 1] == L'*') { - if (_wcsicmp((*iter)->GetName(), measureName.c_str()) == 0) - { - std::wstring value = (*iter)->GetStringValue(AUTOSCALE_OFF, 1, -1, false); - strCommand.replace(start, (end - start) + 1, value); - start += value.length(); - break; - } + strCommand.erase(start + 1, 1); + strCommand.erase(end - 2, 1); + start = end - 1; } - if (iter == measures.end()) + else { - //LogWithArgs(LOG_WARNING, L"No such measure [%s] for execute string: %s", measureName.c_str(), command); - start = end + 1; + const std::list& measures = meterWindow->GetMeasures(); + std::list::const_iterator iter = measures.begin(); + for ( ; iter != measures.end(); ++iter) + { + if (_wcsicmp((*iter)->GetName(), measureName.c_str()) == 0) + { + std::wstring value = (*iter)->GetStringValue(AUTOSCALE_OFF, 1, -1, false); + strCommand.replace(start, (end - start) + 1, value); + start += value.length(); + break; + } + } + if (iter == measures.end()) + { + //LogWithArgs(LOG_WARNING, L"No such measure [%s] for execute string: %s", measureName.c_str(), command); + start = end + 1; + } } } } diff --git a/Library/lua/LuaManager.cpp b/Library/lua/LuaManager.cpp index 2960dac6..47713795 100644 --- a/Library/lua/LuaManager.cpp +++ b/Library/lua/LuaManager.cpp @@ -39,7 +39,6 @@ void LuaManager::Init() tolua_beginmodule(c_State, NULL); RegisterGlobal(c_State); RegisterMeasure(c_State); - RegisterGroup(c_State); RegisterMeasure(c_State); RegisterMeter(c_State); RegisterMeterWindow(c_State); diff --git a/Library/lua/LuaManager.h b/Library/lua/LuaManager.h index 1aff6af8..a8a17586 100644 --- a/Library/lua/LuaManager.h +++ b/Library/lua/LuaManager.h @@ -38,7 +38,6 @@ protected: private: static void RegisterGlobal(lua_State* L); - static void RegisterGroup(lua_State* L); static void RegisterMeasure(lua_State* L); static void RegisterMeter(lua_State* L); static void RegisterMeterWindow(lua_State* L); diff --git a/Library/lua/LuaScript.cpp b/Library/lua/LuaScript.cpp index 2747ff41..e329bcdf 100644 --- a/Library/lua/LuaScript.cpp +++ b/Library/lua/LuaScript.cpp @@ -59,7 +59,7 @@ LuaScript::LuaScript(lua_State* state, const char* file) : m_State(state), lua_setfenv(m_State, -2); // Execute the Lua script - result = lua_pcall(m_State, 0, LUA_MULTRET, 0); + result = lua_pcall(m_State, 0, 0, 0); if (result) { diff --git a/Library/lua/glue/LuaGroup.cpp b/Library/lua/glue/LuaGroup.cpp deleted file mode 100644 index b4b4acdc..00000000 --- a/Library/lua/glue/LuaGroup.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "../../StdAfx.h" -#include "../LuaManager.h" -#include "../../Group.h" - -static int Group_BelongsToGroup(lua_State* L) -{ - CGroup* self = (CGroup*)tolua_tousertype(L, 1, 0); - const std::wstring group = (const std::wstring)to_wstring(L, 2, 0); - bool val = self->BelongsToGroup(group); - lua_pushboolean(L, val); - - return 1; -} - -void LuaManager::RegisterGroup(lua_State* L) -{ - tolua_usertype(L, "CGroup"); - tolua_cclass(L, "CGroup", "CGroup", "", NULL); - - tolua_beginmodule(L, "CGroup"); - tolua_function(L, "BelongsToGroup", Group_BelongsToGroup); - tolua_endmodule(L); -} diff --git a/Library/lua/glue/LuaMeasure.cpp b/Library/lua/glue/LuaMeasure.cpp index 6d8c25fa..09b19cda 100644 --- a/Library/lua/glue/LuaMeasure.cpp +++ b/Library/lua/glue/LuaMeasure.cpp @@ -25,11 +25,7 @@ static int Measure_GetOption(lua_State* L) parser.SetBuiltInVariable(L"CURRENTSECTION", self->GetName()); // Set temporarily parser.ReplaceVariables(strTmp); parser.SetBuiltInVariable(L"CURRENTSECTION", L""); // Reset - - if (self->HasDynamicVariables()) - { - parser.ReplaceMeasures(strTmp); - } + parser.ReplaceMeasures(strTmp); push_wchar(L, strTmp.c_str()); return 1; @@ -113,7 +109,7 @@ static int Measure_GetStringValue(lua_State* L) void LuaManager::RegisterMeasure(lua_State* L) { tolua_usertype(L, "CMeasure"); - tolua_cclass(L, "CMeasure", "CMeasure", "CGroup", NULL); + tolua_cclass(L, "CMeasure", "CMeasure", "", NULL); tolua_beginmodule(L, "CMeasure"); tolua_function(L, "GetName", Measure_GetName); diff --git a/Library/lua/glue/LuaMeter.cpp b/Library/lua/glue/LuaMeter.cpp index aca42b5a..900489b9 100644 --- a/Library/lua/glue/LuaMeter.cpp +++ b/Library/lua/glue/LuaMeter.cpp @@ -23,11 +23,7 @@ static int Meter_GetOption(lua_State* L) parser.SetBuiltInVariable(L"CURRENTSECTION", self->GetName()); // Set temporarily parser.ReplaceVariables(strTmp); parser.SetBuiltInVariable(L"CURRENTSECTION", L""); // Reset - - if (self->HasDynamicVariables()) - { - parser.ReplaceMeasures(strTmp); - } + parser.ReplaceMeasures(strTmp); push_wchar(L, strTmp.c_str()); return 1; @@ -127,7 +123,7 @@ static int Meter_Show(lua_State* L) void LuaManager::RegisterMeter(lua_State* L) { tolua_usertype(L, "CMeter"); - tolua_cclass(L, "CMeter", "CMeter", "CGroup", NULL); + tolua_cclass(L, "CMeter", "CMeter", "", NULL); tolua_beginmodule(L, "CMeter"); tolua_function(L, "GetName", Meter_GetName); diff --git a/Library/lua/glue/LuaMeterWindow.cpp b/Library/lua/glue/LuaMeterWindow.cpp index 3504f171..0261b36c 100644 --- a/Library/lua/glue/LuaMeterWindow.cpp +++ b/Library/lua/glue/LuaMeterWindow.cpp @@ -4,106 +4,6 @@ #include "../../MeterWindow.h" #include "../../MeterString.h" -static int MeterWindow_MoveMeter(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - int x = (int)tolua_tonumber(L, 2, 0); - int y = (int)tolua_tonumber(L, 3, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 4, 0)); - self->MoveMeter(x, y, name); - - return 0; -} - -static int MeterWindow_HideMeter(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->HideMeter(name, group); - - return 0; -} - -static int MeterWindow_ShowMeter(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->ShowMeter(name, group); - - return 0; -} - -static int MeterWindow_ToggleMeter(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->ToggleMeter(name, group); - - return 0; -} - -static int MeterWindow_UpdateMeter(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->UpdateMeter(name, group); - - return 0; -} - -static int MeterWindow_DisableMeasure(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->DisableMeasure(name, group); - - return 0; -} - -static int MeterWindow_EnableMeasure(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->EnableMeasure(name, group); - - return 0; -} - -static int MeterWindow_ToggleMeasure(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - self->ToggleMeasure(name, group); - - return 0; -} - -static int MeterWindow_UpdateMeasure(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - const WCHAR* name = ((const WCHAR*)to_wchar(L, 2, 0)); - bool group = ((bool)tolua_toboolean(L, 3, false)); - - self->UpdateMeasure(name, group); - - return 0; -} - -static int MeterWindow_Redraw(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - self->Redraw(); - - return 0; -} - static int MeterWindow_MoveWindow(lua_State* L) { CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); @@ -179,24 +79,6 @@ static int MeterWindow_GetY(lua_State* L) return 1; } -static int MeterWindow_GetXScreen(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - int val = (int)self->GetXScreen(); - lua_pushnumber(L, (lua_Number)val); - - return 1; -} - -static int MeterWindow_GetYScreen(lua_State* L) -{ - CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); - int val = (int)self->GetYScreen(); - lua_pushnumber(L, (lua_Number)val); - - return 1; -} - static int MeterWindow_MakePathAbsolute(lua_State* L) { CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0); @@ -294,19 +176,9 @@ static int MeterWindow_Bang(lua_State* L) void LuaManager::RegisterMeterWindow(lua_State* L) { tolua_usertype(L, "CMeterWindow"); - tolua_cclass(L, "CMeterWindow", "CMeterWindow", "CGroup", NULL); + tolua_cclass(L, "CMeterWindow", "CMeterWindow", "", NULL); tolua_beginmodule(L, "CMeterWindow"); - tolua_function(L, "MoveMeter", MeterWindow_MoveMeter); - tolua_function(L, "HideMeter", MeterWindow_HideMeter); - tolua_function(L, "ShowMeter", MeterWindow_ShowMeter); - tolua_function(L, "ToggleMeter", MeterWindow_ToggleMeter); - tolua_function(L, "UpdateMeter", MeterWindow_UpdateMeter); - tolua_function(L, "DisableMeasure", MeterWindow_DisableMeasure); - tolua_function(L, "EnableMeasure", MeterWindow_EnableMeasure); - tolua_function(L, "ToggleMeasure", MeterWindow_ToggleMeasure); - tolua_function(L, "UpdateMeasure", MeterWindow_UpdateMeasure); - tolua_function(L, "Redraw", MeterWindow_Redraw); tolua_function(L, "MoveWindow", MeterWindow_MoveWindow); tolua_function(L, "FadeWindow", MeterWindow_FadeWindow); tolua_function(L, "GetSkinName", MeterWindow_GetSkinName); @@ -315,8 +187,6 @@ void LuaManager::RegisterMeterWindow(lua_State* L) tolua_function(L, "GetH", MeterWindow_GetH); tolua_function(L, "GetX", MeterWindow_GetX); tolua_function(L, "GetY", MeterWindow_GetY); - tolua_function(L, "GetXScreen", MeterWindow_GetXScreen); - tolua_function(L, "GetYScreen", MeterWindow_GetYScreen); tolua_function(L, "MakePathAbsolute", MeterWindow_MakePathAbsolute); tolua_function(L, "GetMeter", MeterWindow_GetMeter); tolua_function(L, "GetMeasure", MeterWindow_GetMeasure); diff --git a/Plugins/PluginNowPlaying/NowPlaying.cpp b/Plugins/PluginNowPlaying/NowPlaying.cpp index 1417d209..91fe0bd2 100644 --- a/Plugins/PluginNowPlaying/NowPlaying.cpp +++ b/Plugins/PluginNowPlaying/NowPlaying.cpp @@ -447,7 +447,14 @@ void ExecuteBang(LPCTSTR bang, UINT id) ParentMeasure* parent = child->parent; CPlayer* player = parent->player; - if (_wcsicmp(bang, L"Pause") == 0) + if (!player->IsInitialized()) + { + if (_wcsicmp(bang, L"OpenPlayer") == 0 || _wcsicmp(bang, L"TogglePlayer") == 0) + { + player->OpenPlayer(parent->playerPath); + } + } + else if (_wcsicmp(bang, L"Pause") == 0) { player->Pause(); } @@ -471,14 +478,10 @@ void ExecuteBang(LPCTSTR bang, UINT id) { player->OpenPlayer(parent->playerPath); } - else if (_wcsicmp(bang, L"ClosePlayer") == 0) + else if (_wcsicmp(bang, L"ClosePlayer") == 0 || _wcsicmp(bang, L"TogglePlayer") == 0) { player->ClosePlayer(); } - else if (_wcsicmp(bang, L"TogglePlayer") == 0) - { - player->IsInitialized() ? player->ClosePlayer() : player->OpenPlayer(parent->playerPath); - } else { LPCTSTR arg = wcschr(bang, L' ');