Пример #1
0
void MeasureNet::ReadOptions(ConfigParser& parser, const WCHAR* section)
{
	Measure::ReadOptions(parser, section);

	double value;
	const WCHAR* netName = nullptr;

	if (m_Net == NET_IN)
	{
		netName = L"NetInSpeed";
		value = GetRainmeter().GetGlobalOptions().netInSpeed;
	}
	else if (m_Net == NET_OUT)
	{
		netName = L"NetOutSpeed";
		value = GetRainmeter().GetGlobalOptions().netOutSpeed;
	}
	else // if (m_Net == NET_TOTAL)
	{
		netName = L"NetTotalSpeed";
		value = GetRainmeter().GetGlobalOptions().netInSpeed + GetRainmeter().GetGlobalOptions().netOutSpeed;
	}

	double maxValue = parser.ReadFloat(section, L"MaxValue", -1);
	if (maxValue == -1)
	{
		maxValue = parser.ReadFloat(section, netName, -1);
		if (maxValue == -1)
		{
			maxValue = value;
		}
	}

	// Option 'Interface' represents either the number of the interface in the 'iftable',
	// or the name of the interface (ie. its Description). Optionally, if 'Interface=Best',
	// there will be an attempt to find the best interface.
	std::wstring iface = parser.ReadString(section, L"Interface", L"");
	if (!iface.empty() && !std::all_of(iface.begin(), iface.end(), iswdigit))
	{
		m_Interface = GetBestInterfaceOrByName(iface.c_str());
	}
	else
	{
		m_Interface = parser.ReadInt(section, L"Interface", 0);
	}

	m_Cumulative = parser.ReadBool(section, L"Cumulative", false);
	if (m_Cumulative)
	{
		GetRainmeter().SetNetworkStatisticsTimer();
	}

	if (maxValue == 0.0)
	{
		if (!m_LogMaxValue)
		{
			m_MaxValue = 1.0;
			m_LogMaxValue = true;
			m_MedianValues.clear();
		}
	}
	else
	{
		m_MaxValue = maxValue / 8;
		m_LogMaxValue = false;
	}
}
Пример #2
0
/*
** Reads the tables for all net interfaces
**
*/
void MeasureNet::UpdateIFTable()
{
	bool logging = false;

	if (c_Table)
	{
		FreeMibTable(c_Table);
		c_Table = nullptr;
	}

	if (GetIfTable2(&c_Table) == NO_ERROR)
	{
		if (c_NumOfTables != c_Table->NumEntries)
		{
			c_NumOfTables = c_Table->NumEntries;
			logging = true;
		}

		if (GetRainmeter().GetDebug() && logging)
		{
			LogDebug(L"------------------------------");
			LogDebugF(L"* NETWORK-INTERFACE: Count=%i", c_NumOfTables);

			for (size_t i = 0; i < c_NumOfTables; ++i)
			{
				const WCHAR* type = L"Other";
				switch (c_Table->Table[i].Type)
				{
				case IF_TYPE_ETHERNET_CSMACD:
					type = L"Ethernet";
					break;
				case IF_TYPE_PPP:
					type = L"PPP";
					break;
				case IF_TYPE_SOFTWARE_LOOPBACK:
					type = L"Loopback";
					break;
				case IF_TYPE_IEEE80211:
					type = L"IEEE802.11";
					break;
				case IF_TYPE_TUNNEL:
					type = L"Tunnel";
					break;
				case IF_TYPE_IEEE1394:
					type = L"IEEE1394";
					break;
				}

				LogDebugF(L"%i: %s", (int)i + 1, c_Table->Table[i].Description);
				LogDebugF(L"  Alias: %s", c_Table->Table[i].Alias);
				LogDebugF(L"  Type=%s(%i), Hardware=%s, Filter=%s",
					type, c_Table->Table[i].Type,
					(c_Table->Table[i].InterfaceAndOperStatusFlags.HardwareInterface == 1) ? L"Yes" : L"No",
					(c_Table->Table[i].InterfaceAndOperStatusFlags.FilterInterface == 1) ? L"Yes" : L"No");
			}
			LogDebug(L"------------------------------");
		}
	}
	else
	{
		// Something's wrong. Unable to get the table.
		c_Table = nullptr;
		c_NumOfTables = 0;
	}
}
void CommandHandler::DoQuitBang(std::vector<std::wstring>& args, MeterWindow* meterWindow)
{
	// Quit needs to be delayed since it crashes if done during Update().
	PostMessage(GetRainmeter().GetTrayWindow()->GetWindow(), WM_COMMAND, MAKEWPARAM(IDM_QUIT, 0), 0);
}
Пример #4
0
void Logger::SetLogToFile(bool logToFile)
{
	m_LogToFile = logToFile;
	WritePrivateProfileString(
		L"Rainmeter", L"Logging", logToFile ? L"1" : L"0", GetRainmeter().GetIniFile().c_str());
}
void CommandHandler::DoRefreshApp(std::vector<std::wstring>& args, MeterWindow* meterWindow)
{
	// Refresh needs to be delayed since it crashes if done during Update().
	PostMessage(GetRainmeter().m_Window, WM_RAINMETER_DELAYED_REFRESH_ALL, 0, 0);
}
void CommandHandler::DoWriteKeyValueBang(std::vector<std::wstring>& args, MeterWindow* skin)
{
	if (args.size() == 3 && skin)
	{
		// Add the skin file path to the args
		args.push_back(skin->GetFilePath());
	}
	else if (args.size() < 4)
	{
		LogErrorF(skin, L"!WriteKeyValue: Invalid parameters");
		return;
	}

	std::wstring& strIniFile = args[3];
	if (skin)
	{
		skin->MakePathAbsolute(strIniFile);
	}

	const WCHAR* iniFile = strIniFile.c_str();

	if (strIniFile.find(L"..\\") != std::wstring::npos || strIniFile.find(L"../") != std::wstring::npos)
	{
		LogErrorF(skin, L"!WriteKeyValue: Illegal path: %s", iniFile);
		return;
	}

	if (_wcsnicmp(iniFile, GetRainmeter().m_SkinPath.c_str(), GetRainmeter().m_SkinPath.size()) != 0 &&
		_wcsnicmp(iniFile, GetRainmeter().m_SettingsPath.c_str(), GetRainmeter().m_SettingsPath.size()) != 0)
	{
		LogErrorF(skin, L"!WriteKeyValue: Illegal path: %s", iniFile);
		return;
	}

	// Verify whether the file exists.
	if (_waccess(iniFile, 0) == -1)
	{
		LogErrorF(skin, L"!WriteKeyValue: File not found: %s", iniFile);
		return;
	}

	// Verify whether the file is read-only.
	DWORD attr = GetFileAttributes(iniFile);
	if (attr == -1 || (attr & FILE_ATTRIBUTE_READONLY))
	{
		LogWarningF(skin, L"!WriteKeyValue: File is read-only: %s", iniFile);
		return;
	}

	// Avoid "IniFileMapping"
	System::UpdateIniFileMappingList();
	std::wstring strIniWrite = System::GetTemporaryFile(strIniFile);
	if (strIniWrite.size() == 1 && strIniWrite[0] == L'?')  // error occurred
	{
		return;
	}

	bool temporary = !strIniWrite.empty();

	if (temporary)
	{
		if (GetRainmeter().GetDebug())
		{
			LogDebugF(skin, L"!WriteKeyValue: Writing to: %s (Temp: %s)", iniFile, strIniWrite.c_str());
		}
	}
	else
	{
		if (GetRainmeter().GetDebug())
		{
			LogDebugF(skin, L"!WriteKeyValue: Writing to: %s", iniFile);
		}
		strIniWrite = strIniFile;
	}

	const WCHAR* iniWrite = strIniWrite.c_str();
	const WCHAR* section = args[0].c_str();
	const WCHAR* key = args[1].c_str();
	const std::wstring& strValue = args[2];

	bool formula = false;
	BOOL write = 0;

	if (skin)
	{
		double value;
		formula = skin->GetParser().ParseFormula(strValue, &value); 
		if (formula)
		{
			WCHAR buffer[256];
			int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", value);
			Measure::RemoveTrailingZero(buffer, len);

			write = WritePrivateProfileString(section, key, buffer, iniWrite);
		}
	}

	if (!formula)
	{
		write = WritePrivateProfileString(section, key, strValue.c_str(), iniWrite);
	}

	if (temporary)
	{
		if (write != 0)
		{
			WritePrivateProfileString(nullptr, nullptr, nullptr, iniWrite);  // FLUSH

			// Copy the file back.
			if (!System::CopyFiles(strIniWrite, strIniFile))
			{
				LogErrorF(skin, L"!WriteKeyValue: Failed to copy temporary file to original filepath: %s (Temp: %s)", iniFile, iniWrite);
			}
		}
		else  // failed
		{
			LogErrorF(skin, L"!WriteKeyValue: Failed to write to: %s (Temp: %s)", iniFile, iniWrite);
		}

		// Remove the temporary file.
		System::RemoveFile(strIniWrite);
	}
	else
	{
		if (write == 0)  // failed
		{
			LogErrorF(skin, L"!WriteKeyValue: Failed to write to: %s", iniFile);
		}
	}
}
void CommandHandler::DoResetStatsBang(std::vector<std::wstring>& args, MeterWindow* meterWindow)
{
	GetRainmeter().ResetStats();
}
void CommandHandler::DoTrayMenuBang(std::vector<std::wstring>& args, MeterWindow* skin)
{
	POINT pos = System::GetCursorPosition();
	GetRainmeter().ShowContextMenu(pos, nullptr);
}
Пример #9
0
// Deprecated!
LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data)
{
	if (command == nullptr || *command == L'\0')
	{
		return L"noop";
	}

	NULLCHECK(data);

	if (_wcsicmp(command, L"GetConfig") == 0)
	{
		MeterWindow* meterWindow = GetRainmeter().GetMeterWindowByINI(data);
		if (meterWindow)
		{
			g_Buffer = L"\"";
			g_Buffer += meterWindow->GetFolderPath();
			g_Buffer += L"\"";
			return g_Buffer.c_str();
		}

		return L"";
	}
	else if (_wcsicmp(command, L"GetWindow") == 0)
	{
		std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);

		if (subStrings.size() >= 1)
		{
			const std::wstring& config = subStrings[0];

			MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
			if (meterWindow)
			{
				WCHAR buf1[64];
				_snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow()));
				g_Buffer = buf1;
				return g_Buffer.c_str();
			}
		}

		return L"error";
	}
	else if (_wcsicmp(command, L"GetVariable") == 0)
	{
		std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);

		if (subStrings.size() >= 2)
		{
			const std::wstring& config = subStrings[0];

			MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(config);
			if (meterWindow)
			{
				const std::wstring& variable = subStrings[1];

				const std::wstring* value = meterWindow->GetParser().GetVariable(variable);
				if (value)
				{
					return (*value).c_str();
				}
			}
		}

		return L"";
	}
	else if (_wcsicmp(command, L"SetVariable") == 0)
	{
		std::vector<std::wstring> subStrings = CommandHandler::ParseString(data);

		if (subStrings.size() == 3)
		{
			MeterWindow* meterWindow = GetRainmeter().GetMeterWindow(subStrings[0]);
			if (meterWindow)
			{
				meterWindow->SetVariable(subStrings[1], subStrings[2]);
				return L"success";
			}
		}

		return L"error";
	}

	return L"noop";
}