Reintegrated 2.3 branch into trunk

This commit is contained in:
Birunthan Mohanathas
2012-01-08 17:35:29 +00:00
parent c3335adec5
commit c3ed2e5fa3
87 changed files with 5379 additions and 2732 deletions

View File

@ -869,13 +869,66 @@ void CDialogAbout::CTabPlugins::Initialize()
// Try to get the version and author
std::wstring tmpSz = Rainmeter->GetPluginPath() + fileData.cFileName;
const WCHAR* path = tmpSz.c_str();
vitem.iItem = index;
vitem.pszText = fileData.cFileName;
// Try to get version and author from file resources first
DWORD handle;
DWORD versionSize = GetFileVersionInfoSize(path, &handle);
if (versionSize)
{
bool found = false;
void* data = new BYTE[versionSize];
if (GetFileVersionInfo(path, 0, versionSize, data))
{
UINT len;
struct LANGCODEPAGE
{
WORD wLanguage;
WORD wCodePage;
} *lcp;
if (VerQueryValue(data, L"\\VarFileInfo\\Translation", (LPVOID*)&lcp, &len))
{
WCHAR key[64];
LPWSTR value;
_snwprintf_s(key, _TRUNCATE, L"\\StringFileInfo\\%04x%04x\\ProductName", lcp[0].wLanguage, lcp[0].wCodePage);
if (VerQueryValue(data, (LPTSTR)(LPCTSTR)key, (void**)&value, &len) &&
wcscmp(value, L"Rainmeter") == 0)
{
ListView_InsertItem(item, &vitem);
++index;
found = true;
_snwprintf_s(key, _TRUNCATE, L"\\StringFileInfo\\%04x%04x\\FileVersion", lcp[0].wLanguage, lcp[0].wCodePage);
if (VerQueryValue(data, (LPTSTR)(LPCTSTR)key, (void**)&value, &len))
{
ListView_SetItemText(item, vitem.iItem, 1, value);
}
_snwprintf_s(key, _TRUNCATE, L"\\StringFileInfo\\%04x%04x\\LegalCopyright", lcp[0].wLanguage, lcp[0].wCodePage);
if (VerQueryValue(data, (LPTSTR)(LPCTSTR)key, (void**)&value, &len))
{
ListView_SetItemText(item, vitem.iItem, 2, value);
}
}
}
}
delete [] data;
if (found) continue;
}
// Try old calling GetPluginVersion/GetPluginAuthor for backwards compatibility
DWORD err = 0;
HMODULE dll = CSystem::RmLoadLibrary(tmpSz.c_str(), &err, true);
HMODULE dll = CSystem::RmLoadLibrary(path, &err, true);
if (dll)
{
vitem.iItem = index;
vitem.pszText = fileData.cFileName;
ListView_InsertItem(item, &vitem);
++index;
GETPLUGINVERSION GetVersionFunc = (GETPLUGINVERSION)GetProcAddress(dll, "GetPluginVersion");
if (GetVersionFunc)
@ -896,7 +949,6 @@ void CDialogAbout::CTabPlugins::Initialize()
}
}
++index;
FreeLibrary(dll);
}
else

248
Library/Export.cpp Normal file
View File

