Code cleanups.

This commit is contained in:
spx 2010-11-06 23:13:12 +00:00
parent 5393ea461a
commit 6ef688f387
2 changed files with 17 additions and 26 deletions

View File

@ -26,7 +26,6 @@ UINT CMeasureNet::c_NumOfTables = 0;
std::vector<ULONG64> CMeasureNet::c_StatValues; std::vector<ULONG64> CMeasureNet::c_StatValues;
std::vector<ULONG64> CMeasureNet::c_OldStatValues; std::vector<ULONG64> CMeasureNet::c_OldStatValues;
HINSTANCE CMeasureNet::c_IpHlpApiLibrary = NULL;
FPGETIFTABLE2EX CMeasureNet::c_GetIfTable2Ex = NULL; FPGETIFTABLE2EX CMeasureNet::c_GetIfTable2Ex = NULL;
FPFREEMIBTABLE CMeasureNet::c_FreeMibTable = NULL; FPFREEMIBTABLE CMeasureNet::c_FreeMibTable = NULL;
bool CMeasureNet::c_UseNewApi = false; bool CMeasureNet::c_UseNewApi = false;
@ -146,6 +145,7 @@ void CMeasureNet::UpdateIFTable()
} }
DebugLog(L"%i: %s", i + 1, ifTable->Table[i].Description); DebugLog(L"%i: %s", i + 1, ifTable->Table[i].Description);
DebugLog(L" Alias: %s", ifTable->Table[i].Alias);
DebugLog(L" Type=%s(%i), Hardware=%s, Filter=%s", DebugLog(L" Type=%s(%i), Hardware=%s, Filter=%s",
type.c_str(), ifTable->Table[i].Type, type.c_str(), ifTable->Table[i].Type,
(ifTable->Table[i].InterfaceAndOperStatusFlags.HardwareInterface == 1) ? L"Yes" : L"No", (ifTable->Table[i].InterfaceAndOperStatusFlags.HardwareInterface == 1) ? L"Yes" : L"No",
@ -569,13 +569,7 @@ void CMeasureNet::UpdateStats()
*/ */
void CMeasureNet::ResetStats() void CMeasureNet::ResetStats()
{ {
if (c_Table) c_StatValues.clear();
{
for (size_t i = 0; i < c_StatValues.size(); ++i)
{
c_StatValues[i] = 0;
}
}
} }
/* /*
@ -591,22 +585,22 @@ void CMeasureNet::ReadStats(const std::wstring& iniFile)
c_StatValues.clear(); c_StatValues.clear();
for (int i = 0; i < count; ++i) for (int i = 1; i <= count; ++i)
{ {
ULARGE_INTEGER value; ULARGE_INTEGER value;
wsprintf(buffer, L"NetStatsInHigh%i", i + 1); wsprintf(buffer, L"NetStatsInHigh%i", i);
value.HighPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str()); value.HighPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str());
wsprintf(buffer, L"NetStatsInLow%i", i + 1); wsprintf(buffer, L"NetStatsInLow%i", i);
value.LowPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str()); value.LowPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str());
c_StatValues.push_back(value.QuadPart); c_StatValues.push_back(value.QuadPart);
wsprintf(buffer, L"NetStatsOutHigh%i", i + 1); wsprintf(buffer, L"NetStatsOutHigh%i", i);
value.HighPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str()); value.HighPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str());
wsprintf(buffer, L"NetStatsOutLow%i", i + 1); wsprintf(buffer, L"NetStatsOutLow%i", i);
value.LowPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str()); value.LowPart = (DWORD)GetPrivateProfileInt(L"Statistics", buffer, 0, iniFile.c_str());
c_StatValues.push_back(value.QuadPart); c_StatValues.push_back(value.QuadPart);
@ -661,23 +655,19 @@ void CMeasureNet::WriteStats(const std::wstring& iniFile)
*/ */
void CMeasureNet::InitializeNewApi() void CMeasureNet::InitializeNewApi()
{ {
if (c_IpHlpApiLibrary == NULL) if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
{ {
c_IpHlpApiLibrary = GetModuleHandle(L"IpHlpApi.dll"); HMODULE IpHlpApiLibrary = GetModuleHandle(L"IpHlpApi.dll");
if (c_IpHlpApiLibrary) if (IpHlpApiLibrary)
{ {
c_GetIfTable2Ex = (FPGETIFTABLE2EX)GetProcAddress(c_IpHlpApiLibrary, "GetIfTable2Ex"); c_GetIfTable2Ex = (FPGETIFTABLE2EX)GetProcAddress(IpHlpApiLibrary, "GetIfTable2Ex");
c_FreeMibTable = (FPFREEMIBTABLE)GetProcAddress(c_IpHlpApiLibrary, "FreeMibTable"); c_FreeMibTable = (FPFREEMIBTABLE)GetProcAddress(IpHlpApiLibrary, "FreeMibTable");
} }
c_UseNewApi = (c_IpHlpApiLibrary && c_GetIfTable2Ex && c_FreeMibTable); c_UseNewApi = (IpHlpApiLibrary && c_GetIfTable2Ex && c_FreeMibTable);
if (!c_UseNewApi) if (!c_UseNewApi)
{ {
if (c_IpHlpApiLibrary)
{
c_IpHlpApiLibrary = NULL;
}
c_GetIfTable2Ex = NULL; c_GetIfTable2Ex = NULL;
c_FreeMibTable = NULL; c_FreeMibTable = NULL;
} }
@ -699,9 +689,11 @@ void CMeasureNet::FinalizeNewApi()
{ {
if (c_UseNewApi) if (c_UseNewApi)
{ {
c_FreeMibTable(c_Table); if (c_Table)
{
c_FreeMibTable(c_Table);
}
c_IpHlpApiLibrary = NULL;
c_GetIfTable2Ex = NULL; c_GetIfTable2Ex = NULL;
c_FreeMibTable = NULL; c_FreeMibTable = NULL;
} }

View File

@ -198,7 +198,6 @@ protected:
static BYTE* c_Table; static BYTE* c_Table;
static UINT c_NumOfTables; static UINT c_NumOfTables;
static HINSTANCE c_IpHlpApiLibrary;
static FPGETIFTABLE2EX c_GetIfTable2Ex; static FPGETIFTABLE2EX c_GetIfTable2Ex;
static FPFREEMIBTABLE c_FreeMibTable; static FPFREEMIBTABLE c_FreeMibTable;
static bool c_UseNewApi; static bool c_UseNewApi;