mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
- Added magic sequence """ to escape quotes in bang. Used as follows:
!SetOption StringMeter Text """This is a "quoted" string""" - Minor tweaks
This commit is contained in:
parent
df23df5baf
commit
b6feabdfc8
@ -53,54 +53,67 @@ std::vector<std::wstring> CRainmeter::ParseString(LPCTSTR str)
|
|||||||
// Split the argument between first space.
|
// Split the argument between first space.
|
||||||
// Or if string is in quotes, the after the second quote.
|
// Or if string is in quotes, the after the second quote.
|
||||||
|
|
||||||
size_t quotePos = arg.find(L"\"");
|
size_t pos;
|
||||||
size_t spacePos = arg.find(L" ");
|
std::wstring newStr;
|
||||||
while (quotePos != std::wstring::npos || spacePos != std::wstring::npos)
|
while ((pos = arg.find_first_not_of(L' ')) != std::wstring::npos)
|
||||||
{
|
{
|
||||||
size_t endPos = 0;
|
if (arg[pos] == L'"')
|
||||||
|
|
||||||
if (quotePos == 0)
|
|
||||||
{
|
{
|
||||||
arg.erase(0, 1); // Eat the quote
|
if (arg[pos + 1] == L'"' && arg[pos + 2] == L'"')
|
||||||
|
{
|
||||||
|
// Eat found quotes and finding ending """
|
||||||
|
arg.erase(0, pos + 3);
|
||||||
|
pos = arg.find(L"\"\"\" ");
|
||||||
|
|
||||||
// Find the second quote
|
if (pos != std::wstring::npos)
|
||||||
quotePos = arg.find(L"\"");
|
{
|
||||||
endPos = quotePos;
|
newStr.assign(arg, 0, pos);
|
||||||
|
arg.erase(0, pos + 4);
|
||||||
|
|
||||||
|
result.push_back(newStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip stripping quotes
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Eat found quote and find ending quote
|
||||||
|
arg.erase(0, pos + 1);
|
||||||
|
pos = arg.find_first_of(L"\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (spacePos == std::wstring::npos) spacePos = arg.size() - 1;
|
if (pos > 0)
|
||||||
|
{
|
||||||
|
// Eat everything until non-space (and non-quote) char
|
||||||
|
arg.erase(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
endPos = spacePos;
|
// Find the second quote
|
||||||
|
pos = arg.find_first_of(L' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring newStr = arg.substr(0, endPos);
|
if (pos != std::wstring::npos)
|
||||||
arg.erase(0, endPos + 1);
|
|
||||||
|
|
||||||
if (newStr.size() > 0 || quotePos == 0)
|
|
||||||
{
|
{
|
||||||
|
newStr.assign(arg, 0, pos);
|
||||||
|
arg.erase(0, pos + 1);
|
||||||
|
|
||||||
|
// Strip quotes
|
||||||
|
while ((pos = newStr.find(L"\"")) != std::wstring::npos)
|
||||||
|
{
|
||||||
|
newStr.erase(pos, 1);
|
||||||
|
}
|
||||||
|
|
||||||
result.push_back(newStr);
|
result.push_back(newStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
quotePos = arg.find(L"\"");
|
|
||||||
spacePos = arg.find(L" ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.size() > 0)
|
if (arg.size() > 0)
|
||||||
{
|
{
|
||||||
result.push_back(arg);
|
result.push_back(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip the quotes from all strings
|
|
||||||
for (size_t i = 0, isize = result.size(); i < isize; ++i)
|
|
||||||
{
|
|
||||||
size_t pos = result[i].find(L"\"");
|
|
||||||
while (pos != std::wstring::npos)
|
|
||||||
{
|
|
||||||
result[i].erase(pos, 1);
|
|
||||||
pos = result[i].find(L"\"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -3132,6 +3145,16 @@ BOOL CRainmeter::ExecuteBang(const std::wstring& bang, const std::wstring& arg,
|
|||||||
ExecuteCommand(command.c_str(), meterWindow);
|
ExecuteCommand(command.c_str(), meterWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (arg[i] == L'"' && arg[i + 1] == L'"' && arg[i + 2] == L'"')
|
||||||
|
{
|
||||||
|
i += 3;
|
||||||
|
|
||||||
|
std::wstring::size_type pos = arg.find(L"\"\"\"", i);
|
||||||
|
if (pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
i = pos + 2; // Skip "", loop will skip last "
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3228,51 +3251,18 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
|
|||||||
|
|
||||||
if (!strCommand.empty())
|
if (!strCommand.empty())
|
||||||
{
|
{
|
||||||
// Check for built-ins
|
const WCHAR* command = strCommand.c_str();
|
||||||
if (_wcsnicmp(L"PLAY ", strCommand.c_str(), 5) == 0 ||
|
|
||||||
_wcsnicmp(L"PLAYLOOP ", strCommand.c_str(), 9) == 0)
|
|
||||||
{
|
|
||||||
// Strip built-in command
|
|
||||||
size_t pos = strCommand.find(L' ');
|
|
||||||
strCommand.erase(0, pos + 1);
|
|
||||||
|
|
||||||
if (!strCommand.empty())
|
if (command[0] == L'!' && Rainmeter->GetDummyLitestep()) // Bangs
|
||||||
{
|
|
||||||
DWORD flags = SND_FILENAME | SND_ASYNC;
|
|
||||||
if (pos == 8) // PLAYLOOP
|
|
||||||
{
|
|
||||||
flags |= SND_LOOP | SND_NODEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Strip the quotes
|
|
||||||
std::wstring::size_type len = strCommand.length();
|
|
||||||
if (len >= 2 && strCommand[0] == L'\"' && strCommand[len - 1] == L'\"')
|
|
||||||
{
|
|
||||||
len -= 2;
|
|
||||||
strCommand.assign(strCommand, 1, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
PlaySound(strCommand.c_str(), NULL, flags);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (_wcsnicmp(L"PLAYSTOP", strCommand.c_str(), 8) == 0)
|
|
||||||
{
|
|
||||||
PlaySound(NULL, NULL, SND_PURGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the command
|
|
||||||
if (strCommand.c_str()[0] == L'!' && Rainmeter->GetDummyLitestep())
|
|
||||||
{
|
{
|
||||||
if (meterWindow)
|
if (meterWindow)
|
||||||
{
|
{
|
||||||
// Fake WM_COPY to deliver bangs
|
// Fake WM_COPYDATA to deliver bangs
|
||||||
COPYDATASTRUCT CopyDataStruct;
|
COPYDATASTRUCT cds;
|
||||||
CopyDataStruct.cbData = (DWORD)((wcslen(command) + 1) * sizeof(WCHAR));
|
cds.cbData = (DWORD)((wcslen(command) + 1) * sizeof(WCHAR));
|
||||||
CopyDataStruct.dwData = 1;
|
cds.dwData = 1;
|
||||||
CopyDataStruct.lpData = (void*)strCommand.c_str();
|
cds.lpData = (void*)command;
|
||||||
meterWindow->OnCopyData(WM_COPYDATA, NULL, (LPARAM)&CopyDataStruct);
|
meterWindow->OnCopyData(WM_COPYDATA, NULL, (LPARAM)&cds);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3291,10 +3281,45 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
|
|||||||
ExecuteBang(bang, arg, meterWindow);
|
ExecuteBang(bang, arg, meterWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (_wcsnicmp(L"PLAY", command, 4) == 0)
|
||||||
{
|
{
|
||||||
// This can run bangs also
|
command += 4; // Skip PLAY
|
||||||
LSExecute(NULL, strCommand.c_str(), SW_SHOWNORMAL);
|
if (_wcsnicmp(L"STOP", command, 4) == 0)
|
||||||
|
{
|
||||||
|
PlaySound(NULL, NULL, SND_PURGE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DWORD flags = SND_FILENAME | SND_ASYNC;
|
||||||
|
|
||||||
|
if (_wcsnicmp(L"LOOP", command, 4) == 0)
|
||||||
|
{
|
||||||
|
flags |= SND_LOOP | SND_NODEFAULT;
|
||||||
|
command += 4; // Skip LOOP
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command[1] == L' ')
|
||||||
|
{
|
||||||
|
command += 1; // Skip the space
|
||||||
|
strCommand = command;
|
||||||
|
if (!strCommand.empty())
|
||||||
|
{
|
||||||
|
// Strip the quotes
|
||||||
|
std::wstring::size_type len = strCommand.length();
|
||||||
|
if (len >= 2 && strCommand[0] == L'\"' && strCommand[len - 1] == L'\"')
|
||||||
|
{
|
||||||
|
len -= 2;
|
||||||
|
strCommand.assign(strCommand, 1, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlaySound(strCommand.c_str(), NULL, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // Run command
|
||||||
|
{
|
||||||
|
LSExecute(NULL, command, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user