Code tweaks and cleanup.

This commit is contained in:
spx 2011-12-04 22:18:40 +00:00
parent 320c2d7c83
commit 8e8b7d1268
22 changed files with 131 additions and 136 deletions

View File

@ -209,7 +209,7 @@ HMODULE RmLoadSystemLibrary(LPCWSTR lpLibFileName)
if (GetSystemDirectory(buffer, MAX_PATH)) if (GetSystemDirectory(buffer, MAX_PATH))
{ {
path = buffer; path = buffer;
path += L"\\"; path += L'\\';
path += lpLibFileName; path += lpLibFileName;
return LoadLibrary(path.c_str()); return LoadLibrary(path.c_str());

View File

@ -89,8 +89,8 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterW
ReadVariables(); ReadVariables();
// Clear and minimize // Clear and minimize
std::unordered_set<std::wstring>().swap(m_FoundSections); m_FoundSections.clear();
std::list<std::wstring>().swap(m_ListVariables); m_ListVariables.clear();
} }
/* /*
@ -756,7 +756,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
error += key; error += key;
error += L"\" in ["; error += L"\" in [";
error += section; error += section;
error += L"]"; error += L']';
Log(LOG_ERROR, error.c_str()); Log(LOG_ERROR, error.c_str());
} }
@ -1117,6 +1117,9 @@ 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::wstring section, sectionKey; // buffer
DWORD itemsSize = MAX_LINE_LENGTH; DWORD itemsSize = MAX_LINE_LENGTH;
WCHAR* items = new WCHAR[itemsSize]; WCHAR* items = new WCHAR[itemsSize];
WCHAR* pos = NULL; WCHAR* pos = NULL;
@ -1153,12 +1156,16 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
{ {
if (*pos) if (*pos)
{ {
std::wstring section = pos; section = pos;
if (m_FoundSections.insert(StrToLower(section)).second) StrToLowerC(sectionKey.assign(section));
if (unique.insert(sectionKey).second)
{
if (m_FoundSections.insert(sectionKey).second)
{ {
m_Sections.push_back(section); m_Sections.push_back(section);
} }
sections.push_back(section); sections.push_back(section);
}
pos += section.size() + 1; pos += section.size() + 1;
} }
else // Empty string else // Empty string
@ -1184,13 +1191,15 @@ 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)
{ {
std::unordered_set<std::wstring> foundKeys; unique.clear();
const WCHAR* sectionName = (*iter).c_str(); const WCHAR* sectionName = (*iter).c_str();
bool isVariables = (_wcsicmp(sectionName, L"Variables") == 0); bool isVariables = (_wcsicmp(sectionName, L"Variables") == 0);
bool isMetadata = (config == NULL && _wcsicmp(sectionName, L"Metadata") == 0); bool isMetadata = (config == NULL && !isVariables && _wcsicmp(sectionName, L"Metadata") == 0);
// Read all "key=value" from the section // Read all "key=value" from the section
do do
@ -1220,21 +1229,20 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
{ {
size_t clen = sep - pos; // key's length size_t clen = sep - pos; // key's length
std::wstring key(pos, clen); StrToLowerC(key.assign(pos, clen));
if (foundKeys.insert(StrToLowerC(key)).second) if (unique.insert(key).second)
{ {
++sep; ++sep;
clen = len - (clen + 1); // value's length clen = len - (clen + 1); // value's length
// Trim surrounded quotes from value // Trim surrounded quotes from value
if (clen >= 2 && (sep[0] == L'\"' || sep[0] == L'\'') && sep[clen - 1] == sep[0]) if (clen >= 2 && (sep[0] == L'"' || sep[0] == L'\'') && sep[clen - 1] == sep[0])
{ {
clen -= 2; clen -= 2;
++sep; ++sep;
} }
std::wstring value(sep, clen); value.assign(sep, clen);
if (wcsncmp(key.c_str(), L"@include", 8) == 0) if (wcsncmp(key.c_str(), L"@include", 8) == 0)
{ {
ReadVariables(); ReadVariables();
@ -1251,7 +1259,6 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
if (!isMetadata) // Uncache Metadata's key-value pair in the skin if (!isMetadata) // Uncache Metadata's key-value pair in the skin
{ {
SetValue((*iter), key, value); SetValue((*iter), key, value);
}
if (isVariables) if (isVariables)
{ {
@ -1260,6 +1267,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
} }
} }
} }
}
pos += len + 1; pos += len + 1;
} }
else // Empty string else // Empty string
@ -1268,6 +1276,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
} }
} }
} }
delete [] items; delete [] items;
if (temporary) CSystem::RemoveFile(iniRead); if (temporary) CSystem::RemoveFile(iniRead);
} }
@ -1284,7 +1293,10 @@ void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring&
{ {
// LogWithArgs(LOG_DEBUG, L"[%s] %s=%s (size: %i)", strSection.c_str(), strKey.c_str(), strValue.c_str(), (int)m_Values.size()); // LogWithArgs(LOG_DEBUG, L"[%s] %s=%s (size: %i)", strSection.c_str(), strKey.c_str(), strValue.c_str(), (int)m_Values.size());
std::wstring strTmp = strSection + L"~"; std::wstring strTmp;
strTmp.reserve(strSection.size() + 1 + strKey.size());
strTmp += strSection;
strTmp += L'~';
strTmp += strKey; strTmp += strKey;
m_Values[StrToLowerC(strTmp)] = strValue; m_Values[StrToLowerC(strTmp)] = strValue;
@ -1300,7 +1312,10 @@ void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring&
*/ */
void CConfigParser::DeleteValue(const std::wstring& strSection, const std::wstring& strKey) void CConfigParser::DeleteValue(const std::wstring& strSection, const std::wstring& strKey)
{ {
std::wstring strTmp = strSection + L"~"; std::wstring strTmp;
strTmp.reserve(strSection.size() + 1 + strKey.size());
strTmp += strSection;
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>::iterator iter = m_Values.find(StrToLowerC(strTmp));
@ -1321,14 +1336,12 @@ void CConfigParser::DeleteValue(const std::wstring& strSection, const std::wstri
*/ */
const std::wstring& CConfigParser::GetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strDefault) const std::wstring& CConfigParser::GetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strDefault)
{ {
std::wstring strTmp = strSection + L"~"; std::wstring strTmp;
strTmp.reserve(strSection.size() + 1 + strKey.size());
strTmp += strSection;
strTmp += L'~';
strTmp += strKey; strTmp += strKey;
std::unordered_map<std::wstring, std::wstring>::const_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()) return (iter != m_Values.end()) ? (*iter).second : strDefault;
{
return (*iter).second;
}
return strDefault;
} }

