ConfigParser: Implement ReadBool

This may break backwards compatibility in some cases. For example, the FreeDiskSpace measure treated only `Type=1` as true and `Type={0, 2, 3, ...}` as false. Now `Type=0` is false and everything else is true like with most other boolean options.
This commit is contained in:
Birunthan Mohanathas 2013-07-31 13:36:53 +03:00
parent 6b8d8a65d0
commit 923215c0da
23 changed files with 59 additions and 58 deletions

View File

@ -69,6 +69,7 @@ public:
const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue, bool bReplaceMeasures = true);
bool IsKeyDefined(LPCTSTR section, LPCTSTR key);
bool IsValueDefined(LPCTSTR section, LPCTSTR key);
bool ReadBool(LPCTSTR section, LPCTSTR key, bool defValue) { return ReadInt(section, key, (int)defValue) != 0; }
int ReadInt(LPCTSTR section, LPCTSTR key, int defValue);
uint32_t ReadUInt(LPCTSTR section, LPCTSTR key, uint32_t defValue);
uint64_t ReadUInt64(LPCTSTR section, LPCTSTR key, uint64_t defValue);

View File

@ -126,10 +126,10 @@ void Measure::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_Substitute.clear();
}
m_Invert = 0!=parser.ReadInt(section, L"InvertMeasure", 0);
m_Invert = parser.ReadBool(section, L"InvertMeasure", false);
m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0);
m_Paused = 0!=parser.ReadInt(section, L"Paused", 0);
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);
@ -149,7 +149,7 @@ void Measure::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_AverageSize = parser.ReadUInt(section, L"AverageSize", 0);
m_RegExpSubstitute = 0!=parser.ReadInt(section, L"RegExpSubstitute", 0);
m_RegExpSubstitute = parser.ReadBool(section, L"RegExpSubstitute", false);
std::wstring subs = parser.ReadString(section, L"Substitute", L"");
if (!subs.empty())
{

View File

@ -89,7 +89,7 @@ void MeasureCalc::ReadOptions(ConfigParser& parser, const WCHAR* section)
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);
m_UpdateRandom = parser.ReadBool(section, L"UpdateRandom", false);
if (!m_Initialized ||
wcscmp(m_Formula.c_str(), oldFormula.c_str()) != 0 ||

View File

@ -195,11 +195,11 @@ void MeasureDiskSpace::ReadOptions(ConfigParser& parser, const WCHAR* section)
PathUtil::AppendBacklashIfMissing(m_Drive);
}
m_Type = (1 == parser.ReadInt(section, L"Type", 0));
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
m_Label = (1 == parser.ReadInt(section, L"Label", 0));
m_IgnoreRemovable = (1 == parser.ReadInt(section, L"IgnoreRemovable", 1));
m_DiskQuota = (1 == parser.ReadInt(section, L"DiskQuota", 1));
m_Type = parser.ReadBool(section, L"Type", false);
m_Total = parser.ReadBool(section, L"Total", false);
m_Label = parser.ReadBool(section, L"Label", false);
m_IgnoreRemovable = parser.ReadBool(section, L"IgnoreRemovable", true);
m_DiskQuota = parser.ReadBool(section, L"DiskQuota", true);
// Set the m_MaxValue
if (!m_Initialized)

View File

@ -72,5 +72,5 @@ void MeasureMemory::ReadOptions(ConfigParser& parser, const WCHAR* section)
Measure::ReadOptions(parser, section);
m_MaxValue = oldMaxValue;
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
m_Total = parser.ReadBool(section, L"Total", false);
}

View File

