Fixed line endings and applied gitignore

This commit is contained in:
2014-07-26 09:43:40 +03:00
parent 0c57cabe56
commit 7cba5cc109
542 changed files with 112014 additions and 119759 deletions

View File

@ -1,234 +1,234 @@
/*
Copyright (C) 2005 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <windows.h>
#include <Winsock2.h>
#include <string>
#include <Ipexport.h>
#include <Icmpapi.h>
#include "../../Library/Export.h" // Rainmeter's exported functions
struct MeasureData
{
IPAddr destAddr;
DWORD timeout;
double timeoutValue;
DWORD updateRate;
DWORD updateCounter;
bool threadActive;
double value;
std::wstring finishAction;
void* skin;
MeasureData() :
destAddr(),
timeout(),
timeoutValue(),
updateRate(),
updateCounter(),
threadActive(false),
value(),
finishAction(),
skin(nullptr)
{
}
};
static CRITICAL_SECTION g_CriticalSection;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
InitializeCriticalSection(&g_CriticalSection);
// Disable DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls.
DisableThreadLibraryCalls(hinstDLL);
break;
case DLL_PROCESS_DETACH:
DeleteCriticalSection(&g_CriticalSection);
break;
}
return TRUE;
}
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
MeasureData* measure = new MeasureData;
*data = measure;
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
MeasureData* measure = (MeasureData*)data;
LPCWSTR value = RmReadString(rm, L"DestAddress", L"");
if (*value)
{
int strLen = (int)wcslen(value) + 1;
int bufLen = WideCharToMultiByte(CP_ACP, 0, value, strLen, nullptr, 0, nullptr, nullptr);
if (bufLen > 0)
{
char* buffer = new char[bufLen];
WideCharToMultiByte(CP_ACP, 0, value, strLen, buffer, bufLen, nullptr, nullptr);
measure->destAddr = inet_addr(buffer);
if (measure->destAddr == INADDR_NONE)
{
WSADATA wsaData;
if (WSAStartup(0x0101, &wsaData) == 0)
{
LPHOSTENT pHost = gethostbyname(buffer);
if (pHost)
{
measure->destAddr = *(DWORD*)pHost->h_addr;
}
else
{
RmLog(LOG_WARNING, L"PingPlugin.dll: Unable to get host by name");
}
WSACleanup();
}
else
{
RmLog(LOG_WARNING, L"PingPlugin.dll: Unable to start WSA");
}
}
delete [] buffer;
}
}
measure->updateRate = RmReadInt(rm, L"UpdateRate", 32);
measure->timeout = RmReadInt(rm, L"Timeout", 30000);
measure->timeoutValue = RmReadDouble(rm, L"TimeoutValue", 30000.0);
measure->finishAction = RmReadString(rm, L"FinishAction", L"", false);
measure->skin = RmGetSkin(rm);
}
DWORD WINAPI NetworkThreadProc(void* pParam)
{
// NOTE: Do not use CRT functions (since thread was created by CreateThread())!
MeasureData* measure = (MeasureData*)pParam;
const DWORD bufferSize = sizeof(ICMP_ECHO_REPLY) + 32;
BYTE buffer[bufferSize];
double value = 0.0;
HANDLE hIcmpFile = IcmpCreateFile();
if (hIcmpFile != INVALID_HANDLE_VALUE)
{
IcmpSendEcho(hIcmpFile, measure->destAddr, nullptr, 0, nullptr, buffer, bufferSize, measure->timeout);
IcmpCloseHandle(hIcmpFile);
ICMP_ECHO_REPLY* reply = (ICMP_ECHO_REPLY*)buffer;
value = (reply->Status != IP_SUCCESS) ? measure->timeoutValue : reply->RoundTripTime;
if (!measure->finishAction.empty())
{
RmExecute(measure->skin, measure->finishAction.c_str());
}
}
HMODULE module = nullptr;
EnterCriticalSection(&g_CriticalSection);
if (measure->threadActive)
{
measure->value = value;
measure->threadActive = false;
}
else
{
// Thread is not attached to an existing measure any longer, so delete
// unreferenced data.
delete measure;
DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
GetModuleHandleEx(flags, (LPCWSTR)DllMain, &module);
}
LeaveCriticalSection(&g_CriticalSection);
if (module)
{
// Decrement the ref count and possibly unload the module if this is
// the last instance.
FreeLibraryAndExitThread(module, 0);
}
return 0;
}
PLUGIN_EXPORT double Update(void* data)
{
MeasureData* measure = (MeasureData*)data;
EnterCriticalSection(&g_CriticalSection);
if (!measure->threadActive)
{
if (measure->updateCounter == 0)
{
// Launch a new thread to fetch the web data
DWORD id;
HANDLE thread = CreateThread(nullptr, 0, NetworkThreadProc, measure, 0, &id);
if (thread)
{
CloseHandle(thread);
measure->threadActive = true;
}
}
measure->updateCounter++;
if (measure->updateCounter >= measure->updateRate)
{
measure->updateCounter = 0;
}
}
double value = measure->value;
LeaveCriticalSection(&g_CriticalSection);
return value;
}
PLUGIN_EXPORT void Finalize(void* data)
{
MeasureData* measure = (MeasureData*)data;
EnterCriticalSection(&g_CriticalSection);
if (measure->threadActive)
{
// Increment ref count of this module so that it will not be unloaded prior to
// thread completion.
DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS;
HMODULE module;
GetModuleHandleEx(flags, (LPCWSTR)DllMain, &module);
// Thread will perform cleanup.
measure->threadActive = false;
}
else
{
delete measure;
}
LeaveCriticalSection(&g_CriticalSection);
}
/*
Copyright (C) 2005 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <windows.h>
#include <Winsock2.h>
#include <string>
#include <Ipexport.h>
#include <Icmpapi.h>
#include "../../Library/Export.h" // Rainmeter's exported functions
struct MeasureData
{
IPAddr destAddr;
DWORD timeout;
double timeoutValue;
DWORD updateRate;
DWORD updateCounter;
bool threadActive;
double value;
std::wstring finishAction;
void* skin;
MeasureData() :
destAddr(),
timeout(),
timeoutValue(),
updateRate(),
updateCounter(),
threadActive(false),
value(),
finishAction(),
skin(nullptr)
{
}
};
static CRITICAL_SECTION g_CriticalSection;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
InitializeCriticalSection(&g_CriticalSection);
// Disable DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls.
DisableThreadLibraryCalls(hinstDLL);
break;
case DLL_PROCESS_DETACH:
DeleteCriticalSection(&g_CriticalSection);
break;
}
return TRUE;
}
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
MeasureData* measure = new MeasureData;
*data = measure;
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
MeasureData* measure = (MeasureData*)data;
LPCWSTR value = RmReadString(rm, L"DestAddress", L"");
if (*value)
{
int strLen = (int)wcslen(value) + 1;
int bufLen = WideCharToMultiByte(CP_ACP, 0, value, strLen, nullptr, 0, nullptr, nullptr);
if (bufLen > 0)
{
char* buffer = new char[bufLen];
WideCharToMultiByte(CP_ACP, 0, value, strLen, buffer, bufLen, nullptr, nullptr);
measure->destAddr = inet_addr(buffer);
if (measure->destAddr == INADDR_NONE)
{
WSADATA wsaData;
if (WSAStartup(0x0101, &wsaData) == 0)
{
LPHOSTENT pHost = gethostbyname(buffer);
if (pHost)
{
measure->destAddr = *(DWORD*)pHost->h_addr;
}
else
{
RmLog(LOG_WARNING, L"PingPlugin.dll: Unable to get host by name");
}
WSACleanup();
}
else
{
RmLog(LOG_WARNING, L"PingPlugin.dll: Unable to start WSA");
}
}
delete [] buffer;
}
}
measure->updateRate = RmReadInt(rm, L"UpdateRate", 32);
measure->timeout = RmReadInt(rm, L"Timeout", 30000);
measure->timeoutValue = RmReadDouble(rm, L"TimeoutValue", 30000.0);
measure->finishAction = RmReadString(rm, L"FinishAction", L"", false);
measure->skin = RmGetSkin(rm);
}
DWORD WINAPI NetworkThreadProc(void* pParam)
{
// NOTE: Do not use CRT functions (since thread was created by CreateThread())!
MeasureData* measure = (MeasureData*)pParam;
const DWORD bufferSize = sizeof(ICMP_ECHO_REPLY) + 32;
BYTE buffer[bufferSize];
double value = 0.0;
HANDLE hIcmpFile = IcmpCreateFile();
if (hIcmpFile != INVALID_HANDLE_VALUE)
{
IcmpSendEcho(hIcmpFile, measure->destAddr, nullptr, 0, nullptr, buffer, bufferSize, measure->timeout);
IcmpCloseHandle(hIcmpFile);
ICMP_ECHO_REPLY* reply = (ICMP_ECHO_REPLY*)buffer;
value = (reply->Status != IP_SUCCESS) ? measure->timeoutValue : reply->RoundTripTime;
if (!measure->finishAction.empty())
{
RmExecute(measure->skin, measure->finishAction.c_str());
}
}
HMODULE module = nullptr;
EnterCriticalSection(&g_CriticalSection);
if (measure->threadActive)
{
measure->value = value;
measure->threadActive = false;
}
else
{
// Thread is not attached to an existing measure any longer, so delete
// unreferenced data.
delete measure;
DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
GetModuleHandleEx(flags, (LPCWSTR)DllMain, &module);
}
LeaveCriticalSection(&g_CriticalSection);
if (module)
{
// Decrement the ref count and possibly unload the module if this is
// the last instance.
FreeLibraryAndExitThread(module, 0);
}
return 0;
}
PLUGIN_EXPORT double Update(void* data)
{
MeasureData* measure = (MeasureData*)data;
EnterCriticalSection(&g_CriticalSection);
if (!measure->threadActive)
{
if (measure->updateCounter == 0)
{
// Launch a new thread to fetch the web data
DWORD id;
HANDLE thread = CreateThread(nullptr, 0, NetworkThreadProc, measure, 0, &id);
if (thread)
{
CloseHandle(thread);
measure->threadActive = true;
}
}
measure->updateCounter++;
if (measure->updateCounter >= measure->updateRate)
{
measure->updateCounter = 0;
}
}
double value = measure->value;
LeaveCriticalSection(&g_CriticalSection);
return value;
}
PLUGIN_EXPORT void Finalize(void* data)
{
MeasureData* measure = (MeasureData*)data;
EnterCriticalSection(&g_CriticalSection);
if (measure->threadActive)
{
// Increment ref count of this module so that it will not be unloaded prior to
// thread completion.
DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS;
HMODULE module;
GetModuleHandleEx(flags, (LPCWSTR)DllMain, &module);
// Thread will perform cleanup.
measure->threadActive = false;
}
else
{
delete measure;
}
LeaveCriticalSection(&g_CriticalSection);
}

View File

@ -1,40 +1,40 @@
#include <VerRsrc.h>
#include "../../Version.h"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,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
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "FileVersion", "1.2.0.0"
VALUE "LegalCopyright", "<22> 2010 - Rainy"
VALUE "ProductName", "Rainmeter"
#ifdef _WIN64
VALUE "ProductVersion", STRPRODUCTVER " (64-bit)"
#else
VALUE "ProductVersion", STRPRODUCTVER " (32-bit)"
#endif //_WIN64
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 1252
}
}
#include <VerRsrc.h>
#include "../../Version.h"
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,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
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "FileVersion", "1.2.0.0"
VALUE "LegalCopyright", "<22> 2010 - Rainy"
VALUE "ProductName", "Rainmeter"
#ifdef _WIN64
VALUE "ProductVersion", STRPRODUCTVER " (64-bit)"
#else
VALUE "ProductVersion", STRPRODUCTVER " (32-bit)"
#endif //_WIN64
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 1252
}
}

View File

@ -1,36 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.Default.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{C862B662-5CC6-4E79-B1B3-905E0B98D627}</ProjectGuid>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<TargetName>PingPlugin</TargetName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.props" />
<Import Project="$(SolutionDir)Build\VS\RainmeterPlugin.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>_USRDLL;PluginPing_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>Ws2_32.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Ping.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PluginPing.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.Default.props" />
<PropertyGroup Label="Globals">
<ProjectGuid>{C862B662-5CC6-4E79-B1B3-905E0B98D627}</ProjectGuid>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<TargetName>PingPlugin</TargetName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(SolutionDir)Build\VS\Rainmeter.Cpp.props" />
<Import Project="$(SolutionDir)Build\VS\RainmeterPlugin.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>_USRDLL;PluginPing_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>Ws2_32.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Ping.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PluginPing.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>