Cleanup: Drop unnecessary method definitions
[TortoiseGit.git] / src / TortoiseProc / Settings / SetOverlayHandlers.cpp
bloba1fe3e6e735587861d80f60da5abd9d05b49580a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2010, 2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "SetOverlayHandlers.h"
24 IMPLEMENT_DYNAMIC(CSetOverlayHandlers, ISettingsPropPage)
25 CSetOverlayHandlers::CSetOverlayHandlers()
26 : ISettingsPropPage(CSetOverlayHandlers::IDD)
27 , m_bShowIgnoredOverlay(TRUE)
28 , m_bShowUnversionedOverlay(TRUE)
29 , m_bShowAddedOverlay(TRUE)
30 , m_bShowLockedOverlay(TRUE)
31 , m_bShowReadonlyOverlay(TRUE)
32 , m_bShowDeletedOverlay(TRUE)
34 m_regShowIgnoredOverlay = CRegDWORD(_T("Software\\TortoiseOverlays\\ShowIgnoredOverlay"), TRUE);
35 m_regShowUnversionedOverlay = CRegDWORD(_T("Software\\TortoiseOverlays\\ShowUnversionedOverlay"), TRUE);
36 m_regShowAddedOverlay = CRegDWORD(_T("Software\\TortoiseOverlays\\ShowAddedOverlay"), TRUE);
37 m_regShowLockedOverlay = CRegDWORD(_T("Software\\TortoiseOverlays\\ShowLockedOverlay"), TRUE);
38 m_regShowReadonlyOverlay = CRegDWORD(_T("Software\\TortoiseOverlays\\ShowReadonlyOverlay"), TRUE);
39 m_regShowDeletedOverlay = CRegDWORD(_T("Software\\TortoiseOverlays\\ShowDeletedOverlay"), TRUE);
41 m_bShowIgnoredOverlay = m_regShowIgnoredOverlay;
42 m_bShowUnversionedOverlay = m_regShowUnversionedOverlay;
43 m_bShowAddedOverlay = m_regShowAddedOverlay;
44 m_bShowLockedOverlay = m_regShowLockedOverlay;
45 m_bShowReadonlyOverlay = m_regShowReadonlyOverlay;
46 m_bShowDeletedOverlay = m_regShowDeletedOverlay;
49 CSetOverlayHandlers::~CSetOverlayHandlers()
53 void CSetOverlayHandlers::DoDataExchange(CDataExchange* pDX)
55 ISettingsPropPage::DoDataExchange(pDX);
56 DDX_Check(pDX, IDC_SHOWIGNOREDOVERLAY, m_bShowIgnoredOverlay);
57 DDX_Check(pDX, IDC_SHOWUNVERSIONEDOVERLAY, m_bShowUnversionedOverlay);
58 DDX_Check(pDX, IDC_SHOWADDEDOVERLAY, m_bShowAddedOverlay);
59 DDX_Check(pDX, IDC_SHOWLOCKEDOVERLAY, m_bShowLockedOverlay);
60 DDX_Check(pDX, IDC_SHOWREADONLYOVERLAY, m_bShowReadonlyOverlay);
61 DDX_Check(pDX, IDC_SHOWDELETEDOVERLAY, m_bShowDeletedOverlay);
64 BEGIN_MESSAGE_MAP(CSetOverlayHandlers, ISettingsPropPage)
65 ON_BN_CLICKED(IDC_SHOWIGNOREDOVERLAY, &CSetOverlayHandlers::OnChange)
66 ON_BN_CLICKED(IDC_SHOWUNVERSIONEDOVERLAY, &CSetOverlayHandlers::OnChange)
67 ON_BN_CLICKED(IDC_SHOWADDEDOVERLAY, &CSetOverlayHandlers::OnChange)
68 ON_BN_CLICKED(IDC_SHOWLOCKEDOVERLAY, &CSetOverlayHandlers::OnChange)
69 ON_BN_CLICKED(IDC_SHOWREADONLYOVERLAY, &CSetOverlayHandlers::OnChange)
70 ON_BN_CLICKED(IDC_SHOWDELETEDOVERLAY, &CSetOverlayHandlers::OnChange)
71 END_MESSAGE_MAP()
73 BOOL CSetOverlayHandlers::OnInitDialog()
75 ISettingsPropPage::OnInitDialog();
77 UpdateInfoLabel();
79 UpdateData(FALSE);
81 return TRUE;
84 void CSetOverlayHandlers::OnChange()
86 UpdateInfoLabel();
87 SetModified();
90 BOOL CSetOverlayHandlers::OnApply()
92 UpdateData();
94 if (DWORD(m_regShowIgnoredOverlay) != DWORD(m_bShowIgnoredOverlay))
95 m_restart = Restart_System;
96 Store (m_bShowIgnoredOverlay, m_regShowIgnoredOverlay);
98 if (DWORD(m_regShowUnversionedOverlay) != DWORD(m_bShowUnversionedOverlay))
99 m_restart = Restart_System;
100 Store (m_bShowUnversionedOverlay, m_regShowUnversionedOverlay);
102 if (DWORD(m_regShowAddedOverlay) != DWORD(m_bShowAddedOverlay))
103 m_restart = Restart_System;
104 Store (m_bShowAddedOverlay, m_regShowAddedOverlay);
106 if (DWORD(m_regShowLockedOverlay) != DWORD(m_bShowLockedOverlay))
107 m_restart = Restart_System;
108 Store (m_bShowLockedOverlay, m_regShowLockedOverlay);
110 if (DWORD(m_regShowReadonlyOverlay) != DWORD(m_bShowReadonlyOverlay))
111 m_restart = Restart_System;
112 Store (m_bShowReadonlyOverlay, m_regShowReadonlyOverlay);
114 if (DWORD(m_regShowDeletedOverlay) != DWORD(m_bShowDeletedOverlay))
115 m_restart = Restart_System;
116 Store (m_bShowDeletedOverlay, m_regShowDeletedOverlay);
119 SetModified(FALSE);
120 return ISettingsPropPage::OnApply();
123 int CSetOverlayHandlers::GetInstalledOverlays()
125 // if there are more than 12 overlay handlers installed, then that means not all
126 // of the overlay handlers can be shown. Windows chooses the ones first
127 // returned by RegEnumKeyEx() and just drops the ones that come last in
128 // that enumeration.
129 int nInstalledOverlayhandlers = 0;
130 // scan the registry for installed overlay handlers
131 HKEY hKey;
132 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
133 _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers"),
134 0, KEY_ENUMERATE_SUB_KEYS, &hKey)==ERROR_SUCCESS)
136 TCHAR value[2048];
137 TCHAR keystring[2048];
138 for (int i = 0, rc = ERROR_SUCCESS; rc == ERROR_SUCCESS; i++)
140 DWORD size = _countof(value);
141 FILETIME last_write_time;
142 rc = RegEnumKeyEx(hKey, i, value, &size, NULL, NULL, NULL, &last_write_time);
143 if (rc == ERROR_SUCCESS)
145 if (_tcsnicmp(&value[1], L"tortoise", 8) != 0)
147 // check if there's a 'default' entry with a guid
148 _tcscpy_s(keystring, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers\\"));
149 _tcscat_s(keystring, value);
150 DWORD dwType = 0;
151 DWORD dwSize = _countof(value); // the API docs only specify "The size of the destination data buffer",
152 // but better be safe than sorry using _countof instead of sizeof
153 if (SHGetValue(HKEY_LOCAL_MACHINE,
154 keystring,
155 NULL,
156 &dwType, value, &dwSize) == ERROR_SUCCESS)
158 if ((dwSize > 10)&&(value[0] == '{'))
159 nInstalledOverlayhandlers++;
164 RegCloseKey(hKey);
166 return nInstalledOverlayhandlers;
169 void CSetOverlayHandlers::UpdateInfoLabel()
171 CString sUnversioned, sNeedslock, sIgnored, sLocked;
172 GetDlgItemText(IDC_SHOWUNVERSIONEDOVERLAY, sUnversioned);
173 GetDlgItemText(IDC_SHOWREADONLYOVERLAY, sNeedslock);
174 GetDlgItemText(IDC_SHOWIGNOREDOVERLAY, sIgnored);
175 GetDlgItemText(IDC_SHOWLOCKEDOVERLAY, sLocked);
177 int nInstalledOverlays = GetInstalledOverlays();
178 CString sInfo;
179 sInfo.Format(IDS_SETTINGS_OVERLAYINFO, nInstalledOverlays);
181 const int nOverlayLimit = 3;
182 // max registered: drop the locked overlay
183 // max + 1 registered: drop the locked and the ignored overlay
184 // max + 2 registered: drop the locked, ignored and readonly overlay
185 // max + 3 or more registered: drop the locked, ignored, readonly and unversioned overlay
186 CString sInfo2;
187 if (nInstalledOverlays > nOverlayLimit+3)
188 sInfo2 += L", " + sUnversioned;
189 if (nInstalledOverlays > nOverlayLimit+2)
190 sInfo2 += L", " + sNeedslock;
191 if (nInstalledOverlays > nOverlayLimit+1)
192 sInfo2 += L", " + sIgnored;
193 if (nInstalledOverlays > nOverlayLimit)
194 sInfo2 += L", " + sLocked;
195 sInfo2.Trim(L" ,");
197 if (!sInfo2.IsEmpty())
199 CString sTemp;
200 sTemp.Format(IDS_SETTINGS_OVERLAYINFO2, (LPCWSTR)sInfo2);
201 sInfo += L"\n" + sTemp;
203 SetDlgItemText(IDC_HANDLERHINT, sInfo);