View File

@ -51,7 +51,7 @@ public:
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);
void DeleteValue(const std::wstring& strSection, const std::wstring& strKey); void DeleteValue(const std::wstring& strSection, const std::wstring& strKey);
void SetStyleTemplate(const std::wstring& strStyle) { Tokenize(strStyle, L"|").swap(m_StyleTemplate); Shrink(m_StyleTemplate); } void SetStyleTemplate(const std::wstring& strStyle) { static const std::wstring delim(1, L'|'); Tokenize(strStyle, delim).swap(m_StyleTemplate); Shrink(m_StyleTemplate); }
void ClearStyleTemplate() { m_StyleTemplate.clear(); } void ClearStyleTemplate() { m_StyleTemplate.clear(); }
const std::wstring& GetLastUsedStyle() { return m_LastUsedStyle; } const std::wstring& GetLastUsedStyle() { return m_LastUsedStyle; }

View File

@ -127,7 +127,7 @@ void CDialogManage::OpenSkin(CMeterWindow* meterWindow)
if (c_Dialog) if (c_Dialog)
{ {
std::wstring name = meterWindow->GetSkinName() + L"\\"; std::wstring name = meterWindow->GetSkinName() + L'\\';
name += meterWindow->GetSkinIniFile(); name += meterWindow->GetSkinIniFile();
HWND item = GetDlgItem(c_Dialog->m_TabSkins.GetWindow(), IDC_MANAGESKINS_SKINS_TREEVIEW); HWND item = GetDlgItem(c_Dialog->m_TabSkins.GetWindow(), IDC_MANAGESKINS_SKINS_TREEVIEW);
@ -165,7 +165,7 @@ std::wstring GetTreeSelectionPath(HWND tree)
while ((tvi.hItem = TreeView_GetParent(tree, tvi.hItem)) != NULL) while ((tvi.hItem = TreeView_GetParent(tree, tvi.hItem)) != NULL)
{ {
TreeView_GetItem(tree, &tvi); TreeView_GetItem(tree, &tvi);
path.insert(0, L"\\"); path.insert(0, 1, L'\\');
path.insert(0, buffer); path.insert(0, buffer);
} }
@ -278,7 +278,7 @@ INT_PTR CDialogManage::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
std::wstring command = Rainmeter->GetConfigEditor() + L" \""; std::wstring command = Rainmeter->GetConfigEditor() + L" \"";
command += Rainmeter->GetIniFile(); command += Rainmeter->GetIniFile();
command += L"\""; command += L'"';
RunCommand(Rainmeter->GetTrayWindow()->GetWindow(), command.c_str(), SW_SHOWNORMAL); RunCommand(Rainmeter->GetTrayWindow()->GetWindow(), command.c_str(), SW_SHOWNORMAL);
} }
break; break;
@ -661,7 +661,7 @@ void CDialogManage::CTabSkins::ReadSkin()
EnableWindow(item, TRUE); EnableWindow(item, TRUE);
std::wstring file = Rainmeter->GetSkinPath() + m_SkinName; std::wstring file = Rainmeter->GetSkinPath() + m_SkinName;
file += L"\\"; file += L'\\';
file += m_FileName; file += m_FileName;
m_SkinWindow = Rainmeter->GetMeterWindowByINI(file); m_SkinWindow = Rainmeter->GetMeterWindowByINI(file);
if (!m_SkinWindow) if (!m_SkinWindow)
@ -869,7 +869,7 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
int index = 0; int index = 0;
for ( ; iter != Rainmeter->GetAllMeterWindows().end(); ++iter) for ( ; iter != Rainmeter->GetAllMeterWindows().end(); ++iter)
{ {
std::wstring name = ((*iter).second)->GetSkinName() + L"\\"; std::wstring name = ((*iter).second)->GetSkinName() + L'\\';
name += ((*iter).second)->GetSkinIniFile(); name += ((*iter).second)->GetSkinIniFile();
InsertMenu(menu, index, MF_BYPOSITION, ID_CONFIG_FIRST + index, name.c_str()); InsertMenu(menu, index, MF_BYPOSITION, ID_CONFIG_FIRST + index, name.c_str());
++index; ++index;
@ -932,13 +932,13 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
case IDC_MANAGESKINS_EDIT_BUTTON: case IDC_MANAGESKINS_EDIT_BUTTON:
{ {
std::wstring command = Rainmeter->GetSkinPath() + m_SkinName; std::wstring command = Rainmeter->GetSkinPath() + m_SkinName;
command += L"\\"; command += L'\\';
command += m_FileName; command += m_FileName;
bool writable = CSystem::IsFileWritable(command.c_str()); bool writable = CSystem::IsFileWritable(command.c_str());
command.insert(0, L" \""); command.insert(0, L" \"");
command.insert(0, Rainmeter->GetConfigEditor()); command.insert(0, Rainmeter->GetConfigEditor());
command += L"\""; command += L'"';
// Execute as admin if in protected location // Execute as admin if in protected location
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL, !writable); RunCommand(NULL, command.c_str(), SW_SHOWNORMAL, !writable);
@ -1125,9 +1125,9 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_CONTEXT_MANAGESKINSMENU_OPENFOLDER: case ID_CONTEXT_MANAGESKINSMENU_OPENFOLDER:
{ {
HWND tree = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); HWND tree = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW);
std::wstring command = L"\"" + Rainmeter->GetSkinPath(); std::wstring command = L'"' + Rainmeter->GetSkinPath();
command += GetTreeSelectionPath(tree); command += GetTreeSelectionPath(tree);
command += L"\""; command += L'"';
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL); RunCommand(NULL, command.c_str(), SW_SHOWNORMAL);
} }
break; break;
@ -1142,7 +1142,7 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
if (i == index) if (i == index)
{ {
std::wstring name = ((*iter).second)->GetSkinName() + L"\\"; std::wstring name = ((*iter).second)->GetSkinName() + L'\\';
name += ((*iter).second)->GetSkinIniFile(); name += ((*iter).second)->GetSkinIniFile();
HWND item = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW); HWND item = GetDlgItem(m_Window, IDC_MANAGESKINS_SKINS_TREEVIEW);
@ -1179,7 +1179,7 @@ INT_PTR CDialogManage::CTabSkins::OnNotify(WPARAM wParam, LPARAM lParam)
if (nm->idFrom == IDC_MANAGESKINS_ADDMETADATA_LINK) if (nm->idFrom == IDC_MANAGESKINS_ADDMETADATA_LINK)
{ {
std::wstring file = Rainmeter->GetSkinPath() + m_SkinName; std::wstring file = Rainmeter->GetSkinPath() + m_SkinName;
file += L"\\"; file += L'\\';
file += m_FileName; file += m_FileName;
WritePrivateProfileString(L"Rainmeter", L"\r\n[Metadata]\r\nName=\r\nInformation=\r\nLicense=\r\nVersion", L"", file.c_str()); WritePrivateProfileString(L"Rainmeter", L"\r\n[Metadata]\r\nName=\r\nInformation=\r\nLicense=\r\nVersion", L"", file.c_str());
SendMessage(m_Window, WM_COMMAND, MAKEWPARAM(IDC_MANAGESKINS_EDIT_BUTTON, 0), 0); SendMessage(m_Window, WM_COMMAND, MAKEWPARAM(IDC_MANAGESKINS_EDIT_BUTTON, 0), 0);
@ -1297,7 +1297,7 @@ INT_PTR CDialogManage::CTabSkins::OnNotify(WPARAM wParam, LPARAM lParam)
while ((tvi.hItem = TreeView_GetParent(nm->hwndFrom, tvi.hItem)) != NULL) while ((tvi.hItem = TreeView_GetParent(nm->hwndFrom, tvi.hItem)) != NULL)
{ {
TreeView_GetItem(nm->hwndFrom, &tvi); TreeView_GetItem(nm->hwndFrom, &tvi);
m_SkinName.insert(0, L"\\"); m_SkinName.insert(0, 1, L'\\');
m_SkinName.insert(0, buffer); m_SkinName.insert(0, buffer);
} }
@ -1596,7 +1596,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
case IDC_MANAGETHEMES_BACKUP_BUTTON: case IDC_MANAGETHEMES_BACKUP_BUTTON:
{ {
std::wstring command = L"\"" + Rainmeter->GetPath(); std::wstring command = L'"' + Rainmeter->GetPath();
command += L"SkinInstaller.exe\" /BACKUP"; command += L"SkinInstaller.exe\" /BACKUP";
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL); RunCommand(NULL, command.c_str(), SW_SHOWNORMAL);
} }

View File

@ -310,7 +310,7 @@ BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
Rainmeter->AddAboutLogInfo(nLevel, buffer, pszMessage); Rainmeter->AddAboutLogInfo(nLevel, buffer, pszMessage);
std::wstring message = L"("; std::wstring message(1, L'(');
message += buffer; message += buffer;
message += L") "; message += L") ";
message += pszMessage; message += pszMessage;
@ -374,7 +374,7 @@ BOOL LogInternal(int nLevel, ULONGLONG elapsed, LPCTSTR pszMessage)
break; break;
} }
message += L"\n"; message += L'\n';
fputws(message.c_str(), logFile); fputws(message.c_str(), logFile);
fclose(logFile); fclose(logFile);
} }

