Replaced throw with Log where possible

This commit is contained in:
Birunthan Mohanathas 2012-04-06 19:54:20 +03:00
parent df61f5c1f8
commit ea67809d9b
10 changed files with 46 additions and 136 deletions

View File

@ -796,13 +796,7 @@ CMeasure* CMeasure::Create(const WCHAR* measure, CMeterWindow* meterWindow, cons
return new CMeasureScript(meterWindow, name); return new CMeasureScript(meterWindow, name);
} }
// Error LogWithArgs(LOG_ERROR, L"Measure=%s is not valid in [%s]", measure, name);
std::wstring error = L"Measure=";
error += measure;
error += L" is not valid in [";
error += name;
error += L']';
throw CError(error);
return NULL; return NULL;
} }

View File

@ -60,12 +60,7 @@ bool CMeasureCalc::Update()
const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value); const WCHAR* errMsg = MathParser::Parse(m_Formula.c_str(), this, &m_Value);
if (errMsg != NULL) if (errMsg != NULL)
{ {
std::wstring error = L"Calc: "; LogWithArgs(LOG_ERROR, L"Calc: %s in [%s]", errMsg, m_Name.c_str());
error += errMsg;
error += L" in [";
error += m_Name;
error += L']';
Log(LOG_ERROR, error.c_str());
} }
return PostUpdate(); return PostUpdate();
@ -105,12 +100,8 @@ void CMeasureCalc::ReadConfig(CConfigParser& parser, const WCHAR* section)
const WCHAR* errMsg = MathParser::Check(m_Formula.c_str()); const WCHAR* errMsg = MathParser::Check(m_Formula.c_str());
if (errMsg != NULL) if (errMsg != NULL)
{ {
std::wstring error = L"Calc: "; LogWithArgs(LOG_ERROR, L"Calc: %s in [%s]", errMsg, m_Name.c_str());
error += errMsg; m_Formula.clear();
error += L" in [";
error += m_Name;
error += L']';
throw CError(error);
} }
} }
} }

View File

@ -169,9 +169,8 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_Plugin == NULL) if (m_Plugin == NULL)
{ {
std::wstring error = L"Plugin: \"" + pluginName; LogWithArgs(LOG_ERROR, L"Plugin: \"%s\" not found", pluginName.c_str());
error += L"\" not found"; return;
throw CError(error);
} }
} }

View File

@ -27,7 +27,7 @@
*/ */
CMeasureRegistry::CMeasureRegistry(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name), CMeasureRegistry::CMeasureRegistry(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name),
m_RegKey(), m_RegKey(),
m_HKey() m_HKey(HKEY_CURRENT_USER)
{ {
m_MaxValue = 0.0; m_MaxValue = 0.0;
} }
@ -138,12 +138,7 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"RegHKey="; LogWithArgs(LOG_ERROR, L"RegHKey=%s is not valid in [%s]", keyname, m_Name.c_str());
error += keyname;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
m_RegKeyName = parser.ReadString(section, L"RegKey", L""); m_RegKeyName = parser.ReadString(section, L"RegKey", L"");

View File

@ -488,13 +488,7 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHA
return new CMeterButton(meterWindow, name); return new CMeterButton(meterWindow, name);
} }
// Error LogWithArgs(LOG_ERROR, L"Meter=%s is not valid in [%s]", meter, name);
std::wstring error = L"Meter=";
error += meter;
error += L" is not valid in [";
error += name;
error += L']';
throw CError(error);
return NULL; return NULL;
} }

View File

@ -122,12 +122,7 @@ void CMeterBar::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"BarOrientation="; LogWithArgs(LOG_ERROR, L"BarOrientation=%s is not valid in [%s]", orientation, m_Name.c_str());
error += orientation;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
if (m_Initialized) if (m_Initialized)

View File

@ -201,12 +201,7 @@ void CMeterBitmap::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"BitmapAlign="; LogWithArgs(LOG_ERROR, L"BitmapAlign=%s is not valid in [%s]", align, m_Name.c_str());
error += align;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
if (m_Initialized) if (m_Initialized)

View File

