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,15 +633,22 @@ 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)
SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily
if (ReplaceVariables(result))
{ {
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)) 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,27 +934,30 @@ 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)
{ {
A = _wtoi(token); A = _wtoi(token);
A = max(A, 0); A = max(A, 0);
A = min(A, 255); A = min(A, 255);
}
}
}
} }
free(parseSz); 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) 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,34 +1116,34 @@ 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)
{ {
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,26 +597,30 @@ 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);
} }