Clone
ixen <ixen@copyhandler.com>
committed
on 08 Mar 16
Possible fix to a problem with shell extension communication with CH (CH-230).
LoggerImprovements + 5 more
src/ch/MainWnd.cpp (+159 -144)
650 650         case WM_SHOWMINIVIEW:
651 651                 {
652 652                         OnShowMiniView();
653 653                         return static_cast<LRESULT>(0);
654 654                         break;
655 655                 }
656 656
657 657         case WM_CONFIGNOTIFY:
658 658                 {
659 659                         GetApp().SetAutorun(GetPropValue<PP_PRELOADAFTERRESTART>(GetConfig()));
660 660
661 661                         // set this process class
662 662                         HANDLE hProcess=GetCurrentProcess();
663 663                         ::SetPriorityClass(hProcess, (DWORD)GetPropValue<PP_PPROCESSPRIORITYCLASS>(GetConfig()));
664 664
665 665                         break;
666 666                 }
667 667
668 668         case WM_GETCONFIG:
669 669                 {
  670                         try
  671                         {
670 672                                 chcore::TConfig& rConfig = GetConfig();
671 673                                 ictranslate::CResourceManager& rResManager = GetResManager();
672 674
673 675                                 TShellExtMenuConfig cfgShellExt;
674 676
675 677                                 // experimental - doesn't work on all systems
676 678                                 cfgShellExt.SetShowShortcutIcons(GetPropValue<PP_SHSHOWSHELLICONS>(rConfig));
677 679
678 680                                 cfgShellExt.SetInterceptDragAndDrop(GetPropValue<PP_SHINTERCEPTDRAGDROP>(rConfig));
679 681                                 cfgShellExt.SetInterceptKeyboardActions(GetPropValue<PP_SHINTERCEPTKEYACTIONS>(rConfig));
680 682                                 cfgShellExt.SetInterceptCtxMenuActions(GetPropValue<PP_SHINTERCEPTCTXMENUACTIONS>(rConfig));
681 683
682 684                                 TShellMenuItemPtr spRootItem = cfgShellExt.GetCommandRoot();
683 685
684 686                                 // what kind of menu ?
685 687                                 switch(wParam)
686 688                                 {
687 689                                 case eLocation_DragAndDropMenu:
688 690                                         {
689 691                                                 bool bAddedAnyOption = false;
 
702 704                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move),
703 705                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject),
704 706                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Move));
705 707                                                         bAddedAnyOption = true;
706 708                                                 }
707 709
708 710                                                 if(GetPropValue<PP_SHSHOWCOPYMOVE>(rConfig))
709 711                                                 {
710 712                                                         spRootItem->AddChild(boost::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING),
711 713                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy),
712 714                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject),
713 715                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), true));
714 716                                                         bAddedAnyOption = true;
715 717                                                 }
716 718
717 719                                                 if(bAddedAnyOption)
718 720                                                 {
719 721                                                         // insert separator as an addition to other items
720 722                                                         spRootItem->AddChild(boost::make_shared<TShellMenuItem>());
721 723                                                 }
722                                   }
723 724                                                 break;
  725                                         }
  726
724 727                                 case eLocation_ContextMenu:
725 728                                         {
726 729                                                 if(GetPropValue<PP_SHSHOWPASTE>(rConfig))
727 730                                                 {
728 731                                                         spRootItem->AddChild(boost::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING),
729 732                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy),
730 733                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard),
731 734                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), false));
732 735                                                 }
733 736
734 737                                                 if(GetPropValue<PP_SHSHOWPASTESPECIAL>(rConfig))
735 738                                                 {
736 739                                                         spRootItem->AddChild(boost::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING),
737 740                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy),
738 741                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard),
739 742                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true));
740 743                                                 }
741 744
742 745                                                 if(GetPropValue<PP_SHSHOWCOPYTO>(rConfig) || GetPropValue<PP_SHSHOWMOVETO>(rConfig) || GetPropValue<PP_SHSHOWCOPYMOVETO>(rConfig))
743 746                                                 {
 
826 829                                                                 {
827 830                                                                         menuItem->AddChild(boost::make_shared<TShellMenuItem>((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath,
828 831                                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy),
829 832                                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
830 833                                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true));
831 834                                                                 }
832 835
833 836                                                                 spRootItem->AddChild(menuItem);
834 837
835 838                                                                 // optionally separator
836 839                                                                 if(!vShortcuts.empty())
837 840                                                                         menuItem->AddChild(boost::make_shared<TShellMenuItem>());
838 841
839 842                                                                 // "Choose" menu option
840 843                                                                 menuItem->AddChild(boost::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING),
841 844                                                                         TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy),
842 845                                                                         TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
843 846                                                                         TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true));
844 847                                                         }
845 848                                                 }
846                                   }
847 849
848 850                                                 break;
  851                                         }
  852
849 853                                 default:
850 854                                         ASSERT(false);  // unhandled case
851 855                                 }
852 856
853 857                                 chcore::TConfig cfgStorage;
854 858                                 chcore::TString wstrData;
855 859
856 860                                 cfgShellExt.StoreInConfig(cfgStorage, _T("ShellExtCfg"));
857 861                                 cfgStorage.WriteToString(wstrData);
858 862
859 863                                 std::wstring strSHMName = IPCSupport::GenerateSHMName((unsigned long)lParam);
860 864
861 865                                 m_tCHExtharedMemory.Create(strSHMName.c_str(), wstrData);
862 866                         }
863                   break;
  867                         catch(const std::exception& e)
  868                         {
  869                                 _ASSERTE(FALSE);
  870                                 CString strMsg;
  871                                 strMsg.Format(L"Encountered problem trying to retrieve shell ext configuration.\nReason: %S", e.what());
  872                                 LOG_ERROR(strMsg);
864 873
  874                                 return FALSE;
  875                         }
  876
  877                         return TRUE;
  878                 }
  879
865 880         case WM_IDENTIFY:
866 881                 {
867 882                         //decode
868 883                         unsigned char *dec=new unsigned char[iCount+1];
869 884                         dec[iCount]=0;
870 885
871 886                         unsigned short sData;
872 887                         for (int i=0, j=0;i<iCount;i++)
873 888                         {
874 889                                 sData=static_cast<unsigned short>(msg[i] - _hash[j]);
875 890
876 891                                 sData >>= off[j];
877 892                                 dec[i]=static_cast<unsigned char>(sData);
878 893
879 894                                 if (++j >= iOffCount)
880 895                                         j=0;
881 896                         }
882 897
883 898                         CA2T ca2t(reinterpret_cast<char*>(dec));
884 899                         AfxMessageBox(ca2t);