From 9453780c26cf390a83aca4c1f37c9077d344bcc2 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sat, 19 May 2012 18:16:04 +0300 Subject: [PATCH] Tweaks --- Library/ConfigParser.cpp | 22 +++++++++++----------- Library/ConfigParser.h | 7 +++---- Library/Group.cpp | 3 +-- Library/MeterString.cpp | 4 ++-- Library/MeterWindow.cpp | 27 +++++++-------------------- Library/TintedImage.cpp | 2 +- 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 80f6a50c..f34bc4bd 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -104,7 +104,7 @@ void CConfigParser::SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* me SetBuiltInVariable(L"CRLF", L"\n"); - const std::wstring CURRENTSECTION = StrToLower(L"CURRENTSECTION"); + const std::wstring CURRENTSECTION = L"CURRENTSECTION"; SetBuiltInVariable(CURRENTSECTION, L""); m_CurrentSection = &((*m_BuiltInVariables.find(CURRENTSECTION)).second); // shortcut } @@ -131,7 +131,7 @@ void CConfigParser::SetVariable(std::unordered_map& { // LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)variables.size()); - const std::wstring strTmp = StrToLower(strVariable); + const std::wstring strTmp = StrToUpper(strVariable); variables[strTmp] = strValue; } @@ -139,7 +139,7 @@ void CConfigParser::SetVariable(std::unordered_map& { // LogWithArgs(LOG_DEBUG, L"Variable: %s=%s (size=%i)", strVariable.c_str(), strValue.c_str(), (int)variables.size()); - const std::wstring strTmp = StrToLower(strVariable); + const std::wstring strTmp = StrToUpper(strVariable); variables[strTmp] = strValue; } @@ -150,7 +150,7 @@ void CConfigParser::SetVariable(std::unordered_map& */ bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& strValue) { - const std::wstring strTmp = StrToLower(strVariable); + const std::wstring strTmp = StrToUpper(strVariable); // #1: Built-in variables std::unordered_map::const_iterator iter = m_BuiltInVariables.find(strTmp); @@ -656,13 +656,13 @@ void CConfigParser::AddMeasure(CMeasure* pMeasure) { if (pMeasure) { - m_Measures[StrToLower(pMeasure->GetOriginalName())] = pMeasure; + m_Measures[StrToUpper(pMeasure->GetOriginalName())] = pMeasure; } } CMeasure* CConfigParser::GetMeasure(const std::wstring& name) { - std::unordered_map::const_iterator iter = m_Measures.find(StrToLower(name)); + std::unordered_map::const_iterator iter = m_Measures.find(StrToUpper(name)); if (iter != m_Measures.end()) { return (*iter).second; @@ -1223,7 +1223,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int if (*pos) { value = pos; // section name - StrToLowerC(key.assign(value)); + StrToUpperC(key.assign(value)); if (unique.insert(key).second) { if (m_FoundSections.insert(key).second) @@ -1294,7 +1294,7 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int { size_t clen = sep - pos; // key's length - StrToLowerC(key.assign(pos, clen)); + StrToUpperC(key.assign(pos, clen)); if (unique.insert(key).second) { ++sep; @@ -1364,7 +1364,7 @@ void CConfigParser::SetValue(const std::wstring& strSection, const std::wstring& strTmp += L'~'; strTmp += strKey; - m_Values[StrToLowerC(strTmp)] = strValue; + m_Values[StrToUpperC(strTmp)] = strValue; } /* @@ -1379,7 +1379,7 @@ void CConfigParser::DeleteValue(const std::wstring& strSection, const std::wstri strTmp += L'~'; strTmp += strKey; - std::unordered_map::const_iterator iter = m_Values.find(StrToLowerC(strTmp)); + std::unordered_map::const_iterator iter = m_Values.find(StrToUpperC(strTmp)); if (iter != m_Values.end()) { m_Values.erase(iter); @@ -1398,6 +1398,6 @@ const std::wstring& CConfigParser::GetValue(const std::wstring& strSection, cons strTmp += L'~'; strTmp += strKey; - std::unordered_map::const_iterator iter = m_Values.find(StrToLowerC(strTmp)); + std::unordered_map::const_iterator iter = m_Values.find(StrToUpperC(strTmp)); return (iter != m_Values.end()) ? (*iter).second : strDefault; } diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 5fa5e352..c8872da2 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -46,7 +46,6 @@ public: 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 SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); } - void SetBuiltInVariable(const WCHAR* strVariable, const WCHAR* strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); } const std::unordered_map& GetVariables() { return m_Variables; } @@ -119,9 +118,9 @@ private: static void SetMonitorVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); } static void SetMonitorVariable(const WCHAR* strVariable, const WCHAR* strValue) { SetVariable(c_MonitorVariables, strVariable, strValue); } - static std::wstring StrToLower(const std::wstring& str) { std::wstring strTmp(str); StrToLowerC(strTmp); return strTmp; } - static std::wstring StrToLower(const WCHAR* str) { std::wstring strTmp(str); StrToLowerC(strTmp); return strTmp; } - static std::wstring& StrToLowerC(std::wstring& str) { _wcslwr(&str[0]); return str; } + static std::wstring StrToUpper(const std::wstring& str) { std::wstring strTmp(str); StrToUpperC(strTmp); return strTmp; } + static std::wstring StrToUpper(const WCHAR* str) { std::wstring strTmp(str); StrToUpperC(strTmp); return strTmp; } + static std::wstring& StrToUpperC(std::wstring& str) { _wcsupr(&str[0]); return str; } std::wstring m_Filename; diff --git a/Library/Group.cpp b/Library/Group.cpp index 998b2648..e9e914d8 100644 --- a/Library/Group.cpp +++ b/Library/Group.cpp @@ -59,8 +59,7 @@ std::wstring CGroup::CreateGroup(const std::wstring& str) // Trim white-space strTmp.assign(str, pos, str.find_last_not_of(L" \t\r\n") - pos + 1); - // Convert to lower - _wcslwr(&strTmp[0]); + _wcsupr(&strTmp[0]); } return strTmp; diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 0b910b0e..89281646 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -765,7 +765,7 @@ void CMeterString::FreeFontCache(PrivateFontCollection* collection) size_t len = _snwprintf_s(buffer, _TRUNCATE, L"<%p>", collection); prefix.assign(buffer, len); - StringToLower(prefix); + _wcsupr(&prefix[0]); } std::unordered_map::iterator iter2 = c_Fonts.begin(); @@ -818,7 +818,7 @@ std::wstring CMeterString::FontFaceToString(const std::wstring& fontFace, Privat strTmp.reserve(len + fontFace.size()); strTmp.assign(buffer, len); strTmp += fontFace; - StringToLower(strTmp); + _wcsupr(&strTmp[0]); return strTmp; } diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 6165a217..3a402e76 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2070,9 +2070,8 @@ bool CMeterWindow::ReadSkin() } } - // Checking for localfonts + // Load local fonts const WCHAR* localFont = m_Parser.ReadString(L"Rainmeter", L"LocalFont", L"").c_str(); - // If there is a local font we want to load it if (*localFont) { m_FontCollection = new PrivateFontCollection(); @@ -2080,34 +2079,22 @@ bool CMeterWindow::ReadSkin() do { - // We want to check the fonts folder first - // !!!!!!! - We may want to fix the method in which I get the path to - // Rainmeter/fonts + // Try program folder first std::wstring szFontFile = Rainmeter->GetPath() + L"Fonts\\"; szFontFile += localFont; Status nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); - // It wasn't found in the fonts folder, check the local folder if (nResults != Ok) { - szFontFile = Rainmeter->GetSkinPath(); // Get the local path - szFontFile += m_SkinName; - szFontFile += L'\\'; - szFontFile += localFont; + szFontFile = localFont; + MakePathAbsolute(szFontFile); nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); - // The font wasn't found, check full path. if (nResults != Ok) { - szFontFile = localFont; - nResults = m_FontCollection->AddFontFile(szFontFile.c_str()); - - if (nResults != Ok) - { - std::wstring error = L"Unable to load font file: "; - error += localFont; - Log(LOG_ERROR, error.c_str()); - } + std::wstring error = L"Unable to load font file: "; + error += localFont; + Log(LOG_ERROR, error.c_str()); } } diff --git a/Library/TintedImage.cpp b/Library/TintedImage.cpp index 9aaf52ec..62e4ad0b 100644 --- a/Library/TintedImage.cpp +++ b/Library/TintedImage.cpp @@ -42,7 +42,7 @@ public: { key = name; } - _wcslwr(&key[0]); + _wcsupr(&key[0]); size_t len = _snwprintf_s(buffer, _TRUNCATE, L":%llx:%x", time, size); key.append(buffer, len);