Code optimization.

This commit is contained in:
spx 2010-11-25 15:34:49 +00:00
parent d299d89ede
commit 0e1486f0be
13 changed files with 106 additions and 35 deletions

View File

@ -210,7 +210,7 @@ void UpdateAboutStatistics(LPCTSTR entryName)
CMeasure::GetScaledValue(1, maxVal, buffer);
range += buffer;
if (name && wcslen(name) > 0)
if (name && *name)
{
if (index < count)
{
@ -365,7 +365,7 @@ void ScanPlugins()
if (GetAuthorFunc)
{
LPCTSTR author = GetAuthorFunc();
if (author && wcslen(author) > 0)
if (author && *author)
{
info.author = author;
}

View File

@ -332,7 +332,7 @@ HINSTANCE LSExecute(HWND Owner, LPCTSTR szCommand, int nShowCmd)
HINSTANCE ExecuteCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, LPCTSTR szVerb)
{
// The stub implementation (some of this code is taken from lsapi.cpp)
if (szCommand == NULL || wcslen(szCommand) == 0) return NULL;
if (szCommand == NULL || *szCommand == 0) return NULL;
std::wstring args;
std::wstring command = szCommand;

View File

@ -670,7 +670,10 @@ CMeasure* CMeasure::Create(const WCHAR* measure, CMeterWindow* meterWindow)
}
// Error
throw CError(std::wstring(L"Measure=") + measure + L" is not valid.", __LINE__, __FILE__);
std::wstring error = L"Measure=";
error += measure;
error += L" is not valid.";
throw CError(error, __LINE__, __FILE__);
return NULL;
}

View File

@ -151,7 +151,10 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_Plugin == NULL)
{
throw CError(std::wstring(L"Rainmeter plugin ") + m_PluginName + L" not found!", __LINE__, __FILE__);
std::wstring error = L"Rainmeter plugin ";
error += m_PluginName;
error += L" not found!";
throw CError(error, __LINE__, __FILE__);
}
}
@ -165,7 +168,11 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (UpdateFunc == NULL && UpdateFunc2 == NULL && GetStringFunc == NULL)
{
FreeLibrary(m_Plugin);
throw CError(std::wstring(L"Rainmeter plugin ") + m_PluginName + L" doesn't export Update or GetString function!", __LINE__, __FILE__);
std::wstring error = L"Rainmeter plugin ";
error += m_PluginName;
error += L" doesn't export Update or GetString function!";
throw CError(error, __LINE__, __FILE__);
}
// Initialize the plugin

View File