View File

@ -174,12 +174,12 @@ void CMeasure::ReadConfig(CConfigParser& parser, const WCHAR* section)
std::wstring subs = parser.ReadString(section, L"Substitute", L""); std::wstring subs = parser.ReadString(section, L"Substitute", L"");
if (!subs.empty()) if (!subs.empty())
{ {
if ((subs[0] != L'\"' || subs[subs.length() - 1] != L'\'') && if ((subs[0] != L'"' || subs[subs.length() - 1] != L'\'') &&
(subs[0] != L'\'' || subs[subs.length() - 1] != L'\"')) (subs[0] != L'\'' || subs[subs.length() - 1] != L'"'))
{ {
// Add quotes since they are removed by the GetProfileString // Add quotes since they are removed by the GetProfileString
subs.insert(0, L"\""); subs.insert(0, 1, L'"');
subs.append(L"\""); subs += L'"';
} }
if (!ParseSubstitute(subs)) if (!ParseSubstitute(subs))
{ {
@ -394,7 +394,7 @@ std::wstring CMeasure::ExtractWord(std::wstring& buffer)
buffer.erase(0, end); buffer.erase(0, end);
len = buffer.size(); len = buffer.size();
if (buffer[0] == L'\"' || buffer[0] == L'\'') if (buffer[0] == L'"' || buffer[0] == L'\'')
{ {
WCHAR quote = buffer[0]; WCHAR quote = buffer[0];
@ -837,7 +837,7 @@ CMeasure* CMeasure::Create(const WCHAR* measure, CMeterWindow* meterWindow, cons
error += measure; error += measure;
error += L" is not valid in ["; error += L" is not valid in [";
error += name; error += name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
return NULL; return NULL;

View File

@ -86,7 +86,7 @@ bool CMeasureCalc::Update()
error += ConvertToWide(errMsg); error += ConvertToWide(errMsg);
error += L" in ["; error += L" in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
Log(LOG_ERROR, error.c_str()); Log(LOG_ERROR, error.c_str());
} }

View File

@ -211,7 +211,7 @@ void CMeasureDiskSpace::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else if (!CSystem::IsPathSeparator(m_Drive[m_Drive.length() - 1])) // E.g. "C:" else if (!CSystem::IsPathSeparator(m_Drive[m_Drive.length() - 1])) // E.g. "C:"
{ {
m_Drive += L"\\"; // A trailing backslash is required. m_Drive += L'\\'; // A trailing backslash is required.
} }
m_Type = (1 == parser.ReadInt(section, L"Type", 0)); m_Type = (1 == parser.ReadInt(section, L"Type", 0));

View File

@ -105,7 +105,7 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_PluginName = parser.ReadString(section, L"Plugin", L""); m_PluginName = parser.ReadString(section, L"Plugin", L"");
size_t pos = m_PluginName.rfind(L"."); size_t pos = m_PluginName.rfind(L'.');
if (pos == std::wstring::npos) if (pos == std::wstring::npos)
{ {
m_PluginName += L".dll"; m_PluginName += L".dll";

View File

@ -150,7 +150,7 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += keyname; error += keyname;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }

View File

@ -483,7 +483,7 @@ void CMeter::BindMeasure(const std::list<CMeasure*>& measures)
std::wstring error = L"The meter [" + m_Name; std::wstring error = L"The meter [" + m_Name;
error += L"] cannot be bound with ["; error += L"] cannot be bound with [";
error += m_MeasureName; error += m_MeasureName;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
@ -538,7 +538,7 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHA
error += meter; error += meter;
error += L" is not valid in ["; error += L" is not valid in [";
error += name; error += name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
return NULL; return NULL;

View File

@ -134,7 +134,7 @@ void CMeterBar::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += orientation; error += orientation;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }

View File

@ -215,7 +215,7 @@ void CMeterBitmap::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += align; error += align;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }

View File

@ -530,7 +530,7 @@ void CMeterHistogram::BindMeasure(const std::list<CMeasure*>& measures)
std::wstring error = L"The meter [" + m_Name; std::wstring error = L"The meter [" + m_Name;
error += L"] cannot be bound with ["; error += L"] cannot be bound with [";
error += m_SecondaryMeasureName; error += m_SecondaryMeasureName;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
} }

View File

@ -132,7 +132,7 @@ void CMeterImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
{ {
if (!CSystem::IsPathSeparator(m_Path[m_Path.length() - 1])) if (!CSystem::IsPathSeparator(m_Path[m_Path.length() - 1]))
{ {
m_Path += L"\\"; m_Path += L'\\';
} }
} }
@ -389,7 +389,7 @@ void CMeterImage::BindMeasure(const std::list<CMeasure*>& measures)
std::wstring error = L"The meter [" + m_Name; std::wstring error = L"The meter [" + m_Name;
error += L"] cannot be bound with ["; error += L"] cannot be bound with [";
error += (*j); error += (*j);
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
} }

