2012-01-08 17:35:29 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Birunthan Mohanathas, Peter Souza
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2012-01-08 17:35:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Rainmeter.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "MeterWindow.h"
|
|
|
|
#include "Measure.h"
|
|
|
|
#include "MeasurePlugin.h"
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
#define NULLCHECK(str) { if ((str) == nullptr) { (str) = L""; } }
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
static std::wstring g_Buffer;
|
|
|
|
|
2012-01-28 16:14:03 +00:00
|
|
|
LPCWSTR __stdcall RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
NULLCHECK(option);
|
|
|
|
NULLCHECK(defValue);
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
|
|
|
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
2012-01-08 17:35:29 +00:00
|
|
|
return parser.ReadString(measure->GetName(), option, defValue, (bool)replaceMeasures).c_str();
|
|
|
|
}
|
|
|
|
|
2012-01-28 16:14:03 +00:00
|
|
|
double __stdcall RmReadFormula(void* rm, LPCWSTR option, double defValue)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
NULLCHECK(option);
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
|
|
|
ConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
2012-04-06 12:16:54 +00:00
|
|
|
return parser.ReadFloat(measure->GetName(), option, defValue);
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 16:14:03 +00:00
|
|
|
LPCWSTR __stdcall RmPathToAbsolute(void* rm, LPCWSTR relativePath)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
NULLCHECK(relativePath);
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
2012-01-08 17:35:29 +00:00
|
|
|
g_Buffer = relativePath;
|
|
|
|
measure->GetMeterWindow()->MakePathAbsolute(g_Buffer);
|
|
|
|
return g_Buffer.c_str();
|
|
|
|
}
|
|
|
|
|
2012-01-28 16:14:03 +00:00
|
|
|
void* __stdcall RmGet(void* rm, int type)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeasurePlugin* measure = (MeasurePlugin*)rm;
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case RMG_MEASURENAME:
|
|
|
|
{
|
|
|
|
return (void*)measure->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
case RMG_SKIN:
|
|
|
|
{
|
|
|
|
return (void*)measure->GetMeterWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
case RMG_SETTINGSFILE:
|
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
return (void*)GetRainmeter().GetDataFile().c_str();
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
2013-02-27 11:00:26 +00:00
|
|
|
|
|
|
|
case RMG_SKINNAME:
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* window = measure->GetMeterWindow();
|
2013-02-27 11:00:26 +00:00
|
|
|
if (!window) break;
|
|
|
|
return (void*)window->GetFolderPath().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
case RMG_SKINWINDOWHANDLE:
|
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* window = measure->GetMeterWindow();
|
2013-02-27 11:00:26 +00:00
|
|
|
if (!window) break;
|
|
|
|
return (void*)window->GetWindow();
|
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
return nullptr;
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-28 16:14:03 +00:00
|
|
|
void __stdcall RmExecute(void* skin, LPCWSTR command)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterWindow* mw = (MeterWindow*)skin;
|
2012-02-04 14:29:51 +00:00
|
|
|
if (command)
|
|
|
|
{
|
2012-02-22 06:42:52 +00:00
|
|
|
// WM_RAINMETER_EXECUTE used instead of ExecuteCommand for thread-safety
|
2013-06-13 14:20:27 +00:00
|
|
|
SendMessage(GetRainmeter().GetWindow(), WM_RAINMETER_EXECUTE, (WPARAM)mw, (LPARAM)command);
|
2012-02-04 14:29:51 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage)
|
|
|
|
{
|
|
|
|
NULLCHECK(pszMessage);
|
|
|
|
|
2013-05-29 19:05:41 +00:00
|
|
|
// Ignore Level::Debug messages from plugins unless in debug mode
|
2013-06-13 14:20:27 +00:00
|
|
|
if (nLevel != (int)Logger::Level::Debug || GetRainmeter().GetDebug())
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-06-13 14:22:42 +00:00
|
|
|
GetLogger().Log((Logger::Level)nLevel, pszMessage);
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated!
|
|
|
|
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
|
|
|
|
{
|
|
|
|
NULLCHECK(section);
|
|
|
|
NULLCHECK(option);
|
|
|
|
NULLCHECK(defValue);
|
|
|
|
|
2013-06-13 14:20:27 +00:00
|
|
|
ConfigParser* parser = GetRainmeter().GetCurrentParser();
|
2012-01-08 17:35:29 +00:00
|
|
|
if (parser)
|
|
|
|
{
|
|
|
|
return parser->ReadString(section, option, defValue, false).c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return defValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated!
|
2012-02-01 15:55:29 +00:00
|
|
|
LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
if (command == nullptr || *command == L'\0')
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
|
|
|
return L"noop";
|
|
|
|
}
|
|
|
|
|
2012-02-01 15:55:29 +00:00
|
|
|
NULLCHECK(data);
|
2012-01-08 17:35:29 +00:00
|
|
|
|
2012-02-01 15:55:29 +00:00
|
|
|
if (_wcsicmp(command, L"GetConfig") == 0)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindowByINI(data);
|
2012-01-08 17:35:29 +00:00
|
|
|
if (meterWindow)
|
|
|
|
{
|
|
|
|
g_Buffer = L"\"";
|
2012-06-01 13:06:36 +00:00
|
|
|
g_Buffer += meterWindow->GetFolderPath();
|
2012-01-08 17:35:29 +00:00
|
|
|
g_Buffer += L"\"";
|
|
|
|
return g_Buffer.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return L"";
|
|
|
|
}
|
2012-02-01 15:55:29 +00:00
|
|
|
else if (_wcsicmp(command, L"GetWindow") == 0)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
if (subStrings.size() >= 1)
|
|
|
|
{
|
|
|
|
const std::wstring& config = subStrings[0];
|
|
|
|
|
2013-06-13 14:20:27 +00:00
|
|
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
|
2012-01-08 17:35:29 +00:00
|
|
|
if (meterWindow)
|
|
|
|
{
|
|
|
|
WCHAR buf1[64];
|
|
|
|
_snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow()));
|
|
|
|
g_Buffer = buf1;
|
|
|
|
return g_Buffer.c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return L"error";
|
|
|
|
}
|
2012-02-01 15:55:29 +00:00
|
|
|
else if (_wcsicmp(command, L"GetVariable") == 0)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
if (subStrings.size() >= 2)
|
|
|
|
{
|
|
|
|
const std::wstring& config = subStrings[0];
|
|
|
|
|
2013-06-13 14:20:27 +00:00
|
|
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
|
2012-01-08 17:35:29 +00:00
|
|
|
if (meterWindow)
|
|
|
|
{
|
|
|
|
const std::wstring& variable = subStrings[1];
|
|
|
|
|
2012-08-05 13:12:36 +00:00
|
|
|
const std::wstring* value = meterWindow->GetParser().GetVariable(variable);
|
|
|
|
if (value)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2012-08-05 13:12:36 +00:00
|
|
|
return (*value).c_str();
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return L"";
|
|
|
|
}
|
2012-02-01 15:55:29 +00:00
|
|
|
else if (_wcsicmp(command, L"SetVariable") == 0)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);
|
2012-01-08 17:35:29 +00:00
|
|
|
|
2012-02-01 18:00:32 +00:00
|
|
|
if (subStrings.size() == 3)
|
|
|
|
{
|
2013-06-13 14:20:27 +00:00
|
|
|
MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(subStrings[0]);
|
2012-02-01 18:00:32 +00:00
|
|
|
if (meterWindow)
|
2012-01-08 17:35:29 +00:00
|
|
|
{
|
2012-02-01 18:00:32 +00:00
|
|
|
meterWindow->SetVariable(subStrings[1], subStrings[2]);
|
|
|
|
return L"success";
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return L"error";
|
|
|
|
}
|
|
|
|
|
|
|
|
return L"noop";
|
|
|
|
}
|