void Meter::ReadContainerOptions(ConfigParser& parser, const WCHAR* section) { const std::wstring& style = parser.ReadString(section, L"MeterStyle", L""); if (!style.empty()) { parser.SetStyleTemplate(style); } const std::wstring& container = parser.ReadString(section, L"Container", L""); if (_wcsicmp(section, container.c_str()) == 0) { LogErrorF(this, L"Container cannot self-reference: %s", container.c_str()); return; } if (!m_ContainerMeter || _wcsicmp(m_ContainerMeter->GetName(), container.c_str()) != 0) { if (m_ContainerMeter) { m_ContainerMeter->RemoveContainerItem(this); m_ContainerMeter = nullptr; } auto meter = m_Skin->GetMeter(container); if (meter) { meter->AddContainerItem(this); m_ContainerMeter = meter; } else if (!container.empty()) { LogErrorF(this, L"Invalid container: %s", container.c_str()); } } }
RoundedRectangle::RoundedRectangle(FLOAT x, FLOAT y, FLOAT width, FLOAT height, FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::RoundedRectangle), m_X(x), m_Y(y), m_Width(width + x), m_Height(height + y), m_XRadius(xRadius), m_YRadius(yRadius) { HRESULT hr = E_FAIL; const D2D1_ROUNDED_RECT rect = { m_X, m_Y, m_Width, m_Height, m_XRadius, m_YRadius }; Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> rectangle; hr = Canvas::c_D2DFactory->CreateRoundedRectangleGeometry(rect, rectangle.GetAddressOf()); if (FAILED(hr)) { LogErrorF( L"Could not create rounded rectangle object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i", (int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius); return; } hr = rectangle.CopyTo(m_Shape.GetAddressOf()); if (FAILED(hr)) LogErrorF( L"Could not copy rounded rectangle object to shape object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i", (int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius); }
/* ** Read the options specified in the ini file. ** */ void MeasureCalc::ReadOptions(ConfigParser& parser, const WCHAR* section) { Measure::ReadOptions(parser, section); // Store the current values so we know if the value needs to be updated int oldLowBound = m_LowBound; int oldHighBound = m_HighBound; bool oldUpdateRandom = m_UpdateRandom; bool oldUniqueRandom = m_UniqueRandom; std::wstring oldFormula = m_Formula; m_Formula = parser.ReadString(section, L"Formula", L""); m_LowBound = parser.ReadInt(section, L"LowBound", DEFAULT_LOWER_BOUND); m_HighBound = parser.ReadInt(section, L"HighBound", DEFAULT_UPPER_BOUND); m_UpdateRandom = parser.ReadBool(section, L"UpdateRandom", false); m_UniqueRandom = parser.ReadBool(section, L"UniqueRandom", false); if (!m_UniqueRandom) { m_UniqueNumbers.clear(); } if (!m_Initialized || wcscmp(m_Formula.c_str(), oldFormula.c_str()) != 0 || oldLowBound != m_LowBound || oldHighBound != m_HighBound || oldUpdateRandom != m_UpdateRandom || oldUniqueRandom != m_UniqueRandom) { // Reset bounds if |m_LowBound| is greater than |m_HighBound| if (m_LowBound > m_HighBound) { LogErrorF(this, L"\"LowBound\" (%i) must be less then or equal to \"HighBound\" (%i)", m_LowBound, m_HighBound); m_HighBound = m_LowBound; } // Reset the list if the bounds are changed if (m_UniqueRandom && ( oldLowBound != m_LowBound || oldHighBound != m_HighBound)) { UpdateUniqueNumberList(); } if (!m_UpdateRandom) { FormulaReplace(); } const WCHAR* errMsg = MathParser::Check(m_Formula.c_str()); if (errMsg != nullptr) { LogErrorF(this, L"Calc: %s", errMsg); m_Formula.clear(); } } }
/* ** Reads and binds secondary measures (MeasureName2 - MeasureNameN). ** */ void Meter::BindSecondaryMeasures(ConfigParser& parser, const WCHAR* section) { if (!m_Measures.empty()) { WCHAR tmpName[64]; int i = 2; do { _snwprintf_s(tmpName, _TRUNCATE, L"MeasureName%i", i); const std::wstring& measureName = parser.ReadString(section, tmpName, L""); Measure* measure = parser.GetMeasure(measureName); if (measure) { m_Measures.push_back(measure); } else { if (!measureName.empty()) { LogErrorF(this, L"MeasureName%i=%s is not valid", i, measureName.c_str()); } break; } ++i; } while (true); } }
/* ** Runs the given bang. ** */ void CommandHandler::ExecuteBang(const WCHAR* name, std::vector<std::wstring>& args, Skin* skin) { for (const auto& bangInfo : s_Bangs) { if (_wcsicmp(bangInfo.name, name) == 0) { DoBang(bangInfo, args, skin); return; } } for (const auto& bangInfo : s_GroupBangs) { if (_wcsicmp(bangInfo.name, name) == 0) { DoGroupBang(bangInfo, args, skin); return; } } for (const auto& bangInfo : s_CustomBangs) { if (_wcsicmp(bangInfo.name, name) == 0) { bangInfo.handlerFunc(args, skin); return; } } LogErrorF(skin, L"Invalid bang: !%s", name); }
/* ** Returns the uptime as string. ** */ const WCHAR* MeasureUptime::GetStringValue() { static WCHAR buffer[MAX_LINE_LENGTH]; size_t value = (size_t)m_Value; size_t time[4]; time[0] = value % 60; time[1] = (value / 60) % 60; time[2] = (value / (60 * 60)); time[3] = (value / (60 * 60 * 24)); if (!m_AddDaysToHours) { time[2] %= 24; } __try { FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, m_Format.c_str(), 0, 0, buffer, MAX_LINE_LENGTH, (char**)time); } __except (EXCEPTION_EXECUTE_HANDLER) { LogErrorF(this, L"Uptime: \"Format=%s\" invalid", m_Format.c_str()); buffer[0] = 0; } return CheckSubstitute(buffer); }
Arc::Arc(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, FLOAT xRadius, FLOAT yRadius, FLOAT angle, D2D1_SWEEP_DIRECTION sweep, D2D1_ARC_SIZE size, D2D1_FIGURE_END ending) : Shape(ShapeType::Arc), m_StartPoint(D2D1::Point2F(x1, y1)), m_ArcSegment(D2D1::ArcSegment( D2D1::Point2F(x2, y2), D2D1::SizeF(xRadius, yRadius), angle, sweep, size)), m_ShapeEnding(ending) { Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink; Microsoft::WRL::ComPtr<ID2D1PathGeometry> path; HRESULT hr = Canvas::c_D2DFactory->CreatePathGeometry(path.GetAddressOf()); if (SUCCEEDED(hr)) { hr = path->Open(sink.GetAddressOf()); if (SUCCEEDED(hr)) { sink->BeginFigure(m_StartPoint, D2D1_FIGURE_BEGIN_FILLED); sink->AddArc(m_ArcSegment); sink->EndFigure(m_ShapeEnding); sink->Close(); hr = path.CopyTo(m_Shape.GetAddressOf()); if (SUCCEEDED(hr)) return; } } LogErrorF(L"Could not create arc object. X1=%i, Y1=%i, X2=%i, Y2=%i, XRadius=%i, YRadius=%i, Angle=%i", (int)x1, (int)y1, (int)x2, (int)y2, (int)xRadius, (int)yRadius, (int)angle); }
/* ** Read the options specified in the ini file. ** */ void MeasureCalc::ReadOptions(ConfigParser& parser, const WCHAR* section) { Measure::ReadOptions(parser, section); // Store the current values so we know if the value needs to be updated int oldLowBound = m_LowBound; int oldHighBound = m_HighBound; bool oldUpdateRandom = m_UpdateRandom; std::wstring oldFormula = m_Formula; m_Formula = parser.ReadString(section, L"Formula", L""); m_LowBound = parser.ReadInt(section, L"LowBound", 0); m_HighBound = parser.ReadInt(section, L"HighBound", 100); m_UpdateRandom = 0!=parser.ReadInt(section, L"UpdateRandom", 0); if (!m_Initialized || wcscmp(m_Formula.c_str(), oldFormula.c_str()) != 0 || oldLowBound != m_LowBound || oldHighBound != m_HighBound || oldUpdateRandom != m_UpdateRandom) { if (!m_UpdateRandom) { FormulaReplace(); } const WCHAR* errMsg = MathParser::Check(m_Formula.c_str()); if (errMsg != nullptr) { LogErrorF(this, L"Calc: %s", errMsg); m_Formula.clear(); } } }
/* ** Read the common options specified in the ini file. The inherited classes must ** call this base implementation if they overwrite this method. ** */ void Measure::ReadOptions(ConfigParser& parser, const WCHAR* section) { bool oldOnChangeActionEmpty = m_OnChangeAction.empty(); Section::ReadOptions(parser, section); // Clear substitutes to prevent from being added more than once. if (!m_Substitute.empty()) { m_Substitute.clear(); } m_Invert = parser.ReadBool(section, L"InvertMeasure", false); m_Disabled = parser.ReadBool(section, L"Disabled", false); m_Paused = parser.ReadBool(section, L"Paused", false); m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue); m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue); // The ifabove/ifbelow define actions that are ran when the value goes above/below the given number. m_IfAboveValue = parser.ReadFloat(section, L"IfAboveValue", 0.0); m_IfAboveAction = parser.ReadString(section, L"IfAboveAction", L"", false); m_IfBelowValue = parser.ReadFloat(section, L"IfBelowValue", 0.0); m_IfBelowAction = parser.ReadString(section, L"IfBelowAction", L"", false); m_IfEqualValue = (int64_t)parser.ReadFloat(section, L"IfEqualValue", 0.0); m_IfEqualAction = parser.ReadString(section, L"IfEqualAction", L"", false); m_OnChangeAction = parser.ReadString(section, L"OnChangeAction", L"", false); m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0); m_RegExpSubstitute = parser.ReadBool(section, L"RegExpSubstitute", false); std::wstring subs = parser.ReadString(section, L"Substitute", L""); if (!subs.empty()) { if ((subs[0] != L'"' || subs[subs.length() - 1] != L'\'') && (subs[0] != L'\'' || subs[subs.length() - 1] != L'"')) { // Add quotes since they are removed by the GetProfileString subs.insert(0, 1, L'"'); subs += L'"'; } if (!ParseSubstitute(subs)) { LogErrorF(this, L"Measure: Invalid Substitute=%s", subs.c_str()); } } if (m_Initialized && oldOnChangeActionEmpty && !m_OnChangeAction.empty()) { DoChangeAction(false); } }
/* ** Read the common options specified in the ini file. The inherited classes must ** call this base implementation if they overwrite this method. ** */ void Measure::ReadOptions(ConfigParser& parser, const WCHAR* section) { bool oldOnChangeActionEmpty = m_OnChangeAction.empty(); Section::ReadOptions(parser, section); // Clear substitutes to prevent from being added more than once. if (!m_Substitute.empty()) { m_Substitute.clear(); } m_Invert = parser.ReadBool(section, L"InvertMeasure", false); m_Disabled = parser.ReadBool(section, L"Disabled", false); m_Paused = parser.ReadBool(section, L"Paused", false); m_MinValue = parser.ReadFloat(section, L"MinValue", m_MinValue); m_MaxValue = parser.ReadFloat(section, L"MaxValue", m_MaxValue); m_IfActions.ReadOptions(parser, section); // The first time around, we read the conditions here. Subsequent rereads will be done in // Update() if needed. if (!m_Initialized) { m_IfActions.ReadConditionOptions(parser, section); } m_OnChangeAction = parser.ReadString(section, L"OnChangeAction", L"", false); m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0); m_RegExpSubstitute = parser.ReadBool(section, L"RegExpSubstitute", false); std::wstring subs = parser.ReadString(section, L"Substitute", L""); if (!subs.empty()) { if ((subs[0] != L'"' || subs[subs.length() - 1] != L'\'') && (subs[0] != L'\'' || subs[subs.length() - 1] != L'"')) { // Add quotes since they are removed by the GetProfileString subs.insert(0, 1, L'"'); subs += L'"'; } if (!ParseSubstitute(subs)) { LogErrorF(this, L"Measure: Invalid Substitute=%s", subs.c_str()); } } if (m_Initialized && oldOnChangeActionEmpty && !m_OnChangeAction.empty()) { DoChangeAction(false); } }
void CommandHandler::DoSetClipBang(std::vector<std::wstring>& args, Skin* skin) { if (!args.empty()) { System::SetClipboardText(args[0]); } else { LogErrorF(skin, L"!SetClip: Invalid parameter"); } }
void CommandHandler::DoActivateSkinBang(std::vector<std::wstring>& args, Skin* skin) { if (args.size() == 1) { if (GetRainmeter().ActivateSkin(args[0])) return; } else if (args.size() > 1) { if (GetRainmeter().ActivateSkin(args[0], args[1])) return; } LogErrorF(skin, L"!ActivateConfig: Invalid parameters"); }
Ellipse::Ellipse(FLOAT x, FLOAT y, FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::Ellipse), m_CenterPoint(D2D1::Point2F(x, y)), m_RadiusX(xRadius), m_RadiusY(yRadius) { HRESULT hr = E_FAIL; const D2D1_ELLIPSE ellipse = D2D1::Ellipse(m_CenterPoint, m_RadiusX, m_RadiusY); Microsoft::WRL::ComPtr<ID2D1EllipseGeometry> geometry; hr = Canvas::c_D2DFactory->CreateEllipseGeometry(ellipse, geometry.GetAddressOf()); if (FAILED(hr)) { LogErrorF( L"Could not create ellipse object. X=%i, Y=%i, RadiusX=%i, RadiusY=%i", (int)x, (int)y, (int)xRadius, (int)yRadius); return; } hr = geometry.CopyTo(m_Shape.GetAddressOf()); if (FAILED(hr)) LogErrorF( L"Could not copy ellipse object to shape object. X=%i, Y=%i, RadiusX=%i, RadiusY=%i", (int)x, (int)y, (int)xRadius, (int)yRadius); }
void CommandHandler::DoDeactivateSkinGroupBang(std::vector<std::wstring>& args, Skin* skin) { if (!args.empty()) { std::multimap<int, Skin*> windows; GetRainmeter().GetSkinsByLoadOrder(windows, args[0]); for (const auto& ip : windows) { GetRainmeter().DeactivateSkin(ip.second, -1); } } else { LogErrorF(skin, L"!DeactivateConfigGroup: Invalid parameters"); } }
/* ** Updates the calculation ** */ void MeasureCalc::UpdateValue() { const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), &m_Value, GetMeasureValue, this); if (errMsg != nullptr) { if (!m_ParseError) { LogErrorF(this, L"Calc: %s", errMsg); m_ParseError = true; } } else { m_ParseError = false; } }
/* ** Read the options specified in the ini file. ** */ void MeasureRegistry::ReadOptions(ConfigParser& parser, const WCHAR* section) { Measure::ReadOptions(parser, section); const WCHAR* keyname = parser.ReadString(section, L"RegHKey", L"HKEY_CURRENT_USER").c_str(); if (_wcsicmp(keyname, L"HKEY_CURRENT_USER") == 0) { m_HKey = HKEY_CURRENT_USER; } else if (_wcsicmp(keyname, L"HKEY_LOCAL_MACHINE") == 0) { m_HKey = HKEY_LOCAL_MACHINE; } else if (_wcsicmp(keyname, L"HKEY_CLASSES_ROOT") == 0) { m_HKey = HKEY_CLASSES_ROOT; } else if (_wcsicmp(keyname, L"HKEY_CURRENT_CONFIG") == 0) { m_HKey = HKEY_CURRENT_CONFIG; } else if (_wcsicmp(keyname, L"HKEY_PERFORMANCE_DATA") == 0) { m_HKey = HKEY_PERFORMANCE_DATA; } else if (_wcsicmp(keyname, L"HKEY_DYN_DATA") == 0) { m_HKey = HKEY_DYN_DATA; } else { LogErrorF(this, L"RegHKey=%s is not valid", keyname); } m_RegKeyName = parser.ReadString(section, L"RegKey", L""); m_RegValueName = parser.ReadString(section, L"RegValue", L""); if (m_MaxValue == 0.0) { m_MaxValue = 1.0; m_LogMaxValue = true; } // Try to open the key if (m_RegKey) RegCloseKey(m_RegKey); RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0, KEY_READ, &m_RegKey); }
/* ** Creates the given meter. This is the factory method for the meters. ** If new meters are implemented this method needs to be updated. ** */ Meter* Meter::Create(const WCHAR* meter, Skin* skin, const WCHAR* name) { if (_wcsicmp(L"STRING", meter) == 0) { return new MeterString(skin, name); } else if (_wcsicmp(L"IMAGE", meter) == 0) { return new MeterImage(skin, name); } else if (_wcsicmp(L"HISTOGRAM", meter) == 0) { return new MeterHistogram(skin, name); } else if (_wcsicmp(L"BAR", meter) == 0) { return new MeterBar(skin, name); } else if (_wcsicmp(L"BITMAP", meter) == 0) { return new MeterBitmap(skin, name); } else if (_wcsicmp(L"LINE", meter) == 0) { return new MeterLine(skin, name); } else if (_wcsicmp(L"ROUNDLINE", meter) == 0) { return new MeterRoundLine(skin, name); } else if (_wcsicmp(L"ROTATOR", meter) == 0) { return new MeterRotator(skin, name); } else if (_wcsicmp(L"BUTTON", meter) == 0) { return new MeterButton(skin, name); } else if (_wcsicmp(L"SHAPE", meter) == 0) { return new MeterShape(skin, name); } LogErrorF(skin, L"Meter=%s is not valid in [%s]", meter, name); return nullptr; }
void LuaManager::ReportErrors(const std::wstring& file) { lua_State* L = c_State; const char* error = lua_tostring(L, -1); lua_pop(L, 1); // Skip "[string ...]". const char* pos = strchr(error, ':'); if (pos) { error = pos; } std::wstring str(file, file.find_last_of(L'\\') + 1); str += IsUnicodeState() ? StringUtil::WidenUTF8(error) : StringUtil::Widen(error); LogErrorF(L"Script: %s", str.c_str()); }
/* ** Converts given time to string. ** This function is a wrapper function for wcsftime. ** */ void MeasureTime::TimeToString(WCHAR* buf, size_t bufLen, const WCHAR* format, const struct tm* time) { if (bufLen > 0) { _invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler); _CrtSetReportMode(_CRT_ASSERT, 0); errno = 0; wcsftime(buf, bufLen, format, time); if (errno == EINVAL) { LogErrorF(this, L"Time: \"Format=%s\" invalid", format); buf[0] = 0; } _set_invalid_parameter_handler(oldHandler); } }
void CommandHandler::DoManageBang(std::vector<std::wstring>& args, Skin* skin) { const size_t argsSize = args.size(); if (argsSize >= 2 && argsSize <= 3) { DialogManage::Open(args[0].c_str(), args[1].c_str(), (argsSize == 3) ? args[2].c_str() : L""); } else if (argsSize <= 1) { DialogManage::Open(args.empty() ? L"" : args[0].c_str()); } else { LogErrorF(skin, L"!Manage: Invalid parameters"); } }
void CommandHandler::DoToggleSkinBang(std::vector<std::wstring>& args, Skin* skin) { if (args.size() >= 2) { Skin* skin = GetRainmeter().GetSkin(args[0]); if (skin) { GetRainmeter().DeactivateSkin(skin, -1); return; } // If the skin wasn't active, activate it. DoActivateSkinBang(args, nullptr); } else { LogErrorF(skin, L"!ToggleConfig: Invalid parameters"); } }
/* ** Reads and binds the primary MeasureName. This must always be called in overridden ** BindMeasures() implementations. ** */ bool Meter::BindPrimaryMeasure(ConfigParser& parser, const WCHAR* section, bool optional) { m_Measures.clear(); const std::wstring& measureName = parser.ReadString(section, L"MeasureName", L""); Measure* measure = parser.GetMeasure(measureName); if (measure) { m_Measures.push_back(measure); return true; } else if (!optional) { LogErrorF(this, L"MeasureName=%s is not valid", measureName.c_str()); } return false; }
void CommandHandler::DoSetWallpaperBang(std::vector<std::wstring>& args, Skin* skin) { const size_t argsSize = args.size(); if (argsSize >= 1 && argsSize <= 2) { std::wstring& file = args[0]; const std::wstring& style = (argsSize == 2) ? args[1] : L""; if (skin) { skin->MakePathAbsolute(file); } System::SetWallpaper(file, style); } else { LogErrorF(skin, L"!SetWallpaper: Invalid parameters"); } }
UINT MeasureNet::GetBestInterfaceOrByName(const WCHAR* iface) { if (c_Table == nullptr) return 0; if (_wcsicmp(iface, L"BEST") == 0) { DWORD dwBestIndex; if (NO_ERROR == GetBestInterface(INADDR_ANY, &dwBestIndex)) { MIB_IF_ROW2* table = (MIB_IF_ROW2*)c_Table->Table; for (size_t i = 0; i < c_NumOfTables; ++i) { if (table[i].InterfaceIndex == (NET_IFINDEX)dwBestIndex) { if (GetRainmeter().GetDebug()) { LogDebugF(this, L"Using network interface: Number=(%i), Name=\"%s\"", i + 1, table[i].Description); } return (UINT)(i + 1); } } } } else { MIB_IF_ROW2* table = (MIB_IF_ROW2*)c_Table->Table; for (size_t i = 0; i < c_NumOfTables; ++i) { if (_wcsicmp(iface, table[i].Description) == 0) { return (UINT)(i + 1); } } } LogErrorF(this, L"Cannot find interface: \"%s\"", iface); return 0; }
/* ** Read the options specified in the ini file. ** */ void MeterBar::ReadOptions(ConfigParser& parser, const WCHAR* section) { // Store the current values so we know if the image needs to be updated std::wstring oldImageName = m_ImageName; Meter::ReadOptions(parser, section); m_Color = parser.ReadColor(section, L"BarColor", D2D1::ColorF(D2D1::ColorF::Green)); m_ImageName = parser.ReadString(section, L"BarImage", L""); if (!m_ImageName.empty()) { // Read tinting options m_Image.ReadOptions(parser, section); } m_Border = parser.ReadInt(section, L"BarBorder", 0); m_Flip = parser.ReadBool(section, L"Flip", false); const WCHAR* orientation = parser.ReadString(section, L"BarOrientation", L"VERTICAL").c_str(); if (_wcsicmp(L"VERTICAL", orientation) == 0) { m_Orientation = VERTICAL; } else if (_wcsicmp(L"HORIZONTAL", orientation) == 0) { m_Orientation = HORIZONTAL; } else { LogErrorF(this, L"BarOrientation=%s is not valid", orientation); } if (m_Initialized) { Initialize(); // Reload the image } }
void MeasureMediaKey::Command(const std::wstring& command) { const WCHAR* args = command.c_str(); if (_wcsicmp(args, L"NextTrack") == 0) { SendKey(VK_MEDIA_NEXT_TRACK); } else if (_wcsicmp(args, L"PrevTrack") == 0) { SendKey(VK_MEDIA_PREV_TRACK); } else if (_wcsicmp(args, L"Stop") == 0) { SendKey(VK_MEDIA_STOP); } else if (_wcsicmp(args, L"PlayPause") == 0) { SendKey(VK_MEDIA_PLAY_PAUSE); } else if (_wcsicmp(args, L"VolumeMute") == 0) { SendKey(VK_VOLUME_MUTE); } else if (_wcsicmp(args, L"VolumeDown") == 0) { SendKey(VK_VOLUME_DOWN); } else if (_wcsicmp(args, L"VolumeUp") == 0) { SendKey(VK_VOLUME_UP); } else { LogErrorF(this, L"Unknown command: %s", args); } }
void CommandHandler::DoLogBang(std::vector<std::wstring>& args, Skin* skin) { if (!args.empty()) { Logger::Level level = Logger::Level::Notice; if (args.size() > 1) { const WCHAR* type = args[1].c_str(); if (_wcsicmp(type, L"ERROR") == 0) { level = Logger::Level::Error; } else if (_wcsicmp(type, L"WARNING") == 0) { level = Logger::Level::Warning; } else if (_wcsicmp(type, L"DEBUG") == 0) { level = Logger::Level::Debug; } else if (_wcsicmp(type, L"NOTICE") != 0) { LogErrorF(skin, L"!Log: Invalid type"); return; } } std::wstring source; if (skin) { source = skin->GetSkinPath(); } GetLogger().Log(level, source.c_str(), args[0].c_str()); } }
/* ** Creates the given measure. This is the factory method for the measures. ** If new measures are implemented this method needs to be updated. ** */ Measure* Measure::Create(const WCHAR* measure, Skin* skin, const WCHAR* name) { // Comparison is caseinsensitive if (_wcsicmp(L"CPU", measure) == 0) { return new MeasureCPU(skin, name); } else if (_wcsicmp(L"Memory", measure) == 0) { return new MeasureMemory(skin, name); } else if (_wcsicmp(L"NetIn", measure) == 0) { return new MeasureNetIn(skin, name); } else if (_wcsicmp(L"NetOut", measure) == 0) { return new MeasureNetOut(skin, name); } else if (_wcsicmp(L"NetTotal", measure) == 0) { return new MeasureNetTotal(skin, name); } else if (_wcsicmp(L"PhysicalMemory", measure) == 0) { return new MeasurePhysicalMemory(skin, name); } else if (_wcsicmp(L"SwapMemory", measure) == 0) { return new MeasureVirtualMemory(skin, name); } else if (_wcsicmp(L"FreeDiskSpace", measure) == 0) { return new MeasureDiskSpace(skin, name); } else if (_wcsicmp(L"Uptime", measure) == 0) { return new MeasureUptime(skin, name); } else if (_wcsicmp(L"Time", measure) == 0) { return new MeasureTime(skin, name); } else if (_wcsicmp(L"Plugin", measure) == 0) { return new MeasurePlugin(skin, name); } else if (_wcsicmp(L"Registry", measure) == 0) { return new MeasureRegistry(skin, name); } else if (_wcsicmp(L"Calc", measure) == 0) { return new MeasureCalc(skin, name); } else if (_wcsicmp(L"Script", measure) == 0) { return new MeasureScript(skin, name); } else if (_wcsicmp(L"String", measure) == 0) { return new MeasureString(skin, name); } else if (_wcsicmp(L"Loop", measure) == 0) { return new MeasureLoop(skin, name); } LogErrorF(skin, L"Measure=%s is not valid in [%s]", measure, name); return nullptr; }
UINT MeasureNet::GetBestInterfaceOrByName(const WCHAR* iface) { if (c_Table == nullptr) return 0; if (_wcsicmp(iface, L"BEST") == 0) { DWORD dwBestIndex; if (NO_ERROR == GetBestInterface(INADDR_ANY, &dwBestIndex)) { if (c_GetIfTable2) { MIB_IF_ROW2* table = (MIB_IF_ROW2*)((MIB_IF_TABLE2*)c_Table)->Table; for (size_t i = 0; i < c_NumOfTables; ++i) { if (table[i].InterfaceIndex == (NET_IFINDEX)dwBestIndex) { if (GetRainmeter().GetDebug()) { LogDebugF(this, L"Using network interface: Number=(%i), Name=\"%s\"", i + 1, table[i].Description); } return (i + 1); } } } else { MIB_IFROW* table = (MIB_IFROW*)((MIB_IFTABLE*)c_Table)->table; for (size_t i = 0; i < c_NumOfTables; ++i) { if (table[i].dwIndex == (NET_IFINDEX)dwBestIndex) { if (GetRainmeter().GetDebug()) { LogDebugF(this, L"Using network interface: Number=(%i), Name=\"%.*S\"", (int)i + 1, table[i].dwDescrLen, (char*)table[i].bDescr); } return (i + 1); } } } } } else { if (c_GetIfTable2) { MIB_IF_ROW2* table = (MIB_IF_ROW2*)((MIB_IF_TABLE2*)c_Table)->Table; for (size_t i = 0; i < c_NumOfTables; ++i) { if (_wcsicmp(iface, table[i].Description) == 0) { return (i + 1); } } } else { MIB_IFROW* table = (MIB_IFROW*)((MIB_IFTABLE*)c_Table)->table; for (size_t i = 0; i < c_NumOfTables; ++i) { if (_wcsicmp(iface, StringUtil::Widen((char*)table[i].bDescr).c_str()) == 0) { return (i + 1); } } } } LogErrorF(this, L"Cannot find interface: \"%s\"", iface); return 0; }
void GeneralImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const WCHAR* imagePath) { m_Path = parser.ReadString(section, m_OptionArray[OptionIndexImagePath], imagePath); PathUtil::AppendBackslashIfMissing(m_Path); if (!m_DisableTransform) { m_Options.m_Crop.left = m_Options.m_Crop.top = m_Options.m_Crop.right = m_Options.m_Crop.bottom = -1; m_Options.m_CropMode = ImageOptions::CROPMODE_TL; const std::wstring& crop = parser.ReadString(section, m_OptionArray[OptionIndexImageCrop], L""); if (!crop.empty()) { if (wcschr(crop.c_str(), L',')) { WCHAR* context = nullptr; WCHAR* parseSz = _wcsdup(crop.c_str()); WCHAR* token; token = wcstok(parseSz, L",", &context); if (token) { m_Options.m_Crop.left = (FLOAT)parser.ParseInt(token, 0); token = wcstok(nullptr, L",", &context); if (token) { m_Options.m_Crop.top = (FLOAT)parser.ParseInt(token, 0); token = wcstok(nullptr, L",", &context); if (token) { m_Options.m_Crop.right = (FLOAT)parser.ParseInt(token, 0) + m_Options.m_Crop.left; token = wcstok(nullptr, L",", &context); if (token) { m_Options.m_Crop.bottom = (FLOAT)parser.ParseInt(token, 0) + m_Options.m_Crop.top; token = wcstok(nullptr, L",", &context); if (token) { m_Options.m_CropMode = (ImageOptions::CROPMODE)parser.ParseInt(token, 0); } } } } } free(parseSz); } if (m_Options.m_CropMode < ImageOptions::CROPMODE_TL || m_Options.m_CropMode > ImageOptions::CROPMODE_C) { m_Options.m_CropMode = ImageOptions::CROPMODE_TL; LogErrorF(m_Skin, L"%s=%s (origin) is not valid in [%s]", m_OptionArray[OptionIndexImageCrop], crop, section); } } } m_Options.m_GreyScale = parser.ReadBool(section, m_OptionArray[OptionIndexGreyscale], false); D2D1_COLOR_F tint = parser.ReadColor(section, m_OptionArray[OptionIndexImageTint], D2D1::ColorF(D2D1::ColorF::White)); int alpha = parser.ReadInt(section, m_OptionArray[OptionIndexImageAlpha], (INT)(tint.a * 255)); // for backwards compatibility alpha = min(255, alpha); alpha = max(0, alpha); m_Options.m_ColorMatrix = c_IdentityMatrix; // Read in the Color Matrix // It has to be read in like this because it crashes when reading over 17 floats // at one time. The parser does it fine, but after putting the returned values // into the Color Matrix the next time the parser is used it crashes. // Note: is this still relevant? Kept for BWC std::vector<FLOAT> matrix1 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix1]); if (matrix1.size() == 5) { for (int i = 0; i < 4; ++i) // The fifth column must be 0. { m_Options.m_ColorMatrix.m[0][i] = matrix1[i]; } } else { m_Options.m_ColorMatrix.m[0][0] = tint.r; } std::vector<FLOAT> matrix2 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix2]); if (matrix2.size() == 5) { for (int i = 0; i < 4; ++i) // The fifth column must be 0. { m_Options.m_ColorMatrix.m[1][i] = matrix2[i]; } } else { m_Options.m_ColorMatrix.m[1][1] = tint.g; } std::vector<FLOAT> matrix3 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix3]); if (matrix3.size() == 5) { for (int i = 0; i < 4; ++i) // The fifth column must be 0. { m_Options.m_ColorMatrix.m[2][i] = matrix3[i]; } } else { m_Options.m_ColorMatrix.m[2][2] = tint.b; } std::vector<FLOAT> matrix4 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix4]); if (matrix4.size() == 5) { for (int i = 0; i < 4; ++i) // The fifth column must be 0. { m_Options.m_ColorMatrix.m[3][i] = matrix4[i]; } } else { m_Options.m_ColorMatrix.m[3][3] = alpha / 255.0f; } std::vector<FLOAT> matrix5 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix5]); if (matrix5.size() == 5) { for (int i = 0; i < 4; ++i) // The fifth column must be 1. { m_Options.m_ColorMatrix.m[4][i] = matrix5[i]; } } const WCHAR* flip = parser.ReadString(section, m_OptionArray[OptionIndexImageFlip], L"NONE").c_str(); if (_wcsicmp(flip, L"NONE") == 0) { m_Options.m_Flip = Gfx::Util::FlipType::None; } else if (_wcsicmp(flip, L"HORIZONTAL") == 0) { m_Options.m_Flip = Gfx::Util::FlipType::Horizontal; } else if (_wcsicmp(flip, L"VERTICAL") == 0) { m_Options.m_Flip = Gfx::Util::FlipType::Vertical; } else if (_wcsicmp(flip, L"BOTH") == 0) { m_Options.m_Flip = Gfx::Util::FlipType::Both; } else { LogErrorF(m_Skin, L"%s=%s (origin) is not valid in [%s]", m_OptionArray[OptionIndexImageFlip], flip, section); } if (!m_DisableTransform) { m_Options.m_Rotate = (FLOAT)parser.ReadFloat(section, m_OptionArray[OptionIndexImageRotate], 0.0); } m_Options.m_UseExifOrientation = parser.ReadBool(section, m_OptionArray[OptionIndexUseExifOrientation], false); }