View File

@ -378,7 +378,7 @@ void CMeterLine::BindMeasure(const std::list<CMeasure*>& measures)
std::wstring error = L"The meter [" + m_Name; std::wstring error = L"The meter [" + m_Name;
error += L"] cannot be bound with ["; error += L"] cannot be bound with [";
error += (*j); error += (*j);
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
} }

View File

@ -246,7 +246,7 @@ void CMeterString::Initialize()
REAL size = (REAL)m_FontSize * (96.0f / (REAL)dpi); REAL size = (REAL)m_FontSize * (96.0f / (REAL)dpi);
// Check if the font is in the cache and use it // Check if the font is in the cache and use it
cacheKey += L"-"; cacheKey += L'-';
cacheKey += FontPropertiesToString(size, style); cacheKey += FontPropertiesToString(size, style);
std::unordered_map<std::wstring, Gdiplus::Font*>::const_iterator iter2 = c_Fonts.find(cacheKey); std::unordered_map<std::wstring, Gdiplus::Font*>::const_iterator iter2 = c_Fonts.find(cacheKey);
if (iter2 != c_Fonts.end()) if (iter2 != c_Fonts.end())
@ -381,7 +381,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += align; error += align;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
@ -408,7 +408,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += stringCase; error += stringCase;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
@ -435,7 +435,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += style; error += style;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
@ -458,7 +458,7 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
error += effect; error += effect;
error += L" is not valid in ["; error += L" is not valid in [";
error += m_Name; error += m_Name;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }

