From 02f2d51b4140c786ca4cef39a5afd4fd27c86203 Mon Sep 17 00:00:00 2001 From: spx Date: Thu, 24 Nov 2011 00:30:56 +0000 Subject: [PATCH] Minor tweaks. --- Library/ConfigParser.cpp | 114 +++++++++++++++++++++++---------------- Library/ConfigParser.h | 2 +- Library/MeterWindow.cpp | 48 ++++++++--------- Library/Rainmeter.cpp | 9 ++-- Library/TintedImage.cpp | 44 ++++++++------- 5 files changed, 122 insertions(+), 95 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 021d142d..4f1b3fe3 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -633,15 +633,22 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT { m_LastValueDefined = true; - const std::wstring CURRENTSECTION = L"CURRENTSECTION"; - SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily - - if (ReplaceVariables(result)) + if (result.find(L'#') != std::wstring::npos) { - m_LastReplaced = true; - } + static const std::wstring CURRENTSECTION = L"CURRENTSECTION"; + SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily - SetBuiltInVariable(CURRENTSECTION, L""); // Reset + if (ReplaceVariables(result)) + { + m_LastReplaced = true; + } + + SetBuiltInVariable(CURRENTSECTION, L""); // Reset + } + else + { + CRainmeter::ExpandEnvironmentVariables(result); + } if (bReplaceMeasures && ReplaceMeasures(result)) { @@ -791,7 +798,16 @@ RECT CConfigParser::ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue) { const std::wstring& result = ReadString(section, key, L""); - return (m_LastDefaultUsed) ? defValue : ParseRECT(result.c_str()); + RECT r; + if (m_LastDefaultUsed) + { + r = defValue; + } + else + { + r = ParseRECT(result.c_str()); + } + return r; } /* @@ -903,7 +919,7 @@ double CConfigParser::ParseDouble(const std::wstring& string, double defValue, b ** hex-value. ** */ -Color CConfigParser::ParseColor(LPCTSTR string) +ARGB CConfigParser::ParseColor(LPCTSTR string) { int R = 255, G = 255, B = 255, A = 255; @@ -918,27 +934,30 @@ Color CConfigParser::ParseColor(LPCTSTR string) R = _wtoi(token); R = max(R, 0); R = min(R, 255); - } - token = wcstok(NULL, L","); - if (token) - { - G = _wtoi(token); - G = max(G, 0); - G = min(G, 255); - } - token = wcstok(NULL, L","); - if (token) - { - B = _wtoi(token); - B = max(B, 0); - B = min(B, 255); - } - token = wcstok(NULL, L","); - if (token) - { - A = _wtoi(token); - A = max(A, 0); - A = min(A, 255); + + token = wcstok(NULL, L","); + if (token) + { + G = _wtoi(token); + G = max(G, 0); + G = min(G, 255); + + token = wcstok(NULL, L","); + if (token) + { + B = _wtoi(token); + B = max(B, 0); + B = min(B, 255); + + token = wcstok(NULL, L","); + if (token) + { + A = _wtoi(token); + A = max(A, 0); + A = min(A, 255); + } + } + } } free(parseSz); } @@ -960,7 +979,7 @@ Color CConfigParser::ParseColor(LPCTSTR string) } } - return Color(A, R, G, B); + return Color::MakeARGB(A, R, G, B); } /* @@ -981,21 +1000,24 @@ void ParseInt4(LPCTSTR string, T& v1, T& v2, T& v3, T& v4) if (token) { v1 = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - v2 = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - v3 = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - v4 = _wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + v2 = _wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + v3 = _wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + v4 = _wtoi(token); + } + } + } } free(parseSz); } diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 436eae87..c94eeb79 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -85,7 +85,7 @@ public: static std::vector Tokenize(const std::wstring& str, const std::wstring& delimiters); static void Shrink(std::vector& vec); static double ParseDouble(const std::wstring& string, double defValue, bool rejectExp = false); - static Gdiplus::Color ParseColor(LPCTSTR string); + static Gdiplus::ARGB ParseColor(LPCTSTR string); static Gdiplus::Rect ParseRect(LPCTSTR string); static RECT ParseRECT(LPCTSTR string); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 92c71012..1b4f842c 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1116,34 +1116,34 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode) { while (token[0] == L' ') ++token; type = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - while (token[0] == L' ') ++token; - x = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - } + token = wcstok(NULL, L","); + if (token) + { + while (token[0] == L' ') ++token; + x = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - token = wcstok(NULL, L","); - if (token) - { - while (token[0] == L' ') ++token; - y = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - } + token = wcstok(NULL, L","); + if (token) + { + while (token[0] == L' ') ++token; + y = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - token = wcstok(NULL, L","); - if (token) - { - while (token[0] == L' ') ++token; - w = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - } + token = wcstok(NULL, L","); + if (token) + { + while (token[0] == L' ') ++token; + w = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); - token = wcstok(NULL, L","); - if (token) - { - while (token[0] == L' ') ++token; - h = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + token = wcstok(NULL, L","); + if (token) + { + while (token[0] == L' ') ++token; + h = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); + } + } + } + } } if (w && h) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 2843f804..c3bdbed7 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -3182,16 +3182,17 @@ void CRainmeter::ExpandEnvironmentVariables(std::wstring& strPath) HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer); if (SUCCEEDED(hr)) { - std::wstring path = buffer; + size_t len = wcslen(buffer); do { - strPath.replace(pos, 9, path); + strPath.replace(pos, 9, buffer, len); } - while ((pos = strPath.find(L"%APPDATA%", pos + path.length())) != std::wstring::npos); + while ((pos = strPath.find(L"%APPDATA%", pos + len)) != std::wstring::npos); } } - if (strPath.find(L'%') != std::wstring::npos) + if ((pos = strPath.find(L'%')) != std::wstring::npos && + strPath.find(L'%', pos + 2) != std::wstring::npos) { // Expand the environment variables do diff --git a/Library/TintedImage.cpp b/Library/TintedImage.cpp index 8af30acd..fed708ee 100644 --- a/Library/TintedImage.cpp +++ b/Library/TintedImage.cpp @@ -597,26 +597,30 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section) if (token) { m_Crop.X = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - m_Crop.Y = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - m_Crop.Width = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - m_Crop.Height = _wtoi(token); - } - token = wcstok(NULL, L","); - if (token) - { - m_CropMode = (CROPMODE)_wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + m_Crop.Y = _wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + m_Crop.Width = _wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + m_Crop.Height = _wtoi(token); + + token = wcstok(NULL, L","); + if (token) + { + m_CropMode = (CROPMODE)_wtoi(token); + } + } + } + } } free(parseSz); }