MathParser: Fixed issue with measure names less than 6 chars.

This commit is contained in:
Birunthan Mohanathas
2012-01-27 15:36:46 +00:00
parent 35be827071
commit fd48b9f24a
2 changed files with 7 additions and 162 deletions

View File

@ -94,156 +94,6 @@ void ExecuteBang(LPCTSTR szBang)
}
}
/*
** ReadConfigString
**
** Reads a config string. Used by the plugins.
**
*/
LPCTSTR ReadConfigString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue)
{
if (Rainmeter)
{
CConfigParser* parser = Rainmeter->GetCurrentParser();
if (parser)
{
// NULL checking
if (section == NULL) section = L"";
if (key == NULL) key = L"";
if (defValue == NULL) defValue = L"";
return parser->ReadString(section, key, defValue, false).c_str();
}
}
return NULL;
}
/*
** PluginBridge
**
** Receives a command and data from a plugin and returns a result. Used by plugins.
**
*/
LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
{
if (Rainmeter)
{
static std::wstring result;
if (_sCommand == NULL || *_sCommand == L'\0')
{
return L"noop";
}
if (_sData == NULL) _sData = L"";
// Command GetConfig
// Data unquoted full path and filename given to the plugin on initialize
// (note: this is CaSe-SeNsItIvE!)
// Execution none
// Result the config name if found or a blank string if not
if (_wcsicmp(_sCommand, L"GetConfig") == 0)
{
// returns the config name, lookup by INI file
CMeterWindow *meterWindow = Rainmeter->GetMeterWindowByINI(_sData);
if (meterWindow)
{
result = L'"';
result += meterWindow->GetSkinName();
result += L'"';
return result.c_str();
}
return L"";
}
// Command GetWindow
// Data [the config name]
// Execution none
// Result the HWND to the specified config window if found, 'error' otherwise
if (_wcsicmp(_sCommand, L"GetWindow") == 0)
{
std::vector<std::wstring> subStrings = CRainmeter::ParseString(_sData);
if (subStrings.size() >= 1)
{
const std::wstring& config = subStrings[0];
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
if (meterWindow)
{
WCHAR buf1[64];
_snwprintf_s(buf1, _TRUNCATE, L"%lu", PtrToUlong(meterWindow->GetWindow()));
result = buf1;
return result.c_str();
}
}
return L"error";
}
// Command GetVariable
// Data [the config name]
// Execution none
// Result the value of the variable
if (_wcsicmp(_sCommand, L"GetVariable") == 0)
{
std::vector<std::wstring> subStrings = CRainmeter::ParseString(_sData);
if (subStrings.size() >= 2)
{
const std::wstring& config = subStrings[0];
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
if (meterWindow)
{
const std::wstring& variable = subStrings[1];
if (meterWindow->GetParser().GetVariable(variable, result))
{
return result.c_str();
}
}
}
return L"";
}
// Command SetVariable
// Data [the config name] [variable data]
// Execution the indicated variable is updated
// Result 'success' if the config was found, 'error' otherwise
if (_wcsicmp(_sCommand, L"SetVariable") == 0)
{
std::vector<std::wstring> subStrings = CRainmeter::ParseString(_sData);
if (subStrings.size() >= 2)
{
const std::wstring& config = subStrings[0];
std::wstring arguments;
for (size_t i = 1, isize = subStrings.size(); i < isize; ++i)
{
if (i != 1) arguments += L' ';
arguments += subStrings[i];
}
CMeterWindow *meterWindow = Rainmeter->GetMeterWindow(config);
if (meterWindow)
{
meterWindow->RunBang(BANG_SETVARIABLE, arguments.c_str());
return L"success";
}
}
return L"error";
}
return L"noop";
}
return L"error:no rainmeter!";
}
/*
** ParseString
**
@ -1369,11 +1219,6 @@ CMeterWindow* CRainmeter::GetMeterWindow(const std::wstring& config)
return NULL;
}
// Added by Peter Souza IV / psouza4 / 2010.12.13
//
// Returns a CMeterWindow object given a config's INI path and filename. Since plugins
// get the full path and filename of an INI file on Initialize(), but not the name of
// the config, this is used to convert the INI filename to a config name.
CMeterWindow* CRainmeter::GetMeterWindowByINI(const std::wstring& ini_searching)
{
if (_wcsnicmp(m_SkinPath.c_str(), ini_searching.c_str(), m_SkinPath.length()) == 0)