rainmeter-studio/Library/MeasureNet.cpp

737 lines
16 KiB
C++
Raw Normal View History

2009-02-10 18:37:48 +00:00
/*
Copyright (C) 2001 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.
2009-02-10 18:37:48 +00:00
*/
#include "StdAfx.h"
2009-02-10 18:37:48 +00:00
#include "MeasureNet.h"
#include "Rainmeter.h"
#include "System.h"
2009-02-10 18:37:48 +00:00
2013-05-31 14:28:39 +00:00
BYTE* MeasureNet::c_Table = nullptr;
2013-05-31 14:18:52 +00:00
UINT MeasureNet::c_NumOfTables = 0;
std::vector<ULONG64> MeasureNet::c_StatValues;
std::vector<ULONG64> MeasureNet::c_OldStatValues;
2011-08-02 01:20:05 +00:00
2013-05-31 14:28:39 +00:00
FPGETIFTABLE2 MeasureNet::c_GetIfTable2 = nullptr;
FPFREEMIBTABLE MeasureNet::c_FreeMibTable = nullptr;
2009-02-10 18:37:48 +00:00
/*
2011-03-29 19:21:57 +00:00
** The constructor. This is the base class for the net-meters.
2009-02-10 18:37:48 +00:00
**
*/
2013-05-31 14:18:52 +00:00
MeasureNet::MeasureNet(MeterWindow* meterWindow, const WCHAR* name, NET type) : Measure(meterWindow, name),
2012-10-09 15:33:49 +00:00
m_Net(type),
m_Interface(),
2012-10-09 15:33:49 +00:00
m_Octets(),
m_FirstTime(true),
m_Cumulative(false)
2009-02-10 18:37:48 +00:00
{
}
/*
** The destructor
**
*/
2013-05-31 14:18:52 +00:00
MeasureNet::~MeasureNet()
2009-02-10 18:37:48 +00:00
{
}
/*
** Reads the tables for all net interfaces
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::UpdateIFTable()
2009-02-10 18:37:48 +00:00
{
2011-08-02 01:20:05 +00:00
bool logging = false;
if (c_GetIfTable2)
2011-08-02 01:20:05 +00:00
{
if (c_Table)
2009-02-10 18:37:48 +00:00
{
2011-08-02 01:20:05 +00:00
c_FreeMibTable(c_Table);
2013-05-31 14:28:39 +00:00
c_Table = nullptr;
}
if (c_GetIfTable2((MIB_IF_TABLE2**)&c_Table) == NO_ERROR)
{
2011-08-02 01:20:05 +00:00
MIB_IF_TABLE2* ifTable = (MIB_IF_TABLE2*)c_Table;
if (c_NumOfTables != ifTable->NumEntries)
{
2011-08-02 01:20:05 +00:00
c_NumOfTables = ifTable->NumEntries;
logging = true;
}
2009-02-10 18:37:48 +00:00
if (GetRainmeter().GetDebug() && logging)
2009-02-10 18:37:48 +00:00
{
2013-05-30 14:19:42 +00:00
LogDebug(L"------------------------------");
LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables);
2011-08-02 01:20:05 +00:00
for (size_t i = 0; i < c_NumOfTables; ++i)
{
2012-06-26 17:41:40 +00:00
const WCHAR* type = L"Other";
2011-08-02 01:20:05 +00:00
switch (ifTable->Table[i].Type)
{
case IF_TYPE_ETHERNET_CSMACD:
2012-06-26 17:41:40 +00:00
type = L"Ethernet";
2011-08-02 01:20:05 +00:00
break;
case IF_TYPE_PPP:
2012-06-26 17:41:40 +00:00
type = L"PPP";
2011-08-02 01:20:05 +00:00
break;
case IF_TYPE_SOFTWARE_LOOPBACK:
2012-06-26 17:41:40 +00:00
type = L"Loopback";
2011-08-02 01:20:05 +00:00
break;
case IF_TYPE_IEEE80211:
2012-06-26 17:41:40 +00:00
type = L"IEEE802.11";
2011-08-02 01:20:05 +00:00
break;
case IF_TYPE_TUNNEL:
2012-06-26 17:41:40 +00:00
type = L"Tunnel";
2011-08-02 01:20:05 +00:00
break;
case IF_TYPE_IEEE1394:
2012-06-26 17:41:40 +00:00
type = L"IEEE1394";
2011-08-02 01:20:05 +00:00
break;
}
2013-05-30 14:19:42 +00:00
LogDebugF(L"%i: %s", (int)i + 1, ifTable->Table[i].Description);
LogDebugF(L" Alias: %s", ifTable->Table[i].Alias);
LogDebugF(L" Type=%s(%i), Hardware=%s, Filter=%s",
2012-06-26 17:41:40 +00:00
type, ifTable->Table[i].Type,
2011-08-02 01:20:05 +00:00
(ifTable->Table[i].InterfaceAndOperStatusFlags.HardwareInterface == 1) ? L"Yes" : L"No",
(ifTable->Table[i].InterfaceAndOperStatusFlags.FilterInterface == 1) ? L"Yes" : L"No");
}
2013-05-30 14:19:42 +00:00
LogDebug(L"------------------------------");
2011-08-02 01:20:05 +00:00
}
}
else
{
// Something's wrong. Unable to get the table.
2013-05-31 14:28:39 +00:00
c_Table = nullptr;
2011-08-02 01:20:05 +00:00
c_NumOfTables = 0;
}
}
else
{
2013-05-31 14:28:39 +00:00
if (c_Table == nullptr)
2011-08-02 01:20:05 +00:00
{
// Gotta reserve few bytes for the tables
DWORD value = 0;
if (GetNumberOfInterfaces(&value) == NO_ERROR)
{
if (c_NumOfTables != value)
{
2011-08-02 01:20:05 +00:00
c_NumOfTables = value;
logging = true;
}
2011-08-02 01:20:05 +00:00
if (c_NumOfTables > 0)
{
DWORD size = sizeof(MIB_IFTABLE) + sizeof(MIB_IFROW) * c_NumOfTables;
c_Table = new BYTE[size];
}
}
}
if (c_Table)
{
DWORD ret, size = 0;
MIB_IFTABLE* ifTable = (MIB_IFTABLE*)c_Table;
if ((ret = GetIfTable(ifTable, &size, FALSE)) == ERROR_INSUFFICIENT_BUFFER)
{
delete [] c_Table;
c_Table = new BYTE[size];
ifTable = (MIB_IFTABLE*)c_Table;
ret = GetIfTable(ifTable, &size, FALSE);
}
2011-08-02 01:20:05 +00:00
if (ret == NO_ERROR)
{
2011-08-02 01:20:05 +00:00
if (c_NumOfTables != ifTable->dwNumEntries)
{
c_NumOfTables = ifTable->dwNumEntries;
logging = true;
}
if (GetRainmeter().GetDebug() && logging)
{
2013-05-30 14:19:42 +00:00
LogDebug(L"------------------------------");
LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables);
2011-08-02 01:20:05 +00:00
for (size_t i = 0; i < c_NumOfTables; ++i)
{
2012-05-29 16:43:24 +00:00
const WCHAR* type = L"";
2011-08-02 01:20:05 +00:00
switch (ifTable->table[i].dwType)
{
case IF_TYPE_ETHERNET_CSMACD:
2012-05-29 16:43:24 +00:00
type = L"Ethernet";
break;
case IF_TYPE_PPP:
2012-05-29 16:43:24 +00:00
type = L"PPP";
break;
case IF_TYPE_SOFTWARE_LOOPBACK:
2012-05-29 16:43:24 +00:00
type = L"Loopback";
break;
case IF_TYPE_IEEE80211:
2012-05-29 16:43:24 +00:00
type = L"IEEE802.11";
break;
case IF_TYPE_TUNNEL:
2012-05-29 16:43:24 +00:00
type = L"Tunnel";
break;
case IF_TYPE_IEEE1394:
2012-05-29 16:43:24 +00:00
type = L"IEEE1394";
break;
default:
2012-05-29 16:43:24 +00:00
type = L"Other";
break;
}
2013-05-30 14:19:42 +00:00
LogDebugF(L"%i: %.*S", (int)i + 1, ifTable->table[i].dwDescrLen, (char*)ifTable->table[i].bDescr);
LogDebugF(L" Type=%s(%i)", type, ifTable->table[i].dwType);
}
2013-05-30 14:19:42 +00:00
LogDebug(L"------------------------------");
}
}
2011-08-02 01:20:05 +00:00
else
{
2011-08-02 01:20:05 +00:00
// Something's wrong. Unable to get the table.
delete [] c_Table;
2013-05-31 14:28:39 +00:00
c_Table = nullptr;
2011-08-02 01:20:05 +00:00
c_NumOfTables = 0;
2009-02-10 18:37:48 +00:00
}
}
}
}
/*
** Reads the amount of octets. This is the same for in, out and total.
** the net-parameter informs which inherited class called this method.
**
*/
2013-05-31 14:18:52 +00:00
ULONG64 MeasureNet::GetNetOctets(NET net)
2009-02-10 18:37:48 +00:00
{
ULONG64 value = 0;
2009-02-10 18:37:48 +00:00
if (c_GetIfTable2)
2009-02-10 18:37:48 +00:00
{
2011-08-02 01:20:05 +00:00
MIB_IF_ROW2* table = (MIB_IF_ROW2*)((MIB_IF_TABLE2*)c_Table)->Table;
if (m_Interface == 0)
{
// Get all interfaces
2010-03-30 22:37:05 +00:00
for (UINT i = 0; i < c_NumOfTables; ++i)
{
2011-08-02 01:20:05 +00:00
// Ignore the loopback and filter interfaces
if (table[i].Type == IF_TYPE_SOFTWARE_LOOPBACK ||
table[i].InterfaceAndOperStatusFlags.FilterInterface == 1) continue;
switch (net)
{
case NET_IN:
value += table[i].InOctets;
break;
case NET_OUT:
value += table[i].OutOctets;
break;
case NET_TOTAL:
value += table[i].InOctets;
value += table[i].OutOctets;
break;
}
}
}
else
2009-02-10 18:37:48 +00:00
{
// Get the selected interface
if (m_Interface <= c_NumOfTables)
2009-02-10 18:37:48 +00:00
{
switch (net)
{
case NET_IN:
value += table[m_Interface - 1].InOctets;
2009-02-10 18:37:48 +00:00
break;
case NET_OUT:
value += table[m_Interface - 1].OutOctets;
2009-02-10 18:37:48 +00:00
break;
case NET_TOTAL:
value += table[m_Interface - 1].InOctets;
value += table[m_Interface - 1].OutOctets;
2009-02-10 18:37:48 +00:00
break;
}
}
}
}
else
{
2011-08-02 01:20:05 +00:00
MIB_IFROW* table = (MIB_IFROW*)((MIB_IFTABLE*)c_Table)->table;
if (m_Interface == 0)
2009-02-10 18:37:48 +00:00
{
// Get all interfaces
2010-03-30 22:37:05 +00:00
for (UINT i = 0; i < c_NumOfTables; ++i)
2009-02-10 18:37:48 +00:00
{
2011-08-02 01:20:05 +00:00
// Ignore the loopback
if (table[i].dwType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2009-02-10 18:37:48 +00:00
switch (net)
{
case NET_IN:
value += table[i].dwInOctets;
break;
2009-02-10 18:37:48 +00:00
case NET_OUT:
value += table[i].dwOutOctets;
break;
case NET_TOTAL:
value += table[i].dwInOctets;
value += table[i].dwOutOctets;
break;
}
}
}
else
{
// Get the selected interface
if (m_Interface <= c_NumOfTables)
{
switch (net)
{
case NET_IN:
value += table[m_Interface - 1].dwInOctets;
break;
case NET_OUT:
value += table[m_Interface - 1].dwOutOctets;
break;
case NET_TOTAL:
value += table[m_Interface - 1].dwInOctets;
value += table[m_Interface - 1].dwOutOctets;
break;
}
2009-02-10 18:37:48 +00:00
}
}
}
return value;
}
/*
** Returns the stats value of the interface
**
*/
2013-05-31 14:18:52 +00:00
ULONG64 MeasureNet::GetNetStatsValue(NET net)
2009-02-10 18:37:48 +00:00
{
ULONG64 value = 0;
size_t statsSize = c_StatValues.size() / 2;
2009-02-10 18:37:48 +00:00
if (m_Interface == 0)
{
// Get all interfaces
2011-03-29 19:21:57 +00:00
for (size_t i = 0; i < statsSize; ++i)
2009-02-10 18:37:48 +00:00
{
2011-08-02 01:20:05 +00:00
// Ignore the loopback and filter interfaces
if (c_NumOfTables == statsSize)
{
if (c_GetIfTable2)
{
2011-08-02 01:20:05 +00:00
if (((MIB_IF_TABLE2*)c_Table)->Table[i].Type == IF_TYPE_SOFTWARE_LOOPBACK ||
((MIB_IF_TABLE2*)c_Table)->Table[i].InterfaceAndOperStatusFlags.FilterInterface == 1) continue;
}
else
{
2011-08-02 01:20:05 +00:00
if (((MIB_IFTABLE*)c_Table)->table[i].dwType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
}
}
2009-02-10 18:37:48 +00:00
switch (net)
{
case NET_IN:
value += c_StatValues[i * 2 + 0];
2009-02-10 18:37:48 +00:00
break;
case NET_OUT:
value += c_StatValues[i * 2 + 1];
2009-02-10 18:37:48 +00:00
break;
case NET_TOTAL:
value += c_StatValues[i * 2 + 0];
value += c_StatValues[i * 2 + 1];
2009-02-10 18:37:48 +00:00
break;
}
}
}
else
{
// Get the selected interface
if (m_Interface <= statsSize)
2009-02-10 18:37:48 +00:00
{
switch (net)
{
case NET_IN:
value += c_StatValues[(m_Interface - 1) * 2 + 0];
2009-02-10 18:37:48 +00:00
break;
case NET_OUT:
value += c_StatValues[(m_Interface - 1) * 2 + 1];
2009-02-10 18:37:48 +00:00
break;
case NET_TOTAL:
value += c_StatValues[(m_Interface - 1) * 2 + 0];
value += c_StatValues[(m_Interface - 1) * 2 + 1];
2009-02-10 18:37:48 +00:00
break;
}
}
}
return value;
}
/*
2012-10-09 15:33:49 +00:00
** Updates the current value.
2009-02-10 18:37:48 +00:00
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::UpdateValue()
2009-02-10 18:37:48 +00:00
{
2013-05-31 14:28:39 +00:00
if (c_Table == nullptr) return;
2012-10-09 15:33:49 +00:00
if (m_Cumulative)
{
m_Value = (double)(__int64)GetNetStatsValue(m_Net);
}
else
{
ULONG64 value = 0;
if (!m_FirstTime)
{
value = GetNetOctets(m_Net);
if (value > m_Octets)
{
ULONG64 tmpValue = value;
value -= m_Octets;
m_Octets = tmpValue;
}
else
{
m_Octets = value;
value = 0;
}
}
else
{
m_Octets = GetNetOctets(m_Net);
m_FirstTime = false;
}
m_Value = (double)(__int64)value;
}
}
/*
** Read the options specified in the ini file.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::ReadOptions(ConfigParser& parser, const WCHAR* section)
2012-10-09 15:33:49 +00:00
{
2013-05-31 14:18:52 +00:00
Measure::ReadOptions(parser, section);
2012-10-09 15:33:49 +00:00
2009-02-10 18:37:48 +00:00
double value;
2013-05-31 14:28:39 +00:00
const WCHAR* netName = nullptr;
2009-02-10 18:37:48 +00:00
2012-10-09 15:33:49 +00:00
if (m_Net == NET_IN)
2009-02-10 18:37:48 +00:00
{
netName = L"NetInSpeed";
value = GetRainmeter().GetGlobalOptions().netInSpeed;
2009-02-10 18:37:48 +00:00
}
2012-10-09 15:33:49 +00:00
else if (m_Net == NET_OUT)
2009-02-10 18:37:48 +00:00
{
netName = L"NetOutSpeed";
value = GetRainmeter().GetGlobalOptions().netOutSpeed;
2009-02-10 18:37:48 +00:00
}
2012-10-09 15:33:49 +00:00
else // if (m_Net == NET_TOTAL)
2009-02-10 18:37:48 +00:00
{
netName = L"NetTotalSpeed";
value = GetRainmeter().GetGlobalOptions().netInSpeed + GetRainmeter().GetGlobalOptions().netOutSpeed;
2009-02-10 18:37:48 +00:00
}
double maxValue = parser.ReadFloat(section, L"MaxValue", -1);
2011-03-29 19:21:57 +00:00
if (maxValue == -1)
2009-02-10 18:37:48 +00:00
{
maxValue = parser.ReadFloat(section, netName, -1);
2011-03-29 19:21:57 +00:00
if (maxValue == -1)
2009-02-10 18:37:48 +00:00
{
maxValue = value;
}
}
2011-03-29 19:21:57 +00:00
2009-02-10 18:37:48 +00:00
m_Interface = parser.ReadInt(section, L"Interface", 0);
2012-01-28 19:55:38 +00:00
m_Cumulative = parser.ReadBool(section, L"Cumulative", false);
2012-01-28 19:55:38 +00:00
if (m_Cumulative)
{
GetRainmeter().SetNetworkStatisticsTimer();
2012-01-28 19:55:38 +00:00
}
2009-02-10 18:37:48 +00:00
if (maxValue == 0.0)
2009-02-10 18:37:48 +00:00
{
if (!m_LogMaxValue)
{
m_MaxValue = 1.0;
m_LogMaxValue = true;
m_MedianValues.clear();
}
2009-02-10 18:37:48 +00:00
}
else
{
m_MaxValue = maxValue / 8;
m_LogMaxValue = false;
2009-02-10 18:37:48 +00:00
}
}
/*
** Updates the statistics.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::UpdateStats()
2009-02-10 18:37:48 +00:00
{
if (c_Table)
{
size_t statsSize = c_NumOfTables * 2;
2009-02-10 18:37:48 +00:00
// Fill the vectors
if (c_StatValues.size() < statsSize)
2009-02-10 18:37:48 +00:00
{
c_StatValues.resize(statsSize, 0);
2009-02-10 18:37:48 +00:00
}
if (c_OldStatValues.size() < statsSize)
2011-03-29 19:21:57 +00:00
{
c_OldStatValues.resize(statsSize, 0);
2009-02-10 18:37:48 +00:00
}
2010-03-30 22:37:05 +00:00
for (UINT i = 0; i < c_NumOfTables; ++i)
2009-02-10 18:37:48 +00:00
{
ULONG64 in, out;
2009-02-10 18:37:48 +00:00
if (c_GetIfTable2)
{
in = ((MIB_IF_TABLE2*)c_Table)->Table[i].InOctets;
out = ((MIB_IF_TABLE2*)c_Table)->Table[i].OutOctets;
}
else
{
2011-08-02 01:20:05 +00:00
in = ((MIB_IFTABLE*)c_Table)->table[i].dwInOctets;
out = ((MIB_IFTABLE*)c_Table)->table[i].dwOutOctets;
}
2009-02-10 18:37:48 +00:00
if (c_OldStatValues[i * 2 + 0] != 0)
2009-02-10 18:37:48 +00:00
{
if (in > c_OldStatValues[i * 2 + 0])
{
c_StatValues[i * 2 + 0] += in - c_OldStatValues[i * 2 + 0];
2009-02-10 18:37:48 +00:00
}
}
if (c_OldStatValues[i * 2 + 1] != 0)
{
2009-02-10 18:37:48 +00:00
if (out > c_OldStatValues[i * 2 + 1])
{
c_StatValues[i * 2 + 1] += out - c_OldStatValues[i * 2 + 1];
2009-02-10 18:37:48 +00:00
}
}
c_OldStatValues[i * 2 + 0] = in;
c_OldStatValues[i * 2 + 1] = out;
}
}
}
/*
** Resets the statistics.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::ResetStats()
2009-02-10 18:37:48 +00:00
{
2010-11-06 23:13:12 +00:00
c_StatValues.clear();
2009-02-10 18:37:48 +00:00
}
/*
** Reads statistics.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::ReadStats(const std::wstring& iniFile, std::wstring& statsDate)
2009-02-10 18:37:48 +00:00
{
WCHAR buffer[48];
2013-05-31 14:18:52 +00:00
ConfigParser parser;
2013-05-31 14:28:39 +00:00
parser.Initialize(iniFile, nullptr, L"Statistics");
2011-11-16 16:47:20 +00:00
const std::wstring& date = parser.ReadString(L"Statistics", L"Since", L"", false);
if (!date.empty())
{
statsDate = date;
}
uint32_t count = parser.ReadUInt(L"Statistics", L"Count", 0);
if (parser.GetLastDefaultUsed())
{
count = parser.ReadUInt(L"Statistics", L"NetStatsCount", 0);
}
2009-02-10 18:37:48 +00:00
c_StatValues.clear();
c_StatValues.reserve(count * 2);
2009-02-10 18:37:48 +00:00
for (uint32_t i = 1; i <= count; ++i)
2009-02-10 18:37:48 +00:00
{
ULARGE_INTEGER value;
2009-02-10 18:37:48 +00:00
_snwprintf_s(buffer, _TRUNCATE, L"In%u", i);
value.QuadPart = parser.ReadUInt64(L"Statistics", buffer, 0);
if (parser.GetLastDefaultUsed())
{
_snwprintf_s(buffer, _TRUNCATE, L"NetStatsInHigh%u", i);
value.HighPart = parser.ReadUInt(L"Statistics", buffer, 0);
_snwprintf_s(buffer, _TRUNCATE, L"NetStatsInLow%u", i);
value.LowPart = parser.ReadUInt(L"Statistics", buffer, 0);
}
c_StatValues.push_back(value.QuadPart);
2009-02-10 18:37:48 +00:00
_snwprintf_s(buffer, _TRUNCATE, L"Out%u", i);
value.QuadPart = parser.ReadUInt64(L"Statistics", buffer, 0);
if (parser.GetLastDefaultUsed())
{
_snwprintf_s(buffer, _TRUNCATE, L"NetStatsOutHigh%u", i);
value.HighPart = parser.ReadUInt(L"Statistics", buffer, 0);
_snwprintf_s(buffer, _TRUNCATE, L"NetStatsOutLow%u", i);
value.LowPart = parser.ReadUInt(L"Statistics", buffer, 0);
}
c_StatValues.push_back(value.QuadPart);
2009-02-10 18:37:48 +00:00
}
}
/*
** Writes statistics.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::WriteStats(const WCHAR* iniFile, const std::wstring& statsDate)
2009-02-10 18:37:48 +00:00
{
WCHAR buffer[48];
int len;
2013-12-23 19:42:31 +00:00
uint32_t count = (uint32_t)c_StatValues.size() / 2;
2011-03-29 19:21:57 +00:00
// Reserve sufficient buffer for statistics
std::wstring data;
data.reserve(48 * (2 + count));
// Add date
data = L"Since=";
data += statsDate;
data += L'\0';
auto appendStatsValue = [&]()
{
data.append(buffer, len);
data += L'\0';
};
// Add stats count
len = _snwprintf_s(buffer, _TRUNCATE, L"Count=%u", count);
appendStatsValue();
2009-02-10 18:37:48 +00:00
// Add stats
for (uint32_t i = 0; i < count; ++i)
2009-02-10 18:37:48 +00:00
{
if (c_StatValues[i * 2] > 0)
{
len = _snwprintf_s(buffer, _TRUNCATE, L"In%u=%llu", i + 1, c_StatValues[i * 2]);
appendStatsValue();
}
2009-02-10 18:37:48 +00:00
if (c_StatValues[i * 2 + 1] > 0)
{
len = _snwprintf_s(buffer, _TRUNCATE, L"Out%u=%llu", i + 1, c_StatValues[i * 2 + 1]);
appendStatsValue();
}
2009-02-10 18:37:48 +00:00
}
// Write statistics
WritePrivateProfileSection(L"Statistics", data.c_str(), iniFile);
}
/*
** Prepares in order to use the new APIs which are available on Vista or newer.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::InitializeStatic()
{
if (Platform::IsAtLeastWinVista())
{
2011-08-02 01:20:05 +00:00
HMODULE IpHlpApiLibrary = GetModuleHandle(L"IpHlpApi.dll");
if (IpHlpApiLibrary)
{
c_GetIfTable2 = (FPGETIFTABLE2)GetProcAddress(IpHlpApiLibrary, "GetIfTable2");
2011-08-02 01:20:05 +00:00
c_FreeMibTable = (FPFREEMIBTABLE)GetProcAddress(IpHlpApiLibrary, "FreeMibTable");
}
2011-08-02 01:20:05 +00:00
if (!c_GetIfTable2 || !c_FreeMibTable)
{
2013-05-31 14:28:39 +00:00
c_GetIfTable2 = nullptr;
c_FreeMibTable = nullptr;
}
}
if (GetRainmeter().GetDebug())
{
UpdateIFTable();
}
}
/*
** Frees the resources.
**
*/
2013-05-31 14:18:52 +00:00
void MeasureNet::FinalizeStatic()
{
if (c_GetIfTable2)
{
2011-08-02 01:20:05 +00:00
if (c_Table)
{
c_FreeMibTable(c_Table);
}
2013-05-31 14:28:39 +00:00
c_GetIfTable2 = nullptr;
c_FreeMibTable = nullptr;
2011-08-02 01:20:05 +00:00
}
else
{
delete [] c_Table;
}
2013-05-31 14:28:39 +00:00
c_Table = nullptr;
c_NumOfTables = 0;
}