From 5dd2f249dd22a2be348f683d42db657a826d011c Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 10 Jun 2012 12:17:47 +0300 Subject: [PATCH] Tweaks --- Library/DialogManage.cpp | 11 ++++----- Library/Rainmeter.cpp | 43 ++++++++++++++-------------------- Library/Rainmeter.h | 4 ++-- Library/System.cpp | 3 +-- SkinInstaller/DialogBackup.cpp | 7 +++--- 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index 23f0c39d..006f566f 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -1426,7 +1426,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) Edit_GetText(item, buffer, MAX_PATH); std::wstring theme = buffer; - std::wstring path = Rainmeter->GetSettingsPath() + L"Themes\\"; + std::wstring path = Rainmeter->GetThemePath(); CreateDirectory(path.c_str(), 0); path += theme; @@ -1508,9 +1508,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) item = GetDlgItem(m_Window, IDC_MANAGETHEMES_LIST); ListBox_AddString(item, theme.c_str()); - path = Rainmeter->GetSettingsPath(); - path += L"Themes\\"; - Rainmeter->ScanForThemes(path); + Rainmeter->ScanForThemes(); } } break; @@ -1529,8 +1527,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) int sel = ListBox_GetCurSel(item); const std::vector& themes = Rainmeter->GetAllThemes(); - std::wstring args = Rainmeter->GetSettingsPath(); - args += L"Themes\\"; + std::wstring args = Rainmeter->GetThemePath(); args += themes[sel]; args += L"\\Rainmeter.thm"; RunFile(Rainmeter->GetSkinEditor().c_str(), args.c_str()); @@ -1550,7 +1547,7 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) break; } - std::wstring folder = Rainmeter->GetSettingsPath() + L"Themes\\"; + std::wstring folder = Rainmeter->GetThemePath(); folder += themes[sel]; if (CSystem::RemoveFolder(folder)) diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 874d528a..9940c83a 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -498,11 +498,8 @@ void CRainmeter::Bang_WriteKeyValue(std::vector& args, CMeterWindo return; } - const std::wstring& skinPath = GetSkinPath(); - const std::wstring settingsPath = GetSettingsPath(); - - if (_wcsnicmp(iniFile, skinPath.c_str(), skinPath.size()) != 0 && - _wcsnicmp(iniFile, settingsPath.c_str(), settingsPath.size()) != 0) + if (_wcsnicmp(iniFile, m_SkinPath.c_str(), m_SkinPath.size()) != 0 && + _wcsnicmp(iniFile, m_SettingsPath.c_str(), m_SettingsPath.size()) != 0) { LogWithArgs(LOG_ERROR, L"!WriteKeyValue: Illegal path: %s", iniFile); return; @@ -910,15 +907,15 @@ int CRainmeter::Initialize(LPCWSTR iniPath) m_SkinPath = m_Path + L"Skins\\"; } - // Create user skins, themes, addons, and plugins folders if needed - CreateComponentFolders(bDefaultIniLocation); - // Create a default Rainmeter.ini file if needed if (_waccess(iniFile, 0) == -1) { CreateOptionsFile(); } + // Create user skins, themes, addons, and plugins folders if needed + CreateComponentFolders(bDefaultIniLocation); + delete [] buffer; buffer = NULL; @@ -1145,12 +1142,7 @@ void CRainmeter::SetNetworkStatisticsTimer() void CRainmeter::CreateOptionsFile() { - size_t pos = m_IniFile.find_last_of(L'\\'); - if (pos != std::wstring::npos) - { - std::wstring strPath(m_IniFile, 0, pos); - CreateDirectory(strPath.c_str(), NULL); - } + CreateDirectory(m_SettingsPath.c_str(), NULL); std::wstring defaultIni = GetDefaultThemePath(); defaultIni += L"illustro default\\Rainmeter.thm"; @@ -1159,8 +1151,7 @@ void CRainmeter::CreateOptionsFile() void CRainmeter::CreateDataFile() { - std::wstring tmpSz = GetSettingsPath(); - tmpSz += L"Plugins.ini"; + std::wstring tmpSz = m_SettingsPath + L"Plugins.ini"; const WCHAR* pluginsFile = tmpSz.c_str(); const WCHAR* dataFile = m_DataFile.c_str(); @@ -1237,8 +1228,8 @@ void CRainmeter::CreateComponentFolders(bool defaultIniLocation) void CRainmeter::ReloadSettings() { - ScanForSkins(m_SkinPath); - ScanForThemes(GetThemePath()); + ScanForSkins(); + ScanForThemes(); ReadGeneralSettings(m_IniFile); } @@ -1644,12 +1635,12 @@ int CRainmeter::GetLoadOrder(const std::wstring& folderPath) /* ** Scans all the subfolders and locates the ini-files. */ -void CRainmeter::ScanForSkins(const std::wstring& path) +void CRainmeter::ScanForSkins() { m_SkinFolders.clear(); m_SkinOrders.clear(); - ScanForSkinsRecursive(path, L"", 0, 0); + ScanForSkinsRecursive(m_SkinPath, L"", 0, 0); } int CRainmeter::ScanForSkinsRecursive(const std::wstring& path, std::wstring base, int index, UINT level) @@ -1686,7 +1677,7 @@ int CRainmeter::ScanForSkinsRecursive(const std::wstring& path, std::wstring bas { if (wcscmp(L".", fileData.cFileName) != 0 && wcscmp(L"..", fileData.cFileName) != 0 && - !(level == 0 && wcscmp(L"Backup", fileData.cFileName) == 0) && + !(level == 0 && wcscmp(L"@Backup", fileData.cFileName) == 0) && !(level == 1 && wcscmp(L"@Resources", fileData.cFileName) == 0)) { subfolders.push_back(filename); @@ -1757,7 +1748,7 @@ int CRainmeter::ScanForSkinsRecursive(const std::wstring& path, std::wstring bas /* ** Scans the given folder for themes */ -void CRainmeter::ScanForThemes(const std::wstring& path) +void CRainmeter::ScanForThemes() { m_Themes.clear(); @@ -1765,7 +1756,8 @@ void CRainmeter::ScanForThemes(const std::wstring& path) HANDLE hSearch; // Search handle returned by FindFirstFile // Scan for folders - std::wstring folders = path + L"\\*"; + std::wstring folders = GetThemePath(); + folders += L'*'; hSearch = FindFirstFileEx( folders.c_str(), @@ -2465,7 +2457,8 @@ void CRainmeter::LoadTheme(const std::wstring& name) // Delete all meter windows DeleteMeterWindow(NULL); - std::wstring backup = GetSettingsPath() + L"Themes\\Backup"; + std::wstring backup = GetThemePath(); + backup += L"Backup"; CreateDirectory(backup.c_str(), NULL); backup += L"\\Rainmeter.thm"; @@ -2480,7 +2473,7 @@ void CRainmeter::LoadTheme(const std::wstring& name) CSystem::CopyFiles(m_IniFile, backup); // Replace Rainmeter.ini with theme - std::wstring theme = GetSettingsPath() + L"Themes\\"; + std::wstring theme = GetThemePath(); theme += name; std::wstring wallpaper = theme + L"\\RainThemes.bmp"; theme += L"\\Rainmeter.thm"; diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 99873280..51e293d2 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -240,8 +240,8 @@ private: void ActivateActiveSkins(); void CreateMeterWindow(const std::wstring& folderPath, const std::wstring& file); void WriteActive(const std::wstring& folderPath, int fileIndex); - void ScanForSkins(const std::wstring& path); - void ScanForThemes(const std::wstring& path); + void ScanForSkins(); + void ScanForThemes(); void ReadGeneralSettings(const std::wstring& iniFile); void SetLoadOrder(int folderIndex, int order); int GetLoadOrder(const std::wstring& folderPath); diff --git a/Library/System.cpp b/Library/System.cpp index 779d297f..3e4c4903 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -1165,8 +1165,7 @@ void CSystem::SetWallpaper(const std::wstring& wallpaper, const std::wstring& st Bitmap* bitmap = Bitmap::FromFile(wallpaper.c_str()); if (bitmap && bitmap->GetLastStatus() == Ok) { - std::wstring file = Rainmeter->GetSettingsPath(); - file += L"Wallpaper.bmp"; + std::wstring file = Rainmeter->GetSettingsPath() + L"Wallpaper.bmp"; const CLSID bmpClsid = { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } }; if (bitmap->Save(file.c_str(), &bmpClsid) == Ok) diff --git a/SkinInstaller/DialogBackup.cpp b/SkinInstaller/DialogBackup.cpp index ca20cfd8..fab4716f 100644 --- a/SkinInstaller/DialogBackup.cpp +++ b/SkinInstaller/DialogBackup.cpp @@ -226,7 +226,7 @@ bool CDialogBackup::CreateBackup() } if ((_waccess(addonsPath.c_str(), 0) == 0 && !AddFolderToBackup(addonsPath, L"", "Addons", true)) || - //(_waccess(skinsPath.c_str(), 0) == 0 && !AddFolderToBackup(skinsPath, L"", "Skins", true)) || + (_waccess(skinsPath.c_str(), 0) == 0 && !AddFolderToBackup(skinsPath, L"", "Skins", true)) || (_waccess(themesPath.c_str(), 0) == 0 && !AddFolderToBackup(themesPath, L"", "Themes", true)) || #ifdef _WIN64 (_waccess(pluginsPath.c_str(), 0) == 0 && !AddFolderToBackup(pluginsPath, L"", "Plugins\\64bit", false))) @@ -371,7 +371,8 @@ bool CDialogBackup::AddFolderToBackup(const std::wstring& path, std::wstring bas { if (wcscmp(L".", fd.cFileName) != 0 && wcscmp(L"..", fd.cFileName) != 0 && - wcscmp(L"Backup", fd.cFileName) != 0) + wcscmp(L"Backup", fd.cFileName) != 0 && + wcscmp(L"@Backup", fd.cFileName) != 0) { folders.push_back(fd.cFileName); } @@ -443,7 +444,7 @@ void CDialogBackup::CTabBackup::Initialize() SYSTEMTIME lt; GetLocalTime(<); - _snwprintf_s(buffer, _TRUNCATE, L"%02d.%02d.%02d-%02d.%02d", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute); + _snwprintf_s(buffer, _TRUNCATE, L"%04d.%02d.%02d-%02d.%02d", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute); c_Dialog->m_BackupTime = buffer;