View File

@ -86,8 +86,8 @@ CMeterWindow::CMeterWindow(const std::wstring& path, const std::wstring& config,
m_MouseOver(false), m_MouseOver(false),
m_BackgroundMargins(), m_BackgroundMargins(),
m_DragMargins(), m_DragMargins(),
m_WindowX(L"0"), m_WindowX(1, L'0'),
m_WindowY(L"0"), m_WindowY(1, L'0'),
m_WindowXScreen(1), m_WindowXScreen(1),
m_WindowYScreen(1), m_WindowYScreen(1),
m_WindowXScreenDefined(false), m_WindowXScreenDefined(false),
@ -333,9 +333,9 @@ void CMeterWindow::Refresh(bool init, bool all)
m_Rainmeter->SetCurrentParser(&m_Parser); m_Rainmeter->SetCurrentParser(&m_Parser);
std::wstring notice = L"Refreshing skin \"" + m_SkinName; std::wstring notice = L"Refreshing skin \"" + m_SkinName;
notice += L"\\"; notice += L'\\';
notice += m_SkinIniFile; notice += m_SkinIniFile;
notice += L"\""; notice += L'"';
Log(LOG_NOTICE, notice.c_str()); Log(LOG_NOTICE, notice.c_str());
m_Refreshing = true; m_Refreshing = true;
@ -956,7 +956,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
std::wstring::size_type pos3; std::wstring::size_type pos3;
do do
{ {
pos3 = args.find(L'\"'); pos3 = args.find(L'"');
if (pos3 != std::wstring::npos) if (pos3 != std::wstring::npos)
{ {
args.erase(pos3, 1); args.erase(pos3, 1);
@ -1892,10 +1892,10 @@ void CMeterWindow::ReadConfig()
const WCHAR* section = L"Rainmeter"; const WCHAR* section = L"Rainmeter";
// Reset settings to the default value // Reset settings to the default value
m_WindowX = L"0"; m_WindowX = L'0';
m_WindowY = L"0"; m_WindowY = L'0';
m_AnchorX = L"0"; m_AnchorX = L'0';
m_AnchorY = L"0"; m_AnchorY = L'0';
m_WindowZPosition = ZPOSITION_NORMAL; m_WindowZPosition = ZPOSITION_NORMAL;
m_WindowDraggable = true; m_WindowDraggable = true;
m_WindowHide = HIDEMODE_NONE; m_WindowHide = HIDEMODE_NONE;
@ -2068,7 +2068,7 @@ void CMeterWindow::WriteConfig(INT setting)
bool CMeterWindow::ReadSkin() bool CMeterWindow::ReadSkin()
{ {
std::wstring iniFile = m_SkinPath + m_SkinName; std::wstring iniFile = m_SkinPath + m_SkinName;
iniFile += L"\\"; iniFile += L'\\';
iniFile += m_SkinIniFile; iniFile += m_SkinIniFile;
// Verify whether the file exists // Verify whether the file exists
@ -2087,7 +2087,7 @@ bool CMeterWindow::ReadSkin()
const std::wstring& group = m_Parser.ReadString(L"Rainmeter", L"Group", L""); const std::wstring& group = m_Parser.ReadString(L"Rainmeter", L"Group", L"");
if (!group.empty()) if (!group.empty())
{ {
m_ConfigGroup += L"|"; m_ConfigGroup += L'|';
m_ConfigGroup += group; m_ConfigGroup += group;
} }
InitializeGroup(m_ConfigGroup); InitializeGroup(m_ConfigGroup);
@ -2213,7 +2213,7 @@ bool CMeterWindow::ReadSkin()
{ {
szFontFile = m_SkinPath; // Get the local path szFontFile = m_SkinPath; // Get the local path
szFontFile += m_SkinName; szFontFile += m_SkinName;
szFontFile += L"\\"; szFontFile += L'\\';
szFontFile += localFont; szFontFile += localFont;
nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); nResults = m_FontCollection->AddFontFile(szFontFile.c_str());
@ -3543,13 +3543,13 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (wParam == ID_CONTEXT_SKINMENU_EDITSKIN) if (wParam == ID_CONTEXT_SKINMENU_EDITSKIN)
{ {
std::wstring command = m_SkinPath + m_SkinName; std::wstring command = m_SkinPath + m_SkinName;
command += L"\\"; command += L'\\';
command += m_SkinIniFile; command += m_SkinIniFile;
bool writable = CSystem::IsFileWritable(command.c_str()); bool writable = CSystem::IsFileWritable(command.c_str());
command.insert(0, L" \""); command.insert(0, L" \"");
command.insert(0, m_Rainmeter->GetConfigEditor()); command.insert(0, m_Rainmeter->GetConfigEditor());
command += L"\""; command += L'"';
// Execute as admin if in protected location // Execute as admin if in protected location
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL, !writable); RunCommand(NULL, command.c_str(), SW_SHOWNORMAL, !writable);
@ -3560,9 +3560,9 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
else if (wParam == ID_CONTEXT_SKINMENU_OPENSKINSFOLDER) else if (wParam == ID_CONTEXT_SKINMENU_OPENSKINSFOLDER)
{ {
std::wstring command = L"\"" + m_SkinPath; std::wstring command = L'"' + m_SkinPath;
command += m_SkinName; command += m_SkinName;
command += L"\""; command += L'"';
RunCommand(NULL, command.c_str(), SW_SHOWNORMAL); RunCommand(NULL, command.c_str(), SW_SHOWNORMAL);
} }
else if (wParam == ID_CONTEXT_SKINMENU_MANAGESKIN) else if (wParam == ID_CONTEXT_SKINMENU_MANAGESKIN)
@ -5017,9 +5017,9 @@ LRESULT CMeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam)
arg += L" \""; arg += L" \"";
arg += m_SkinPath; arg += m_SkinPath;
arg += m_SkinName; arg += m_SkinName;
arg += L"\\"; arg += L'\\';
arg += m_SkinIniFile; arg += m_SkinIniFile;
arg += L"\""; arg += L'"';
} }
} }
@ -5028,7 +5028,7 @@ LRESULT CMeterWindow::OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam)
// another one doesn't matter. // another one doesn't matter.
arg += L" \""; arg += L" \"";
arg += m_SkinName; arg += m_SkinName;
arg += L"\""; arg += L'"';
return m_Rainmeter->ExecuteBang(bang, arg, this); return m_Rainmeter->ExecuteBang(bang, arg, this);
} }
@ -5088,7 +5088,7 @@ void CMeterWindow::MakePathAbsolute(std::wstring& path)
absolute.reserve(m_SkinPath.size() + m_SkinName.size() + 1 + path.size()); absolute.reserve(m_SkinPath.size() + m_SkinName.size() + 1 + path.size());
absolute = m_SkinPath; absolute = m_SkinPath;
absolute += m_SkinName; absolute += m_SkinName;
absolute += L"\\"; absolute += L'\\';
absolute += path; absolute += path;
absolute.swap(path); absolute.swap(path);
} }
@ -5106,7 +5106,7 @@ std::wstring CMeterWindow::GetSkinRootPath()
else else
{ {
path += m_SkinName; path += m_SkinName;
path += L"\\"; path += L'\\';
} }
return path; return path;

