diff --git a/Plugins/PluginProcess/PluginProcess.cpp b/Plugins/PluginProcess/PluginProcess.cpp new file mode 100644 index 00000000..b60d9fbd --- /dev/null +++ b/Plugins/PluginProcess/PluginProcess.cpp @@ -0,0 +1,169 @@ +/* + 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. +*/ + +#include +#include +#include +#include +#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) UINT Update(UINT id); +__declspec(dllexport) UINT GetPluginVersion(); +__declspec(dllexport) LPCTSTR GetPluginAuthor(); +} + +struct MeasureData +{ + std::wstring processName; + bool isRunning; + + MeasureData() : isRunning(false) {} +}; + +static std::map g_Values; +static UINT g_UpdateCount = 0; + +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) +{ + MeasureData data; + + const WCHAR* value = ReadConfigString(section, L"ProcessName", L""); + if (*value) + { + data.processName = value; + g_Values[id] = std::move(data); + } + + return 1; +} + +/* + This function is called when new value should be measured. + The function returns the new value. +*/ +UINT Update(UINT id) +{ + UINT result = 0; + + std::map::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 = (UINT)(*iter).second.isRunning; + } + + 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::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)"; +} + +void CheckProcesses() +{ + // Set everything to false + std::map::iterator iter = g_Values.begin(); + for ( ; iter != g_Values.end(); ++iter) + { + (*iter).second.isRunning = false; + } + + int bufSize = 256; + DWORD* pids = new DWORD[bufSize]; + DWORD bytesReturned = 0; + while (!EnumProcesses(pids, bufSize * sizeof(DWORD), &bytesReturned) && + bytesReturned == bufSize * sizeof(DWORD)) + { + delete [] pids; + bufSize *= 2; + pids = new DWORD[bufSize]; + } + + for (UINT i = 0, isize = bytesReturned / sizeof(DWORD); i < isize; ++i) + { + const DWORD flags = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ; + HANDLE hProcess = OpenProcess(flags, FALSE, pids[i]); + if (hProcess) + { + WCHAR buffer[MAX_PATH]; + if (GetModuleBaseName(hProcess, NULL, buffer, _countof(buffer))) + { + iter = g_Values.begin(); + for ( ; iter != g_Values.end(); ++iter) + { + if (_wcsicmp(buffer, (*iter).second.processName.c_str()) == 0) + { + (*iter).second.isRunning = true; + } + } + } + + CloseHandle(hProcess); + } + } + + delete [] pids; +} diff --git a/Plugins/PluginProcess/PluginProcess.rc b/Plugins/PluginProcess/PluginProcess.rc new file mode 100644 index 00000000..82341f7b --- /dev/null +++ b/Plugins/PluginProcess/PluginProcess.rc @@ -0,0 +1,46 @@ +// Microsoft Developer Studio generated resource script. +// + +#include "../../Version.h" +#define APSTUDIO_READONLY_SYMBOLS +#include "windows.h" +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION PRODUCTVER + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS_NT_WINDOWS32 + FILETYPE VFT_DLL + FILESUBTYPE VFT_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileVersion", "1.0.0.0" + VALUE "LegalCopyright", "Copyright (C) 2011 - Birunthan Mohanathas" + VALUE "OriginalFilename", "Process.dll" + VALUE "ProductName", "Rainmeter" +#ifdef _WIN64 + VALUE "ProductVersion", STRPRODUCTVER " (64-bit)" +#else + VALUE "ProductVersion", STRPRODUCTVER " (32-bit)" +#endif //_WIN64 + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/Plugins/PluginProcess/PluginProcess.vcxproj b/Plugins/PluginProcess/PluginProcess.vcxproj new file mode 100644 index 00000000..8fcb3214 --- /dev/null +++ b/Plugins/PluginProcess/PluginProcess.vcxproj @@ -0,0 +1,273 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {05203741-CD80-4060-8218-EC5D1120FE3E} + + + + + DynamicLibrary + false + Unicode + true + + + DynamicLibrary + false + Unicode + + + DynamicLibrary + false + Unicode + $(COMPILER64) + true + + + DynamicLibrary + false + Unicode + $(COMPILER64) + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)TestBench\x32\$(Configuration)\Plugins\ + .\x32\$(Configuration)\ + false + $(SolutionDir)TestBench\x64\$(Configuration)\Plugins\ + .\x64\$(Configuration)\ + false + $(SolutionDir)TestBench\x32\$(Configuration)\Plugins\ + .\x32\$(Configuration)\ + false + $(SolutionDir)TestBench\x64\$(Configuration)\Plugins\ + .\x64\$(Configuration)\ + false + Process + Process + Process + Process + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\x32/Debug/PluginProcess.tlb + + + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;PluginProcess_EXPORTS;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + + + .\x32/Debug/PluginProcess.pch + .\x32/Debug/ + .\x32/Debug/ + .\x32/Debug/ + Level3 + true + EditAndContinue + 4018;4090;4114;4351;4786;4800;4996 + + + _DEBUG;%(PreprocessorDefinitions) + 0x0409 + + + ../../TestBench/x32/Debug/Plugins/Process.dll + true + true + .\x32/Debug/ProcessPlugin.pdb + .\x32/Debug/ProcessPlugin.lib + MachineX86 + ..\..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories) + Psapi.lib;Rainmeter.lib;%(AdditionalDependencies) + + + + + _DEBUG;%(PreprocessorDefinitions) + true + true + X64 + .\x64/Debug/PluginProcess.tlb + + + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;PluginProcess_EXPORTS;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebugDLL + + + .\x64/Debug/PluginProcess.pch + .\x64/Debug/ + .\x64/Debug/ + .\x64/Debug/ + Level3 + true + ProgramDatabase + 4018;4090;4114;4351;4786;4800;4996 + + + _DEBUG;_WIN64;%(PreprocessorDefinitions) + 0x0409 + + + ../../TestBench/x64/Debug/Plugins/Process.dll + true + true + .\x64/Debug/ProcessPlugin.pdb + .\x64/Debug/ProcessPlugin.lib + MachineX64 + ..\..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories) + Psapi.lib;Rainmeter.lib;%(AdditionalDependencies) + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + Win32 + .\x32/Release/PluginProcess.tlb + + + + + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;_USRDLL;PluginProcess_EXPORTS;%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + + + .\x32/Release/PluginProcess.pch + .\x32/Release/ + .\x32/Release/ + .\x32/Release/ + Level3 + true + ProgramDatabase + 4018;4090;4114;4351;4786;4800;4996 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0409 + + + Psapi.lib;Rainmeter.lib;%(AdditionalDependencies) + ../../TestBench/x32/Release/Plugins/Process.dll + true + ..\..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories) + true + .\x32/Release/ProcessPlugin.pdb + .\x32/Release/ProcessPlugin.lib + MachineX86 + .rdata=.text + true + true + + + + + NDEBUG;%(PreprocessorDefinitions) + true + true + X64 + .\x64/Release/PluginProcess.tlb + + + + + /GL %(AdditionalOptions) + MaxSpeed + OnlyExplicitInline + WIN32;NDEBUG;_WINDOWS;_USRDLL;PluginProcess_EXPORTS;%(PreprocessorDefinitions) + true + MultiThreadedDLL + true + .\x64/Release/PluginProcess.pch + .\x64/Release/ + .\x64/Release/ + .\x64/Release/ + Level3 + true + ProgramDatabase + 4018;4090;4114;4351;4786;4800;4996 + + + NDEBUG;_WIN64;%(PreprocessorDefinitions) + 0x0409 + + + /LTCG %(AdditionalOptions) + Psapi.lib;Rainmeter.lib;%(AdditionalDependencies) + ../../TestBench/x64/Release/Plugins/Process.dll + true + ..\..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories) + .\x64/Release/ProcessPlugin.pdb + .\x64/Release/ProcessPlugin.lib + MachineX64 + .rdata=.text + true + true + + + + + + + + + + + {be9d2400-7f1c-49d6-8498-5ce495491ad6} + false + + + + + + \ No newline at end of file diff --git a/Rainmeter.sln b/Rainmeter.sln index 695dc854..0176deb7 100644 --- a/Rainmeter.sln +++ b/Rainmeter.sln @@ -51,6 +51,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginCoreTemp", "Plugins\P EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginNowPlaying", "Plugins\PluginNowPlaying\PluginNowPlaying.vcxproj", "{C7FECFCD-E6C6-4F95-BB9A-E1762B043969}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginProcess", "Plugins\PluginProcess\PluginProcess.vcxproj", "{05203741-CD80-4060-8218-EC5D1120FE3E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -248,6 +250,14 @@ Global {C7FECFCD-E6C6-4F95-BB9A-E1762B043969}.Debug|x64.ActiveCfg = Debug|x64 {C7FECFCD-E6C6-4F95-BB9A-E1762B043969}.Release|Win32.ActiveCfg = Release|Win32 {C7FECFCD-E6C6-4F95-BB9A-E1762B043969}.Release|x64.ActiveCfg = Release|x64 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Debug|Win32.ActiveCfg = Debug|Win32 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Debug|Win32.Build.0 = Debug|Win32 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Debug|x64.ActiveCfg = Debug|x64 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Debug|x64.Build.0 = Debug|x64 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Release|Win32.ActiveCfg = Release|Win32 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Release|Win32.Build.0 = Release|Win32 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Release|x64.ActiveCfg = Release|x64 + {05203741-CD80-4060-8218-EC5D1120FE3E}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE