Removed unneeded codes, for VC2010.

This commit is contained in:
spx 2011-02-20 23:03:15 +00:00
parent 480a1bd1d6
commit 9f152e0076
9 changed files with 27 additions and 183 deletions

View File

@ -78,12 +78,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
// _CrtSetBreakAlloc(5055);
// Avoid loading a dll from current directory
typedef BOOL (WINAPI *FPSETDLLDIRECTORYW)(LPCWSTR lpPathName);
FPSETDLLDIRECTORYW SetDllDirectoryW = (FPSETDLLDIRECTORYW)GetProcAddress(GetModuleHandle(L"Kernel32.dll"), "SetDllDirectoryW");
if (SetDllDirectoryW)
{
SetDllDirectoryW(L"");
}
SetDllDirectory(L"");
if (lpCmdLine && lpCmdLine[0] == L'!')
{

View File

@ -32,7 +32,6 @@
#define Ft2Double(x) ((double)((x).dwHighDateTime) * 4.294967296E9 + (double)((x).dwLowDateTime))
PROCNTQSI CMeasureCPU::c_NtQuerySystemInformation = NULL;
PROCGST CMeasureCPU::c_GetSystemTimes = NULL;
int CMeasureCPU::c_NumOfProcessors = 0;
ULONG CMeasureCPU::c_BufferSize = 0;
@ -62,7 +61,8 @@ ULONG CMeasureCPU::c_BufferSize = 0;
*/
CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
m_FirstTime(true),
m_Processor()
m_Processor(),
m_OldTime()
{
m_MaxValue = 100.0;
@ -70,10 +70,6 @@ CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow, const WCHAR* name) : CMeasur
{
c_NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(GetModuleHandle(L"ntdll"), "NtQuerySystemInformation");
}
if (c_GetSystemTimes == NULL)
{
c_GetSystemTimes = (PROCGST)GetProcAddress(GetModuleHandle(L"kernel32"), "GetSystemTimes");
}
if (c_NumOfProcessors == 0)
{
SYSTEM_INFO systemInfo = {0};
@ -119,14 +115,7 @@ void CMeasureCPU::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_FirstTime)
{
if (m_Processor == 0 && c_GetSystemTimes == NULL)
{
m_OldTime.assign(c_NumOfProcessors * 2, 0.0);
}
else
{
m_OldTime.assign(2, 0.0);
}
m_OldTime[0] = m_OldTime[1] = 0.0;
}
}
@ -140,13 +129,13 @@ bool CMeasureCPU::Update()
{
if (!CMeasure::PreUpdate()) return false;
if (m_Processor == 0 && c_GetSystemTimes)
if (m_Processor == 0)
{
BOOL status;
FILETIME ftIdleTime, ftKernelTime, ftUserTime;
// get new CPU's idle/kernel/user time
status = c_GetSystemTimes(&ftIdleTime, &ftKernelTime, &ftUserTime);
status = GetSystemTimes(&ftIdleTime, &ftKernelTime, &ftUserTime);
if (status == 0) return false;
CalcUsage(Ft2Double(ftIdleTime),
@ -212,17 +201,10 @@ bool CMeasureCPU::Update()
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo = (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION*)buf;
if (m_Processor == 0)
{
CalcAverageUsage(systemPerfInfo);
}
else
{
int processor = m_Processor - 1;
int processor = m_Processor - 1;
CalcUsage(Li2Double(systemPerfInfo[processor].IdleTime),
Li2Double(systemPerfInfo[processor].KernelTime) + Li2Double(systemPerfInfo[processor].UserTime));
}
CalcUsage(Li2Double(systemPerfInfo[processor].IdleTime),
Li2Double(systemPerfInfo[processor].KernelTime) + Li2Double(systemPerfInfo[processor].UserTime));
delete [] buf;
}
@ -261,51 +243,3 @@ void CMeasureCPU::CalcUsage(double idleTime, double systemTime)
m_OldTime[0] = idleTime;
m_OldTime[1] = systemTime;
}
/*
** CalcAverageUsage
**
** Calculates the current CPU average utilization value.
** This function is used if GetSystemTimes function is not available.
**
*/
void CMeasureCPU::CalcAverageUsage(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo)
{
if (!m_FirstTime)
{
double dbIdleTimeDiff = 0, dbSystemTimeDiff = 0;
double dbCpuUsage;
for (int i = 0; i < c_NumOfProcessors; ++i)
{
double dbIdleTime, dbSystemTime;
dbIdleTime = Li2Double(systemPerfInfo[i].IdleTime);
dbSystemTime = Li2Double(systemPerfInfo[i].KernelTime) + Li2Double(systemPerfInfo[i].UserTime);
dbIdleTimeDiff += dbIdleTime - m_OldTime[i * 2 + 0];
dbSystemTimeDiff += dbSystemTime - m_OldTime[i * 2 + 1];
// store new CPU's idle and system time
m_OldTime[i * 2 + 0] = dbIdleTime;
m_OldTime[i * 2 + 1] = dbSystemTime;
}
// CurrentCpuUsage% = 100 - ((IdleTime / SystemTime) * 100)
dbCpuUsage = 100.0 - (dbIdleTimeDiff / dbSystemTimeDiff) * 100.0;
dbCpuUsage = min(dbCpuUsage, 100.0);
m_Value = max(dbCpuUsage, 0.0);
}
else
{
// store new CPU's idle and system time
for (int i = 0; i < c_NumOfProcessors; ++i)
{
m_OldTime[i * 2 + 0] = Li2Double(systemPerfInfo[i].IdleTime);
m_OldTime[i * 2 + 1] = Li2Double(systemPerfInfo[i].KernelTime) + Li2Double(systemPerfInfo[i].UserTime);
}
m_FirstTime = false;
}
}

View File

@ -30,7 +30,6 @@ typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
typedef BOOL (WINAPI *PROCGST)(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime);
class CMeasureCPU : public CMeasure
{
@ -49,10 +48,9 @@ protected:
int m_Processor;
std::vector<double> m_OldTime;
double m_OldTime[2];
static PROCNTQSI c_NtQuerySystemInformation;
static PROCGST c_GetSystemTimes;
static int c_NumOfProcessors;
static ULONG c_BufferSize;

View File

@ -192,7 +192,7 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
SetCurrentDirectory(dir.c_str());
// Remove current directory from DLL search path
CSystem::RmSetDllDirectory(L"");
SetDllDirectory(L"");
double maxValue;
maxValue = InitializeFunc(m_Plugin, parser.GetFilename().c_str(), section, m_ID);

View File

@ -1668,12 +1668,6 @@ void CMeterWindow::ReadConfig()
section = m_SkinName.c_str();
}
// Disable native transparency if older OS
if (CSystem::GetOSPlatform() < OSPLATFORM_2K)
{
m_NativeTransparency = 0;
}
// Set WindowXScreen/WindowYScreen temporarily
WindowToScreen();
}

View File

@ -1021,13 +1021,9 @@ OSPLATFORM CSystem::GetOSPlatform()
{
c_Platform = OSPLATFORM_2K;
}
else if (osvi.dwMinorVersion == 1 && osvi.wServicePackMajor == 0)
{
c_Platform = OSPLATFORM_XP;
}
else
{
c_Platform = OSPLATFORM_XP_SP1;
c_Platform = OSPLATFORM_XP;
}
}
else if (osvi.dwMajorVersion == 6) // Vista (Server 2008) / 7 (Server 2008R2)
@ -1051,37 +1047,6 @@ OSPLATFORM CSystem::GetOSPlatform()
return c_Platform;
}
/*
** RmSetDllDirectory
**
** This function is a wrapper function for SetDllDirectory() that is enabled on Windows XP sp1 or newer.
**
** Adds a directory to the search path used to locate DLLs for the application.
**
** If lpPathName is an empty string (""), the call removes the current directory from the default DLL search order.
** If lpPathName is NULL, the function restores the default search order.
**
*/
BOOL CSystem::RmSetDllDirectory(LPCWSTR lpPathName)
{
if (GetOSPlatform() >= OSPLATFORM_XP_SP1)
{
static FPSETDLLDIRECTORYW c_SetDllDirectoryW = NULL;
if (!c_SetDllDirectoryW)
{
c_SetDllDirectoryW = (FPSETDLLDIRECTORYW)GetProcAddress(GetModuleHandle(L"Kernel32.dll"), "SetDllDirectoryW");
}
if (c_SetDllDirectoryW)
{
return c_SetDllDirectoryW(lpPathName);
}
}
return FALSE;
}
/*
** RmLoadLibrary
**
@ -1092,9 +1057,6 @@ BOOL CSystem::RmSetDllDirectory(LPCWSTR lpPathName)
*/
HMODULE CSystem::RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError, bool ignoreErrors)
{
OSPLATFORM platform = GetOSPlatform();
WCHAR buffer[MAX_PATH];
HMODULE hLib = NULL;
DWORD err;
UINT oldMode;
@ -1105,28 +1067,13 @@ HMODULE CSystem::RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError, bool ignor
SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box
}
if (platform < OSPLATFORM_XP_SP1)
{
// Replace current directory to application directory
GetCurrentDirectory(MAX_PATH, buffer);
SetCurrentDirectory(Rainmeter->GetPath().c_str());
}
else
{
// Remove current directory from DLL search path
RmSetDllDirectory(L"");
}
// Remove current directory from DLL search path
SetDllDirectory(L"");
SetLastError(ERROR_SUCCESS);
hLib = LoadLibrary(lpLibFileName);
err = GetLastError();
if (platform < OSPLATFORM_XP_SP1)
{
// Reset to old current directory
SetCurrentDirectory(buffer);
}
if (ignoreErrors)
{
SetErrorMode(oldMode); // Reset

View File

@ -31,7 +31,6 @@ enum OSPLATFORM
OSPLATFORM_NT4,
OSPLATFORM_2K,
OSPLATFORM_XP,
OSPLATFORM_XP_SP1,
OSPLATFORM_VISTA,
OSPLATFORM_7
};
@ -76,10 +75,8 @@ public:
static HWND GetHelperWindow() { return c_HelperWindow; }
static void PrepareHelperWindow(HWND WorkerW);
static bool IsNT() { return (GetOSPlatform() >= OSPLATFORM_NT4); }
static OSPLATFORM GetOSPlatform();
static BOOL RmSetDllDirectory(LPCWSTR lpPathName);
static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false);
static bool CopyFiles(const std::wstring& strFrom, const std::wstring& strTo, bool bMove = false);

