Minor tweaks.

This commit is contained in:
spx 2011-11-24 00:30:56 +00:00
parent 2c5d592cd8
commit 02f2d51b41
5 changed files with 122 additions and 95 deletions

View File

@ -633,7 +633,9 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
{ {
m_LastValueDefined = true; m_LastValueDefined = true;
const std::wstring CURRENTSECTION = L"CURRENTSECTION"; if (result.find(L'#') != std::wstring::npos)
{
static const std::wstring CURRENTSECTION = L"CURRENTSECTION";
SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily
if (ReplaceVariables(result)) if (ReplaceVariables(result))
@ -642,6 +644,11 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
} }
SetBuiltInVariable(CURRENTSECTION, L""); // Reset SetBuiltInVariable(CURRENTSECTION, L""); // Reset
}
else
{
CRainmeter::ExpandEnvironmentVariables(result);
}
if (bReplaceMeasures && ReplaceMeasures(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""); 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. ** hex-value.
** **
*/ */
Color CConfigParser::ParseColor(LPCTSTR string) ARGB CConfigParser::ParseColor(LPCTSTR string)
{ {
int R = 255, G = 255, B = 255, A = 255; int R = 255, G = 255, B = 255, A = 255;
@ -918,21 +934,21 @@ Color CConfigParser::ParseColor(LPCTSTR string)
R = _wtoi(token); R = _wtoi(token);
R = max(R, 0); R = max(R, 0);
R = min(R, 255); R = min(R, 255);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
G = _wtoi(token); G = _wtoi(token);
G = max(G, 0); G = max(G, 0);
G = min(G, 255); G = min(G, 255);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
B = _wtoi(token); B = _wtoi(token);
B = max(B, 0); B = max(B, 0);
B = min(B, 255); B = min(B, 255);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
@ -940,6 +956,9 @@ Color CConfigParser::ParseColor(LPCTSTR string)
A = max(A, 0); A = max(A, 0);
A = min(A, 255); A = min(A, 255);
} }
}
}
}
free(parseSz); free(parseSz);
} }
else else
@ -960,7 +979,7 @@ Color CConfigParser::ParseColor(LPCTSTR string)
} }
} }
return Color(A, R, G, B); return Color::MakeARGB(A, R, G, B);
} }
/* /*
@ -981,22 +1000,25 @@ void ParseInt4(LPCTSTR string, T& v1, T& v2, T& v3, T& v4)
if (token) if (token)
{ {
v1 = _wtoi(token); v1 = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
v2 = _wtoi(token); v2 = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
v3 = _wtoi(token); v3 = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
v4 = _wtoi(token); v4 = _wtoi(token);
} }
}
}
}
free(parseSz); free(parseSz);
} }
} }

View File

@ -85,7 +85,7 @@ public:
static std::vector<std::wstring> Tokenize(const std::wstring& str, const std::wstring& delimiters); static std::vector<std::wstring> Tokenize(const std::wstring& str, const std::wstring& delimiters);
static void Shrink(std::vector<std::wstring>& vec); static void Shrink(std::vector<std::wstring>& vec);
static double ParseDouble(const std::wstring& string, double defValue, bool rejectExp = false); 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 Gdiplus::Rect ParseRect(LPCTSTR string);
static RECT ParseRECT(LPCTSTR string); static RECT ParseRECT(LPCTSTR string);

View File

@ -1116,28 +1116,24 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode)
{ {
while (token[0] == L' ') ++token; while (token[0] == L' ') ++token;
type = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); type = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++token; while (token[0] == L' ') ++token;
x = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); x = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++token; while (token[0] == L' ') ++token;
y = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); y = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
while (token[0] == L' ') ++token; while (token[0] == L' ') ++token;
w = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); w = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
@ -1145,6 +1141,10 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode)
while (token[0] == L' ') ++token; while (token[0] == L' ') ++token;
h = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token); h = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
} }
}
}
}
}
if (w && h) if (w && h)
{ {

View File

@ -3182,16 +3182,17 @@ void CRainmeter::ExpandEnvironmentVariables(std::wstring& strPath)
HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer); HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
std::wstring path = buffer; size_t len = wcslen(buffer);
do 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 // Expand the environment variables
do do

View File

@ -597,27 +597,31 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (token) if (token)
{ {
m_Crop.X = _wtoi(token); m_Crop.X = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_Crop.Y = _wtoi(token); m_Crop.Y = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_Crop.Width = _wtoi(token); m_Crop.Width = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_Crop.Height = _wtoi(token); m_Crop.Height = _wtoi(token);
}
token = wcstok(NULL, L","); token = wcstok(NULL, L",");
if (token) if (token)
{ {
m_CropMode = (CROPMODE)_wtoi(token); m_CropMode = (CROPMODE)_wtoi(token);
} }
}
}
}
}
free(parseSz); free(parseSz);
} }