@ -488,7 +488,7 @@ void MeasureNet::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_Interface = parser.ReadInt(section, L"Interface", 0);
m_Cumulative = 0!=parser.ReadInt(section, L"Cumulative", 0);
m_Cumulative = parser.ReadBool(section, L"Cumulative", false);
if (m_Cumulative)
{
GetRainmeter().SetNetworkStatisticsTimer();

View File

@ -67,7 +67,7 @@ void MeasurePhysicalMemory::ReadOptions(ConfigParser& parser, const WCHAR* secti
Measure::ReadOptions(parser, section);
m_MaxValue = oldMaxValue;
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
m_Total = parser.ReadBool(section, L"Total", false);
if (m_Total)
{
m_Value = m_MaxValue;

View File

@ -248,7 +248,7 @@ void MeasureTime::ReadOptions(ConfigParser& parser, const WCHAR* section)
else
{
double zone = parser.ParseDouble(timezone, 0.0);
bool dst = 1 == parser.ReadInt(section, L"DaylightSavingTime", 1);
bool dst = parser.ReadBool(section, L"DaylightSavingTime", true);
struct tm* today;
time_t now;

View File

@ -50,7 +50,7 @@ void MeasureUptime::ReadOptions(ConfigParser& parser, const WCHAR* section)
if (m_Format.find(L"%4") == std::wstring::npos)
{
m_AddDaysToHours = 0!=parser.ReadInt(section, L"AddDaysToHours", 1);
m_AddDaysToHours = parser.ReadBool(section, L"AddDaysToHours", true);
}
else
{

View File

@ -72,6 +72,6 @@ void MeasureVirtualMemory::ReadOptions(ConfigParser& parser, const WCHAR* sectio
Measure::ReadOptions(parser, section);
m_MaxValue = oldMaxValue;
m_Total = (1 == parser.ReadInt(section, L"Total", 0));
m_Total = parser.ReadBool(section, L"Total", false);
}

View File

@ -331,7 +331,7 @@ void Meter::ReadOptions(ConfigParser& parser, const WCHAR* section)
}
bool oldHidden = m_Hidden;
m_Hidden = 0!=parser.ReadInt(section, L"Hidden", 0);
m_Hidden = parser.ReadBool(section, L"Hidden", false);
if (oldX != m_X || oldY != m_Y || oldHidden != m_Hidden)
{
@ -351,10 +351,10 @@ void Meter::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ToolTipTitle = parser.ReadString(section, L"ToolTipTitle", L"");
m_ToolTipIcon = parser.ReadString(section, L"ToolTipIcon", L"");
m_ToolTipWidth = parser.ReadInt(section, L"ToolTipWidth", 1000);
m_ToolTipType = 0!=parser.ReadInt(section, L"ToolTipType", 0);
m_ToolTipHidden = 0!=parser.ReadInt(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());
m_ToolTipType = parser.ReadBool(section, L"ToolTipType", false);
m_ToolTipHidden = parser.ReadBool(section, L"ToolTipHidden", m_MeterWindow->GetMeterToolTipHidden());
m_AntiAlias = 0!=parser.ReadInt(section, L"AntiAlias", 0);
m_AntiAlias = parser.ReadBool(section, L"AntiAlias", false);
std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
if (matrix.size() == 6)

View File

@ -105,7 +105,7 @@ void MeterBar::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_Border = parser.ReadInt(section, L"BarBorder", 0);
m_Flip = 0!=parser.ReadInt(section, L"Flip", 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)

View File

@ -177,10 +177,10 @@ void MeterBitmap::ReadOptions(ConfigParser& parser, const WCHAR* section)
}
m_FrameCount = parser.ReadInt(section, L"BitmapFrames", 1);
m_ZeroFrame = 0!=parser.ReadInt(section, L"BitmapZeroFrame", 0);
m_ZeroFrame = parser.ReadBool(section, L"BitmapZeroFrame", false);
m_Separation = parser.ReadInt(section, L"BitmapSeparation", 0);
m_Extend = 0!=parser.ReadInt(section, L"BitmapExtend", 0);
m_Extend = parser.ReadBool(section, L"BitmapExtend", false);
m_Digits = parser.ReadInt(section, L"BitmapDigits", 0);
m_TransitionFrameCount = parser.ReadInt(section, L"BitmapTransitionFrames", 0);

View File

@ -243,8 +243,8 @@ void MeterHistogram::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_OverlapImage.ClearOptionFlags();
}
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0);
m_Flip = 0!=parser.ReadInt(section, L"Flip", 0);
m_Autoscale = parser.ReadBool(section, L"AutoScale", false);
m_Flip = parser.ReadBool(section, L"Flip", false);
const WCHAR* graph = parser.ReadString(section, L"GraphStart", L"RIGHT").c_str();
if (_wcsicmp(graph, L"RIGHT") == 0)

View File

@ -141,10 +141,10 @@ void MeterLine::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ScaleValues.push_back(parser.ReadFloat(section, tmpName, 1.0));
}
m_Flip = 0!=parser.ReadInt(section, L"Flip", 0);
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0);
m_Flip = parser.ReadBool(section, L"Flip", false);
m_Autoscale = parser.ReadBool(section, L"AutoScale", false);
m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
m_HorizontalLines = 0!=parser.ReadInt(section, L"HorizontalLines", 0);
m_HorizontalLines = parser.ReadBool(section, L"HorizontalLines", false);
ARGB color = parser.ReadColor(section, L"HorizontalColor", Color::Black); // This is left here for backwards compatibility
m_HorizontalColor = parser.ReadColor(section, L"HorizontalLineColor", color); // This is what it should be

