diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 420905fb..e2553434 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -80,12 +80,15 @@ public: static void ClearMultiMonitorVariables() { c_MonitorVariables.clear(); } static void UpdateWorkareaVariables() { SetMultiMonitorVariables(false); } + // Updated by Peter Souza IV / psouza4 / 2010.12.13 + // + // Made this public so the plugin bridge can read variables directly + bool GetVariable(const std::wstring& strVariable, std::wstring& strValue); private: void SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* meterWindow); void SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); } - bool GetVariable(const std::wstring& strVariable, std::wstring& strValue); void ReadVariables(); CMeasure* GetMeasure(const std::wstring& name); diff --git a/Library/Export.h b/Library/Export.h index 6e870aa3..8cad1074 100644 --- a/Library/Export.h +++ b/Library/Export.h @@ -38,6 +38,11 @@ extern "C" EXPORT_PLUGIN BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage); EXPORT_PLUGIN LPCTSTR ReadConfigString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue); + + // Added by Peter Souza IV / psouza4 / 2010.12.13 + // + // Read comments in Rainmeter.cpp for details. + EXPORT_PLUGIN LPCTSTR PluginBridge(LPCTSTR sCommand, LPCTSTR sData); #ifdef __cplusplus } diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index 565f514b..77eb7723 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -174,6 +174,11 @@ public: const std::wstring& GetSkinAuthor() { return m_Author; } const std::wstring& GetSkinName() { return m_SkinName; } const std::wstring& GetSkinIniFile() { return m_SkinIniFile; } + + // Added by Peter Souza IV / psouza4 / 2010.12.13 + // + // Public read-only access to the skin's pathname (necessary for the plugin bridge) + const std::wstring& GetSkinPath() { return m_SkinPath; } std::list& GetMeasures() { return m_Measures; } std::list& GetMeters() { return m_Meters; } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index d89125d4..6f06e77d 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -2015,6 +2015,32 @@ CMeterWindow* CRainmeter::GetMeterWindow(const std::wstring& config) return NULL; } +// Added by Peter Souza IV / psouza4 / 2010.12.13 +// +// Returns a CMeterWindow object given a config's INI path and filename. Since plugins +// get the full path and filename of an INI file on Initialize(), but not the name of +// the config, this is used to convert the INI filename to a config name. +CMeterWindow* CRainmeter::GetMeterWindowByINI(const std::wstring& ini_searching) +{ + std::map::const_iterator iter = m_Meters.begin(); + + for (; iter != m_Meters.end(); ++iter) + { + std::wstring ini_current = L""; + ini_current += ((*iter).second->GetSkinPath()); // includes trailing backslash + ini_current += ((*iter).second->GetSkinName()); + ini_current += L"\\"; + ini_current += ((*iter).second->GetSkinIniFile()); + + if (_wcsicmp(ini_current.c_str(), ini_searching.c_str()) == 0) + { + return (*iter).second; + } + } + + return NULL; +} + CMeterWindow* CRainmeter::GetMeterWindow(HWND hwnd) { std::map::const_iterator iter = m_Meters.begin(); @@ -3883,3 +3909,168 @@ void CRainmeter::ExpandEnvironmentVariables(std::wstring& strPath) } } } + +/* +** PluginBridge +** +** Receives a command and data from a plugin and returns a result. Used by plugins. +** +** Revision history: +** 2010.12.13 Peter Souza IV / psouza4 initial creation +** +*/ +LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData) +{ + if (Rainmeter) + { + static std::wstring result; + std::wstring sCommand = _sCommand; + std::wstring sData = _sData; + std::transform(sCommand.begin(), sCommand.end(), sCommand.begin(), ::towlower); + + // Command GetConfig + // Data unquoted full path and filename given to the plugin on initialize + // (note: this is CaSe-SeNsItIvE!) + // Execution none + // Result the config name if found or a blank string if not + if (sCommand == L"getconfig") + { + // returns the config name, lookup by INI file + + CMeterWindow *meterWindow = Rainmeter->GetMeterWindowByINI(sData); + if (meterWindow) + { + result = meterWindow->GetSkinName(); + return result.c_str(); + } + + return L""; + } + + // Command SkinAuthor + // Data the config name + // Execution none + // Result the skin author of the skin name or 'error' if the config name + // was not found + if (sCommand == L"skinauthor") + { + std::vector subStrings = CRainmeter::ParseString(_sData); + std::wstring config; + + if (subStrings.size() >= 1) + { + config = subStrings[0]; + + CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); + if (meterWindow) + { + result = meterWindow->GetSkinAuthor(); + return result.c_str(); + } + } + + return L"error"; + } + + + // Command GetVariable + // Data [the config name] + // Execution none + // Result the value of the variable + if (sCommand == L"getvariable") + { + std::vector subStrings = CRainmeter::ParseString(_sData); + std::wstring config; + std::wstring variable; + + if (subStrings.size() >= 2) + { + config = subStrings[0]; + variable = subStrings[1]; + + CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); + if (meterWindow) + { + std::wstring result_from_parser = L""; + + if (meterWindow->GetParser().GetVariable(variable, result_from_parser)) + { + result = result_from_parser; + return result.c_str(); + } + } + } + + return L""; + } + + // Command SetVariable + // Data [the config name] [variable data] + // Execution the indicated variable is updated + // Result 'success' if the config was found, 'error' otherwise + if (sCommand == L"setvariable") + { + std::vector subStrings = CRainmeter::ParseString(_sData); + std::wstring config; + std::wstring arguments; + + if (subStrings.size() >= 2) + { + config = subStrings[0]; + + for (size_t i = 1; i < subStrings.size(); ++i) + { + if (i != 1) arguments += L" "; + arguments += subStrings[i]; + } + + CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); + if (meterWindow) + { + meterWindow->RunBang(BANG_SETVARIABLE, arguments.c_str()); + return L"success"; + } + } + + /* + result = L"er1/"; + result += subStrings[0]; + result += L"/"; + TCHAR x[100]; + swprintf(x, L"%d", subStrings.size()); + result += x; + return result.c_str(); + */ + return L"error"; + } + + // Command GetWindow + // Data [the config name] + // Execution none + // Result the HWND to the specified config window if found, 'error' otherwise + if (sCommand == L"getwindow") + { + std::vector subStrings = CRainmeter::ParseString(_sData); + std::wstring config; + + if (subStrings.size() >= 1) + { + config = subStrings[0]; + + CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config); + if (meterWindow) + { + TCHAR buf1[100]; + swprintf(buf1, L"%lu", meterWindow->GetWindow()); + result = buf1; + return result.c_str(); + } + } + return L"error"; + } + + return L"noop"; + } + + return L"error:no rainmeter!"; +} diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index b17ee4e3..5607e57f 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -147,6 +147,12 @@ public: CTrayWindow* GetTrayWindow() { return m_TrayWindow; } CMeterWindow* GetMeterWindow(const std::wstring& config); + + // Added by Peter Souza IV / psouza4 / 2010.12.13 + // + // Read comments in Rainmeter.cpp for details. + CMeterWindow* GetMeterWindowByINI(const std::wstring& ini_searching); + CMeterWindow* GetMeterWindow(HWND hwnd); void GetMeterWindowsByLoadOrder(std::multimap& windows, const std::wstring& group = L""); std::map& GetAllMeterWindows() { return m_Meters; }