From fd5de0095582cf2b00727067f7f70d415ecd82b6 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 13 Nov 2012 17:54:32 +0200 Subject: [PATCH] Manage Settings: Changed to remove ConfigEditor if it matches associated editor --- Library/DialogManage.cpp | 8 +++++--- Library/Rainmeter.cpp | 25 ++++++++++++------------- Library/Rainmeter.h | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index 7c104728..40c6be79 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -1827,9 +1827,11 @@ INT_PTR CDialogManage::CTabSettings::OnCommand(WPARAM wParam, LPARAM lParam) case IDC_MANAGESETTINGS_CONFIGEDITOR_TEXT: if (HIWORD(wParam) == EN_CHANGE) { - WCHAR buffer[MAX_LINE_LENGTH]; - std::wstring editor = (GetWindowText((HWND)lParam, buffer, MAX_LINE_LENGTH) > 0) ? buffer : L""; - Rainmeter->SetSkinEditor(editor); + WCHAR buffer[MAX_PATH]; + if (GetWindowText((HWND)lParam, buffer, _countof(buffer)) > 0) + { + Rainmeter->SetSkinEditor(buffer); + } } break; diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 90599b83..5b6da022 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -1503,23 +1503,22 @@ void CRainmeter::SetSkinPath(const std::wstring& skinPath) WritePrivateProfileString(L"Rainmeter", L"SkinPath", skinPath.c_str(), m_IniFile.c_str()); } -void CRainmeter::SetSkinEditor(const std::wstring& editor) +void CRainmeter::SetSkinEditor(const std::wstring& path) { - LPCWSTR tmp = editor.empty() ? NULL : editor.c_str(); - if (!tmp) + assert(!path.empty()); + + const WCHAR* pathSz = path.c_str(); + WCHAR buffer[MAX_PATH]; + DWORD cchOut = MAX_PATH; + HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut); + if (SUCCEEDED(hr) && _wcsicmp(pathSz, buffer) == 0) { - // Get the program path associated with .ini files - WCHAR buffer[MAX_PATH]; - DWORD cchOut = MAX_PATH; - HRESULT hr = AssocQueryString(ASSOCF_NOTRUNCATE, ASSOCSTR_EXECUTABLE, L".ini", L"open", buffer, &cchOut); - m_SkinEditor = (SUCCEEDED(hr) && cchOut > 0) ? buffer : L"Notepad"; - } - else - { - m_SkinEditor = editor; + // The selected editor and the associated editor is the same, so remove from Rainmeter.ini. + pathSz = NULL; } - WritePrivateProfileString(L"Rainmeter", L"ConfigEditor", tmp, m_IniFile.c_str()); + m_SkinEditor = path; + WritePrivateProfileString(L"Rainmeter", L"ConfigEditor", pathSz, m_IniFile.c_str()); } void CRainmeter::WriteActive(const std::wstring& folderPath, int fileIndex) diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 6dece2d8..5376d551 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -154,7 +154,7 @@ public: const std::wstring& GetDrive() { return m_Drive; } const std::wstring& GetSkinEditor() { return m_SkinEditor; } - void SetSkinEditor(const std::wstring& editor); + void SetSkinEditor(const std::wstring& path); const std::wstring& GetStatsDate() { return m_StatsDate; } HWND GetWindow() { return m_Window; }