mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Reintegrated 2.3 branch into trunk
This commit is contained in:
@ -18,117 +18,72 @@
|
||||
|
||||
#include <windows.h>
|
||||
#include <Psapi.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "../../Library/RawString.h"
|
||||
#include "../../Library/Export.h" // Rainmeter's exported functions
|
||||
|
||||
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
|
||||
|
||||
/* The exported functions */
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
|
||||
__declspec(dllexport) void Finalize(HMODULE instance, UINT id);
|
||||
__declspec(dllexport) double Update2(UINT id);
|
||||
__declspec(dllexport) UINT GetPluginVersion();
|
||||
__declspec(dllexport) LPCTSTR GetPluginAuthor();
|
||||
}
|
||||
|
||||
struct MeasureData
|
||||
{
|
||||
std::wstring processName;
|
||||
CRawString processName;
|
||||
bool isRunning;
|
||||
|
||||
MeasureData() : isRunning(false) {}
|
||||
};
|
||||
|
||||
static std::map<UINT, MeasureData> g_Values;
|
||||
static UINT g_UpdateCount = 0;
|
||||
static std::vector<MeasureData*> g_Measures;
|
||||
|
||||
void CheckProcesses();
|
||||
|
||||
/*
|
||||
This function is called when the measure is initialized.
|
||||
The function must return the maximum value that can be measured.
|
||||
The return value can also be 0, which means that Rainmeter will
|
||||
track the maximum value automatically. The parameters for this
|
||||
function are:
|
||||
|
||||
instance The instance of this DLL
|
||||
iniFile The name of the ini-file (usually Rainmeter.ini)
|
||||
section The name of the section in the ini-file for this measure
|
||||
id The identifier for the measure. This is used to identify the measures that use the same plugin.
|
||||
*/
|
||||
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
|
||||
PLUGIN_EXPORT void Initialize(void** data)
|
||||
{
|
||||
MeasureData data;
|
||||
MeasureData* measure = new MeasureData;
|
||||
g_Measures.push_back(measure);
|
||||
|
||||
const WCHAR* value = ReadConfigString(section, L"ProcessName", L"");
|
||||
if (*value)
|
||||
*data = measure;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
LPCWSTR value = RmReadString(rm, L"ProcessName", L"");
|
||||
measure->processName = value;
|
||||
}
|
||||
|
||||
PLUGIN_EXPORT double Update(void* data)
|
||||
{
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
|
||||
// Updates the measure only once per combined updates of all measures
|
||||
++g_UpdateCount;
|
||||
if (g_UpdateCount >= g_Measures.size())
|
||||
{
|
||||
data.processName = value;
|
||||
g_Values[id] = std::move(data);
|
||||
CheckProcesses();
|
||||
g_UpdateCount = 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return measure->isRunning ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is called when new value should be measured.
|
||||
The function returns the new value.
|
||||
*/
|
||||
double Update2(UINT id)
|
||||
PLUGIN_EXPORT void Finalize(void* data)
|
||||
{
|
||||
double result = -1.0;
|
||||
MeasureData* measure = (MeasureData*)data;
|
||||
std::vector<MeasureData*>::iterator iter = std::find(g_Measures.begin(), g_Measures.end(), measure);
|
||||
g_Measures.erase(iter);
|
||||
|
||||
std::map<UINT, MeasureData>::const_iterator iter = g_Values.find(id);
|
||||
if (iter != g_Values.end())
|
||||
{
|
||||
// Updates the measure only once per combined updates of all measures
|
||||
++g_UpdateCount;
|
||||
if (g_UpdateCount >= g_Values.size())
|
||||
{
|
||||
CheckProcesses();
|
||||
g_UpdateCount = 0;
|
||||
}
|
||||
|
||||
result = (*iter).second.isRunning ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
If the measure needs to free resources before quitting.
|
||||
The plugin can export Finalize function, which is called
|
||||
when Rainmeter quits (or refreshes).
|
||||
*/
|
||||
void Finalize(HMODULE instance, UINT id)
|
||||
{
|
||||
std::map<UINT, MeasureData>::iterator iter = g_Values.find(id);
|
||||
if (iter != g_Values.end())
|
||||
{
|
||||
g_Values.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
UINT GetPluginVersion()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
LPCTSTR GetPluginAuthor()
|
||||
{
|
||||
return L"Birunthan Mohanathas (poiru.net)";
|
||||
delete measure;
|
||||
}
|
||||
|
||||
void CheckProcesses()
|
||||
{
|
||||
// Set everything to false
|
||||
std::map<UINT, MeasureData>::iterator iter = g_Values.begin();
|
||||
for ( ; iter != g_Values.end(); ++iter)
|
||||
std::vector<MeasureData*>::iterator iter = g_Measures.begin();
|
||||
for ( ; iter != g_Measures.end(); ++iter)
|
||||
{
|
||||
(*iter).second.isRunning = false;
|
||||
(*iter)->isRunning = false;
|
||||
}
|
||||
|
||||
int bufSize = 256;
|
||||
@ -151,12 +106,12 @@ void CheckProcesses()
|
||||
WCHAR buffer[MAX_PATH];
|
||||
if (GetModuleBaseName(hProcess, NULL, buffer, _countof(buffer)))
|
||||
{
|
||||
iter = g_Values.begin();
|
||||
for ( ; iter != g_Values.end(); ++iter)
|
||||
iter = g_Measures.begin();
|
||||
for ( ; iter != g_Measures.end(); ++iter)
|
||||
{
|
||||
if (_wcsicmp(buffer, (*iter).second.processName.c_str()) == 0)
|
||||
if (_wcsicmp(buffer, (*iter)->processName.c_str()) == 0)
|
||||
{
|
||||
(*iter).second.isRunning = true;
|
||||
(*iter)->isRunning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ BEGIN
|
||||
BLOCK "040904E4"
|
||||
BEGIN
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2011 - Birunthan Mohanathas"
|
||||
VALUE "LegalCopyright", "<EFBFBD> 2011 - Birunthan Mohanathas"
|
||||
VALUE "OriginalFilename", "Process.dll"
|
||||
VALUE "ProductName", "Rainmeter"
|
||||
#ifdef _WIN64
|
||||
|
@ -67,10 +67,10 @@
|
||||
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)TestBench\x32\$(Configuration)\Plugins\</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)\Plugins\</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)\Plugins\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\x32\$(Configuration)\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
|
Reference in New Issue
Block a user