@ -0,0 +1,248 @@
/*
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"
#define NULLCHECK(str) { if ((str) == NULL) { (str) = L""; } }
extern CRainmeter* Rainmeter;
static std::wstring g_Buffer;
LPCWSTR RmReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)
{
NULLCHECK(option);
NULLCHECK(defValue);
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)
{
NULLCHECK(option);
CMeasurePlugin* measure = (CMeasurePlugin*)rm;
CConfigParser& parser = measure->GetMeterWindow()->GetParser();
return parser.ReadFormula(measure->GetName(), option, defValue);
}
LPCWSTR RmPathToAbsolute(void* rm, LPCWSTR relativePath)
{
NULLCHECK(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);
}
BOOL LSLog(int nLevel, LPCWSTR unused, LPCWSTR pszMessage)
{
NULLCHECK(pszMessage);
// Ignore LOG_DEBUG messages from plugins unless in debug mode
if (nLevel != LOG_DEBUG || Rainmeter->GetDebug())
{
Log(nLevel, pszMessage);
}
return TRUE;
}
// Deprecated!
LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue)
{
NULLCHECK(section);
NULLCHECK(option);
NULLCHECK(defValue);
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 (_sCommand == NULL || *_sCommand == L'\0')
{
return L"noop";
}
NULLCHECK(_sData);
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";
}

View File

@ -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,100 @@
#define __EXPORT_H__
#ifdef LIBRARY_EXPORTS
#define EXPORT_PLUGIN __declspec(dllexport)
#define LIBRARY_DECLSPEC __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 LIBRARY_DECLSPEC __declspec(dllimport)
#endif // LIBRARY_EXPORTS
#ifdef __cplusplus
extern "C"
#define LIBRARY_EXPORT extern "C" LIBRARY_DECLSPEC
#define PLUGIN_EXPORT extern "C" __declspec(dllexport)
#else
#define LIBRARY_EXPORT LIBRARY_DECLSPEC
#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 void* RmGet(void* rm, int type);
enum RmGetType
{
#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);
LIBRARY_EXPORT BOOL LSLog(int type, LPCWSTR unused, LPCWSTR message);
#ifdef __cplusplus
/* DEPRECATED */ LIBRARY_EXPORT __declspec(deprecated) LPCWSTR ReadConfigString(LPCWSTR section, LPCWSTR option, LPCWSTR defValue);
/* DEPRECATED */ LIBRARY_EXPORT __declspec(deprecated) LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data);
//
// Wrapper functions
//
#ifndef LIBRARY_EXPORTS
__inline LPCWSTR RmReadPath(void* rm, LPCWSTR option, LPCWSTR defValue)
{
LPCWSTR relativePath = RmReadString(rm, option, defValue, TRUE);
return RmPathToAbsolute(rm, relativePath);
}
#endif
#endif
__inline int RmReadInt(void* rm, LPCWSTR option, int defValue)
{
LPCWSTR value = RmReadString(rm, option, L"", TRUE);
return (*value) ? _wtoi(value) : defValue;
}
__inline double RmReadDouble(void* rm, LPCWSTR option, double defValue)
{
LPCWSTR value = RmReadString(rm, option, L"", TRUE);
return (*value) ? wcstod(value, NULL) : defValue;
}
__inline LPCWSTR RmGetMeasureName(void* rm)
{
return (LPCWSTR)RmGet(rm, RMG_MEASURENAME);
}
__inline LPCWSTR RmGetSettingsFile()
{
return (LPCWSTR)RmGet(NULL, 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

View File

@ -67,10 +67,10 @@
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)TestBench\x32\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\x32\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)TestBench\x64\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\x64\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)TestBench\x32\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\x32\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
@ -115,7 +115,7 @@
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../TestBench/x32/Debug/Rainmeter.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
@ -123,6 +123,7 @@
<ProgramDatabaseFile>.\x32/Debug/Rainmeter.pdb</ProgramDatabaseFile>
<ImportLibrary>.\x32/Debug/Rainmeter.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<DelayLoadDLLs>Winmm.dll;Version.dll</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -158,7 +159,7 @@
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../TestBench/x64/Debug/Rainmeter.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
@ -166,6 +167,7 @@
<ProgramDatabaseFile>.\x64/Debug/Rainmeter.pdb</ProgramDatabaseFile>
<ImportLibrary>.\x64/Debug/Rainmeter.lib</ImportLibrary>
<TargetMachine>MachineX64</TargetMachine>
<DelayLoadDLLs>Winmm.dll;Version.dll</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -204,7 +206,7 @@
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../TestBench/x32/Release/Rainmeter.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>lua/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
@ -215,6 +217,7 @@
<MergeSections>.rdata=.text</MergeSections>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DelayLoadDLLs>Winmm.dll;Version.dll</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -250,7 +253,7 @@
<Culture>0x0409</Culture>
</ResourceCompile>
<Link>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>comctl32.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;Version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../TestBench/x64/Release/Rainmeter.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
@ -260,6 +263,7 @@
<MergeSections>.rdata=.text</MergeSections>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<DelayLoadDLLs>Winmm.dll;Version.dll</DelayLoadDLLs>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@ -657,6 +661,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 +852,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,7 +887,9 @@
<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="RawString.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="System.h" />

View File

@ -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">

View File

@ -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);

View File

