diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index 48ce30b8..adaf32d1 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -126,20 +126,6 @@ void CDialogManage::UpdateSkins(CMeterWindow* meterWindow, bool deleted) } } -/* -** UpdateThemes -** -** Updates Themes tab. -** -*/ -void CDialogManage::UpdateThemes() -{ - if (c_Dialog && c_Dialog->m_TabThemes && c_Dialog->m_TabThemes->IsInitialized()) - { - c_Dialog->m_TabThemes->Update(); - } -} - std::wstring GetTreeSelectionPath(HWND tree) { WCHAR buffer[MAX_PATH]; @@ -1308,85 +1294,6 @@ void CDialogManage::CTabThemes::Initialize() } } -/* -** Update -** -** Loads new theme. -** -*/ -void CDialogManage::CTabThemes::Update() -{ - if (m_LoadTheme) - { - // Called by ClearDeleteLaterList(), all MeterWindows have been deleted now so - // proceed to loading theme - m_LoadTheme = false; - const std::vector& themes = Rainmeter->GetAllThemes(); - - HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST); - int sel = ListBox_GetCurSel(item); - - // Make a copy of current Rainmeter.ini - std::wstring backup = Rainmeter->GetSettingsPath() + L"Themes\\Backup"; - CreateDirectory(backup.c_str(), NULL); - backup += L"\\Rainmeter.thm"; - CSystem::CopyFiles(Rainmeter->GetIniFile(), backup); - - // Replace Rainmeter.ini with theme - std::wstring theme = Rainmeter->GetSettingsPath() + L"Themes\\"; - theme += themes[sel]; - std::wstring wallpaper = theme + L"\\RainThemes.bmp"; - theme += L"\\Rainmeter.thm"; - CSystem::CopyFiles(theme, Rainmeter->GetIniFile()); - - PreserveSetting(backup, L"SkinPath"); - PreserveSetting(backup, L"ConfigEditor"); - PreserveSetting(backup, L"LogViewer"); - PreserveSetting(backup, L"Logging"); - PreserveSetting(backup, L"DisableVersionCheck"); - PreserveSetting(backup, L"TrayExecuteL", false); - PreserveSetting(backup, L"TrayExecuteM", false); - PreserveSetting(backup, L"TrayExecuteR", false); - PreserveSetting(backup, L"TrayExecuteDM", false); - PreserveSetting(backup, L"TrayExecuteDR", false); - - Rainmeter->ReadGeneralSettings(Rainmeter->GetIniFile()); - - if (_waccess(wallpaper.c_str(), 0) != -1) - { - // Set wallpaper - SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)wallpaper.c_str(), 0); - } - - // Create meter windows for active configs - const std::multimap& configOrders = Rainmeter->m_ConfigOrders; - for (std::multimap::const_iterator iter = configOrders.begin(); iter != configOrders.end(); ++iter) - { - const CRainmeter::CONFIG& config = Rainmeter->GetAllConfigs()[(*iter).second]; - if (config.active > 0 && config.active <= (int)config.iniFiles.size()) - { - Rainmeter->ActivateConfig((*iter).second, config.active - 1); - } - } - - item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LOAD_BUTTON); - EnableWindow(item, TRUE); - } -} - -void CDialogManage::CTabThemes::PreserveSetting(const std::wstring& backupFile, LPCTSTR key, bool replace) -{ - WCHAR* buffer = new WCHAR[MAX_LINE_LENGTH]; - - if ((replace || GetPrivateProfileString(L"Rainmeter", key, L"", buffer, 4, Rainmeter->GetIniFile().c_str()) == 0) && - GetPrivateProfileString(L"Rainmeter", key, L"", buffer, MAX_LINE_LENGTH, backupFile.c_str()) > 0) - { - WritePrivateProfileString(L"Rainmeter", key, buffer, Rainmeter->GetIniFile().c_str()); - } - - delete [] buffer; -} - /* ** DlgProc ** @@ -1566,23 +1473,9 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) case IDC_MANAGETHEMES_LOAD_BUTTON: { - EnableWindow((HWND)lParam, FALSE); - m_LoadTheme = true; - - // Deactivate all skins - std::map& meterWindows = Rainmeter->GetAllMeterWindows(); - if (!meterWindows.empty()) - { - std::map::const_iterator iter = meterWindows.begin(); - for ( ; iter != meterWindows.end(); ++iter) - { - Rainmeter->DeactivateConfig((*iter).second, -1, false); - } - } - else - { - Update(); - } + HWND item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST); + int sel = ListBox_GetCurSel(item); + Rainmeter->LoadTheme(Rainmeter->m_Themes[sel]); } break; diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 81fb3731..feda7293 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -2330,8 +2330,6 @@ void CRainmeter::ClearDeleteLaterList() } while (!m_DelayDeleteList.empty()); - - CDialogManage::UpdateThemes(); CDialogAbout::UpdateSkins(); } } @@ -3540,9 +3538,72 @@ void CRainmeter::RefreshAll() } } + CDialogAbout::UpdateSkins(); CDialogManage::UpdateSkins(NULL); } +void CRainmeter::LoadTheme(const std::wstring& name) +{ + // Delete all meter windows + DeleteMeterWindow(NULL, false); + + // Make a copy of current Rainmeter.ini + std::wstring backup = GetSettingsPath() + L"Themes\\Backup"; + CreateDirectory(backup.c_str(), NULL); + backup += L"\\Rainmeter.thm"; + CSystem::CopyFiles(m_IniFile, backup); + + // Replace Rainmeter.ini with theme + std::wstring theme = Rainmeter->GetSettingsPath() + L"Themes\\"; + theme += name; + std::wstring wallpaper = theme + L"\\RainThemes.bmp"; + theme += L"\\Rainmeter.thm"; + CSystem::CopyFiles(theme, Rainmeter->GetIniFile()); + + PreserveSetting(backup, L"SkinPath"); + PreserveSetting(backup, L"ConfigEditor"); + PreserveSetting(backup, L"LogViewer"); + PreserveSetting(backup, L"Logging"); + PreserveSetting(backup, L"DisableVersionCheck"); + PreserveSetting(backup, L"TrayExecuteL", false); + PreserveSetting(backup, L"TrayExecuteM", false); + PreserveSetting(backup, L"TrayExecuteR", false); + PreserveSetting(backup, L"TrayExecuteDM", false); + PreserveSetting(backup, L"TrayExecuteDR", false); + + // Set wallpaper if it exists + if (_waccess(wallpaper.c_str(), 0) != -1) + { + SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)wallpaper.c_str(), 0); + } + + ReloadSettings(); + + // Create meter windows for active configs + std::multimap::const_iterator iter = m_ConfigOrders.begin(); + for ( ; iter != m_ConfigOrders.end(); ++iter) + { + const CONFIG& config = m_ConfigStrings[(*iter).second]; + if (config.active > 0 && config.active <= (int)config.iniFiles.size()) + { + ActivateConfig((*iter).second, config.active - 1); + } + } +} + +void CRainmeter::PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace) +{ + WCHAR* buffer = new WCHAR[MAX_LINE_LENGTH]; + + if ((replace || GetPrivateProfileString(L"Rainmeter", key, L"", buffer, 4, m_IniFile.c_str()) == 0) && + GetPrivateProfileString(L"Rainmeter", key, L"", buffer, MAX_LINE_LENGTH, from.c_str()) > 0) + { + WritePrivateProfileString(L"Rainmeter", key, buffer, m_IniFile.c_str()); + } + + delete [] buffer; +} + /* ** UpdateDesktopWorkArea ** diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 52e61f12..13959627 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -256,6 +256,9 @@ public: void RefreshAll(); + void LoadTheme(const std::wstring& name); + void PreserveSetting(const std::wstring& from, LPCTSTR key, bool replace = true); + void ClearDeleteLaterList(); static std::vector ParseString(LPCTSTR str); diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index 8f0e709d..15f26dce 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -495,11 +495,7 @@ LRESULT CALLBACK CTrayWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA const std::vector& themes = Rainmeter->GetAllThemes(); if (pos >= 0 && pos < (int)themes.size()) { - std::wstring command = L"\"" + Rainmeter->GetAddonPath(); - command += L"RainThemes\\RainThemes.exe\" /load \""; - command += themes[pos]; - command += L"\""; - LSExecute(tray->GetWindow(), command.c_str(), SW_SHOWNORMAL); + Rainmeter->LoadTheme(themes[pos]); } } else if ((wParam & 0x0ffff) >= ID_CONFIG_FIRST && (wParam & 0x0ffff) <= ID_CONFIG_LAST) diff --git a/Library/lua/LuaManager.cpp b/Library/lua/LuaManager.cpp index 5464a52f..a9e5cc68 100644 --- a/Library/lua/LuaManager.cpp +++ b/Library/lua/LuaManager.cpp @@ -78,7 +78,7 @@ void LuaManager::ReportErrors(lua_State* L) } std::wstring str = L"Script: "; - str += ConvertUTF8ToWide(error.c_str()); + str += ConvertToWide(error.c_str()); Log(LOG_ERROR, str.c_str()); } @@ -100,7 +100,7 @@ void LuaManager::LuaLog(int nLevel, const char* format, ... ) _set_invalid_parameter_handler(oldHandler); - std::wstring str = ConvertUTF8ToWide(buffer); + std::wstring str = ConvertToWide(buffer); Log(nLevel, str.c_str()); va_end(args);