View File

@ -149,9 +149,9 @@ LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
CMeterWindow *meterWindow = Rainmeter->GetMeterWindowByINI(_sData); CMeterWindow *meterWindow = Rainmeter->GetMeterWindowByINI(_sData);
if (meterWindow) if (meterWindow)
{ {
result = L"\""; result = L'"';
result += meterWindow->GetSkinName(); result += meterWindow->GetSkinName();
result += L"\""; result += L'"';
return result.c_str(); return result.c_str();
} }
@ -223,7 +223,7 @@ LPCTSTR PluginBridge(LPCTSTR _sCommand, LPCTSTR _sData)
for (size_t i = 1, isize = subStrings.size(); i < isize; ++i) for (size_t i = 1, isize = subStrings.size(); i < isize; ++i)
{ {
if (i != 1) arguments += L" "; if (i != 1) arguments += L' ';
arguments += subStrings[i]; arguments += subStrings[i];
} }
@ -360,7 +360,7 @@ void CRainmeter::BangWithArgs(BANGCOMMAND bang, const WCHAR* arg, size_t numOfAr
// Don't include the config name from the arg if there is one // Don't include the config name from the arg if there is one
for (size_t i = 0; i < numOfArgs; ++i) for (size_t i = 0; i < numOfArgs; ++i)
{ {
if (i != 0) argument += L" "; if (i != 0) argument += L' ';
if (i < subStringsSize) if (i < subStringsSize)
{ {
argument += subStrings[i]; argument += subStrings[i];
@ -374,7 +374,7 @@ void CRainmeter::BangWithArgs(BANGCOMMAND bang, const WCHAR* arg, size_t numOfAr
config = subStrings[numOfArgs]; config = subStrings[numOfArgs];
} }
if ((!config.empty()) && (config != L"*")) if (!config.empty() && (config.size() != 1 || config[0] != L'*'))
{ {
// Config defined, so bang only that // Config defined, so bang only that
CMeterWindow* meterWindow = GetMeterWindow(config); CMeterWindow* meterWindow = GetMeterWindow(config);
@ -422,14 +422,14 @@ void CRainmeter::BangGroupWithArgs(BANGCOMMAND bang, const WCHAR* arg, size_t nu
std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin(); std::multimap<int, CMeterWindow*>::const_iterator iter = windows.begin();
for (; iter != windows.end(); ++iter) for (; iter != windows.end(); ++iter)
{ {
std::wstring argument = L"\""; std::wstring argument(1, L'"');
for (size_t i = 0; i < numOfArgs; ++i) for (size_t i = 0; i < numOfArgs; ++i)
{ {
argument += subStrings[i]; argument += subStrings[i];
argument += L"\" \""; argument += L"\" \"";
} }
argument += (*iter).second->GetSkinName(); argument += (*iter).second->GetSkinName();
argument += L"\""; argument += L'"';
BangWithArgs(bang, argument.c_str(), numOfArgs); BangWithArgs(bang, argument.c_str(), numOfArgs);
} }
} }
@ -835,13 +835,13 @@ int CRainmeter::Initialize(HWND hParent, HINSTANCE hInstance, LPCWSTR szPath)
{ {
// The command line defines the location of Rainmeter.ini (or whatever it calls it). // The command line defines the location of Rainmeter.ini (or whatever it calls it).
std::wstring iniFile = szPath; std::wstring iniFile = szPath;
if (iniFile[0] == L'\"') if (iniFile[0] == L'"')
{ {
if (iniFile.length() == 1) if (iniFile.length() == 1)
{ {
iniFile.clear(); iniFile.clear();
} }
else if (iniFile[iniFile.length() - 1] == L'\"') else if (iniFile[iniFile.length() - 1] == L'"')
{ {
iniFile.assign(iniFile, 1, iniFile.length() - 2); iniFile.assign(iniFile, 1, iniFile.length() - 2);
} }
@ -976,7 +976,7 @@ int CRainmeter::Initialize(HWND hParent, HINSTANCE hInstance, LPCWSTR szPath)
{ {
if (!CSystem::IsPathSeparator(m_SkinPath[m_SkinPath.size() - 1])) if (!CSystem::IsPathSeparator(m_SkinPath[m_SkinPath.size() - 1]))
{ {
m_SkinPath += L"\\"; m_SkinPath += L'\\';
} }
} }
} }
@ -1168,7 +1168,7 @@ void CRainmeter::ActivateConfig(int configIndex, int iniIndex)
// Verify whether the ini-file exists // Verify whether the ini-file exists
std::wstring skinIniPath = skinPath + skinConfig; std::wstring skinIniPath = skinPath + skinConfig;
skinIniPath += L"\\"; skinIniPath += L'\\';
skinIniPath += skinIniFile; skinIniPath += skinIniFile;
if (_waccess(skinIniPath.c_str(), 0) == -1) if (_waccess(skinIniPath.c_str(), 0) == -1)
@ -1368,7 +1368,7 @@ CMeterWindow* CRainmeter::GetMeterWindowByINI(const std::wstring& ini_searching)
std::map<std::wstring, CMeterWindow*>::const_iterator iter = m_Meters.begin(); std::map<std::wstring, CMeterWindow*>::const_iterator iter = m_Meters.begin();
for (; iter != m_Meters.end(); ++iter) for (; iter != m_Meters.end(); ++iter)
{ {
std::wstring config_current = (*iter).second->GetSkinName() + L"\\"; std::wstring config_current = (*iter).second->GetSkinName() + L'\\';
config_current += (*iter).second->GetSkinIniFile(); config_current += (*iter).second->GetSkinIniFile();
if (_wcsicmp(config_current.c_str(), config_searching.c_str()) == 0) if (_wcsicmp(config_current.c_str(), config_searching.c_str()) == 0)
@ -1576,7 +1576,7 @@ int CRainmeter::ScanForConfigsRecursive(const std::wstring& path, std::wstring b
if (!first) if (!first)
{ {
base += L"\\"; base += L'\\';
} }
menu.reserve(menu.size() + folders.size()); menu.reserve(menu.size() + folders.size());
@ -2066,7 +2066,7 @@ void CRainmeter::ExecuteCommand(const WCHAR* command, CMeterWindow* meterWindow)
// Strip the quotes // Strip the quotes
std::wstring::size_type len = strCommand.length(); std::wstring::size_type len = strCommand.length();
if (len >= 2 && strCommand[0] == L'\"' && strCommand[len - 1] == L'\"') if (len >= 2 && strCommand[0] == L'"' && strCommand[len - 1] == L'"')
{ {
len -= 2; len -= 2;
strCommand.assign(strCommand, 1, len); strCommand.assign(strCommand, 1, len);
@ -2135,22 +2135,13 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
{ {
// Get the program path associated with .ini files // Get the program path associated with .ini files
DWORD cchOut = MAX_PATH; DWORD cchOut = MAX_PATH;
buffer[0] = L'\0';
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut); HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut);
if (SUCCEEDED(hr) && cchOut > 0) m_ConfigEditor = (SUCCEEDED(hr) && cchOut > 0) ? buffer : L"Notepad";
{
m_ConfigEditor = buffer;
} }
else if (!m_ConfigEditor.empty() && m_ConfigEditor[0] != L'"')
{ {
m_ConfigEditor = L"Notepad"; m_ConfigEditor.insert(0, 1, L'"');
} m_ConfigEditor += L'"';
}
if (!m_ConfigEditor.empty() && m_ConfigEditor[0] != L'\"')
{
m_ConfigEditor.insert(0, L"\"");
m_ConfigEditor.append(L"\"");
} }
m_LogViewer = parser.ReadString(L"Rainmeter", L"LogViewer", L""); m_LogViewer = parser.ReadString(L"Rainmeter", L"LogViewer", L"");
@ -2158,22 +2149,13 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile)
{ {
// Get the program path associated with .log files // Get the program path associated with .log files
DWORD cchOut = MAX_PATH; DWORD cchOut = MAX_PATH;
buffer[0] = L'\0';
HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".log", L"open", buffer, &cchOut); HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".log", L"open", buffer, &cchOut);
if (SUCCEEDED(hr) && cchOut > 0) m_LogViewer = (SUCCEEDED(hr) && cchOut > 0) ? buffer : L"Notepad";
{
m_LogViewer = buffer;
} }
else if (!m_LogViewer.empty() && m_LogViewer[0] != L'"')
{ {
m_LogViewer = L"Notepad"; m_LogViewer.insert(0, 1, L'"');
} m_LogViewer += L'"';
}
if (!m_LogViewer.empty() && m_LogViewer[0] != L'\"')
{
m_LogViewer.insert(0, L"\"");
m_LogViewer.append(L"\"");
} }
if (m_Debug) if (m_Debug)

View File

@ -90,7 +90,7 @@ public:
std::pair<int, int> GetMeterWindowIndex(UINT menuCommand); std::pair<int, int> GetMeterWindowIndex(UINT menuCommand);
CMeterWindow* GetMeterWindow(HWND hwnd); CMeterWindow* GetMeterWindow(HWND hwnd);
void GetMeterWindowsByLoadOrder(std::multimap<int, CMeterWindow*>& windows, const std::wstring& group = L""); void GetMeterWindowsByLoadOrder(std::multimap<int, CMeterWindow*>& windows, const std::wstring& group = std::wstring());
std::map<std::wstring, CMeterWindow*>& GetAllMeterWindows() { return m_Meters; } std::map<std::wstring, CMeterWindow*>& GetAllMeterWindows() { return m_Meters; }
const std::vector<CONFIG>& GetAllConfigs() { return m_ConfigStrings; } const std::vector<CONFIG>& GetAllConfigs() { return m_ConfigStrings; }
const std::vector<std::wstring>& GetAllThemes() { return m_Themes; } const std::vector<std::wstring>& GetAllThemes() { return m_Themes; }

View File

@ -637,11 +637,11 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C) if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C)
{ {
std::wstring error = m_ConfigArray[ConfigIndexImageCrop]; std::wstring error = m_ConfigArray[ConfigIndexImageCrop];
error += L"="; error += L'=';
error += crop; error += crop;
error += L" (origin) is not valid in ["; error += L" (origin) is not valid in [";
error += section; error += section;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }
} }
@ -745,11 +745,11 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
else else
{ {
std::wstring error = m_ConfigArray[ConfigIndexImageFlip]; std::wstring error = m_ConfigArray[ConfigIndexImageFlip];
error += L"="; error += L'=';
error += flip; error += flip;
error += L" is not valid in ["; error += L" is not valid in [";
error += section; error += section;
error += L"]"; error += L']';
throw CError(error); throw CError(error);
} }

View File

@ -484,7 +484,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
{ {
std::wstring command = Rainmeter->GetConfigEditor() + L" \""; std::wstring command = Rainmeter->GetConfigEditor() + L" \"";
command += Rainmeter->GetIniFile(); command += Rainmeter->GetIniFile();
command += L"\""; command += L'"';
RunCommand(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL); RunCommand(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL);
} }
else if (wParam == ID_CONTEXT_QUIT) else if (wParam == ID_CONTEXT_QUIT)
@ -494,8 +494,8 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
} }
else if (wParam == ID_CONTEXT_OPENSKINSFOLDER) else if (wParam == ID_CONTEXT_OPENSKINSFOLDER)
{ {
std::wstring command = L"\"" + Rainmeter->GetSkinPath(); std::wstring command = L'"' + Rainmeter->GetSkinPath();
command += L"\""; command += L'"';
RunCommand(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL); RunCommand(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL);
} }
else if ((wParam & 0x0ffff) >= ID_THEME_FIRST && (wParam & 0x0ffff) <= ID_THEME_LAST) else if ((wParam & 0x0ffff) >= ID_THEME_FIRST && (wParam & 0x0ffff) <= ID_THEME_LAST)