mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Code tweaks and cleanup.
This commit is contained in:
parent
8e8b7d1268
commit
2835739b12
@ -119,9 +119,9 @@ void CConfigParser::SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* me
|
|||||||
|
|
||||||
SetBuiltInVariable(L"CRLF", L"\n");
|
SetBuiltInVariable(L"CRLF", L"\n");
|
||||||
|
|
||||||
static const std::wstring CURRENTSECTION = L"CURRENTSECTION";
|
const std::wstring CURRENTSECTION = StrToLower(L"CURRENTSECTION");
|
||||||
SetBuiltInVariable(CURRENTSECTION, L"");
|
SetBuiltInVariable(CURRENTSECTION, L"");
|
||||||
m_CurrentSection = &((*m_BuiltInVariables.find(StrToLower(CURRENTSECTION))).second); // shortcut
|
m_CurrentSection = &((*m_BuiltInVariables.find(CURRENTSECTION)).second); // shortcut
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -151,7 +151,17 @@ void CConfigParser::SetVariable(std::unordered_map<std::wstring, std::wstring>&
|
|||||||
{
|
{
|
||||||
// LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)variables.size());
|
// LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)variables.size());
|
||||||
|
|
||||||
variables[StrToLower(strVariable)] = strValue;
|
const std::wstring strTmp = StrToLower(strVariable);
|
||||||
|
|
||||||
|
variables[strTmp] = strValue;
|
||||||
|
}
|
||||||
|
void CConfigParser::SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const WCHAR* strVariable, const WCHAR* strValue)
|
||||||
|
{
|
||||||
|
// LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)variables.size());
|
||||||
|
|
||||||
|
const std::wstring strTmp = StrToLower(strVariable);
|
||||||
|
|
||||||
|
variables[strTmp] = strValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,7 +173,7 @@ void CConfigParser::SetVariable(std::unordered_map<std::wstring, std::wstring>&
|
|||||||
*/
|
*/
|
||||||
bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& strValue)
|
bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& strValue)
|
||||||
{
|
{
|
||||||
std::wstring strTmp = StrToLower(strVariable);
|
const std::wstring strTmp = StrToLower(strVariable);
|
||||||
|
|
||||||
// #1: Built-in variables
|
// #1: Built-in variables
|
||||||
std::unordered_map<std::wstring, std::wstring>::const_iterator iter = m_BuiltInVariables.find(strTmp);
|
std::unordered_map<std::wstring, std::wstring>::const_iterator iter = m_BuiltInVariables.find(strTmp);
|
||||||
@ -645,14 +655,14 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
|
|||||||
{
|
{
|
||||||
if (result.find(L'#') != std::wstring::npos)
|
if (result.find(L'#') != std::wstring::npos)
|
||||||
{
|
{
|
||||||
m_CurrentSection->assign(strSection); // Set temporarily
|
SetCurrentSection(strSection); // Set temporarily
|
||||||
|
|
||||||
if (ReplaceVariables(result))
|
if (ReplaceVariables(result))
|
||||||
{
|
{
|
||||||
m_LastReplaced = true;
|
m_LastReplaced = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_CurrentSection->clear(); // Reset
|
ClearCurrentSection(); // Reset
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1118,7 +1128,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
|
|||||||
// Get all the sections (i.e. different meters)
|
// Get all the sections (i.e. different meters)
|
||||||
std::list<std::wstring> sections;
|
std::list<std::wstring> sections;
|
||||||
std::unordered_set<std::wstring> unique;
|
std::unordered_set<std::wstring> unique;
|
||||||
std::wstring section, sectionKey; // buffer
|
std::wstring key, value; // buffer
|
||||||
|
|
||||||
DWORD itemsSize = MAX_LINE_LENGTH;
|
DWORD itemsSize = MAX_LINE_LENGTH;
|
||||||
WCHAR* items = new WCHAR[itemsSize];
|
WCHAR* items = new WCHAR[itemsSize];
|
||||||
@ -1156,17 +1166,17 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
|
|||||||
{
|
{
|
||||||
if (*pos)
|
if (*pos)
|
||||||
{
|
{
|
||||||
section = pos;
|
value = pos; // section name
|
||||||
StrToLowerC(sectionKey.assign(section));
|
StrToLowerC(key.assign(value));
|
||||||
if (unique.insert(sectionKey).second)
|
if (unique.insert(key).second)
|
||||||
{
|
{
|
||||||
if (m_FoundSections.insert(sectionKey).second)
|
if (m_FoundSections.insert(key).second)
|
||||||
{
|
{
|
||||||
m_Sections.push_back(section);
|
m_Sections.push_back(value);
|
||||||
}
|
}
|
||||||
sections.push_back(section);
|
sections.push_back(value);
|
||||||
}
|
}
|
||||||
pos += section.size() + 1;
|
pos += value.size() + 1;
|
||||||
}
|
}
|
||||||
else // Empty string
|
else // Empty string
|
||||||
{
|
{
|
||||||
@ -1191,7 +1201,6 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read the keys and values
|
// Read the keys and values
|
||||||
std::wstring key, value; // buffer
|
|
||||||
std::list<std::wstring>::const_iterator iter = sections.begin();
|
std::list<std::wstring>::const_iterator iter = sections.begin();
|
||||||
for ( ; iter != sections.end(); ++iter)
|
for ( ; iter != sections.end(); ++iter)
|
||||||
{
|
{
|
||||||
@ -1242,22 +1251,26 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
|
|||||||
++sep;
|
++sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
value.assign(sep, clen);
|
|
||||||
if (wcsncmp(key.c_str(), L"@include", 8) == 0)
|
if (wcsncmp(key.c_str(), L"@include", 8) == 0)
|
||||||
{
|
{
|
||||||
ReadVariables();
|
if (clen > 0)
|
||||||
ReplaceVariables(value);
|
|
||||||
if (!CSystem::IsAbsolutePath(value))
|
|
||||||
{
|
{
|
||||||
// It's a relative path so add the current path as a prefix
|
value.assign(sep, clen);
|
||||||
value.insert(0, CRainmeter::ExtractPath(iniFile));
|
ReadVariables();
|
||||||
|
ReplaceVariables(value);
|
||||||
|
if (!CSystem::IsAbsolutePath(value))
|
||||||
|
{
|
||||||
|
// It's a relative path so add the current path as a prefix
|
||||||
|
value.insert(0, CRainmeter::ExtractPath(iniFile));
|
||||||
|
}
|
||||||
|
ReadIniFile(value, config, depth + 1);
|
||||||
}
|
}
|
||||||
ReadIniFile(value, config, depth + 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!isMetadata) // Uncache Metadata's key-value pair in the skin
|
if (!isMetadata) // Uncache Metadata's key-value pair in the skin
|
||||||
{
|
{
|
||||||
|
value.assign(sep, clen);
|
||||||
SetValue((*iter), key, value);
|
SetValue((*iter), key, value);
|
||||||
|
|
||||||
if (isVariables)
|
if (isVariables)
|
||||||
@ -1318,7 +1331,7 @@ void CConfigParser::DeleteValue(const std::wstring& strSection, const std::wstri
|
|||||||
strTmp += L'~';
|
strTmp += L'~';
|
||||||
strTmp += strKey;
|
strTmp += strKey;
|
||||||
|
|
||||||
std::unordered_map<std::wstring, std::wstring>::iterator iter = m_Values.find(StrToLowerC(strTmp));
|
std::unordered_map<std::wstring, std::wstring>::const_iterator iter = m_Values.find(StrToLowerC(strTmp));
|
||||||
if (iter != m_Values.end())
|
if (iter != m_Values.end())
|
||||||
{
|
{
|
||||||
m_Values.erase(iter);
|
m_Values.erase(iter);
|
||||||
|
@ -43,9 +43,13 @@ public:
|
|||||||
void Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterWindow* meterWindow = NULL, LPCTSTR config = NULL);
|
void Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterWindow* meterWindow = NULL, LPCTSTR config = NULL);
|
||||||
void AddMeasure(CMeasure* pMeasure);
|
void AddMeasure(CMeasure* pMeasure);
|
||||||
|
|
||||||
|
bool GetVariable(const std::wstring& strVariable, std::wstring& strValue);
|
||||||
void SetVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_Variables, strVariable, strValue); }
|
void SetVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_Variables, strVariable, strValue); }
|
||||||
void SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); }
|
void SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); }
|
||||||
bool GetVariable(const std::wstring& strVariable, std::wstring& strValue);
|
void SetBuiltInVariable(const WCHAR* strVariable, const WCHAR* strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); }
|
||||||
|
|
||||||
|
void SetCurrentSection(const std::wstring& strSection) { m_CurrentSection->assign(strSection); }
|
||||||
|
void ClearCurrentSection() { m_CurrentSection->clear(); }
|
||||||
|
|
||||||
const std::wstring& GetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strDefault);
|
const std::wstring& GetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strDefault);
|
||||||
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue);
|
void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue);
|
||||||
@ -106,6 +110,7 @@ private:
|
|||||||
void SetAutoSelectedMonitorVariables(CMeterWindow* meterWindow);
|
void SetAutoSelectedMonitorVariables(CMeterWindow* meterWindow);
|
||||||
|
|
||||||
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const std::wstring& strVariable, const std::wstring& strValue);
|
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const std::wstring& strVariable, const std::wstring& strValue);
|
||||||
|
static void SetVariable(std::unordered_map<std::wstring, std::wstring>& variables, const WCHAR* strVariable, const WCHAR* strValue);
|
||||||
|
|
||||||
static void SetMultiMonitorVariables(bool reset);
|
static void SetMultiMonitorVariables(bool reset);
|
||||||
static void SetMonitorVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); }
|
static void SetMonitorVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); }
|
||||||
|
@ -198,16 +198,15 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|||||||
*/
|
*/
|
||||||
bool CMeasure::MakePlainSubstitute(std::wstring& str, size_t index)
|
bool CMeasure::MakePlainSubstitute(std::wstring& str, size_t index)
|
||||||
{
|
{
|
||||||
size_t start = 0;
|
size_t start = 0, pos;
|
||||||
size_t pos = std::wstring::npos;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
pos = str.find(m_Substitute[index].first, start);
|
pos = str.find(m_Substitute[index], start);
|
||||||
if (pos != std::wstring::npos)
|
if (pos != std::wstring::npos)
|
||||||
{
|
{
|
||||||
str.replace(pos, m_Substitute[index].first.length(), m_Substitute[index].second);
|
str.replace(pos, m_Substitute[index].length(), m_Substitute[index + 1]);
|
||||||
start = pos + m_Substitute[index].second.length();
|
start = pos + m_Substitute[index + 1].length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (pos != std::wstring::npos);
|
while (pos != std::wstring::npos);
|
||||||
@ -230,16 +229,16 @@ const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer)
|
|||||||
{
|
{
|
||||||
str = buffer;
|
str = buffer;
|
||||||
|
|
||||||
for (size_t i = 0, isize = m_Substitute.size(); i < isize; ++i)
|
for (size_t i = 0, isize = m_Substitute.size(); i < isize; i += 2)
|
||||||
{
|
{
|
||||||
if (!m_Substitute[i].first.empty())
|
if (!m_Substitute[i].empty())
|
||||||
{
|
{
|
||||||
MakePlainSubstitute(str, i);
|
MakePlainSubstitute(str, i);
|
||||||
}
|
}
|
||||||
else if (str.empty())
|
else if (str.empty())
|
||||||
{
|
{
|
||||||
// Empty result and empty substitute -> use second
|
// Empty result and empty substitute -> use second
|
||||||
str = m_Substitute[i].second;
|
str = m_Substitute[i + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,7 +247,7 @@ const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer)
|
|||||||
std::string utf8str = ConvertToUTF8(buffer);
|
std::string utf8str = ConvertToUTF8(buffer);
|
||||||
int* ovector = new int[OVECCOUNT];
|
int* ovector = new int[OVECCOUNT];
|
||||||
|
|
||||||
for (size_t i = 0, isize = m_Substitute.size() ; i < isize ; ++i)
|
for (size_t i = 0, isize = m_Substitute.size() ; i < isize ; i += 2)
|
||||||
{
|
{
|
||||||
pcre* re;
|
pcre* re;
|
||||||
const char* error;
|
const char* error;
|
||||||
@ -258,7 +257,7 @@ const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer)
|
|||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
re = pcre_compile(
|
re = pcre_compile(
|
||||||
ConvertToUTF8(m_Substitute[i].first.c_str()).c_str(), // the pattern
|
ConvertToUTF8(m_Substitute[i].c_str()).c_str(), // the pattern
|
||||||
flags, // default options
|
flags, // default options
|
||||||
&error, // for error message
|
&error, // for error message
|
||||||
&erroffset, // for error offset
|
&erroffset, // for error offset
|
||||||
@ -289,25 +288,30 @@ const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string result = ConvertToUTF8(m_Substitute[i].second.c_str());
|
std::string result = ConvertToUTF8(m_Substitute[i + 1].c_str());
|
||||||
|
|
||||||
if (rc > 1)
|
if (rc > 1)
|
||||||
{
|
{
|
||||||
for (int j = rc - 1 ; j >= 0 ; --j)
|
for (int j = rc - 1 ; j >= 0 ; --j)
|
||||||
{
|
{
|
||||||
size_t new_start = ovector[2*j];
|
size_t new_start = ovector[2 * j];
|
||||||
size_t in_length = ovector[2*j+1] - ovector[2*j];
|
size_t in_length = ovector[2 * j + 1] - ovector[2 * j];
|
||||||
|
|
||||||
char tmpName[64];
|
char tmpName[64];
|
||||||
_snprintf_s(tmpName, _TRUNCATE, "\\%i", j);
|
_snprintf_s(tmpName, _TRUNCATE, "\\%i", j);
|
||||||
|
|
||||||
size_t cut_length = strlen(tmpName);
|
size_t cut_length = strlen(tmpName);
|
||||||
size_t pos = result.find(tmpName);
|
size_t start = 0, pos;
|
||||||
while (pos != std::string::npos)
|
do
|
||||||
{
|
{
|
||||||
result.replace(pos, cut_length, utf8str, new_start, in_length);
|
pos = result.find(tmpName, start, cut_length);
|
||||||
pos = result.find(tmpName, pos + in_length);
|
if (pos != std::string::npos)
|
||||||
|
{
|
||||||
|
result.replace(pos, cut_length, utf8str, new_start, in_length);
|
||||||
|
start = pos + in_length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (pos != std::string::npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +360,8 @@ bool CMeasure::ParseSubstitute(std::wstring buffer)
|
|||||||
|
|
||||||
if (wcscmp(word1.c_str(), word2.c_str()) != 0)
|
if (wcscmp(word1.c_str(), word2.c_str()) != 0)
|
||||||
{
|
{
|
||||||
m_Substitute.push_back(std::pair<std::wstring, std::wstring>(word1, word2));
|
m_Substitute.push_back(word1);
|
||||||
|
m_Substitute.push_back(word2);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring sep2 = ExtractWord(buffer);
|
std::wstring sep2 = ExtractWord(buffer);
|
||||||
|
@ -105,7 +105,7 @@ protected:
|
|||||||
const std::wstring m_Name; // Name of this Measure
|
const std::wstring m_Name; // Name of this Measure
|
||||||
const std::string m_AsciiName; // Name of this Measure in ANSI
|
const std::string m_AsciiName; // Name of this Measure in ANSI
|
||||||
|
|
||||||
std::vector< std::pair<std::wstring, std::wstring> > m_Substitute; // Vec of substitute strings
|
std::vector<std::wstring> m_Substitute; // Vec of substitute strings
|
||||||
bool m_RegExpSubstitute;
|
bool m_RegExpSubstitute;
|
||||||
|
|
||||||
std::vector<double> m_MedianMaxValues; // The values for the median filtering
|
std::vector<double> m_MedianMaxValues; // The values for the median filtering
|
||||||
|
@ -27,7 +27,14 @@
|
|||||||
|
|
||||||
#define SystemProcessorPerformanceInformation 8
|
#define SystemProcessorPerformanceInformation 8
|
||||||
|
|
||||||
//#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
|
typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
|
||||||
|
LARGE_INTEGER IdleTime;
|
||||||
|
LARGE_INTEGER KernelTime;
|
||||||
|
LARGE_INTEGER UserTime;
|
||||||
|
LARGE_INTEGER Reserved1[2];
|
||||||
|
ULONG Reserved2;
|
||||||
|
} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
|
||||||
|
|
||||||
#define Li2Double(x) ((double)((x).QuadPart))
|
#define Li2Double(x) ((double)((x).QuadPart))
|
||||||
#define Ft2Double(x) ((double)((x).dwHighDateTime) * 4.294967296E9 + (double)((x).dwLowDateTime))
|
#define Ft2Double(x) ((double)((x).dwHighDateTime) * 4.294967296E9 + (double)((x).dwLowDateTime))
|
||||||
|
|
||||||
@ -72,7 +79,7 @@ CMeasureCPU::CMeasureCPU(CMeterWindow* meterWindow, const WCHAR* name) : CMeasur
|
|||||||
}
|
}
|
||||||
if (c_NumOfProcessors == 0)
|
if (c_NumOfProcessors == 0)
|
||||||
{
|
{
|
||||||
SYSTEM_INFO systemInfo = {0};
|
SYSTEM_INFO systemInfo;
|
||||||
GetSystemInfo(&systemInfo);
|
GetSystemInfo(&systemInfo);
|
||||||
c_NumOfProcessors = (int)systemInfo.dwNumberOfProcessors;
|
c_NumOfProcessors = (int)systemInfo.dwNumberOfProcessors;
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,6 @@
|
|||||||
|
|
||||||
#include "Measure.h"
|
#include "Measure.h"
|
||||||
|
|
||||||
typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
|
|
||||||
LARGE_INTEGER IdleTime;
|
|
||||||
LARGE_INTEGER KernelTime;
|
|
||||||
LARGE_INTEGER UserTime;
|
|
||||||
LARGE_INTEGER Reserved1[2];
|
|
||||||
ULONG Reserved2;
|
|
||||||
} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
|
|
||||||
|
|
||||||
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
|
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
|
||||||
|
|
||||||
class CMeasureCPU : public CMeasure
|
class CMeasureCPU : public CMeasure
|
||||||
@ -44,7 +36,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void CalcUsage(double idleTime, double systemTime);
|
void CalcUsage(double idleTime, double systemTime);
|
||||||
void CalcAverageUsage(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* systemPerfInfo);
|
|
||||||
|
|
||||||
bool m_FirstTime;
|
bool m_FirstTime;
|
||||||
|
|
||||||
|
@ -169,30 +169,35 @@ void CMeasureCalc::FormulaReplace()
|
|||||||
//To implement random numbers the word "Random" in the string
|
//To implement random numbers the word "Random" in the string
|
||||||
//formula is being replaced by the random number value
|
//formula is being replaced by the random number value
|
||||||
m_Formula = m_FormulaHolder;
|
m_Formula = m_FormulaHolder;
|
||||||
std::wstring::size_type loc = 0;
|
size_t start = 0, pos;
|
||||||
|
|
||||||
while ((loc = m_Formula.find_first_of(L"Rr", loc)) != std::wstring::npos)
|
do
|
||||||
{
|
{
|
||||||
if (_wcsnicmp(L"Random", m_Formula.c_str() + loc, 6) == 0 &&
|
pos = m_Formula.find_first_of(L"Rr", start);
|
||||||
(loc == 0 || IsDelimiter(*(m_Formula.c_str() + loc - 1))) &&
|
if (pos != std::wstring::npos)
|
||||||
(loc == (m_Formula.length() - 6) || IsDelimiter(*(m_Formula.c_str() + loc + 6))))
|
|
||||||
{
|
{
|
||||||
int range = (m_HighBound - m_LowBound) + 1;
|
if (_wcsnicmp(L"Random", m_Formula.c_str() + pos, 6) == 0 &&
|
||||||
srand((unsigned) rand());
|
(pos == 0 || IsDelimiter(*(m_Formula.c_str() + pos - 1))) &&
|
||||||
int randNumber = m_LowBound + (int)(range * rand()/(RAND_MAX + 1.0));
|
(pos == (m_Formula.length() - 6) || IsDelimiter(*(m_Formula.c_str() + pos + 6))))
|
||||||
|
{
|
||||||
|
int range = (m_HighBound - m_LowBound) + 1;
|
||||||
|
srand((unsigned) rand());
|
||||||
|
int randNumber = m_LowBound + (int)(range * rand() / (RAND_MAX + 1.0));
|
||||||
|
|
||||||
WCHAR buffer[32];
|
WCHAR buffer[32];
|
||||||
_itow_s(randNumber, buffer, 10);
|
_itow_s(randNumber, buffer, 10);
|
||||||
size_t len = wcslen(buffer);
|
size_t len = wcslen(buffer);
|
||||||
|
|
||||||
m_Formula.replace(loc, 6, buffer, len);
|
m_Formula.replace(pos, 6, buffer, len);
|
||||||
loc += len;
|
start = pos + len;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++loc;
|
start = pos + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (pos != std::wstring::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -568,6 +568,7 @@ bool CMeter::Update()
|
|||||||
void CMeter::SetAllMeasures(CMeasure* measure)
|
void CMeter::SetAllMeasures(CMeasure* measure)
|
||||||
{
|
{
|
||||||
m_AllMeasures.clear();
|
m_AllMeasures.clear();
|
||||||
|
m_AllMeasures.reserve(2);
|
||||||
m_AllMeasures.push_back(m_Measure);
|
m_AllMeasures.push_back(m_Measure);
|
||||||
m_AllMeasures.push_back(measure);
|
m_AllMeasures.push_back(measure);
|
||||||
}
|
}
|
||||||
@ -580,6 +581,7 @@ void CMeter::SetAllMeasures(CMeasure* measure)
|
|||||||
void CMeter::SetAllMeasures(const std::vector<CMeasure*>& measures)
|
void CMeter::SetAllMeasures(const std::vector<CMeasure*>& measures)
|
||||||
{
|
{
|
||||||
m_AllMeasures.clear();
|
m_AllMeasures.clear();
|
||||||
|
m_AllMeasures.reserve(1 + measures.size());
|
||||||
m_AllMeasures.push_back(m_Measure);
|
m_AllMeasures.push_back(m_Measure);
|
||||||
|
|
||||||
std::vector<CMeasure*>::const_iterator i = measures.begin();
|
std::vector<CMeasure*>::const_iterator i = measures.begin();
|
||||||
@ -635,15 +637,14 @@ bool CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std:
|
|||||||
{
|
{
|
||||||
_snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i);
|
_snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i);
|
||||||
|
|
||||||
size_t start = 0;
|
size_t len = wcslen(buffer);
|
||||||
size_t pos = std::wstring::npos;
|
size_t start = 0, pos;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
pos = str.find(buffer, start);
|
pos = str.find(buffer, start, len);
|
||||||
if (pos != std::wstring::npos)
|
if (pos != std::wstring::npos)
|
||||||
{
|
{
|
||||||
str.replace(pos, wcslen(buffer), stringValues[i - 1]);
|
str.replace(pos, len, stringValues[i - 1]);
|
||||||
start = pos + stringValues[i - 1].length();
|
start = pos + stringValues[i - 1].length();
|
||||||
replaced = true;
|
replaced = true;
|
||||||
}
|
}
|
||||||
|
@ -316,10 +316,17 @@ std::vector<std::wstring> CRainmeter::ParseString(LPCTSTR str)
|
|||||||
arg.erase(0, pos + 1);
|
arg.erase(0, pos + 1);
|
||||||
|
|
||||||
// Strip quotes
|
// Strip quotes
|
||||||
while ((pos = newStr.find(L'"')) != std::wstring::npos)
|
size_t start = 0;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
newStr.erase(pos, 1);
|
pos = newStr.find(L'"', start);
|
||||||
|
if (pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
newStr.erase(pos, 1);
|
||||||
|
start = pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (pos != std::wstring::npos);
|
||||||
|
|
||||||
result.push_back(newStr);
|
result.push_back(newStr);
|
||||||
}
|
}
|
||||||
@ -332,10 +339,17 @@ std::vector<std::wstring> CRainmeter::ParseString(LPCTSTR str)
|
|||||||
if (!arg.empty())
|
if (!arg.empty())
|
||||||
{
|
{
|
||||||
// Strip quotes
|
// Strip quotes
|
||||||
while ((pos = arg.find(L'"')) != std::wstring::npos)
|
size_t start = 0;
|
||||||
|
do
|
||||||
{
|
{
|
||||||
arg.erase(pos, 1);
|
pos = arg.find(L'"', start);
|
||||||
|
if (pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
arg.erase(pos, 1);
|
||||||
|
start = pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (pos != std::wstring::npos);
|
||||||
|
|
||||||
result.push_back(arg);
|
result.push_back(arg);
|
||||||
}
|
}
|
||||||
@ -1557,7 +1571,7 @@ int CRainmeter::ScanForConfigsRecursive(const std::wstring& path, std::wstring b
|
|||||||
CONFIGMENU menuItem;
|
CONFIGMENU menuItem;
|
||||||
menuItem.name = filename;
|
menuItem.name = filename;
|
||||||
menuItem.index = m_ConfigStrings.size();
|
menuItem.index = m_ConfigStrings.size();
|
||||||
menu.push_back(menuItem);
|
menu.push_back(std::move(menuItem));
|
||||||
|
|
||||||
config.iniFiles.push_back(filename);
|
config.iniFiles.push_back(filename);
|
||||||
++index;
|
++index;
|
||||||
@ -1570,7 +1584,7 @@ int CRainmeter::ScanForConfigsRecursive(const std::wstring& path, std::wstring b
|
|||||||
|
|
||||||
if (!config.iniFiles.empty())
|
if (!config.iniFiles.empty())
|
||||||
{
|
{
|
||||||
m_ConfigStrings.push_back(config);
|
m_ConfigStrings.push_back(std::move(config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1587,7 +1601,7 @@ int CRainmeter::ScanForConfigsRecursive(const std::wstring& path, std::wstring b
|
|||||||
CONFIGMENU menuItem;
|
CONFIGMENU menuItem;
|
||||||
menuItem.name = (*iter);
|
menuItem.name = (*iter);
|
||||||
menuItem.index = -1;
|
menuItem.index = -1;
|
||||||
menu.push_back(menuItem);
|
menu.push_back(std::move(menuItem));
|
||||||
|
|
||||||
if (!DontRecurse)
|
if (!DontRecurse)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,26 @@ public:
|
|||||||
std::vector<std::wstring> iniFiles;
|
std::vector<std::wstring> iniFiles;
|
||||||
UINT commandBase;
|
UINT commandBase;
|
||||||
int active;
|
int active;
|
||||||
|
|
||||||
|
CONFIG() {}
|
||||||
|
~CONFIG() {}
|
||||||
|
|
||||||
|
CONFIG(CONFIG&& r) :
|
||||||
|
config(std::move(r.config)),
|
||||||
|
iniFiles(std::move(r.iniFiles)),
|
||||||
|
commandBase(r.commandBase),
|
||||||
|
active(r.active)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG& operator=(CONFIG&& r)
|
||||||
|
{
|
||||||
|
config = std::move(r.config);
|
||||||
|
iniFiles = std::move(r.iniFiles);
|
||||||
|
commandBase = r.commandBase;
|
||||||
|
active = r.active;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CONFIGMENU
|
struct CONFIGMENU
|
||||||
@ -64,6 +84,24 @@ public:
|
|||||||
std::wstring name;
|
std::wstring name;
|
||||||
size_t index;
|
size_t index;
|
||||||
std::vector<CONFIGMENU> children;
|
std::vector<CONFIGMENU> children;
|
||||||
|
|
||||||
|
CONFIGMENU() {}
|
||||||
|
~CONFIGMENU() {}
|
||||||
|
|
||||||
|
CONFIGMENU(CONFIGMENU&& r) :
|
||||||
|
name(std::move(r.name)),
|
||||||
|
index(r.index),
|
||||||
|
children(std::move(r.children))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIGMENU& operator=(CONFIGMENU&& r)
|
||||||
|
{
|
||||||
|
name = std::move(r.name);
|
||||||
|
index = r.index;
|
||||||
|
children = std::move(r.children);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LOG_INFO
|
struct LOG_INFO
|
||||||
|
@ -25,10 +25,9 @@ static int Measure_GetOption(lua_State* L)
|
|||||||
{
|
{
|
||||||
if (strTmp.find(L'#') != std::wstring::npos)
|
if (strTmp.find(L'#') != std::wstring::npos)
|
||||||
{
|
{
|
||||||
static const std::wstring CURRENTSECTION = L"CURRENTSECTION";
|
parser.SetCurrentSection(self->GetOriginalName()); // Set temporarily
|
||||||
parser.SetBuiltInVariable(CURRENTSECTION, self->GetOriginalName()); // Set temporarily
|
|
||||||
parser.ReplaceVariables(strTmp);
|
parser.ReplaceVariables(strTmp);
|
||||||
parser.SetBuiltInVariable(CURRENTSECTION, L""); // Reset
|
parser.ClearCurrentSection(); // Reset
|
||||||
}
|
}
|
||||||
parser.ReplaceMeasures(strTmp);
|
parser.ReplaceMeasures(strTmp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user