Index: src/ch/MainWnd.cpp =================================================================== diff -u -r8dc649003961dad64b92da67426814fb5dd862e0 -rc17c4aa7bb4c96219af4191623abe40d18e02713 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 8dc649003961dad64b92da67426814fb5dd862e0) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision c17c4aa7bb4c96219af4191623abe40d18e02713) @@ -667,200 +667,215 @@ case WM_GETCONFIG: { - chcore::TConfig& rConfig = GetConfig(); - ictranslate::CResourceManager& rResManager = GetResManager(); + try + { + chcore::TConfig& rConfig = GetConfig(); + ictranslate::CResourceManager& rResManager = GetResManager(); - TShellExtMenuConfig cfgShellExt; + TShellExtMenuConfig cfgShellExt; - // experimental - doesn't work on all systems - cfgShellExt.SetShowShortcutIcons(GetPropValue(rConfig)); + // experimental - doesn't work on all systems + cfgShellExt.SetShowShortcutIcons(GetPropValue(rConfig)); - cfgShellExt.SetInterceptDragAndDrop(GetPropValue(rConfig)); - cfgShellExt.SetInterceptKeyboardActions(GetPropValue(rConfig)); - cfgShellExt.SetInterceptCtxMenuActions(GetPropValue(rConfig)); + cfgShellExt.SetInterceptDragAndDrop(GetPropValue(rConfig)); + cfgShellExt.SetInterceptKeyboardActions(GetPropValue(rConfig)); + cfgShellExt.SetInterceptCtxMenuActions(GetPropValue(rConfig)); - TShellMenuItemPtr spRootItem = cfgShellExt.GetCommandRoot(); + TShellMenuItemPtr spRootItem = cfgShellExt.GetCommandRoot(); - // what kind of menu ? - switch (wParam) - { - case eLocation_DragAndDropMenu: + // what kind of menu ? + switch(wParam) { - bool bAddedAnyOption = false; - if(GetPropValue(rConfig)) + case eLocation_DragAndDropMenu: { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUCOPY_STRING), rResManager.LoadString(IDS_MENUTIPCOPY_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Copy)); - bAddedAnyOption = true; - } + bool bAddedAnyOption = false; + if(GetPropValue(rConfig)) + { + spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUCOPY_STRING), rResManager.LoadString(IDS_MENUTIPCOPY_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Copy)); + bAddedAnyOption = true; + } - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUMOVE_STRING), rResManager.LoadString(IDS_MENUTIPMOVE_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Move)); - bAddedAnyOption = true; - } + if(GetPropValue(rConfig)) + { + spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUMOVE_STRING), rResManager.LoadString(IDS_MENUTIPMOVE_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Move)); + bAddedAnyOption = true; + } - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), true)); - bAddedAnyOption = true; - } + if(GetPropValue(rConfig)) + { + spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), true)); + bAddedAnyOption = true; + } - if(bAddedAnyOption) - { - // insert separator as an addition to other items - spRootItem->AddChild(boost::make_shared()); + if(bAddedAnyOption) + { + // insert separator as an addition to other items + spRootItem->AddChild(boost::make_shared()); + } + break; } - } - break; - case eLocation_ContextMenu: - { - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), false)); - } - if(GetPropValue(rConfig)) + case eLocation_ContextMenu: { - spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true)); - } + if(GetPropValue(rConfig)) + { + spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), false)); + } - if(GetPropValue(rConfig) || GetPropValue(rConfig) || GetPropValue(rConfig)) - { - // prepare shortcuts for all menu options - std::vector vShortcutStrings; - GetPropValue(rConfig, vShortcutStrings); + if(GetPropValue(rConfig)) + { + spRootItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true)); + } - bool bRetrieveFreeSpace = GetPropValue(rConfig); + if(GetPropValue(rConfig) || GetPropValue(rConfig) || GetPropValue(rConfig)) + { + // prepare shortcuts for all menu options + std::vector vShortcutStrings; + GetPropValue(rConfig, vShortcutStrings); - std::vector vShortcuts; + bool bRetrieveFreeSpace = GetPropValue(rConfig); - BOOST_FOREACH(const CString& strShortcutString, vShortcutStrings) - { - CShortcut tShortcut; - if(tShortcut.FromString(strShortcutString)) - { - unsigned long long ullSize = 0; + std::vector vShortcuts; - // retrieving free space might fail, but it's not critical - we just won't show the free space - if(bRetrieveFreeSpace && GetDynamicFreeSpace(tShortcut.m_strPath, &ullSize, NULL)) + BOOST_FOREACH(const CString& strShortcutString, vShortcutStrings) + { + CShortcut tShortcut; + if(tShortcut.FromString(strShortcutString)) { - CString strNameFormat; - strNameFormat.Format(_T("%s (%s)"), tShortcut.m_strName, GetSizeString(ullSize)); + unsigned long long ullSize = 0; - tShortcut.m_strName = strNameFormat; - } + // retrieving free space might fail, but it's not critical - we just won't show the free space + if(bRetrieveFreeSpace && GetDynamicFreeSpace(tShortcut.m_strPath, &ullSize, NULL)) + { + CString strNameFormat; + strNameFormat.Format(_T("%s (%s)"), tShortcut.m_strName, GetSizeString(ullSize)); - vShortcuts.push_back(tShortcut); + tShortcut.m_strName = strNameFormat; + } + + vShortcuts.push_back(tShortcut); + } + else + BOOST_ASSERT(false); // non-critical, but not very nice } - else - BOOST_ASSERT(false); // non-critical, but not very nice - } - if(GetPropValue(rConfig)) - { - boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING))); - BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) + if(GetPropValue(rConfig)) { - menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING))); + BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) + { + menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); + } + + spRootItem->AddChild(menuItem); + + // optionally separator + if(!vShortcuts.empty()) + menuItem->AddChild(boost::make_shared()); + + // "Choose" menu option + menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); + TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); } - spRootItem->AddChild(menuItem); + if(GetPropValue(rConfig)) + { + boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING))); + BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) + { + menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); + } - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(boost::make_shared()); + spRootItem->AddChild(menuItem); - // "Choose" menu option - menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); - } + // optionally separator + if(!vShortcuts.empty()) + menuItem->AddChild(boost::make_shared()); - if(GetPropValue(rConfig)) - { - boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING))); - BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) - { - menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + // "Choose" menu option + menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); + TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); } - spRootItem->AddChild(menuItem); + if(GetPropValue(rConfig)) + { + boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING))); + BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) + { + menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true)); + } - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(boost::make_shared()); + spRootItem->AddChild(menuItem); - // "Choose" menu option - menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); - } + // optionally separator + if(!vShortcuts.empty()) + menuItem->AddChild(boost::make_shared()); - if(GetPropValue(rConfig)) - { - boost::shared_ptr menuItem(boost::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING))); - BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts) - { - menuItem->AddChild(boost::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + // "Choose" menu option + menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true)); + TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true)); } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(boost::make_shared()); - - // "Choose" menu option - menuItem->AddChild(boost::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true)); } + + break; } + + default: + ASSERT(false); // unhandled case } - break; - default: - ASSERT(false); // unhandled case - } + chcore::TConfig cfgStorage; + chcore::TString wstrData; - chcore::TConfig cfgStorage; - chcore::TString wstrData; + cfgShellExt.StoreInConfig(cfgStorage, _T("ShellExtCfg")); + cfgStorage.WriteToString(wstrData); - cfgShellExt.StoreInConfig(cfgStorage, _T("ShellExtCfg")); - cfgStorage.WriteToString(wstrData); + std::wstring strSHMName = IPCSupport::GenerateSHMName((unsigned long)lParam); - std::wstring strSHMName = IPCSupport::GenerateSHMName((unsigned long)lParam); + m_tCHExtharedMemory.Create(strSHMName.c_str(), wstrData); + } + catch(const std::exception& e) + { + _ASSERTE(FALSE); + CString strMsg; + strMsg.Format(L"Encountered problem trying to retrieve shell ext configuration.\nReason: %S", e.what()); + LOG_ERROR(strMsg); - m_tCHExtharedMemory.Create(strSHMName.c_str(), wstrData); + return FALSE; + } + + return TRUE; } - break; case WM_IDENTIFY: { Index: src/chext/DropMenuExt.cpp =================================================================== diff -u -rc33d4855ebf17772c28012a66c829a1f21d080f5 -rc17c4aa7bb4c96219af4191623abe40d18e02713 --- src/chext/DropMenuExt.cpp (.../DropMenuExt.cpp) (revision c33d4855ebf17772c28012a66c829a1f21d080f5) +++ src/chext/DropMenuExt.cpp (.../DropMenuExt.cpp) (revision c17c4aa7bb4c96219af4191623abe40d18e02713) @@ -232,6 +232,9 @@ HRESULT CDropMenuExt::ReadShellConfig() { BOOST_LOG_FUNC(); + + TLogger& rLogger = Logger::get(); + try { HWND hWnd = ShellExtensionVerifier::VerifyShellExt(m_piShellExtControl); @@ -240,7 +243,11 @@ // get cfg from ch unsigned long ulSHMID = GetTickCount(); - ::SendMessage(hWnd, WM_GETCONFIG, eLocation_DragAndDropMenu, ulSHMID); + if(::SendMessage(hWnd, WM_GETCONFIG, eLocation_DragAndDropMenu, ulSHMID) != TRUE) + { + BOOST_LOG_SEV(rLogger, error) << L"Failed to retrieve configuration from Copy Handler"; + return E_FAIL; + } std::wstring strSHMName = IPCSupport::GenerateSHMName(ulSHMID); Index: src/chext/MenuExt.cpp =================================================================== diff -u -r3d1de44762647618faf9b5b3a87f89b293899d8d -rc17c4aa7bb4c96219af4191623abe40d18e02713 --- src/chext/MenuExt.cpp (.../MenuExt.cpp) (revision 3d1de44762647618faf9b5b3a87f89b293899d8d) +++ src/chext/MenuExt.cpp (.../MenuExt.cpp) (revision c17c4aa7bb4c96219af4191623abe40d18e02713) @@ -390,6 +390,8 @@ { BOOST_LOG_FUNC(); + TLogger& rLogger = Logger::get(); + try { HWND hWnd = ShellExtensionVerifier::VerifyShellExt(m_piShellExtControl); @@ -398,7 +400,11 @@ // get cfg from ch unsigned long ulSHMID = GetTickCount(); - ::SendMessage(hWnd, WM_GETCONFIG, eLocation_ContextMenu, ulSHMID); + if(::SendMessage(hWnd, WM_GETCONFIG, eLocation_ContextMenu, ulSHMID) != TRUE) + { + BOOST_LOG_SEV(rLogger, error) << L"Failed to retrieve configuration from Copy Handler"; + return E_FAIL; + } std::wstring strSHMName = IPCSupport::GenerateSHMName(ulSHMID); @@ -409,8 +415,6 @@ tSharedMemory.Open(strSHMName.c_str()); tSharedMemory.Read(wstrData); - //::MessageBox(NULL, wstrData.GetData(), _T("CMenuExt::ReadShellConfig"), MB_OK); - cfgShellExtData.ReadFromString(wstrData); m_tShellExtMenuConfig.ReadFromConfig(cfgShellExtData, _T("ShellExtCfg"));