View File

@ -73,10 +73,10 @@ void MeterRoundLine::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);
m_LineColor = parser.ReadColor(section, L"LineColor", Color::Black);
m_Solid = 0!=parser.ReadInt(section, L"Solid", 0);
m_CntrlAngle = 0!=parser.ReadInt(section, L"ControlAngle", 1);
m_CntrlLineStart = 0!=parser.ReadInt(section, L"ControlStart", 0);
m_CntrlLineLength = 0!=parser.ReadInt(section, L"ControlLength", 0);
m_Solid = parser.ReadBool(section, L"Solid", false);
m_CntrlAngle = parser.ReadBool(section, L"ControlAngle", true);
m_CntrlLineStart = parser.ReadBool(section, L"ControlStart", false);
m_CntrlLineLength = parser.ReadBool(section, L"ControlLength", false);
m_LineStartShift = parser.ReadFloat(section, L"StartShift", 0.0);
m_LineLengthShift = parser.ReadFloat(section, L"LengthShift", 0.0);
}

View File

@ -178,7 +178,7 @@ void MeterString::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_Postfix = parser.ReadString(section, L"Postfix", L"");
m_Text = parser.ReadString(section, L"Text", L"");
m_Percentual = 0!=parser.ReadInt(section, L"Percentual", 0);
m_Percentual = parser.ReadBool(section, L"Percentual", false);
int clipping = parser.ReadInt(section, L"ClipString", 0);
switch (clipping)

View File

