From 8515877c483a439ced222be9051afdf8d907c816 Mon Sep 17 00:00:00 2001 From: spx Date: Fri, 15 Jul 2011 16:54:47 +0000 Subject: [PATCH] Tweaks. --- Library/ConfigParser.cpp | 5 +- Library/ConfigParser.h | 1 + Library/Rainmeter.cpp | 54 ++++++------ Library/Rainmeter.h | 2 +- Library/TrayWindow.cpp | 175 ++++++++++++++++++++------------------- 5 files changed, 126 insertions(+), 111 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 08b41b69..6e1a148b 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -80,7 +80,8 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterW ReadIniFile(iniFileMappings, m_Filename, config); ReadVariables(); - std::unordered_set().swap(m_FoundSections); // clear and minimize + // Clear and minimize + std::vector().swap(m_ListVariables); } /* @@ -1107,6 +1108,8 @@ void CConfigParser::ReadIniFile(const std::vector& iniFileMappings { m_Sections.push_back(L"Rainmeter"); m_Sections.push_back(config); + m_FoundSections.insert(L"rainmeter"); + m_FoundSections.insert(StrToLower(config)); } } diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 770b5ceb..4d0e24a3 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -72,6 +72,7 @@ public: const std::wstring& GetFilename() { return m_Filename; } const std::vector& GetSections() { return m_Sections; } + bool IsSectionDefined(LPCTSTR section) { return m_FoundSections.find(StrToLower(section)) != m_FoundSections.end(); } bool ReplaceVariables(std::wstring& result); bool ReplaceMeasures(std::wstring& result); diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index fed89c0b..59219a93 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -2516,31 +2516,8 @@ void CRainmeter::GetMeterWindowsByLoadOrder(std::multimap& w } } -void CRainmeter::SetConfigOrder(int configIndex) +void CRainmeter::SetLoadOrder(int configIndex, int order) { - WCHAR buffer[256]; - int order; - - if (GetPrivateProfileString(m_ConfigStrings[configIndex].config.c_str(), L"LoadOrder", L"", buffer, 256, m_IniFile.c_str()) > 0) - { - if (_wcsicmp(buffer, L"LAST") == 0) - { - order = INT_MAX; - } - else if (_wcsicmp(buffer, L"FIRST") == 0) - { - order = INT_MIN; - } - else - { - order = _wtoi(buffer); - } - } - else // LoadOrder not exists - { - order = 0; - } - std::multimap::iterator iter = m_ConfigOrders.begin(); for ( ; iter != m_ConfigOrders.end(); ++iter) { @@ -3394,7 +3371,6 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile) for (UINT i = 1; i <= CSystem::GetMonitorCount(); ++i) { - WCHAR buffer[64]; _snwprintf_s(buffer, _TRUNCATE, L"DesktopWorkArea@%i", i); area = parser.ReadString(L"Rainmeter", buffer, L""); if (!area.empty()) @@ -3450,7 +3426,33 @@ void CRainmeter::ReadGeneralSettings(const std::wstring& iniFile) m_ConfigStrings[i].active = active; } - SetConfigOrder(i); + int order; + if (parser.IsSectionDefined(m_ConfigStrings[i].config.c_str())) + { + std::wstring orderStr = parser.ReadString(m_ConfigStrings[i].config.c_str(), L"LoadOrder", L"", false); + if (orderStr.empty()) + { + order = 0; + } + else if (_wcsicmp(orderStr.c_str(), L"LAST") == 0) + { + order = INT_MAX; + } + else if (_wcsicmp(orderStr.c_str(), L"FIRST") == 0) + { + order = INT_MIN; + } + else + { + order = _wtoi(orderStr.c_str()); + } + } + else + { + order = 0; + } + + SetLoadOrder(i, order); } } diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 720118d0..051a7141 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -263,7 +263,7 @@ private: void ScanForConfigs(const std::wstring& path); void ScanForThemes(const std::wstring& path); void ReadGeneralSettings(const std::wstring& iniFile); - void SetConfigOrder(int configIndex); + void SetLoadOrder(int configIndex, int order); int GetLoadOrder(const std::wstring& config); bool SetActiveConfig(const std::wstring& skinName, const std::wstring& skinIni); void UpdateDesktopWorkArea(bool reset); diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index cc85b70f..df9fa473 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -272,105 +272,114 @@ HICON CTrayWindow::CreateTrayIcon(double value) void CTrayWindow::ReadConfig(CConfigParser& parser) { + // Clear old Settings KillTimer(m_Window, TRAYTIMER); delete m_Measure; m_Measure = NULL; + delete m_Bitmap; + m_Bitmap = NULL; + for (size_t i = 0, isize = m_TrayIcons.size(); i < isize; ++i) { DestroyIcon(m_TrayIcons[i]); } m_TrayIcons.clear(); - std::wstring measureName = parser.ReadString(L"TrayMeasure", L"Measure", L""); - - if (!measureName.empty()) - { - CConfigParser* oldParser = Rainmeter->GetCurrentParser(); - Rainmeter->SetCurrentParser(&parser); - - try - { - m_Measure = CMeasure::Create(measureName.c_str(), NULL, L"TrayMeasure"); - if (m_Measure) - { - m_Measure->ReadConfig(parser); - } - } - catch (CError& error) - { - delete m_Measure; - m_Measure = NULL; - MessageBox(m_Window, error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); - } - - Rainmeter->SetCurrentParser(oldParser); - } - m_MeterType = TRAY_METER_TYPE_NONE; - std::wstring type = parser.ReadString(L"TrayMeasure", L"TrayMeter", L"HISTOGRAM"); - if (_wcsicmp(type.c_str(), L"HISTOGRAM") == 0) - { - m_MeterType = TRAY_METER_TYPE_HISTOGRAM; - m_TrayColor1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color(0, 100, 0)); - m_TrayColor2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color(0, 255, 0)); - } - else if (_wcsicmp(type.c_str(), L"BITMAP") == 0) - { - m_MeterType = TRAY_METER_TYPE_BITMAP; - - std::wstring imageName = parser.ReadString(L"TrayMeasure", L"TrayBitmap", L""); - - // Load the bitmaps if defined - if (!imageName.empty()) - { - imageName.insert(0, Rainmeter->GetSkinPath()); - if (imageName.size() > 3) - { - std::wstring extension = imageName.substr(imageName.size() - 3); - if (extension == L"ico" || extension == L"ICO") - { - int count = 1; - HICON hIcon = NULL; - - // Load the icons - do - { - WCHAR buffer[MAX_PATH]; - _snwprintf_s(buffer, _TRUNCATE, imageName.c_str(), count++); - - hIcon = (HICON)LoadImage(NULL, buffer, IMAGE_ICON, TRAYICON_SIZE, TRAYICON_SIZE, LR_LOADFROMFILE); - if (hIcon) m_TrayIcons.push_back(hIcon); - if (imageName == buffer) break; - } while(hIcon != NULL); - } - } - - if (m_TrayIcons.empty()) - { - // No icons found so load as bitmap - delete m_Bitmap; - m_Bitmap = new Bitmap(imageName.c_str()); - Status status = m_Bitmap->GetLastStatus(); - if (Ok != status) - { - LogWithArgs(LOG_WARNING, L"Bitmap image not found: %s", imageName.c_str()); - delete m_Bitmap; - m_Bitmap = NULL; - } - } - } - } - else - { - LogWithArgs(LOG_ERROR, L"No such TrayMeter: %s", type.c_str()); - } - + // Read tray settings m_TrayIconEnabled = 0!=parser.ReadInt(L"Rainmeter", L"TrayIcon", 1); if (m_TrayIconEnabled) { + std::wstring measureName = parser.ReadString(L"TrayMeasure", L"Measure", L""); + + if (!measureName.empty()) + { + CConfigParser* oldParser = Rainmeter->GetCurrentParser(); + Rainmeter->SetCurrentParser(&parser); + + try + { + m_Measure = CMeasure::Create(measureName.c_str(), NULL, L"TrayMeasure"); + if (m_Measure) + { + m_Measure->ReadConfig(parser); + } + } + catch (CError& error) + { + delete m_Measure; + m_Measure = NULL; + MessageBox(m_Window, error.GetString().c_str(), APPNAME, MB_OK | MB_TOPMOST | MB_ICONEXCLAMATION); + } + + Rainmeter->SetCurrentParser(oldParser); + } + + std::wstring type = parser.ReadString(L"TrayMeasure", L"TrayMeter", m_Measure ? L"HISTOGRAM" : L"NONE"); + if (_wcsicmp(type.c_str(), L"NONE") == 0) + { + // Use main icon + } + else if (_wcsicmp(type.c_str(), L"HISTOGRAM") == 0) + { + m_MeterType = TRAY_METER_TYPE_HISTOGRAM; + m_TrayColor1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color(0, 100, 0)); + m_TrayColor2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color(0, 255, 0)); + } + else if (_wcsicmp(type.c_str(), L"BITMAP") == 0) + { + m_MeterType = TRAY_METER_TYPE_BITMAP; + + std::wstring imageName = parser.ReadString(L"TrayMeasure", L"TrayBitmap", L""); + + // Load the bitmaps if defined + if (!imageName.empty()) + { + imageName.insert(0, Rainmeter->GetSkinPath()); + if (imageName.size() > 3) + { + std::wstring extension = imageName.substr(imageName.size() - 3); + if (extension == L"ico" || extension == L"ICO") + { + int count = 1; + HICON hIcon = NULL; + + // Load the icons + do + { + WCHAR buffer[MAX_PATH]; + _snwprintf_s(buffer, _TRUNCATE, imageName.c_str(), count++); + + hIcon = (HICON)LoadImage(NULL, buffer, IMAGE_ICON, TRAYICON_SIZE, TRAYICON_SIZE, LR_LOADFROMFILE); + if (hIcon) m_TrayIcons.push_back(hIcon); + if (imageName == buffer) break; + } while(hIcon != NULL); + } + } + + if (m_TrayIcons.empty()) + { + // No icons found so load as bitmap + delete m_Bitmap; + m_Bitmap = new Bitmap(imageName.c_str()); + Status status = m_Bitmap->GetLastStatus(); + if (Ok != status) + { + LogWithArgs(LOG_WARNING, L"Bitmap image not found: %s", imageName.c_str()); + delete m_Bitmap; + m_Bitmap = NULL; + } + } + } + } + else + { + LogWithArgs(LOG_ERROR, L"No such TrayMeter: %s", type.c_str()); + } + AddTrayIcon(); if (m_Measure)