From da8b11351d03bae9a9d4d5a03f97c42973872a01 Mon Sep 17 00:00:00 2001 From: jsmorley Date: Mon, 2 Apr 2012 10:47:13 -0400 Subject: [PATCH] Added !Log bang to write to the Rainmeter log --- Library/Rainmeter.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ Library/Rainmeter.h | 1 + 2 files changed, 43 insertions(+) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index f1505175..7eb63607 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -635,6 +635,44 @@ void CRainmeter::Bang_WriteKeyValue(const WCHAR* arg, CMeterWindow* meterWindow) } } +/* +** !Log bang +** +*/ +void CRainmeter::Bang_Log(const WCHAR* arg) +{ + std::vector subStrings = ParseString(arg); + + if (!subStrings.empty()) + { + int level = LOG_NOTICE; + + if (subStrings.size() > 1) + { + const WCHAR* type = subStrings[1].c_str(); + if (_wcsicmp(type, L"ERROR") == 0) + { + level = LOG_ERROR; + } + else if (_wcsicmp(type, L"WARNING") == 0) + { + level = LOG_WARNING; + } + else if (_wcsicmp(type, L"DEBUG") == 0) + { + level = LOG_DEBUG; + } + else if (_wcsicmp(type, L"NOTICE") != 0) + { + Log(LOG_ERROR, L"!Log: Invalid type"); + return; + } + } + + Log(level, subStrings[0].c_str()); + } +} + // ----------------------------------------------------------------------------------------------- // @@ -1935,6 +1973,10 @@ void CRainmeter::ExecuteBang(const std::wstring& name, std::wstring& arg, CMeter { ResetStats(); } + else if (_wcsicmp(bang, L"Log") == 0) + { + Bang_Log(args); + } else if (_wcsicmp(bang, L"Quit") == 0) { // Quit needs to be delayed since it crashes if done during Update() diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 69e412bf..ce5bcfac 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -245,6 +245,7 @@ private: void Bang_SkinMenu(const WCHAR* arg, CMeterWindow* meterWindow); void Bang_TrayMenu(); void Bang_WriteKeyValue(const WCHAR* arg, CMeterWindow* meterWindow); + void Bang_Log(const WCHAR* arg); void ExecuteBang(const std::wstring& name, std::wstring& arg, CMeterWindow* meterWindow);