View File

@ -111,35 +111,24 @@ double Update2(UINT id)
if(measure)
{
// Check the platform
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx((OSVERSIONINFO*)&osvi) && osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion > 4)
{
ULONGLONG longvalue = 0;
longvalue = GetPerfData(measure->ObjectName.c_str(),
measure->InstanceName.c_str(),
measure->CounterName.c_str());
ULONGLONG longvalue;
longvalue = GetPerfData(measure->ObjectName.c_str(),
measure->InstanceName.c_str(),
measure->CounterName.c_str());
if(measure->Difference)
if(measure->Difference)
{
// Compare with the old value
if(!measure->FirstTime)
{
// Compare with the old value
if(!measure->FirstTime)
{
value = (double)(longvalue - measure->OldValue);
}
measure->OldValue = longvalue;
measure->FirstTime = false;
}
else
{
value = (double)longvalue;
value = (double)(longvalue - measure->OldValue);
}
measure->OldValue = longvalue;
measure->FirstTime = false;
}
else
{
LSLog(LOG_NOTICE, L"Rainmeter", L"PerfMon plugin works only in Win2K and later.");
value = (double)longvalue;
}
}
}

View File

@ -611,17 +611,7 @@ void GetOSVersion(WCHAR* buffer)
void GetOSBits(WCHAR* buffer)
{
SYSTEM_INFO systemInfo = {0};
typedef void (WINAPI *FPGETNATIVESYSTEMINFO)(LPSYSTEM_INFO lpSystemInfo);
FPGETNATIVESYSTEMINFO GetNativeSystemInfo = (FPGETNATIVESYSTEMINFO)GetProcAddress(GetModuleHandle(L"kernel32"), "GetNativeSystemInfo");
if (GetNativeSystemInfo != NULL)
{
GetNativeSystemInfo(&systemInfo);
}
else
{
GetSystemInfo(&systemInfo);
}
GetNativeSystemInfo(&systemInfo);
if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)