@ -191,8 +191,7 @@ void CMeterString::Initialize()
// It couldn't find the font family: Log it. // It couldn't find the font family: Log it.
if (Ok != status) if (Ok != status)
{ {
std::wstring error = L"String: Unable to load font: " + m_FontFace; LogWithArgs(LOG_ERROR, L"String: Unable to load font: %s", m_FontFace.c_str());
Log(LOG_ERROR, error.c_str());
delete m_FontFamily; delete m_FontFamily;
m_FontFamily = NULL; m_FontFamily = NULL;
@ -357,12 +356,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"StringAlign="; LogWithArgs(LOG_ERROR, L"StringAlign=%s is not valid in [%s]", align, m_Name.c_str());
error += align;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
const WCHAR* stringCase = parser.ReadString(section, L"StringCase", L"NONE").c_str(); const WCHAR* stringCase = parser.ReadString(section, L"StringCase", L"NONE").c_str();
@ -384,12 +378,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"StringCase="; LogWithArgs(LOG_ERROR, L"StringCase=%s is not valid in [%s]", stringCase, m_Name.c_str());
error += stringCase;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
const WCHAR* style = parser.ReadString(section, L"StringStyle", L"NORMAL").c_str(); const WCHAR* style = parser.ReadString(section, L"StringStyle", L"NORMAL").c_str();
@ -411,12 +400,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"StringStyle="; LogWithArgs(LOG_ERROR, L"StringStyle=%s is not valid in [%s]", style, m_Name.c_str());
error += style;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
const WCHAR* effect = parser.ReadString(section, L"StringEffect", L"NONE").c_str(); const WCHAR* effect = parser.ReadString(section, L"StringEffect", L"NONE").c_str();
@ -434,12 +418,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = L"StringEffect="; LogWithArgs(LOG_ERROR, L"StringEffect=%s is not valid in [%s]", effect, m_Name.c_str());
error += effect;
error += L" is not valid in [";
error += m_Name;
error += L']';
throw CError(error);
} }
if (m_Initialized && if (m_Initialized &&

View File

@ -157,6 +157,17 @@ CMeterWindow::CMeterWindow(const std::wstring& config, const std::wstring& iniFi
} }
} }
if (c_InstanceCount == 0)
{
WNDCLASSEX wc = {sizeof(WNDCLASSEX)};
wc.style = CS_NOCLOSE | CS_DBLCLKS;
wc.lpfnWndProc = InitialWndProc;
wc.hInstance = m_Rainmeter->GetInstance();
wc.hCursor = NULL; // The cursor should be controlled by using SetCursor() when needed.
wc.lpszClassName = METERWINDOW_CLASS_NAME;
RegisterClassEx(&wc);
}
++c_InstanceCount; ++c_InstanceCount;
} }
@ -211,16 +222,7 @@ CMeterWindow::~CMeterWindow()
if (c_InstanceCount == 0) if (c_InstanceCount == 0)
{ {
BOOL Result; UnregisterClass(METERWINDOW_CLASS_NAME, m_Rainmeter->GetInstance());
int counter = 0;
do
{
// Wait for the window to die
Result = UnregisterClass(METERWINDOW_CLASS_NAME, m_Rainmeter->GetInstance());
Sleep(100);
++counter;
}
while(!Result && counter < 10);
if (c_DwmInstance) if (c_DwmInstance)
{ {
@ -243,25 +245,8 @@ int CMeterWindow::Initialize(CRainmeter& Rainmeter)
{ {
m_Rainmeter = &Rainmeter; m_Rainmeter = &Rainmeter;
// Register the windowclass m_Window = CreateWindowEx(
WNDCLASSEX wc = {sizeof(WNDCLASSEX)}; WS_EX_TOOLWINDOW,
wc.style = CS_NOCLOSE | CS_DBLCLKS;
wc.lpfnWndProc = InitialWndProc;
wc.hInstance = m_Rainmeter->GetInstance();
wc.hCursor = NULL; // The cursor should be controlled by using SetCursor() when needed.
wc.lpszClassName = METERWINDOW_CLASS_NAME;
if (!RegisterClassEx(&wc))
{
DWORD err = GetLastError();
if (err != 0 && ERROR_CLASS_ALREADY_EXISTS != err)
{
throw CError(L"Unable to register class");
}
}
m_Window = CreateWindowEx(WS_EX_TOOLWINDOW,
METERWINDOW_CLASS_NAME, METERWINDOW_CLASS_NAME,
NULL, NULL,
WS_POPUP, WS_POPUP,
@ -462,16 +447,10 @@ void CMeterWindow::Refresh(bool init, bool all)
// Start the timers // Start the timers
if (m_WindowUpdate >= 0) if (m_WindowUpdate >= 0)
{ {
if (0 == SetTimer(m_Window, TIMER_METER, m_WindowUpdate, NULL)) SetTimer(m_Window, TIMER_METER, m_WindowUpdate, NULL);
{
throw CError(L"Unable to set timer");
}
} }
if (0 == SetTimer(m_Window, TIMER_MOUSE, INTERVAL_MOUSE, NULL)) // Mouse position is checked twice per sec SetTimer(m_Window, TIMER_MOUSE, INTERVAL_MOUSE, NULL);
{
throw CError(L"Unable to set timer");
}
m_Rainmeter->SetCurrentParser(NULL); m_Rainmeter->SetCurrentParser(NULL);

View File

@ -623,13 +623,8 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C) if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C)
{ {
std::wstring error = m_ConfigArray[ConfigIndexImageCrop]; m_CropMode = CROPMODE_TL;
error += L'='; LogWithArgs(LOG_ERROR, L"%s=%s (origin) is not valid in [%s]", m_ConfigArray[ConfigIndexImageCrop], crop, section);
error += crop;
error += L" (origin) is not valid in [";
error += section;
error += L']';
throw CError(error);
} }
} }
} }
@ -731,13 +726,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
std::wstring error = m_ConfigArray[ConfigIndexImageFlip]; LogWithArgs(LOG_ERROR, L"%s=%s (origin) is not valid in [%s]", m_ConfigArray[ConfigIndexImageFlip], flip, section);
error += L'=';
error += flip;
error += L" is not valid in [";
error += section;
error += L']';
throw CError(error);
} }
if (!m_DisableTransform) if (!m_DisableTransform)