@ -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,13 @@ 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_Update2(false),
m_PluginData(),
m_UpdateFunc(),
m_GetStringFunc(),
m_ExecuteBangFunc()
{
m_MaxValue = 0.0;
}
@ -53,7 +54,19 @@ CMeasurePlugin::~CMeasurePlugin()
{
if (m_Plugin)
{
if (FinalizeFunc) FinalizeFunc(m_Plugin, m_ID);
FARPROC finalizeFunc = GetProcAddress(m_Plugin, "Finalize");
if (finalizeFunc)
{
if (IsNewApi())
{
((NEWFINALIZE)finalizeFunc)(m_PluginData);
}
else
{
((FINALIZE)finalizeFunc)(m_Plugin, m_ID);
}
}
FreeLibrary(m_Plugin);
}
}
@ -68,19 +81,27 @@ bool CMeasurePlugin::Update()
{
if (!CMeasure::PreUpdate()) return false;
if (UpdateFunc)
if (m_UpdateFunc)
{
// Update the plugin
m_Value = UpdateFunc(m_ID);
}
else if (UpdateFunc2)
{
// Update the plugin
m_Value = UpdateFunc2(m_ID);
}
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);
}
}
// Reset to default
CSystem::ResetWorkingDirectory();
// Reset to default
CSystem::ResetWorkingDirectory();
}
return PostUpdate();
}
@ -93,110 +114,111 @@ 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;
}
m_PluginName = parser.ReadString(section, L"Plugin", L"");
std::wstring pluginName = parser.ReadString(section, L"Plugin", L"");
size_t pos = m_PluginName.rfind(L'.');
size_t pos = pluginName.rfind(L'.');
if (pos == std::wstring::npos)
{
m_PluginName += L".dll";
pluginName += L".dll";
}
pos = m_PluginName.rfind(L'\\');
pos = pluginName.rfind(L'\\');
if (pos != std::wstring::npos)
{
m_PluginName.insert(0, L"..\\");
pluginName.insert(0, L"..\\");
}
m_PluginName.insert(0, Rainmeter->GetPluginPath());
DWORD err = 0;
m_Plugin = CSystem::RmLoadLibrary(m_PluginName.c_str(), &err);
pluginName.insert(0, Rainmeter->GetPluginPath());
m_Plugin = CSystem::RmLoadLibrary(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'\\');
pos = pluginName.rfind(L'\\');
if (pos != std::wstring::npos)
{
std::wstring pluginName = Rainmeter->GetPath();
pluginName.append(m_PluginName, pos + 1, m_PluginName.length() - (pos + 1));
std::wstring pluginName2 = Rainmeter->GetPath();
pluginName2.append(pluginName, pos + 1, 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(pluginName2.c_str(), NULL);
}
if (m_Plugin == NULL)
{
std::wstring error = L"Plugin: \"" + m_PluginName;
std::wstring error = L"Plugin: \"" + pluginName;
error += L"\" not found";
throw CError(error);
}
}
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)
// Remove current directory from DLL search path
SetDllDirectory(L"");
if (IsNewApi())
{
FreeLibrary(m_Plugin);
m_PluginData = (void*)id;
std::wstring error = L"Plugin: \"" + m_PluginName;
error += L"\" doesn't export Update() or GetString()";
throw CError(error);
if (initializeFunc)
{
((NEWINITIALIZE)initializeFunc)(&m_PluginData);
}
((NEWRELOAD)m_ReloadFunc)(m_PluginData, this, &m_MaxValue);
}
// Initialize the plugin
m_ID = id++;
if (InitializeFunc)
else
{
// Remove current directory from DLL search path
SetDllDirectory(L"");
m_ID = id;
double maxValue;
maxValue = InitializeFunc(m_Plugin, parser.GetFilename().c_str(), section, m_ID);
if (!m_UpdateFunc)
{
m_UpdateFunc = GetProcAddress(m_Plugin, "Update2");
m_Update2 = true;
}
// Reset to default
SetDllDirectory(L"");
CSystem::ResetWorkingDirectory();
double maxValue = 0;
if (initializeFunc)
{
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;
}
}
if (m_MaxValue == 0)
{
m_MaxValue = 1;
m_LogMaxValue = true;
}
// Reset to default
SetDllDirectory(L"");
CSystem::ResetWorkingDirectory();
++id;
}
/*
@ -207,9 +229,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,12 +255,19 @@ 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
{
CMeasure::ExecuteBang(args);
}
}
}

View File

@ -20,14 +20,22 @@
#define __MEASUREPLUGIN_H__
#include "Measure.h"
#include "Export.h"
typedef UINT (*INITIALIZE)(HMODULE, LPCTSTR, LPCTSTR, UINT);
typedef UINT (*INITIALIZE)(HMODULE, LPCTSTR, LPCTSTR, UINT);
typedef VOID (*FINALIZE)(HMODULE, UINT);
typedef UINT (*UPDATE)(UINT);
typedef double (*UPDATE2)(UINT);
typedef LPCTSTR (*GETSTRING)(UINT, UINT);
typedef UINT (*UPDATE)(UINT);
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 +50,29 @@ protected:
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
private:
std::wstring m_PluginName;
HMODULE m_Plugin;
UINT m_ID;
bool IsNewApi() { return m_ReloadFunc != NULL; }
INITIALIZE InitializeFunc;
FINALIZE FinalizeFunc;
UPDATE UpdateFunc;
UPDATE2 UpdateFunc2;
GETSTRING GetStringFunc;
EXECUTEBANG ExecuteBangFunc;
HMODULE m_Plugin;
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

View File

@ -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);

View File

@ -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;

91
Library/RawString.h Normal file
View File

@ -0,0 +1,91 @@
/*
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(str_alloc(str))
{
}
~CRawString()
{
clear();
}
CRawString& operator=(const WCHAR* rhs)
{
clear();
m_String = str_alloc(rhs);
return *this;
}
CRawString& operator=(const CRawString& rhs)
{
if (&rhs != this)
{
clear();
m_String = str_alloc(rhs.m_String);
}
return *this;
}
const WCHAR* c_str() const
{
return m_String ? m_String : L"";
}
bool empty() const
{
return !m_String || !(*m_String);
}
void clear()
{
if (m_String)
{
free(m_String);
m_String = NULL;
}
}
private:
CRawString(const CRawString& p)
{
}
WCHAR* str_alloc(const WCHAR* str)
{
return str ? _wcsdup(str) : NULL;
}
WCHAR* m_String;
};
#endif