CAPTION "Shell Integration"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- GROUPBOX "Explorer",IDC_STATIC,7,7,218,46
+ GROUPBOX "Explorer",IDC_STATIC,7,7,218,80
CONTROL "E&nable advanced menu",IDC_EXPLORER_ADVANCED,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,27,28,190,10
CONTROL "In&clude subfolders by default",IDC_EXPLORER_SUBFOLDERS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,27,38,190,10
CONTROL "&Add to context menu",IDC_EXPLORER_CONTEXT,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,17,18,200,10
+ PUSHBUTTON "&Register shell extension",IDC_REGISTER_SHELLEXTENSION,17,48,200,14
+ PUSHBUTTON "&Unregister shell extension",IDC_UNREGISTER_SHELLEXTENSION,17,64,200,14
END
IDD_PROPPAGE_COMPARE_FOLDER DIALOGEX 0, 0, 235, 205
#include "OptionsDef.h"
#include "OptionsMgr.h"
#include "OptionsPanel.h"
+#include "Environment.h"
+#include "paths.h"
#ifdef _DEBUG
#define new DEBUG_NEW
static LPCTSTR f_RegValueEnabled = _T("ContextMenuEnabled");
static LPCTSTR f_RegValuePath = _T("Executable");
+static bool IsShellExtensionRegistered()
+{
+ HKEY hKey;
+ if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("CLSID\\{4E716236-AA30-4C65-B225-D68BBA81E9C2}"), 0, KEY_QUERY_VALUE, &hKey)) {
+ RegCloseKey(hKey);
+ return true;
+ }
+ return false;
+}
+
+static bool RegisterShellExtension(bool unregister)
+{
+ TCHAR szSystem32[260] = { 0 };
+ TCHAR szSysWow64[260] = { 0 };
+ GetSystemDirectory(szSystem32, sizeof(szSystem32) / sizeof(szSystem32[0]));
+ GetSystemWow64Directory(szSysWow64, sizeof(szSysWow64) / sizeof(szSysWow64[0]));
+
+ String progpath = env_GetProgPath();
+ String regsvr32 = paths_ConcatPath(szSystem32, _T("regsvr32.exe"));
+ String args;
+ SHELLEXECUTEINFO sei = { sizeof(sei) };
+ sei.lpVerb = _T("runas");
+ if (szSysWow64[0])
+ {
+ args = (unregister ? _T("/s /u \"") : _T("/s \"")) + paths_ConcatPath(progpath, _T("ShellExtensionX64.dll")) + _T("\"");
+ sei.lpFile = regsvr32.c_str();
+ sei.lpParameters = args.c_str();
+ ShellExecuteEx(&sei);
+
+ regsvr32 = paths_ConcatPath(szSysWow64, _T("regsvr32.exe"));
+ args = (unregister ? _T("/s /u \"") : _T("/s \"")) + paths_ConcatPath(progpath, _T("ShellExtensionU.dll")) + _T("\"");
+ sei.lpFile = regsvr32.c_str();
+ sei.lpParameters = args.c_str();
+ return !!ShellExecuteEx(&sei);
+ }
+ else
+ {
+ args = (unregister ? _T("/s /u \"") : _T("/s \"")) + paths_ConcatPath(progpath, _T("ShellExtensionU.dll")) + _T("\"");
+ sei.lpFile = regsvr32.c_str();
+ sei.lpParameters = args.c_str();
+ return !!ShellExecuteEx(&sei);
+ }
+}
PropShell::PropShell(COptionsMgr *optionsMgr)
: OptionsPanel(optionsMgr, PropShell::IDD)
theApp.TranslateDialog(m_hWnd);
CPropertyPage::OnInitDialog();
+#ifndef BCM_SETSHIELD
+#define BCM_SETSHIELD (0x1600/*BCM_FIRST*/ + 0x000C)
+#endif
+
+ ::SendMessage(GetDlgItem(IDC_REGISTER_SHELLEXTENSION)->m_hWnd, BCM_SETSHIELD, 0, TRUE);
+ ::SendMessage(GetDlgItem(IDC_UNREGISTER_SHELLEXTENSION)->m_hWnd, BCM_SETSHIELD, 0, TRUE);
+
// Update shell extension checkboxes
+ UpdateButtons();
GetContextRegValues();
AdvancedContextMenuCheck();
SubfolderOptionCheck();
UpdateData(FALSE);
+ SetTimer(0, 1000, NULL);
+
return TRUE; // return TRUE unless you set the focus to a control
}
BEGIN_MESSAGE_MAP(PropShell, CPropertyPage)
//{{AFX_MSG_MAP(PropShell)
ON_BN_CLICKED(IDC_EXPLORER_CONTEXT, OnAddToExplorer)
+ ON_BN_CLICKED(IDC_REGISTER_SHELLEXTENSION, OnRegisterShellExtension)
+ ON_BN_CLICKED(IDC_UNREGISTER_SHELLEXTENSION, OnUnregisterShellExtension)
+ ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
{
AdvancedContextMenuCheck();
SubfolderOptionCheck();
+ UpdateButtons();
}
/// Saves given path to registry for ShellExtension, and Context Menu settings
/// Enable/Disable "Advanced menu" checkbox.
void PropShell::AdvancedContextMenuCheck()
{
- if (IsDlgButtonChecked(IDC_EXPLORER_CONTEXT))
- GetDlgItem(IDC_EXPLORER_ADVANCED)->EnableWindow(TRUE);
- else
+ if (!IsDlgButtonChecked(IDC_EXPLORER_CONTEXT))
{
- GetDlgItem(IDC_EXPLORER_ADVANCED)->EnableWindow(FALSE);
CheckDlgButton(IDC_EXPLORER_ADVANCED, FALSE);
m_bContextAdvanced = FALSE;
}
/// Enable/Disable "Include subfolders by default" checkbox.
void PropShell::SubfolderOptionCheck()
{
- if (IsDlgButtonChecked(IDC_EXPLORER_CONTEXT))
- GetDlgItem(IDC_EXPLORER_SUBFOLDERS)->EnableWindow(TRUE);
- else
+ if (!IsDlgButtonChecked(IDC_EXPLORER_CONTEXT))
{
- GetDlgItem(IDC_EXPLORER_SUBFOLDERS)->EnableWindow(FALSE);
CheckDlgButton(IDC_EXPLORER_SUBFOLDERS, FALSE);
m_bContextSubfolders = FALSE;
}
}
+
+void PropShell::UpdateButtons()
+{
+ bool registered = IsShellExtensionRegistered();
+ GetDlgItem(IDC_EXPLORER_CONTEXT)->EnableWindow(registered);
+ GetDlgItem(IDC_REGISTER_SHELLEXTENSION)->EnableWindow(!registered);
+ GetDlgItem(IDC_UNREGISTER_SHELLEXTENSION)->EnableWindow(registered);
+ GetDlgItem(IDC_EXPLORER_ADVANCED)->EnableWindow(
+ GetDlgItem(IDC_EXPLORER_CONTEXT)->IsWindowEnabled() && IsDlgButtonChecked(IDC_EXPLORER_CONTEXT));
+ GetDlgItem(IDC_EXPLORER_SUBFOLDERS)->EnableWindow(
+ GetDlgItem(IDC_EXPLORER_CONTEXT)->IsWindowEnabled() && IsDlgButtonChecked(IDC_EXPLORER_CONTEXT));
+}
+
+void PropShell::OnRegisterShellExtension()
+{
+ RegisterShellExtension(false);
+}
+
+void PropShell::OnUnregisterShellExtension()
+{
+ RegisterShellExtension(true);
+}
+
+void PropShell::OnTimer(UINT_PTR nIDEvent)
+{
+ UpdateButtons();
+}