diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2015-12-31 03:00:00 +0300 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:16:58 +0300 |
commit | 9608215ad8deb58355bae27692669fda067c4f43 (patch) | |
tree | 1227131a3f19bc36e5da4ba11791154d05cc08af /CPP/7zip/UI/FileManager/MenuPage.cpp | |
parent | 5de23c1deb52b8be4c43ad9f694c64bbddd0c38a (diff) |
15.1315.13
Diffstat (limited to 'CPP/7zip/UI/FileManager/MenuPage.cpp')
-rw-r--r-- | CPP/7zip/UI/FileManager/MenuPage.cpp | 240 |
1 files changed, 190 insertions, 50 deletions
diff --git a/CPP/7zip/UI/FileManager/MenuPage.cpp b/CPP/7zip/UI/FileManager/MenuPage.cpp index 0784f92c..8852ce35 100644 --- a/CPP/7zip/UI/FileManager/MenuPage.cpp +++ b/CPP/7zip/UI/FileManager/MenuPage.cpp @@ -4,25 +4,34 @@ #include "../Common/ZipRegistry.h" +#include "../../../Windows/DLL.h" +#include "../../../Windows/ErrorMsg.h" +#include "../../../Windows/FileFind.h" + #include "../Explorer/ContextMenuFlags.h" #include "../Explorer/RegistryContextMenu.h" #include "../Explorer/resource.h" +#include "../FileManager/PropertyNameRes.h" + +#include "../GUI/ExtractDialogRes.h" + +#include "FormatUtils.h" #include "HelpUtils.h" #include "LangUtils.h" #include "MenuPage.h" #include "MenuPageRes.h" -#include "FormatUtils.h" -#include "../FileManager/PropertyNameRes.h" +using namespace NWindows; using namespace NContextMenuFlags; static const UInt32 kLangIDs[] = { - IDX_SYSTEM_INTEGRATE_TO_CONTEXT_MENU, + IDX_SYSTEM_INTEGRATE_TO_MENU, IDX_SYSTEM_CASCADED_MENU, IDX_SYSTEM_ICON_IN_MENU, + IDX_EXTRACT_ELIM_DUP, IDT_SYSTEM_CONTEXT_MENU_ITEMS }; @@ -34,64 +43,147 @@ struct CContextMenuItem UInt32 Flag; }; -static CContextMenuItem kMenuItems[] = +static const CContextMenuItem kMenuItems[] = { - { IDS_CONTEXT_OPEN, kOpen}, - { IDS_CONTEXT_OPEN, kOpenAs}, - { IDS_CONTEXT_EXTRACT, kExtract}, + { IDS_CONTEXT_OPEN, kOpen }, + { IDS_CONTEXT_OPEN, kOpenAs }, + { IDS_CONTEXT_EXTRACT, kExtract }, { IDS_CONTEXT_EXTRACT_HERE, kExtractHere }, { IDS_CONTEXT_EXTRACT_TO, kExtractTo }, - { IDS_CONTEXT_TEST, kTest}, + { IDS_CONTEXT_TEST, kTest }, { IDS_CONTEXT_COMPRESS, kCompress }, { IDS_CONTEXT_COMPRESS_TO, kCompressTo7z }, - { IDS_CONTEXT_COMPRESS_TO, kCompressToZip } + { IDS_CONTEXT_COMPRESS_TO, kCompressToZip }, #ifndef UNDER_CE - , { IDS_CONTEXT_COMPRESS_EMAIL, kCompressEmail }, { IDS_CONTEXT_COMPRESS_TO_EMAIL, kCompressTo7zEmail }, - { IDS_CONTEXT_COMPRESS_TO_EMAIL, kCompressToZipEmail } + { IDS_CONTEXT_COMPRESS_TO_EMAIL, kCompressToZipEmail }, #endif - , { IDS_PROP_CHECKSUM, kCRC } + { IDS_PROP_CHECKSUM, kCRC } }; + +#if !defined(_WIN64) +extern bool g_Is_Wow64; +#endif + + bool CMenuPage::OnInit() { _initMode = true; + + Clear_MenuChanged(); + LangSetDlgItems(*this, kLangIDs, ARRAY_SIZE(kLangIDs)); #ifdef UNDER_CE - EnableItem(IDX_SYSTEM_INTEGRATE_TO_CONTEXT_MENU, false); + + HideItem(IDX_SYSTEM_INTEGRATE_TO_MENU); + HideItem(IDX_SYSTEM_INTEGRATE_TO_MENU_2); + #else - CheckButton(IDX_SYSTEM_INTEGRATE_TO_CONTEXT_MENU, NZipRootRegistry::CheckContextMenuHandler()); + + { + UString s; + { + CWindow window(GetItem(IDX_SYSTEM_INTEGRATE_TO_MENU)); + window.GetText(s); + } + UString bit64 = LangString(IDS_PROP_BIT64); + if (bit64.IsEmpty()) + bit64.SetFromAscii("64-bit"); + #ifdef _WIN64 + bit64.Replace(L"64", L"32"); + #endif + s.Add_Space(); + s += L'('; + s += bit64; + s += L')'; + SetItemText(IDX_SYSTEM_INTEGRATE_TO_MENU_2, s); + } + + const FString prefix = NDLL::GetModuleDirPrefix(); + + _dlls[0].ctrl = IDX_SYSTEM_INTEGRATE_TO_MENU; + _dlls[1].ctrl = IDX_SYSTEM_INTEGRATE_TO_MENU_2; + + _dlls[0].wow = 0; + _dlls[1].wow = + #ifdef _WIN64 + KEY_WOW64_32KEY + #else + KEY_WOW64_64KEY + #endif + ; + + for (unsigned d = 0; d < 2; d++) + { + CShellDll &dll = _dlls[d]; + + dll.wasChanged = false; + + #ifndef _WIN64 + if (d != 0 && !g_Is_Wow64) + { + HideItem(dll.ctrl); + continue; + } + #endif + + FString &path = dll.Path; + path = prefix; + path.AddAscii(d == 0 ? "7-zip.dll" : + #ifdef _WIN64 + "7-zip32.dll" + #else + "7-zip64.dll" + #endif + ); + + + if (!NFile::NFind::DoesFileExist(path)) + { + path.Empty(); + EnableItem(dll.ctrl, false); + } + else + { + dll.prevValue = CheckContextMenuHandler(fs2us(path), dll.wow); + CheckButton(dll.ctrl, dll.prevValue); + } + } + #endif + CContextMenuInfo ci; ci.Load(); - CheckButton(IDX_SYSTEM_CASCADED_MENU, ci.Cascaded); - CheckButton(IDX_SYSTEM_ICON_IN_MENU, ci.MenuIcons); + CheckButton(IDX_SYSTEM_CASCADED_MENU, ci.Cascaded.Val); + CheckButton(IDX_SYSTEM_ICON_IN_MENU, ci.MenuIcons.Val); + CheckButton(IDX_EXTRACT_ELIM_DUP, ci.ElimDup.Val); _listView.Attach(GetItem(IDL_SYSTEM_OPTIONS)); - UInt32 newFlags = LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT; + const UInt32 newFlags = LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT; _listView.SetExtendedListViewStyle(newFlags, newFlags); - _listView.InsertColumn(0, L"", 100); + _listView.InsertColumn(0, L"", 200); - for (int i = 0; i < ARRAY_SIZE(kMenuItems); i++) + for (unsigned i = 0; i < ARRAY_SIZE(kMenuItems); i++) { - CContextMenuItem &menuItem = kMenuItems[i]; + const CContextMenuItem &menuItem = kMenuItems[i]; UString s = LangString(menuItem.ControlID); if (menuItem.Flag == kCRC) - s = L"CRC SHA"; + s.SetFromAscii("CRC SHA"); if (menuItem.Flag == kOpenAs || menuItem.Flag == kCRC) - s += L" >"; + s.AddAscii(" >"); switch (menuItem.ControlID) { @@ -108,11 +200,11 @@ bool CMenuPage::OnInit() { case kCompressTo7z: case kCompressTo7zEmail: - s2 += L".7z"; + s2.AddAscii(".7z"); break; case kCompressToZip: case kCompressToZipEmail: - s2 += L".zip"; + s2.AddAscii(".zip"); break; } s = MyFormatNew(s, s2); @@ -126,39 +218,68 @@ bool CMenuPage::OnInit() _listView.SetColumnWidthAuto(0); _initMode = false; + return CPropertyPage::OnInit(); } + #ifndef UNDER_CE -STDAPI DllRegisterServer(void); -STDAPI DllUnregisterServer(void); -HWND g_MenuPageHWND = 0; + +static void ShowMenuErrorMessage(const wchar_t *m, HWND hwnd) +{ + MessageBoxW(hwnd, m, L"7-Zip", MB_ICONERROR); +} + #endif + LONG CMenuPage::OnApply() { #ifndef UNDER_CE - g_MenuPageHWND = *this; - if (IsButtonCheckedBool(IDX_SYSTEM_INTEGRATE_TO_CONTEXT_MENU)) + + for (unsigned d = 2; d != 0;) { - DllRegisterServer(); - NZipRootRegistry::AddContextMenuHandler(); + d--; + CShellDll &dll = _dlls[d]; + if (dll.wasChanged && !dll.Path.IsEmpty()) + { + bool newVal = IsButtonCheckedBool(dll.ctrl); + LONG res = SetContextMenuHandler(newVal, fs2us(dll.Path), dll.wow); + if (res != ERROR_SUCCESS && (dll.prevValue != newVal || newVal)) + ShowMenuErrorMessage(NError::MyFormatMessage(res), *this); + dll.prevValue = CheckContextMenuHandler(fs2us(dll.Path), dll.wow); + CheckButton(dll.ctrl, dll.prevValue); + dll.wasChanged = false; + } } - else + + #endif + + if (_cascaded_Changed || _menuIcons_Changed || _elimDup_Changed || _flags_Changed) { - DllUnregisterServer(); - NZipRootRegistry::DeleteContextMenuHandler(); + CContextMenuInfo ci; + ci.Cascaded.Val = IsButtonCheckedBool(IDX_SYSTEM_CASCADED_MENU); + ci.Cascaded.Def = _cascaded_Changed; + + ci.MenuIcons.Val = IsButtonCheckedBool(IDX_SYSTEM_ICON_IN_MENU); + ci.MenuIcons.Def = _menuIcons_Changed; + + ci.ElimDup.Val = IsButtonCheckedBool(IDX_EXTRACT_ELIM_DUP); + ci.ElimDup.Def = _elimDup_Changed; + + ci.Flags = 0; + + for (unsigned i = 0; i < ARRAY_SIZE(kMenuItems); i++) + if (_listView.GetCheckState(i)) + ci.Flags |= kMenuItems[i].Flag; + + ci.Flags_Def = _flags_Changed; + ci.Save(); + + Clear_MenuChanged(); } - #endif - CContextMenuInfo ci; - ci.Cascaded = IsButtonCheckedBool(IDX_SYSTEM_CASCADED_MENU); - ci.MenuIcons = IsButtonCheckedBool(IDX_SYSTEM_ICON_IN_MENU); - ci.Flags = 0; - for (int i = 0; i < ARRAY_SIZE(kMenuItems); i++) - if (_listView.GetCheckState(i)) - ci.Flags |= kMenuItems[i].Flag; - ci.Save(); + // UnChanged(); return PSNRET_NOERROR; } @@ -172,14 +293,30 @@ bool CMenuPage::OnButtonClicked(int buttonID, HWND buttonHWND) { switch (buttonID) { - case IDX_SYSTEM_INTEGRATE_TO_CONTEXT_MENU: - case IDX_SYSTEM_CASCADED_MENU: - case IDX_SYSTEM_ICON_IN_MENU: - Changed(); - return true; + #ifndef UNDER_CE + case IDX_SYSTEM_INTEGRATE_TO_MENU: + case IDX_SYSTEM_INTEGRATE_TO_MENU_2: + { + for (unsigned d = 0; d < 2; d++) + { + CShellDll &dll = _dlls[d]; + if (buttonID == dll.ctrl && !dll.Path.IsEmpty()) + dll.wasChanged = true; + } + break; + } + #endif + + case IDX_SYSTEM_CASCADED_MENU: _cascaded_Changed = true; break; + case IDX_SYSTEM_ICON_IN_MENU: _menuIcons_Changed = true; break; + case IDX_EXTRACT_ELIM_DUP: _elimDup_Changed = true; break; + + default: + return CPropertyPage::OnButtonClicked(buttonID, buttonHWND); } - return CPropertyPage::OnButtonClicked(buttonID, buttonHWND); - + + Changed(); + return true; } bool CMenuPage::OnNotify(UINT controlID, LPNMHDR lParam) @@ -205,7 +342,10 @@ bool CMenuPage::OnItemChanged(const NMLISTVIEW *info) UINT oldState = info->uOldState & LVIS_STATEIMAGEMASK; UINT newState = info->uNewState & LVIS_STATEIMAGEMASK; if (oldState != newState) + { + _flags_Changed = true; Changed(); + } } return true; } |