@ -1916,21 +1916,21 @@ void MeterWindow::ReadOptions()
int hideMode = parser.ReadInt(section, L"HideOnMouseOver", HIDEMODE_NONE);
m_WindowHide = (hideMode >= HIDEMODE_NONE && hideMode <= HIDEMODE_FADEOUT) ? (HIDEMODE)hideMode : HIDEMODE_NONE;
m_WindowDraggable = 0!=parser.ReadInt(section, L"Draggable", 1);
m_WindowDraggable = parser.ReadBool(section, L"Draggable", true);
addWriteFlag(OPTION_DRAGGABLE);
m_SnapEdges = 0!=parser.ReadInt(section, L"SnapEdges", 1);
m_SnapEdges = parser.ReadBool(section, L"SnapEdges", true);
addWriteFlag(OPTION_SNAPEDGES);
m_ClickThrough = 0!=parser.ReadInt(section, L"ClickThrough", 0);
m_ClickThrough = parser.ReadBool(section, L"ClickThrough", false);
addWriteFlag(OPTION_CLICKTHROUGH);
m_KeepOnScreen = 0!=parser.ReadInt(section, L"KeepOnScreen", 1);
m_KeepOnScreen = parser.ReadBool(section, L"KeepOnScreen", true);
addWriteFlag(OPTION_KEEPONSCREEN);
m_SavePosition = 0!=parser.ReadInt(section, L"SavePosition", 1);
m_WindowStartHidden = 0!=parser.ReadInt(section, L"StartHidden", 0);
m_AutoSelectScreen = 0!=parser.ReadInt(section, L"AutoSelectScreen", 0);
m_SavePosition = parser.ReadBool(section, L"SavePosition", true);
m_WindowStartHidden = parser.ReadBool(section, L"StartHidden", false);
m_AutoSelectScreen = parser.ReadBool(section, L"AutoSelectScreen", false);
m_AlphaValue = parser.ReadInt(section, L"AlphaValue", 255);
m_AlphaValue = max(m_AlphaValue, 0);
@ -2074,7 +2074,7 @@ bool MeterWindow::ReadSkin()
bool useD2D = GetRainmeter().GetUseD2D();
if (revision_beta)
{
useD2D = 0!=m_Parser.ReadInt(L"Rainmeter", L"__UseD2D", useD2D ? 1 : 0);
useD2D = m_Parser.ReadBool(L"Rainmeter", L"__UseD2D", useD2D);
}
m_Canvas = Gfx::Canvas::Create(useD2D ? Gfx::Renderer::PreferD2D : Gfx::Renderer::GDIP);
@ -2082,7 +2082,7 @@ bool MeterWindow::ReadSkin()
// Gotta have some kind of buffer during initialization
CreateDoubleBuffer(1, 1);
m_AccurateText = 0!=m_Parser.ReadInt(L"Rainmeter", L"AccurateText", 0);
m_AccurateText = m_Parser.ReadBool(L"Rainmeter", L"AccurateText", false);
m_Canvas->SetAccurateText(m_AccurateText);
// Check the version
@ -2118,7 +2118,7 @@ bool MeterWindow::ReadSkin()
m_SolidColor2 = m_Parser.ReadColor(L"Rainmeter", L"SolidColor2", m_SolidColor.GetValue());
m_SolidAngle = (Gdiplus::REAL)m_Parser.ReadFloat(L"Rainmeter", L"GradientAngle", 0.0);
m_DynamicWindowSize = 0!=m_Parser.ReadInt(L"Rainmeter", L"DynamicWindowSize", 0);
m_DynamicWindowSize = m_Parser.ReadBool(L"Rainmeter", L"DynamicWindowSize", false);
if (m_BackgroundMode == BGMODE_IMAGE || m_BackgroundMode == BGMODE_SCALED_IMAGE || m_BackgroundMode == BGMODE_TILED_IMAGE)
{
@ -2144,11 +2144,11 @@ bool MeterWindow::ReadSkin()
m_WindowUpdate = m_Parser.ReadInt(L"Rainmeter", L"Update", INTERVAL_METER);
m_TransitionUpdate = m_Parser.ReadInt(L"Rainmeter", L"TransitionUpdate", INTERVAL_TRANSITION);
m_ToolTipHidden = 0 != m_Parser.ReadInt(L"Rainmeter", L"ToolTipHidden", 0);
m_ToolTipHidden = m_Parser.ReadBool(L"Rainmeter", L"ToolTipHidden", false);
if (Platform::IsAtLeastWinVista())
{
if (0 != m_Parser.ReadInt(L"Rainmeter", L"Blur", 0))
if (m_Parser.ReadBool(L"Rainmeter", L"Blur", false))
{
const WCHAR* blurRegion = m_Parser.ReadString(L"Rainmeter", L"BlurRegion", L"", false).c_str();

View File

@ -69,7 +69,7 @@ void Mouse::ReadOptions(ConfigParser& parser, const WCHAR* section)
}
const bool defaultState = (section == L"Rainmeter") ? true : m_MeterWindow->GetMouse().GetCursorState();
m_CursorState = 0!=parser.ReadInt(section, L"MouseActionCursor", defaultState);
m_CursorState = parser.ReadBool(section, L"MouseActionCursor", defaultState);
const WCHAR* defaultMouseCursor = (section == L"Rainmeter") ? L"HAND" : L"";
const WCHAR* mouseCursor = parser.ReadString(section, L"MouseActionCursorName", defaultMouseCursor).c_str();

View File

@ -1255,13 +1255,13 @@ void Rainmeter::ReadGeneralSettings(const std::wstring& iniFile)
ConfigParser parser;
parser.Initialize(iniFile, nullptr, nullptr);
m_UseD2D = 0!=parser.ReadInt(L"Rainmeter", L"UseD2D", 0);
m_UseD2D = parser.ReadBool(L"Rainmeter", L"UseD2D", false);
m_Debug = 0!=parser.ReadInt(L"Rainmeter", L"Debug", 0);
m_Debug = parser.ReadBool(L"Rainmeter", L"Debug", false);
// Read Logging settings
Logger& logger = GetLogger();
const bool logging = parser.ReadInt(L"Rainmeter", L"Logging", 0) != 0;
const bool logging = parser.ReadBool(L"Rainmeter", L"Logging", false);
logger.SetLogToFile(logging);
if (logging)
{
@ -1276,8 +1276,8 @@ void Rainmeter::ReadGeneralSettings(const std::wstring& iniFile)
m_GlobalOptions.netInSpeed = parser.ReadFloat(L"Rainmeter", L"NetInSpeed", 0.0);
m_GlobalOptions.netOutSpeed = parser.ReadFloat(L"Rainmeter", L"NetOutSpeed", 0.0);
m_DisableDragging = 0!=parser.ReadInt(L"Rainmeter", L"DisableDragging", 0);
m_DisableRDP = 0!=parser.ReadInt(L"Rainmeter", L"DisableRDP", 0);
m_DisableDragging = parser.ReadBool(L"Rainmeter", L"DisableDragging", false);
m_DisableRDP = parser.ReadBool(L"Rainmeter", L"DisableRDP", false);
m_SkinEditor = parser.ReadString(L"Rainmeter", L"ConfigEditor", L"");
if (m_SkinEditor.empty())
@ -1298,7 +1298,7 @@ void Rainmeter::ReadGeneralSettings(const std::wstring& iniFile)
m_TrayExecuteDR = parser.ReadString(L"Rainmeter", L"TrayExecuteDR", L"", false);
m_TrayExecuteDM = parser.ReadString(L"Rainmeter", L"TrayExecuteDM", L"", false);
m_DisableVersionCheck = 0!=parser.ReadInt(L"Rainmeter", L"DisableVersionCheck", 0);
m_DisableVersionCheck = parser.ReadBool(L"Rainmeter", L"DisableVersionCheck", false);
const std::wstring& area = parser.ReadString(L"Rainmeter", L"DesktopWorkArea", L"");
if (!area.empty())
@ -1318,9 +1318,9 @@ void Rainmeter::ReadGeneralSettings(const std::wstring& iniFile)
}
}
m_DesktopWorkAreaType = 0!=parser.ReadInt(L"Rainmeter", L"DesktopWorkAreaType", 0);
m_DesktopWorkAreaType = parser.ReadBool(L"Rainmeter", L"DesktopWorkAreaType", false);
m_NormalStayDesktop = 0!=parser.ReadInt(L"Rainmeter", L"NormalStayDesktop", 1);
m_NormalStayDesktop = parser.ReadBool(L"Rainmeter", L"NormalStayDesktop", true);
for (auto iter = parser.GetSections().cbegin(); iter != parser.GetSections().end(); ++iter)
{

View File

@ -53,7 +53,7 @@ void Section::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_UpdateCounter = m_UpdateDivider = updateDivider;
}
m_DynamicVariables = 0!=parser.ReadInt(section, L"DynamicVariables", 0);
m_DynamicVariables = parser.ReadBool(section, L"DynamicVariables", false);
m_OnUpdateAction = parser.ReadString(section, L"OnUpdateAction", L"", false);

View File

@ -691,7 +691,7 @@ void TintedImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
m_NeedsCrop = (oldCrop.X != m_Crop.X || oldCrop.Y != m_Crop.Y || oldCrop.Width != m_Crop.Width || oldCrop.Height != m_Crop.Height || oldCropMode != m_CropMode);
m_GreyScale = 0!=parser.ReadInt(section, m_OptionArray[OptionIndexGreyscale], 0);
m_GreyScale = parser.ReadBool(section, m_OptionArray[OptionIndexGreyscale], false);
Color tint = parser.ReadColor(section, m_OptionArray[OptionIndexImageTint], Color::White);
int alpha = parser.ReadInt(section, m_OptionArray[OptionIndexImageAlpha], tint.GetAlpha()); // for backwards compatibility
@ -767,7 +767,7 @@ void TintedImage::ReadOptions(ConfigParser& parser, const WCHAR* section, const
m_NeedsTinting = (oldGreyScale != m_GreyScale || !CompareColorMatrix(&oldColorMatrix, m_ColorMatrix));
m_UseExifOrientation = 0!=parser.ReadInt(section, m_OptionArray[OptionIndexUseExifOrientation], 0);
m_UseExifOrientation = parser.ReadBool(section, m_OptionArray[OptionIndexUseExifOrientation], false);
const WCHAR* flip = parser.ReadString(section, m_OptionArray[OptionIndexImageFlip], L"NONE").c_str();
if (_wcsicmp(flip, L"NONE") == 0)

View File

@ -363,7 +363,7 @@ void TrayWindow::ReadOptions(ConfigParser& parser)
m_MeterType = TRAY_METER_TYPE_NONE;
// Read tray settings
m_IconEnabled = 0!=parser.ReadInt(L"Rainmeter", L"TrayIcon", 1);
m_IconEnabled = parser.ReadBool(L"Rainmeter", L"TrayIcon", true);
if (m_IconEnabled)
{
const std::wstring& measureName = parser.ReadString(L"TrayMeasure", L"Measure", L"");