mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Cosmetic changes.
This commit is contained in:
parent
b99b275f44
commit
8867c94482
@ -765,25 +765,24 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue);
|
||||
}
|
||||
|
||||
// Returns 1 if the formula was read successfully, -1 for failure.
|
||||
// Returns true if the formula was read successfully, false for failure.
|
||||
// Pass a pointer to a double.
|
||||
int CConfigParser::ReadFormula(const std::wstring& result, double* resultValue)
|
||||
bool CConfigParser::ReadFormula(const std::wstring& result, double* resultValue)
|
||||
{
|
||||
// Formulas must be surrounded by parenthesis
|
||||
if (result.size() > 0 && result[0] == L'(' && result[result.size() - 1] == L')')
|
||||
{
|
||||
char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.substr(1, result.size() - 2).c_str()).c_str(), resultValue);
|
||||
|
||||
if (errMsg != NULL)
|
||||
{
|
||||
Log(LOG_ERROR, ConvertToWide(errMsg).c_str());
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, const Color& defValue)
|
||||
@ -885,76 +884,58 @@ double CConfigParser::ParseDouble(const std::wstring& string, double defValue, b
|
||||
*/
|
||||
Color CConfigParser::ParseColor(LPCTSTR string)
|
||||
{
|
||||
int R, G, B, A;
|
||||
int R = 255, G = 255, B = 255, A = 255;
|
||||
|
||||
if (wcschr(string, L',') != NULL)
|
||||
if (wcschr(string, L','))
|
||||
{
|
||||
WCHAR* parseSz = _wcsdup(string);
|
||||
WCHAR* token;
|
||||
|
||||
token = wcstok(parseSz, L",");
|
||||
if (token != NULL)
|
||||
if (token)
|
||||
{
|
||||
R = _wtoi(token);
|
||||
R = max(R, 0);
|
||||
R = min(R, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
R = 255;
|
||||
}
|
||||
token = wcstok( NULL, L",");
|
||||
if (token != NULL)
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
G = _wtoi(token);
|
||||
G = max(G, 0);
|
||||
G = min(G, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
G = 255;
|
||||
}
|
||||
token = wcstok( NULL, L",");
|
||||
if (token != NULL)
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
B = _wtoi(token);
|
||||
B = max(B, 0);
|
||||
B = min(B, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
B = 255;
|
||||
}
|
||||
token = wcstok( NULL, L",");
|
||||
if (token != NULL)
|
||||
token = wcstok(NULL, L",");
|
||||
if (token)
|
||||
{
|
||||
A = _wtoi(token);
|
||||
A = max(A, 0);
|
||||
A = min(A, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
A = 255;
|
||||
}
|
||||
free(parseSz);
|
||||
}
|
||||
else
|
||||
{
|
||||
const WCHAR* start = string;
|
||||
|
||||
if (wcsncmp(string, L"0x", 2) == 0)
|
||||
{
|
||||
start = string + 2;
|
||||
string += 2; // skip prefix
|
||||
}
|
||||
|
||||
if (wcslen(string) > 6 && !iswspace(string[6]))
|
||||
size_t len = wcslen(string);
|
||||
if (len >= 8 && !iswspace(string[6]))
|
||||
{
|
||||
swscanf(string, L"%02x%02x%02x%02x", &R, &G, &B, &A);
|
||||
}
|
||||
else
|
||||
else if (len >= 6)
|
||||
{
|
||||
swscanf(string, L"%02x%02x%02x", &R, &G, &B);
|
||||
A = 255; // Opaque
|
||||
}
|
||||
}
|
||||
|
||||
@ -1188,7 +1169,12 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
|
||||
}
|
||||
else
|
||||
{
|
||||
SetValue((*iter), key, value, isVariables);
|
||||
SetValue((*iter), key, value);
|
||||
|
||||
if (isVariables)
|
||||
{
|
||||
m_ListVariables.push_back(lowerKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1212,21 +1198,14 @@ void CConfigParser::ReadIniFile(const std::vector<std::wstring>& iniFileMappings
|
||||
** \param strKey The name of the key.
|
||||
** \param strValue The value for the key.
|
||||
*/
|
||||
void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue, bool isVariables)
|
||||
void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue)
|
||||
{
|
||||
// LogWithArgs(LOG_DEBUG, L"[%s] %s=%s (size: %i)", strSection.c_str(), strKey.c_str(), strValue.c_str(), (int)m_Values.size());
|
||||
|
||||
std::wstring strTmpSection = StrToLower(strSection);
|
||||
std::wstring strTmpKey = StrToLower(strKey);
|
||||
std::wstring strTmp = strSection + L"::";
|
||||
strTmp += strKey;
|
||||
|
||||
if (isVariables)
|
||||
{
|
||||
m_ListVariables.push_back(strTmpKey);
|
||||
}
|
||||
|
||||
strTmpSection += L"::";
|
||||
strTmpSection += strTmpKey;
|
||||
m_Values[strTmpSection] = strValue;
|
||||
m_Values[StrToLower(strTmp)] = strValue;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
@ -67,12 +67,11 @@ public:
|
||||
RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue);
|
||||
std::vector<Gdiplus::REAL> ReadFloats(LPCTSTR section, LPCTSTR key);
|
||||
|
||||
bool ReadFormula(const std::wstring& result, double* resultValue);
|
||||
|
||||
const std::wstring& GetFilename() { return m_Filename; }
|
||||
const std::vector<std::wstring>& GetSections() { return m_Sections; }
|
||||
|
||||
// Returns an int if the formula was read successfully, -1 for failure.
|
||||
int ReadFormula(const std::wstring& result, double* number);
|
||||
|
||||
bool ReplaceVariables(std::wstring& result);
|
||||
bool ReplaceMeasures(std::wstring& result);
|
||||
|
||||
@ -93,7 +92,7 @@ private:
|
||||
CMeasure* GetMeasure(const std::wstring& name);
|
||||
|
||||
void ReadIniFile(const std::vector<std::wstring>& iniFileMappings, const std::wstring& strFileName, LPCTSTR config = NULL, int depth = 0);
|
||||
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue, bool isVariables);
|
||||
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue);
|
||||
const std::wstring& GetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strDefault);
|
||||
|
||||
void SetAutoSelectedMonitorVariables(CMeterWindow* meterWindow);
|
||||
|
@ -302,7 +302,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
|
||||
double val;
|
||||
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && -1 != parser.ReadFormula(coord, &val))
|
||||
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ReadFormula(coord, &val))
|
||||
{
|
||||
m_X = (int)val;
|
||||
}
|
||||
@ -341,7 +341,7 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
|
||||
double val;
|
||||
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && -1 != parser.ReadFormula(coord, &val))
|
||||
if (len >= 2 && coord[0] == L'(' && coord[len - 1] == L')' && parser.ReadFormula(coord, &val))
|
||||
{
|
||||
m_Y = (int)val;
|
||||
}
|
||||
|
@ -976,10 +976,9 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
|
||||
std::wstring strVariable(arg, pos - arg);
|
||||
std::wstring strValue(pos + 1);
|
||||
double value;
|
||||
int result = m_Parser.ReadFormula(strValue, &value);
|
||||
|
||||
// Formula read fine
|
||||
if (result != -1)
|
||||
if (m_Parser.ReadFormula(strValue, &value))
|
||||
{
|
||||
WCHAR buffer[256];
|
||||
int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", value);
|
||||
@ -1083,35 +1082,35 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode)
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
type = (m_Parser.ReadFormula(token, &val) == 1) ? (int)val : _wtoi(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) == 1) ? (int)val : _wtoi(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) == 1) ? (int)val : _wtoi(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) == 1) ? (int)val : _wtoi(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) == 1) ? (int)val : _wtoi(token);
|
||||
h = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
}
|
||||
|
||||
if (w && h)
|
||||
@ -1129,7 +1128,7 @@ void CMeterWindow::ResizeBlur(const WCHAR* arg, int mode)
|
||||
if (token)
|
||||
{
|
||||
while (token[0] == L' ') ++token;
|
||||
int r = (m_Parser.ReadFormula(token, &val) == 1) ? (int)val : _wtoi(token);
|
||||
int r = (m_Parser.ReadFormula(token, &val)) ? (int)val : _wtoi(token);
|
||||
tempRegion = CreateRoundRectRgn(x, y, w, h, r, r);
|
||||
}
|
||||
break;
|
||||
|
@ -1508,7 +1508,7 @@ void RainmeterWriteKeyValueWide(const WCHAR* arg)
|
||||
const std::wstring& strKey = subStrings[1];
|
||||
const std::wstring& strValue = subStrings[2];
|
||||
|
||||
int formula = -1;
|
||||
bool formula = false;
|
||||
BOOL write = 0;
|
||||
|
||||
if (subStrings.size() > 4)
|
||||
@ -1520,7 +1520,7 @@ void RainmeterWriteKeyValueWide(const WCHAR* arg)
|
||||
formula = mw->GetParser().ReadFormula(strValue, &value);
|
||||
|
||||
// Formula read fine
|
||||
if (formula != -1)
|
||||
if (formula)
|
||||
{
|
||||
WCHAR buffer[256];
|
||||
int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", value);
|
||||
@ -1533,7 +1533,7 @@ void RainmeterWriteKeyValueWide(const WCHAR* arg)
|
||||
}
|
||||
}
|
||||
|
||||
if (formula == -1)
|
||||
if (!formula)
|
||||
{
|
||||
write = WritePrivateProfileString(strSection.c_str(), strKey.c_str(), strValue.c_str(), iniWrite.c_str());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user