@ -149,7 +149,12 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
}
else
{
throw CError(std::wstring(L"HKEY=") + keyname + L" is not valid in measure [" + section + L"].", __LINE__, __FILE__);
std::wstring error = L"HKEY=";
error += keyname;
error += L" is not valid in measure [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
m_RegKeyName = parser.ReadString(section, L"RegKey", L"");

View File

@ -430,13 +430,6 @@ void CMeter::ReadConfig(const WCHAR* section)
std::wstring group = parser.ReadString(section, L"Group", L"");
InitializeGroup(group);
/* Are these necessary?
if (m_W == 0 || m_H == 0)
{
throw CError(std::wstring(L"The meter ") + section + L" has zero dimensions.", __LINE__, __FILE__);
}
*/
}
/*
@ -451,7 +444,10 @@ void CMeter::BindMeasure(const std::list<CMeasure*>& measures)
// The meter is not bound to anything
if (m_MeasureName.empty())
{
throw CError(std::wstring(L"The meter [") + m_Name + L"] is not bound to anything!", __LINE__, __FILE__);
std::wstring error = L"The meter [";
error += m_Name;
error += L"] is not bound to anything!";
throw CError(error, __LINE__, __FILE__);
}
// Go through the list and check it there is a measure for us
@ -466,7 +462,12 @@ void CMeter::BindMeasure(const std::list<CMeasure*>& measures)
}
// Error :)
throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + m_MeasureName + L"]!", __LINE__, __FILE__);
std::wstring error = L"The meter [";
error += m_Name;
error += L"] cannot be bound with [";
error += m_MeasureName;
error += L"]!";
throw CError(error, __LINE__, __FILE__);
}
/*
@ -516,7 +517,10 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow)
}
// Error
throw CError(std::wstring(L"Meter=") + meter + L" is not valid.", __LINE__, __FILE__);
std::wstring error = L"Meter=";
error += meter;
error += L" is not valid.";
throw CError(error, __LINE__, __FILE__);
return NULL;
}

View File

@ -126,7 +126,12 @@ void CMeterBar::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"BarOrientation=") + orientation + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"BarOrientation=";
error += orientation;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
if (m_Initialized)

View File

@ -211,7 +211,12 @@ void CMeterBitmap::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"BitmapAlign=") + align + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"BitmapAlign=";
error += align;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
if (m_Initialized)

View File

@ -580,6 +580,11 @@ void CMeterHistogram::BindMeasure(const std::list<CMeasure*>& measures)
}
}
throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + m_SecondaryMeasureName + L"]!", __LINE__, __FILE__);
std::wstring error = L"The meter [";
error += m_Name;
error += L"] cannot be bound with [";
error += m_SecondaryMeasureName;
error += L"]!";
throw CError(error, __LINE__, __FILE__);
}
}

View File

@ -539,7 +539,12 @@ void CMeterImage::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"ImageFlip=") + flip + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"ImageFlip=";
error += flip;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
m_Rotate = (REAL)parser.ReadFloat(section, L"ImageRotate", 0.0);

View File

@ -397,7 +397,12 @@ void CMeterLine::BindMeasure(const std::list<CMeasure*>& measures)
if (i == measures.end())
{
throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__);
std::wstring error = L"The meter [";
error += m_Name;
error += L"] cannot be bound with [";
error += (*j);
error += L"]!";
throw CError(error, __LINE__, __FILE__);
}
}
CMeter::SetAllMeasures(m_Measures);

View File

@ -230,7 +230,9 @@ void CMeterString::Initialize()
if (m_FontSize != 0)
{
throw CError(std::wstring(L"Unable to create font: ") + m_FontFace, __LINE__, __FILE__);
std::wstring error = L"Unable to create font: ";
error += m_FontFace;
throw CError(error, __LINE__, __FILE__);
}
}
}
@ -331,7 +333,12 @@ void CMeterString::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"StringAlign=") + align + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"StringAlign=";
error += align;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
std::wstring stringCase = parser.ReadString(section, L"StringCase", L"NONE");
@ -354,7 +361,12 @@ void CMeterString::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"StringCase=") + stringCase + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"StringCase=";
error += stringCase;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
std::wstring style = parser.ReadString(section, L"StringStyle", L"NORMAL");
@ -377,7 +389,12 @@ void CMeterString::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"StringStyle=") + style + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"StringStyle=";
error += style;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
std::wstring effect = parser.ReadString(section, L"StringEffect", L"NONE");
@ -396,7 +413,12 @@ void CMeterString::ReadConfig(const WCHAR* section)
}
else
{
throw CError(std::wstring(L"StringEffect=") + effect + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__);
std::wstring error = L"StringEffect=";
error += effect;
error += L" is not valid in meter [";
error += m_Name;
error += L"].";
throw CError(error, __LINE__, __FILE__);
}
if (-1 != (int)parser.ReadFormula(section, L"W", -1) && -1 != (int)parser.ReadFormula(section, L"H", -1))
@ -634,7 +656,12 @@ void CMeterString::BindMeasure(const std::list<CMeasure*>& measures)
if (i == measures.end())
{
throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__);
std::wstring error = L"The meter [";
error += m_Name;
error += L"] cannot be bound with [";
error += (*j);
error += L"]!";
throw CError(error, __LINE__, __FILE__);
}
}
CMeter::SetAllMeasures(m_Measures);

View File

@ -955,7 +955,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
*/
void CMeterWindow::ShowMeter(const WCHAR* name, bool group)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeter*>::const_iterator j = m_Meters.begin();
for( ; j != m_Meters.end(); ++j)
@ -985,7 +985,7 @@ void CMeterWindow::ShowMeter(const WCHAR* name, bool group)
*/
void CMeterWindow::HideMeter(const WCHAR* name, bool group)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeter*>::const_iterator j = m_Meters.begin();
for( ; j != m_Meters.end(); ++j)
@ -1015,7 +1015,7 @@ void CMeterWindow::HideMeter(const WCHAR* name, bool group)
*/
void CMeterWindow::ToggleMeter(const WCHAR* name, bool group)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeter*>::const_iterator j = m_Meters.begin();
for( ; j != m_Meters.end(); ++j)
@ -1052,7 +1052,7 @@ void CMeterWindow::ToggleMeter(const WCHAR* name, bool group)
*/
void CMeterWindow::MoveMeter(int x, int y, const WCHAR* name)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeter*>::const_iterator j = m_Meters.begin();
for( ; j != m_Meters.end(); ++j)
@ -1077,7 +1077,7 @@ void CMeterWindow::MoveMeter(int x, int y, const WCHAR* name)
*/
void CMeterWindow::EnableMeasure(const WCHAR* name, bool group)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeasure*>::const_iterator i = m_Measures.begin();
for( ; i != m_Measures.end(); ++i)
@ -1107,7 +1107,7 @@ void CMeterWindow::EnableMeasure(const WCHAR* name, bool group)
*/
void CMeterWindow::DisableMeasure(const WCHAR* name, bool group)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeasure*>::const_iterator i = m_Measures.begin();
for( ; i != m_Measures.end(); ++i)
@ -1137,7 +1137,7 @@ void CMeterWindow::DisableMeasure(const WCHAR* name, bool group)
*/
void CMeterWindow::ToggleMeasure(const WCHAR* name, bool group)
{
if (name == NULL || wcslen(name) == 0) return;
if (name == NULL || *name == 0) return;
std::list<CMeasure*>::const_iterator i = m_Measures.begin();
for( ; i != m_Measures.end(); ++i)