mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added new plugin API.
This commit is contained in:
parent
61d7a3d221
commit
7b3b0277ec
241
Library/Export.cpp
Normal file
241
Library/Export.cpp
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
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
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "Export.h"
|
||||
#include "MeterWindow.h"
|
||||
#include "Measure.h"
|
||||
#include "MeasurePlugin.h"
|
||||
|
||||
extern CRainmeter* Rainmeter;
|
||||
|
||||
static std::wstring g_Buffer;
|
||||
|
||||
BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage)
|
||||
{
|
||||
// Ignore LOG_DEBUG messages from plugins unless in debug mode
|
||||
if (nLevel != LOG_DEBUG || Rainmeter->GetDebug())
|
||||
{
|
||||
Log(nLevel, pszMessage);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LPCWSTR RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
|
||||
{
|
||||
CMeasurePlugin* measure = (CMeasurePlugin*)rm;
|
||||
CConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
||||
return parser.ReadString(measure->GetName(), option, defValue, (bool)replaceMeasures).c_str();
|
||||
}
|
||||
|
||||
double RmReadFormula(void* rm, LPCWSTR option, double defValue)
|
||||
{
|
||||
CMeasurePlugin* measure = (CMeasurePlugin*)rm;
|
||||
CConfigParser& parser = measure->GetMeterWindow()->GetParser();
|
||||
return parser.ReadFormula(measure->GetName(), option, defValue);
|
||||
}
|
||||
|
||||
LPCWSTR RmPathToAbsolute(void* rm, LPCWSTR relativePath)
|
||||
{
|
||||
CMeasurePlugin* measure = (CMeasurePlugin*)rm;
|
||||
g_Buffer = relativePath;
|
||||
measure->GetMeterWindow()->MakePathAbsolute(g_Buffer);
|
||||
return g_Buffer.c_str();
|
||||
}
|
||||
|
||||
void* RmGet(void* rm, int type)
|
||||
{
|
||||
CMeasurePlugin* measure = (CMeasurePlugin*)rm;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case RMG_MEASURENAME:
|
||||
{
|
||||
return (void*)measure->GetName();
|
||||
}
|
||||
|
||||
case RMG_SKIN:
|
||||
{
|
||||
return (void*)measure->GetMeterWindow();
|
||||
}
|
||||
|
||||
case RMG_SETTINGSFILE:
|
||||
{
|
||||
g_Buffer = Rainmeter->GetSettingsPath();
|
||||
g_Buffer += L"Plugins.ini";
|
||||
return (void*)g_Buffer.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void RmExecute(void* skin, LPCWSTR command)
|
||||
{
|
||||
CMeterWindow* mw = (CMeterWindow*)skin;
|
||||
|
||||
// Fake WM_COPYDATA message to deliver bang
|
||||
COPYDATASTRUCT cds;
|
||||
cds.cbData = 1;
|
||||
cds.dwData = 1;
|
||||
cds.lpData = (void*)command;
|
||||
mw->OnCopyData(WM_COPYDATA, NULL, (LPARAM)&cds);
|
||||
}
|
||||
|
||||
// Deprecated!
|
||||
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
|
||||
{
|
||||
// NULL checking
|
||||
if (section == NULL) section = L"";
|
||||
if (option == NULL) option = L"";
|
||||
if (defValue == NULL) defValue = L"";
|
||||
|
||||
CConfigParser* parser = Rainmeter->GetCurrentParser();
|
||||
if (parser)
|
||||
{
|
||||
return parser->ReadString(section, option, defValue, false).c_str();
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
// Deprecated!
|
||||
LPCWSTR PluginBridge(LPCWSTR _sCommand, LPCWSTR _sData)
|
||||
{
|
||||
if (Rainmeter)
|
||||
{
|
||||
if (_sCommand == NULL || *_sCommand == L'\0')
|
||||
{
|
||||
return L"noop";
|
||||
}
|
||||
|
||||
if (_sData == NULL) _sData = L"";
|
||||
|
||||
std::wstring sCommand = _sCommand;
|
||||
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)
|
||||
{
|
||||
g_Buffer = L"\"";
|
||||
g_Buffer += meterWindow->GetSkinName();
|
||||
g_Buffer += L"\"";
|
||||
return g_Buffer.c_str();
|
||||
}
|
||||
|
||||
return L"";
|
||||
}
|
||||
|
||||
// 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<std::wstring> subStrings = CRainmeter::ParseString(_sData);
|
||||
|
||||
if (subStrings.size() >= 1)
|
||||
{
|
||||
const std::wstring& config = subStrings[0];
|
||||
|
||||
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
|
||||
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";
|
||||
}
|
||||
|
||||
// Command GetVariable
|
||||
// Data [the config name]
|
||||
// Execution none
|
||||
// Result the value of the variable
|
||||
if (sCommand == L"getvariable")
|
||||
{
|
||||
std::vector<std::wstring> subStrings = CRainmeter::ParseString(_sData);
|
||||
|
||||
if (subStrings.size() >= 2)
|
||||
{
|
||||
const std::wstring& config = subStrings[0];
|
||||
|
||||
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
|
||||
if (meterWindow)
|
||||
{
|
||||
const std::wstring& variable = subStrings[1];
|
||||
std::wstring result_from_parser;
|
||||
|
||||
if (meterWindow->GetParser().GetVariable(variable, result_from_parser))
|
||||
{
|
||||
g_Buffer = result_from_parser;
|
||||
return g_Buffer.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<std::wstring> subStrings = CRainmeter::ParseString(_sData);
|
||||
|
||||
if (subStrings.size() >= 2)
|
||||
{
|
||||
const std::wstring& config = subStrings[0];
|
||||
std::wstring arguments;
|
||||
|
||||
for (size_t i = 1, isize = subStrings.size(); i < isize; ++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";
|
||||
}
|
||||
}
|
||||
return L"error";
|
||||
}
|
||||
|
||||
return L"noop";
|
||||
}
|
||||
|
||||
return L"error:no rainmeter!";
|
||||
}
|
108
Library/Export.h
108
Library/Export.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2004 Kimmo Pekkola
|
||||
Copyright (C) 2011 Kimmo Pekkola, Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -20,28 +20,102 @@
|
||||
#define __EXPORT_H__
|
||||
|
||||
#ifdef LIBRARY_EXPORTS
|
||||
#define EXPORT_PLUGIN __declspec(dllexport)
|
||||
#define DECLSPEC_LIBRARY __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT_PLUGIN __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
// log level constants
|
||||
#define LOG_ERROR 1
|
||||
#define LOG_WARNING 2
|
||||
#define LOG_NOTICE 3
|
||||
#define LOG_DEBUG 4
|
||||
#define DECLSPEC_LIBRARY __declspec(dllimport)
|
||||
#endif // LIBRARY_EXPORTS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#define LIBRARY_EXPORT extern "C" DECLSPEC_LIBRARY
|
||||
#define PLUGIN_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define LIBRARY_EXPORT DECLSPEC_LIBRARY
|
||||
#define PLUGIN_EXPORT __declspec(dllexport)
|
||||
#endif // __cplusplus
|
||||
|
||||
//
|
||||
// Exported functions
|
||||
//
|
||||
|
||||
#ifdef __cplusplus
|
||||
LIBRARY_EXPORT LPCWSTR RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures = TRUE);
|
||||
#else
|
||||
LIBRARY_EXPORT LPCWSTR RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures);
|
||||
#endif // __cplusplus
|
||||
|
||||
LIBRARY_EXPORT double RmReadFormula(void* rm, LPCWSTR option, double defValue);
|
||||
|
||||
LIBRARY_EXPORT LPCWSTR RmPathToAbsolute(void* rm, LPCWSTR relativePath);
|
||||
|
||||
LIBRARY_EXPORT void RmExecute(void* skin, LPCWSTR command);
|
||||
|
||||
LIBRARY_EXPORT BOOL LSLog(int level, LPCWSTR unused, LPCWSTR message);
|
||||
|
||||
LIBRARY_EXPORT void* RmGet(void* rm, int type);
|
||||
|
||||
enum RMGTYPE
|
||||
{
|
||||
#endif
|
||||
RMG_MEASURENAME = 0,
|
||||
RMG_SKIN = 1,
|
||||
RMG_SETTINGSFILE = 2
|
||||
};
|
||||
|
||||
EXPORT_PLUGIN BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage);
|
||||
EXPORT_PLUGIN LPCTSTR ReadConfigString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue);
|
||||
EXPORT_PLUGIN LPCTSTR PluginBridge(LPCTSTR sCommand, LPCTSTR sData);
|
||||
/* DEPRECATED */ LIBRARY_EXPORT __declspec(deprecated) LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* DEPRECATED */ LIBRARY_EXPORT __declspec(deprecated) LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data);
|
||||
|
||||
//
|
||||
// Wrapper functions
|
||||
//
|
||||
|
||||
#ifndef LIBRARY_EXPORTS
|
||||
enum LOGLEVEL
|
||||
{
|
||||
LOG_ERROR = 1,
|
||||
LOG_WARNING = 2,
|
||||
LOG_NOTICE = 3,
|
||||
LOG_DEBUG = 4
|
||||
};
|
||||
|
||||
__inline LPCWSTR RmReadPath(void* rm, LPCWSTR option, LPCWSTR defValue)
|
||||
{
|
||||
LPCWSTR relativePath = RmReadString(rm, option, defValue, TRUE);
|
||||
return RmPathToAbsolute(rm, relativePath);
|
||||
}
|
||||
#endif
|
||||
|
||||
__inline int RmReadInt(void* rm, LPCWSTR option, int defValue)
|
||||
{
|
||||
LPCWSTR value = RmReadString(rm, option, L"", TRUE);
|
||||
return (*value) ? _wtoi(value) : defValue;
|
||||
}
|
||||
|
||||
__inline LPCWSTR RmGetMeasureName(void* rm)
|
||||
{
|
||||
return (LPCWSTR)RmGet(rm, RMG_MEASURENAME);
|
||||
}
|
||||
|
||||
__inline LPCWSTR RmGetSettingsFile(void* rm)
|
||||
{
|
||||
return (LPCWSTR)RmGet(rm, RMG_SETTINGSFILE);
|
||||
}
|
||||
|
||||
__inline void* RmGetSkin(void* rm)
|
||||
{
|
||||
return (void*)RmGet(rm, RMG_SKIN);
|
||||
}
|
||||
|
||||
__inline void RmLog(int level, LPCWSTR message)
|
||||
{
|
||||
LSLog(level, NULL, message);
|
||||
}
|
||||
|
||||
enum LOGLEVEL
|
||||
{
|
||||
LOG_ERROR = 1,
|
||||
LOG_WARNING = 2,
|
||||
LOG_NOTICE = 3,
|
||||
LOG_DEBUG = 4
|
||||
};
|
||||
#endif // LIBRARY_EXPORTS
|
||||
|
||||
#endif
|
@ -657,6 +657,17 @@
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MaxSpeed</Optimization>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Export.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Disabled</Optimization>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">EnableFastChecks</BasicRuntimeChecks>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MaxSpeed</Optimization>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StdAfx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
@ -837,7 +848,6 @@
|
||||
<ClInclude Include="DialogAbout.h" />
|
||||
<ClInclude Include="DisableThreadLibraryCalls.h" />
|
||||
<ClInclude Include="Error.h" />
|
||||
<ClInclude Include="Export.h" />
|
||||
<ClInclude Include="Group.h" />
|
||||
<ClInclude Include="Litestep.h" />
|
||||
<ClInclude Include="DialogManage.h" />
|
||||
@ -873,6 +883,7 @@
|
||||
<ClInclude Include="pcre-8.10\pcre_internal.h" />
|
||||
<ClInclude Include="pcre-8.10\ucp.h" />
|
||||
<ClInclude Include="Rainmeter.h" />
|
||||
<ClInclude Include="Export.h" />
|
||||
<ClInclude Include="RainmeterQuery.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="StdAfx.h" />
|
||||
|
@ -351,6 +351,9 @@
|
||||
<ClCompile Include="DialogManage.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Export.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ConfigParser.h">
|
||||
@ -362,9 +365,6 @@
|
||||
<ClInclude Include="Error.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Export.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Group.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -593,6 +593,9 @@
|
||||
<ClInclude Include="DialogManage.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Export.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Library.rc">
|
||||
|
@ -23,7 +23,14 @@
|
||||
#include <comdef.h>
|
||||
#include <string>
|
||||
#include "Error.h"
|
||||
#include "Export.h"
|
||||
|
||||
enum LOGLEVEL
|
||||
{
|
||||
LOG_ERROR = 1,
|
||||
LOG_WARNING = 2,
|
||||
LOG_NOTICE = 3,
|
||||
LOG_DEBUG = 4
|
||||
};
|
||||
|
||||
void InitalizeLitestep();
|
||||
void FinalizeLitestep();
|
||||
@ -38,7 +45,7 @@ std::string ConvertToUTF8(LPCWSTR str);
|
||||
std::wstring ConvertUTF8ToWide(LPCSTR str);
|
||||
|
||||
void Log(int nLevel, const WCHAR* message);
|
||||
void LogWithArgs(int nLevel, const WCHAR* format, ... );
|
||||
void LogWithArgs(int nLevel, const WCHAR* format, ...);
|
||||
void LogError(CError& error);
|
||||
|
||||
void RunCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, bool asAdmin = false);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "MeasurePlugin.h"
|
||||
#include "Rainmeter.h"
|
||||
#include "Export.h"
|
||||
#include "System.h"
|
||||
#include "Error.h"
|
||||
|
||||
@ -32,13 +33,11 @@ extern CRainmeter* Rainmeter;
|
||||
*/
|
||||
CMeasurePlugin::CMeasurePlugin(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
|
||||
m_Plugin(),
|
||||
m_ReloadFunc(),
|
||||
m_ID(),
|
||||
InitializeFunc(),
|
||||
UpdateFunc(),
|
||||
UpdateFunc2(),
|
||||
FinalizeFunc(),
|
||||
GetStringFunc(),
|
||||
ExecuteBangFunc()
|
||||
m_UpdateFunc(),
|
||||
m_GetStringFunc(),
|
||||
m_ExecuteBangFunc()
|
||||
{
|
||||
m_MaxValue = 0.0;
|
||||
}
|
||||
@ -53,7 +52,16 @@ CMeasurePlugin::~CMeasurePlugin()
|
||||
{
|
||||
if (m_Plugin)
|
||||
{
|
||||
if (FinalizeFunc) FinalizeFunc(m_Plugin, m_ID);
|
||||
FARPROC finalizeFunc = GetProcAddress(m_Plugin, "Finalize");
|
||||
if (IsNewApi())
|
||||
{
|
||||
((NEWFINALIZE)finalizeFunc)(m_PluginData);
|
||||
}
|
||||
else if (finalizeFunc)
|
||||
{
|
||||
((FINALIZE)finalizeFunc)(m_Plugin, m_ID);
|
||||
}
|
||||
|
||||
FreeLibrary(m_Plugin);
|
||||
}
|
||||
}
|
||||
@ -68,15 +76,20 @@ bool CMeasurePlugin::Update()
|
||||
{
|
||||
if (!CMeasure::PreUpdate()) return false;
|
||||
|
||||
if (UpdateFunc)
|
||||
if (IsNewApi())
|
||||
{
|
||||
// Update the plugin
|
||||
m_Value = UpdateFunc(m_ID);
|
||||
m_Value = ((NEWUPDATE)m_UpdateFunc)(m_PluginData);
|
||||
}
|
||||
else if (UpdateFunc2)
|
||||
else if (m_UpdateFunc)
|
||||
{
|
||||
// Update the plugin
|
||||
m_Value = UpdateFunc2(m_ID);
|
||||
if (m_Update2)
|
||||
{
|
||||
m_Value = ((UPDATE2)m_UpdateFunc)(m_ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Value = ((UPDATE)m_UpdateFunc)(m_ID);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset to default
|
||||
@ -93,13 +106,17 @@ bool CMeasurePlugin::Update()
|
||||
*/
|
||||
void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
{
|
||||
static UINT id = 1;
|
||||
static UINT id = 0;
|
||||
|
||||
CMeasure::ReadConfig(parser, section);
|
||||
|
||||
if (m_Initialized)
|
||||
{
|
||||
// DynamicVariables doesn't work with plugins, so stop here.
|
||||
if (IsNewApi())
|
||||
{
|
||||
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &m_MaxValue);
|
||||
}
|
||||
|
||||
// DynamicVariables doesn't work with old plugins
|
||||
return;
|
||||
}
|
||||
|
||||
@ -118,16 +135,9 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
m_PluginName.insert(0, Rainmeter->GetPluginPath());
|
||||
|
||||
DWORD err = 0;
|
||||
m_Plugin = CSystem::RmLoadLibrary(m_PluginName.c_str(), &err);
|
||||
|
||||
m_Plugin = CSystem::RmLoadLibrary(m_PluginName.c_str(), NULL);
|
||||
if (m_Plugin == NULL)
|
||||
{
|
||||
if (Rainmeter->GetDebug())
|
||||
{
|
||||
LogWithArgs(LOG_ERROR, L"Plugin: Unable to load \"%s\" (%u)", m_PluginName.c_str(), err);
|
||||
}
|
||||
|
||||
// Try to load from Rainmeter's folder
|
||||
pos = m_PluginName.rfind(L'\\');
|
||||
if (pos != std::wstring::npos)
|
||||
@ -135,16 +145,7 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
std::wstring pluginName = Rainmeter->GetPath();
|
||||
pluginName.append(m_PluginName, pos + 1, m_PluginName.length() - (pos + 1));
|
||||
|
||||
err = 0;
|
||||
m_Plugin = CSystem::RmLoadLibrary(pluginName.c_str(), &err);
|
||||
|
||||
if (m_Plugin == NULL)
|
||||
{
|
||||
if (Rainmeter->GetDebug())
|
||||
{
|
||||
LogWithArgs(LOG_ERROR, L"Plugin: Unable to load \"%s\" (%u)", pluginName.c_str(), err);
|
||||
}
|
||||
}
|
||||
m_Plugin = CSystem::RmLoadLibrary(pluginName.c_str(), NULL);
|
||||
}
|
||||
|
||||
if (m_Plugin == NULL)
|
||||
@ -155,48 +156,50 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
}
|
||||
|
||||
InitializeFunc = (INITIALIZE)GetProcAddress(m_Plugin, "Initialize");
|
||||
FinalizeFunc = (FINALIZE)GetProcAddress(m_Plugin, "Finalize");
|
||||
UpdateFunc = (UPDATE)GetProcAddress(m_Plugin, "Update");
|
||||
UpdateFunc2 = (UPDATE2)GetProcAddress(m_Plugin, "Update2");
|
||||
GetStringFunc = (GETSTRING)GetProcAddress(m_Plugin, "GetString");
|
||||
ExecuteBangFunc = (EXECUTEBANG)GetProcAddress(m_Plugin, "ExecuteBang");
|
||||
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");
|
||||
|
||||
if (UpdateFunc == NULL && UpdateFunc2 == NULL && GetStringFunc == NULL)
|
||||
{
|
||||
FreeLibrary(m_Plugin);
|
||||
|
||||
std::wstring error = L"Plugin: \"" + m_PluginName;
|
||||
error += L"\" doesn't export Update() or GetString()";
|
||||
throw CError(error);
|
||||
}
|
||||
|
||||
// Initialize the plugin
|
||||
m_ID = id++;
|
||||
if (InitializeFunc)
|
||||
{
|
||||
// Remove current directory from DLL search path
|
||||
SetDllDirectory(L"");
|
||||
|
||||
double maxValue;
|
||||
maxValue = InitializeFunc(m_Plugin, parser.GetFilename().c_str(), section, m_ID);
|
||||
if (IsNewApi())
|
||||
{
|
||||
((NEWINITIALIZE)initializeFunc)(&m_PluginData);
|
||||
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &m_MaxValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ID = id;
|
||||
|
||||
// Reset to default
|
||||
SetDllDirectory(L"");
|
||||
CSystem::ResetWorkingDirectory();
|
||||
if (!m_UpdateFunc)
|
||||
{
|
||||
m_UpdateFunc = GetProcAddress(m_Plugin, "Update2");
|
||||
m_Update2 = true;
|
||||
}
|
||||
|
||||
double maxValue = ((INITIALIZE)initializeFunc)(m_Plugin, parser.GetFilename().c_str(), section, m_ID);
|
||||
|
||||
const std::wstring& szMaxValue = parser.ReadString(section, L"MaxValue", L"");
|
||||
if (szMaxValue.empty())
|
||||
{
|
||||
m_MaxValue = maxValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_MaxValue == 0)
|
||||
{
|
||||
m_MaxValue = 1;
|
||||
m_LogMaxValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset to default
|
||||
SetDllDirectory(L"");
|
||||
CSystem::ResetWorkingDirectory();
|
||||
|
||||
++id;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -207,9 +210,18 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
*/
|
||||
const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
|
||||
{
|
||||
if (GetStringFunc)
|
||||
if (m_GetStringFunc)
|
||||
{
|
||||
const WCHAR* ret = GetStringFunc(m_ID, 0);
|
||||
const WCHAR* ret;
|
||||
if (IsNewApi())
|
||||
{
|
||||
ret = ((NEWGETSTRING)m_GetStringFunc)(m_PluginData);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ((GETSTRING)m_GetStringFunc)(m_ID, 0);
|
||||
}
|
||||
|
||||
if (ret) return CheckSubstitute(ret);
|
||||
}
|
||||
|
||||
@ -224,9 +236,16 @@ const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, i
|
||||
*/
|
||||
void CMeasurePlugin::ExecuteBang(const WCHAR* args)
|
||||
{
|
||||
if (ExecuteBangFunc)
|
||||
if (m_ExecuteBangFunc)
|
||||
{
|
||||
ExecuteBangFunc(args, m_ID);
|
||||
if (IsNewApi())
|
||||
{
|
||||
((NEWEXECUTEBANG)m_ExecuteBangFunc)(m_PluginData, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
((EXECUTEBANG)m_ExecuteBangFunc)(args, m_ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -28,6 +28,13 @@ typedef double (*UPDATE2)(UINT);
|
||||
typedef LPCTSTR (*GETSTRING)(UINT, UINT);
|
||||
typedef void (*EXECUTEBANG)(LPCTSTR, UINT);
|
||||
|
||||
typedef void (*NEWINITIALIZE)(void*);
|
||||
typedef void (*NEWRELOAD)(void*, void*, double*);
|
||||
typedef void (*NEWFINALIZE)(void*);
|
||||
typedef double (*NEWUPDATE)(void*);
|
||||
typedef LPCWSTR (*NEWGETSTRING)(void*);
|
||||
typedef void (*NEWEXECUTEBANG)(void*, const WCHAR*);
|
||||
|
||||
class CMeasurePlugin : public CMeasure
|
||||
{
|
||||
public:
|
||||
@ -42,16 +49,30 @@ protected:
|
||||
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
|
||||
|
||||
private:
|
||||
bool IsNewApi() { return m_ReloadFunc != NULL; }
|
||||
|
||||
std::wstring m_PluginName;
|
||||
HMODULE m_Plugin;
|
||||
UINT m_ID;
|
||||
|
||||
INITIALIZE InitializeFunc;
|
||||
FINALIZE FinalizeFunc;
|
||||
UPDATE UpdateFunc;
|
||||
UPDATE2 UpdateFunc2;
|
||||
GETSTRING GetStringFunc;
|
||||
EXECUTEBANG ExecuteBangFunc;
|
||||
void* m_ReloadFunc;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
UINT m_ID;
|
||||
bool m_Update2;
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
void* m_PluginData;
|
||||
};
|
||||
};
|
||||
|
||||
void* m_UpdateFunc;
|
||||
void* m_GetStringFunc;
|
||||
void* m_ExecuteBangFunc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2110,8 +2110,6 @@ bool CMeterWindow::ReadSkin()
|
||||
MessageBox(m_Window, text.c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION);
|
||||
}
|
||||
|
||||
m_Author = m_Parser.ReadString(L"Rainmeter", L"Author", L"");
|
||||
|
||||
static const RECT defMargins = {0};
|
||||
m_BackgroundMargins = m_Parser.ReadRECT(L"Rainmeter", L"BackgroundMargins", defMargins);
|
||||
m_DragMargins = m_Parser.ReadRECT(L"Rainmeter", L"DragMargins", defMargins);
|
||||
|
@ -200,7 +200,6 @@ public:
|
||||
|
||||
CConfigParser& GetParser() { return m_Parser; }
|
||||
|
||||
const std::wstring& GetSkinAuthor() { return m_Author; }
|
||||
const std::wstring& GetSkinName() { return m_SkinName; }
|
||||
const std::wstring& GetSkinIniFile() { return m_SkinIniFile; }
|
||||
std::wstring GetSkinRootPath();
|
||||
@ -375,7 +374,6 @@ private:
|
||||
|
||||
bool m_MouseOver;
|
||||
|
||||
std::wstring m_Author; // Skin's author
|
||||
std::wstring m_ConfigGroup;
|
||||
std::wstring m_BackgroundName; // Name of the background image
|
||||
RECT m_BackgroundMargins;
|
||||
|
77
Library/RawString.h
Normal file
77
Library/RawString.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright (C) 2011 Birunthan Mohanathas
|
||||
|
||||
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
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __RAWSTRING_H__
|
||||
#define __RAWSTRING_H__
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class CRawString
|
||||
{
|
||||
public:
|
||||
CRawString() :
|
||||
m_String()
|
||||
{
|
||||
}
|
||||
|
||||
CRawString(const WCHAR* str) :
|
||||
m_String(_wcsdup(str))
|
||||
{
|
||||
}
|
||||
|
||||
~CRawString()
|
||||
{
|
||||
if (m_String) free(m_String);
|
||||
}
|
||||
|
||||
CRawString& operator=(const WCHAR* rhs)
|
||||
{
|
||||
if (m_String) free(m_String);
|
||||
m_String = _wcsdup(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
CRawString& operator=(const CRawString& rhs)
|
||||
{
|
||||
if (&rhs != this)
|
||||
{
|
||||
if (m_String) free(m_String);
|
||||
m_String = _wcsdup(rhs.m_String);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const WCHAR* c_str() const
|
||||
{
|
||||
return m_String;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return !(*m_String);
|
||||
}
|
||||
|
||||
private:
|
||||
CRawString(const CRawString& p)
|
||||
{
|
||||
}
|
||||
|
||||
WCHAR* m_String;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user