2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001 Kimmo Pekkola
|
|
|
|
|
|
|
|
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.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "MeasurePlugin.h"
|
|
|
|
#include "Rainmeter.h"
|
2012-01-08 17:35:29 +00:00
|
|
|
#include "Export.h"
|
2010-09-11 19:39:45 +00:00
|
|
|
#include "System.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "Error.h"
|
|
|
|
|
|
|
|
extern CRainmeter* Rainmeter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2011-02-15 16:26:54 +00:00
|
|
|
CMeasurePlugin::CMeasurePlugin(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_Plugin(),
|
2012-01-08 17:35:29 +00:00
|
|
|
m_ReloadFunc(),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_ID(),
|
2012-01-08 17:35:29 +00:00
|
|
|
m_Update2(false),
|
|
|
|
m_PluginData(),
|
|
|
|
m_UpdateFunc(),
|
|
|
|
m_GetStringFunc(),
|
|
|
|
m_ExecuteBangFunc()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
2011-03-29 19:21:57 +00:00
|
|
|
CMeasurePlugin::~CMeasurePlugin()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
if (m_Plugin)
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
FARPROC finalizeFunc = GetProcAddress(m_Plugin, "Finalize");
|
|
|
|
if (finalizeFunc)
|
|
|
|
{
|
|
|
|
if (IsNewApi())
|
|
|
|
{
|
|
|
|
((NEWFINALIZE)finalizeFunc)(m_PluginData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((FINALIZE)finalizeFunc)(m_Plugin, m_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
FreeLibrary(m_Plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Gets the current value from the plugin
|
|
|
|
**
|
|
|
|
*/
|
2012-05-30 06:46:11 +00:00
|
|
|
void CMeasurePlugin::UpdateValue()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_UpdateFunc)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (IsNewApi())
|
|
|
|
{
|
|
|
|
m_Value = ((NEWUPDATE)m_UpdateFunc)(m_PluginData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_Update2)
|
|
|
|
{
|
|
|
|
m_Value = ((UPDATE2)m_UpdateFunc)(m_ID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Value = ((UPDATE)m_UpdateFunc)(m_ID);
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Reset to default
|
|
|
|
CSystem::ResetWorkingDirectory();
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Reads the configs and loads & initializes the plugin
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
static UINT id = 0;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
CMeasure::ReadConfig(parser, section);
|
2011-12-30 17:18:34 +00:00
|
|
|
|
2011-09-26 14:05:07 +00:00
|
|
|
if (m_Initialized)
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (IsNewApi())
|
|
|
|
{
|
|
|
|
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &m_MaxValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// DynamicVariables doesn't work with old plugins
|
2011-09-26 14:05:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-08-17 07:19:48 +00:00
|
|
|
|
2012-05-30 05:37:03 +00:00
|
|
|
const std::wstring& plugin = parser.ReadString(section, L"Plugin", L"");
|
|
|
|
std::wstring pluginFile = Rainmeter->GetPluginPath();
|
|
|
|
size_t pos = plugin.rfind(L'\\');
|
2011-03-29 19:21:57 +00:00
|
|
|
if (pos != std::wstring::npos)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-30 05:37:03 +00:00
|
|
|
pluginFile.append(plugin, pos, plugin.length() - pos);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2012-05-30 05:37:03 +00:00
|
|
|
else
|
2012-02-09 08:57:20 +00:00
|
|
|
{
|
2012-05-30 05:37:03 +00:00
|
|
|
pluginFile += plugin;
|
2012-02-09 08:57:20 +00:00
|
|
|
}
|
|
|
|
|
2012-05-30 05:37:03 +00:00
|
|
|
m_Plugin = CSystem::RmLoadLibrary(pluginFile.c_str());
|
2011-03-29 19:21:57 +00:00
|
|
|
if (m_Plugin == NULL)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-30 05:37:03 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"Plugin: \"%s\" not found", pluginFile.c_str());
|
|
|
|
return;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
FARPROC initializeFunc = GetProcAddress(m_Plugin, "Initialize");
|
|
|
|
m_ReloadFunc = GetProcAddress(m_Plugin, "Reload");
|
|
|
|
m_UpdateFunc = GetProcAddress(m_Plugin, "Update");
|
|
|
|
m_GetStringFunc = GetProcAddress(m_Plugin, "GetString");
|
|
|
|
m_ExecuteBangFunc = GetProcAddress(m_Plugin, "ExecuteBang");
|
2010-11-25 15:34:49 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
// Remove current directory from DLL search path
|
|
|
|
SetDllDirectory(L"");
|
|
|
|
|
2012-04-07 15:10:41 +00:00
|
|
|
double maxValue = 0.0;
|
2012-04-07 11:25:38 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (IsNewApi())
|
2011-12-30 16:16:22 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
m_PluginData = (void*)id;
|
2011-12-30 17:18:34 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (initializeFunc)
|
|
|
|
{
|
2012-02-02 07:39:14 +00:00
|
|
|
((NEWINITIALIZE)initializeFunc)(&m_PluginData, this);
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
2011-12-30 17:18:34 +00:00
|
|
|
|
2012-04-07 11:25:38 +00:00
|
|
|
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &maxValue);
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
m_ID = id;
|
2011-09-29 17:14:51 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (!m_UpdateFunc)
|
|
|
|
{
|
|
|
|
m_UpdateFunc = GetProcAddress(m_Plugin, "Update2");
|
|
|
|
m_Update2 = true;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
if (initializeFunc)
|
|
|
|
{
|
2012-05-20 13:12:13 +00:00
|
|
|
maxValue = ((INITIALIZE)initializeFunc)(m_Plugin, m_MeterWindow->GetSkinFilePath().c_str(), section, m_ID);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2012-03-25 14:15:59 +00:00
|
|
|
}
|
2011-12-30 16:16:22 +00:00
|
|
|
|
2012-04-07 11:25:38 +00:00
|
|
|
const std::wstring& szMaxValue = parser.ReadString(section, L"MaxValue", L"");
|
|
|
|
if (szMaxValue.empty())
|
2012-03-25 14:15:59 +00:00
|
|
|
{
|
2012-04-07 11:25:38 +00:00
|
|
|
if (maxValue == 0.0)
|
|
|
|
{
|
|
|
|
m_MaxValue = 1.0;
|
|
|
|
m_LogMaxValue = true;
|
2012-04-07 16:38:13 +00:00
|
|
|
|
|
|
|
// Plugin options changed, so reset
|
|
|
|
m_MedianMaxValues.clear();
|
|
|
|
m_MedianMinValues.clear();
|
2012-04-07 11:25:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_MaxValue = maxValue;
|
|
|
|
}
|
2011-12-30 17:18:34 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
|
|
|
|
// Reset to default
|
|
|
|
SetDllDirectory(L"");
|
|
|
|
CSystem::ResetWorkingDirectory();
|
|
|
|
|
|
|
|
++id;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Gets the string value from the plugin.
|
|
|
|
**
|
|
|
|
*/
|
2011-01-19 15:31:45 +00:00
|
|
|
const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_GetStringFunc)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
const WCHAR* ret;
|
|
|
|
if (IsNewApi())
|
|
|
|
{
|
|
|
|
ret = ((NEWGETSTRING)m_GetStringFunc)(m_PluginData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = ((GETSTRING)m_GetStringFunc)(m_ID, 0);
|
|
|
|
}
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
if (ret) return CheckSubstitute(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMeasure::GetStringValue(autoScale, scale, decimals, percentual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Sends a bang to the plugin
|
|
|
|
**
|
|
|
|
*/
|
2012-02-01 15:55:29 +00:00
|
|
|
void CMeasurePlugin::Command(const std::wstring& command)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
if (m_ExecuteBangFunc)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-02-01 15:55:29 +00:00
|
|
|
const WCHAR* str = command.c_str();
|
2012-01-08 17:35:29 +00:00
|
|
|
if (IsNewApi())
|
|
|
|
{
|
2012-02-01 15:55:29 +00:00
|
|
|
((NEWEXECUTEBANG)m_ExecuteBangFunc)(m_PluginData, str);
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-01 15:55:29 +00:00
|
|
|
((EXECUTEBANG)m_ExecuteBangFunc)(str, m_ID);
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-01 15:55:29 +00:00
|
|
|
CMeasure::Command(command);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
}
|