private void HandleClick(Point pt, Keys modifierKeys) {
     IShellItem item = null;
     try {
         TVHITTESTINFO structure = new TVHITTESTINFO { pt = pt };
         IntPtr wParam = PInvoke.SendMessage(treeController.Handle, 0x1111, IntPtr.Zero, ref structure);
         if(wParam != IntPtr.Zero) {
             if((structure.flags & 0x10) == 0 && (structure.flags & 0x80) == 0) {
                 treeControl.HitTest(pt, out item);
                 if(item != null) {
                     IntPtr pidl;
                     if(PInvoke.SHGetIDListFromObject(item, out pidl) == 0) {
                         using(IDLWrapper wrapper = new IDLWrapper(pidl)) {
                             TreeViewMiddleClicked(wrapper, modifierKeys);
                         }
                     }
                 }
             }
         }
     }
     finally {
         if(item != null) {
             Marshal.ReleaseComObject(item);
         }
     }
 }
 public AppLauncher(Address[] addresses, string pathCurrent) {
     List<string> list = new List<string>();
     List<string> list2 = new List<string>();
     this.strCurrentPath = this.strSelFiles = this.strSelDirs = this.strSelObjs = string.Empty;
     this.iSelItemsCount = this.iSelFileCount = this.iSelDirsCount = 0;
     if(addresses != null) {
         this.iSelItemsCount = addresses.Length;
         for(int i = 0; i < addresses.Length; i++) {
             using(IDLWrapper wrapper = new IDLWrapper(addresses[i].ITEMIDLIST)) {
                 if(wrapper.Available && wrapper.HasPath) {
                     if(wrapper.IsFileSystemFile) {
                         list.Add(addresses[i].Path);
                     }
                     else {
                         list2.Add(addresses[i].Path);
                     }
                 }
             }
         }
     }
     if(Directory.Exists(pathCurrent)) {
         this.strCurrentPath = "\"" + pathCurrent + "\"";
     }
     foreach(string str in list) {
         this.strSelFiles = this.strSelFiles + "\"" + str + "\" ";
     }
     foreach(string str2 in list2) {
         this.strSelDirs = this.strSelDirs + "\"" + str2 + "\" ";
     }
     this.strSelObjs = (this.strSelFiles + this.strSelDirs).Trim();
     this.strSelFiles = this.strSelFiles.Trim();
     this.strSelDirs = this.strSelDirs.Trim();
     this.iSelFileCount = list.Count;
     this.iSelDirsCount = list2.Count;
 }
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            string root = Environment.GetFolderPath(RootFolder);
            using(IDLWrapper wrapper = new IDLWrapper(root)) {
                BROWSEINFO bi = new BROWSEINFO();
                bi.hwndOwner = hwndOwner;
                bi.pidlRoot = wrapper.PIDL;
                bi.lpszTitle = Description;
                bi.ulFlags = BROWSEINFO.BIF_NEWDIALOGSTYLE | BROWSEINFO.BIF_SHAREABLE | BROWSEINFO.BIF_EDITBOX;
                if(!ShowNewFolderButton) {
                    bi.ulFlags |= BROWSEINFO.BIF_NONEWFOLDERBUTTON;
                }

                using(IDLWrapper wrapper2 = new IDLWrapper(PInvoke.SHBrowseForFolder(ref bi))) {
                    SelectedPath = wrapper2.Path;
                    SelectedIDL = wrapper2.IDL;
                    return !String.IsNullOrEmpty(SelectedPath);
                }
            }
        }
        public static int PopUpSystemContextMenu(IDLWrapper idlw, Point pntShow, ref IContextMenu2 pIContextMenu2, IntPtr hwndParent, bool fCanRemove) {
            IShellFolder ppv = null;
            int num5;
            try {
                IntPtr ptr;
                if((!idlw.Available || (PInvoke.SHBindToParent(idlw.PIDL, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr) != 0)) || (ppv == null)) {
                    return -1;
                }
                IntPtr[] apidl = new IntPtr[] { ptr };
                uint rgfReserved = 0;
                Guid riid = ExplorerGUIDs.IID_IContextMenu;
                object obj2 = null;
                ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2);
                if(pIContextMenu2 != null) {
                    Marshal.ReleaseComObject(pIContextMenu2);
                    pIContextMenu2 = null;
                }
                pIContextMenu2 = obj2 as IContextMenu2;
                if(pIContextMenu2 == null) {
                    return -2;
                }
                ContextMenu menu = new ContextMenu();
                uint uFlags = 0;
                if((Control.ModifierKeys & Keys.Shift) == Keys.Shift) {
                    uFlags |= 0x100;
                }
                pIContextMenu2.QueryContextMenu(menu.Handle, 0, 1, 0xffff, uFlags);
                if(fCanRemove) {
                    PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null);
                    PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xffff), QTUtility.ResMain[0x19]);
                }
                if((idlw.HasPath && (idlw.Path.Length > 3)) && (idlw.IsFileSystemFolder || idlw.IsFileSystemFile)) {
                    if(!fCanRemove) {
                        PInvoke.AppendMenu(menu.Handle, 0x800, IntPtr.Zero, null);
                    }
                    PInvoke.AppendMenu(menu.Handle, 0, new IntPtr(0xfffe), QTUtility.ResMain[0x1a]);
                }
                uint num3 = PInvoke.TrackPopupMenu(menu.Handle, 0x100, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero);
                int num4 = -3;
                switch(num3) {
                    case 0:
                        num4 = 0xfffd;
                        break;

                    case 0xffff:
                        menu.Dispose();
                        return 0xffff;

                    case 0xfffe:
                        if(idlw.HasPath) {
                            try {
                                string directoryName = Path.GetDirectoryName(idlw.Path);
                                if(Directory.Exists(directoryName)) {
                                    IntPtr currentHandle = QTUtility.instanceManager.CurrentHandle;
                                    if(PInvoke.IsWindow(currentHandle)) {
                                        QTUtility2.SendCOPYDATASTRUCT(currentHandle, (IntPtr)0x10, directoryName, IntPtr.Zero);
                                        num4 = 0xfffe;
                                    }
                                    else {
                                        Process.Start(directoryName);
                                        num4 = -4;
                                    }
                                }
                            }
                            catch {
                                SystemSounds.Asterisk.Play();
                            }
                        }
                        break;

                    default: {
                            CMINVOKECOMMANDINFO structure = new CMINVOKECOMMANDINFO();
                            structure.cbSize = Marshal.SizeOf(structure);
                            structure.fMask = 0;
                            structure.hwnd = hwndParent;
                            structure.lpVerb = (IntPtr)((num3 - 1) & 0xffff);
                            structure.lpParameters = IntPtr.Zero;
                            structure.lpDirectory = IntPtr.Zero;
                            structure.nShow = 1;
                            structure.dwHotKey = 0;
                            structure.hIcon = IntPtr.Zero;
                            num4 = pIContextMenu2.InvokeCommand(ref structure);
                            break;
                        }
                }
                menu.Dispose();
                num5 = num4;
            }
            catch {
                num5 = -1;
            }
            finally {
                if(ppv != null) {
                    Marshal.ReleaseComObject(ppv);
                    ppv = null;
                }
            }
            return num5;
        }
 private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     if(e.RowIndex >= 0 && e.ColumnIndex > 0) {
         string path = dgvHash.Rows[e.RowIndex].Cells[1].ToolTipText;
         InstanceManager.InvokeMain(tabBar => {
             using(IDLWrapper idlw = new IDLWrapper(Path.GetDirectoryName(path))) {
                 if(idlw.Available) {
                     tabBar.OpenNewTabOrWindow(idlw);
                 }
             }
         });
     }
 }
Exemple #6
0
        private void DoFileTools(int index)
        {
            // desktop thread

            // 0	copy path
            // 1	copy name
            // 2	copy path current
            // 3	copy name current
            // 4	file hash
            // 5	show SubDirTip for selected folder
            // 6	copy file hash

            try {
                if(index == 2 || index == 3) {
                    // Send desktop path/name to Clipboard.
                    string str = String.Empty;
                    if(index == 2) {
                        str = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    }
                    else {
                        byte[] idl = new byte[] {0, 0};
                        using(IDLWrapper idlw = new IDLWrapper(idl)) {
                            if(idlw.Available) {
                                str = idlw.DisplayName;
                            }
                        }
                    }

                    if(str.Length > 0) {
                        QTUtility2.SetStringClipboard(str);
                    }
                    return;
                }

                // File Hash
                if(index == 4 || index == 6) {
                    List<string> lstPaths = new List<string>();
                    foreach(IDLWrapper idlw in ShellBrowser.GetItems(true)) {
                        if(idlw.IsLink) {
                            string pathLinkTarget = ShellMethods.GetLinkTargetPath(idlw.Path);
                            if(File.Exists(pathLinkTarget)) {
                                lstPaths.Add(pathLinkTarget);
                            }
                        }
                        else if(idlw.IsFileSystemFile) {
                            lstPaths.Add(idlw.Path);
                        }
                    }

                    /* TODO
                    if(index == 4) {
                        FileHashComputer.ShowForm(lstPaths.ToArray());
                    }
                    else {
                        FileHashComputer.GetForPath(lstPaths, hwndListView);
                    }*/
                    return;
                }

                // Show subdirtip.
                if(index == 5) {
                    slvDesktop.ShowAndClickSubDirTip();
                    return;
                }

                // Copy name/path
                if(index == 0 || index == 1) {
                    string str = ShellBrowser.GetItems(true)
                            .Select(idlw => index == 0 ? idlw.ParseName : idlw.DisplayName)
                            .StringJoin(Environment.NewLine);
                    if(str.Length > 0) QTUtility2.SetStringClipboard(str);
                }
            }
            catch(Exception ex) {
                QTUtility2.MakeErrorLog(ex);
            }
        }
Exemple #7
0
 private static void OpenWindow(IDLWrapper pidl)
 {
     const int SW_SHOWNORMAL = 1;
     const int SEE_MASK_IDLIST = 0x00000004;
     SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO {
         cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)),
         nShow = SW_SHOWNORMAL,
         fMask = SEE_MASK_IDLIST,
         lpIDList = pidl.PIDL
     };
     PInvoke.ShellExecuteEx(ref sei);
 }
Exemple #8
0
        private void timer_HoverSubDirTipMenu_Tick(object sender, EventArgs e)
        {
            // drop hilited and MouseHoverTime elapsed

            // desktop thread
            timer_HoverSubDirTipMenu.Enabled = false;
            int iItem = itemIndexDROPHILITED;

            if(MouseButtons != MouseButtons.None) {
                Point pnt = MousePosition;
                PInvoke.MapWindowPoints(IntPtr.Zero, hwndListView, ref pnt, 1);
                if(iItem == PInvoke.ListView_HitTest(hwndListView, QTUtility2.Make_LPARAM(pnt.X, pnt.Y))) {
                    using(IDLWrapper idlw = new IDLWrapper(GetItemPIDL(iItem))) {
                        if(idlw.Available) {
                            if(subDirTip != null) {
                                subDirTip.HideMenu();
                            }

                            if(!String.Equals(idlw.Path, CLSIDSTR_TRASHBIN, StringComparison.OrdinalIgnoreCase)) {
                                if(ShowSubDirTip(idlw.PIDL, iItem, true)) {
                                    itemIndexDROPHILITED = iItem;
                                    PInvoke.SetFocus(hwndListView);
                                    PInvoke.SetForegroundWindow(hwndListView);
                                    HideThumbnailTooltip();
                                    subDirTip.ShowMenuForDropHilited(GetDesktopIconSize());
                                    return;
                                }
                            }
                        }
                    }
                }

                if(subDirTip != null) {
                    if(subDirTip.IsMouseOnMenus) {
                        itemIndexDROPHILITED = -1;
                        return;
                    }
                }
            }

            HideSubDirTip();
        }
Exemple #9
0
        private void subDirTip_MenuItemRightClicked(object sender, ItemRightClickedEventArgs e)
        {
            // the calling thread can be taskBar or desktop

            using(IDLWrapper idlw = new IDLWrapper(((QMenuItem)e.ClickedItem).IDL, false)) {
                if(sender == subDirTip) {
                    e.Result = ShellMethods.PopUpShellContextMenu(idlw, e.IsKey ? e.Point : MousePosition,
                            ref iContextMenu2_Desktop, subDirTip.Handle, false);
                }
                else // subDirTip_TB
                {
                    e.Result = ShellMethods.PopUpShellContextMenu(idlw, e.IsKey ? e.Point : MousePosition,
                            ref iContextMenu2, subDirTip_TB.Handle, false);
                }

                if(e.Result == MC.COMMANDID_OPENPARENT) {
                    using(IDLWrapper idlwParent = new IDLWrapper(ShellMethods.GetParentIDL(idlw.PIDL))) {
                        if(idlwParent.Available) {
                            Thread thread = new Thread(OpenTab);
                            thread.SetApartmentState(ApartmentState.STA);
                            thread.IsBackground = true;
                            thread.Start(new object[] {null, ModifierKeys, idlwParent.IDL});
                        }
                    }
                }
            }
        }
Exemple #10
0
 private void subDirTip_MultipleMenuItemsRightClicked(object sender, ItemRightClickedEventArgs e)
 {
     List<string> executedDirectories = ((SubDirTipForm)sender).ExecutedDirectories;
     // TODO: Replace ExecutedDirectories with ExecutedIDLs.
     List<byte[]> executedIDLs = executedDirectories.Select(path => {
         using(IDLWrapper wrapper = new IDLWrapper(path)) {
             return wrapper.IDL;
         }
     }).ToList();
     e.HRESULT = iContextMenu2_Desktop.Open(executedIDLs, e.IsKey ? e.Point : MousePosition, ((SubDirTipForm)sender).Handle);
 }
Exemple #11
0
 private void OpenGroup(string group)
 {
     bool fForceNewWindow = (ModifierKeys == Keys.Control);
     if(!fForceNewWindow && Config.Window.CaptureNewWindows && InstanceManager.GetTotalInstanceCount() > 0) {
         InstanceManager.BeginInvokeMain(tabbar => tabbar.OpenGroup(@group, false));
     }
     else {
         Group g = GroupsManager.GetGroup(group);
         if(g == null || g.Paths.Count == 0) return;
         StaticReg.CreateWindowGroup = group;
         using(var pidl = new IDLWrapper(g.Paths[0])) {
             // todo: ensure it gets locked and what not
             OpenWindow(pidl);
         }
     }
 }
Exemple #12
0
 private bool DoItemClick(int itemId, Keys modKeys, bool middle)
 {
     IntPtr lParam = GetButtonLParam(itemId);
     IntPtr ptr = PInvoke.DPA_GetPtr(hdpa, (int)lParam); // This pointer is NOT AddRef'd.  Do not Release it!!
     if(ptr == IntPtr.Zero) return false;
     IntPtr pidl;
     PInvoke.SHGetIDListFromObject(ptr, out pidl);
     using(IDLWrapper wrapper = new IDLWrapper(pidl)) {
         return ItemClicked(wrapper, modKeys, middle);
     }
 }
Exemple #13
0
 public static void Execute(MenuItemArguments mia, IntPtr hwnd)
 {
     if (((mia == null) || (mia.Genre != MenuGenre.Application)) || string.IsNullOrEmpty(mia.Path))
     {
         QTUtility2.MakeErrorLog(null, "Applauncher.Execute bug found");
     }
     else
     {
         string path             = mia.Path;
         string argument         = mia.Argument;
         string workingDirectory = mia.WorkingDirectory;
         if (!string.Equals(path, "separator", StringComparison.OrdinalIgnoreCase))
         {
             bool flag = false;
             if (path.StartsWith("::"))
             {
                 using (IDLWrapper wrapper = new IDLWrapper(path)) {
                     if (wrapper.Available)
                     {
                         SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO();
                         structure.cbSize   = Marshal.SizeOf(structure);
                         structure.nShow    = 1;
                         structure.fMask    = 4;
                         structure.lpIDList = wrapper.PIDL;
                         structure.hwnd     = hwnd;
                         PInvoke.ShellExecuteEx(ref structure);
                         return;
                     }
                 }
                 flag = true;
             }
             if (path.StartsWith(@"\\"))
             {
                 using (IDLWrapper wrapper2 = new IDLWrapper(path)) {
                     if (!wrapper2.Available)
                     {
                         flag = true;
                     }
                 }
             }
             if (!flag && Directory.Exists(path))
             {
                 ProcessStartInfo startInfo = new ProcessStartInfo(path);
                 startInfo.ErrorDialog = true;
                 try {
                     Process.Start(startInfo);
                 }
                 catch {
                 }
                 return;
                 //flag = true;
             }
             if (!flag)
             {
                 SHELLEXECUTEINFO shellexecuteinfo2 = new SHELLEXECUTEINFO();
                 shellexecuteinfo2.cbSize = Marshal.SizeOf(shellexecuteinfo2);
                 shellexecuteinfo2.nShow  = 1;
                 shellexecuteinfo2.fMask  = 0x4000200;
                 shellexecuteinfo2.hwnd   = hwnd;
                 try {
                     shellexecuteinfo2.lpFile = Marshal.StringToHGlobalUni(path);
                     if (!string.IsNullOrEmpty(argument))
                     {
                         shellexecuteinfo2.lpParameters = Marshal.StringToHGlobalUni(argument);
                     }
                     if (!string.IsNullOrEmpty(workingDirectory))
                     {
                         workingDirectory = workingDirectory.Trim(new char[] { '"', '\'' });
                         shellexecuteinfo2.lpDirectory = Marshal.StringToHGlobalUni(workingDirectory);
                     }
                     else
                     {
                         try {
                             shellexecuteinfo2.lpDirectory = Marshal.StringToHGlobalUni(Path.GetDirectoryName(path));
                         }
                         catch {
                         }
                     }
                     if (PInvoke.ShellExecuteEx(ref shellexecuteinfo2))
                     {
                         string extension = Path.GetExtension(path);
                         if (!string.Equals(".exe", extension, StringComparison.OrdinalIgnoreCase) && !string.Equals(".com", extension, StringComparison.OrdinalIgnoreCase))
                         {
                             QTUtility.ExecutedPathsList.Add(path);
                         }
                     }
                 }
                 finally {
                     if (shellexecuteinfo2.lpFile != IntPtr.Zero)
                     {
                         Marshal.FreeHGlobal(shellexecuteinfo2.lpFile);
                     }
                     if (shellexecuteinfo2.lpParameters != IntPtr.Zero)
                     {
                         Marshal.FreeHGlobal(shellexecuteinfo2.lpParameters);
                     }
                     if (shellexecuteinfo2.lpDirectory != IntPtr.Zero)
                     {
                         Marshal.FreeHGlobal(shellexecuteinfo2.lpDirectory);
                     }
                 }
             }
             else
             {
                 if (!string.IsNullOrEmpty(argument))
                 {
                     path = path + ", " + argument;
                 }
                 if (!string.IsNullOrEmpty(workingDirectory))
                 {
                     path = path + ", " + workingDirectory;
                 }
                 MessageBox.Show("Operation failed.\r\nPlease make sure the file or the target of link exists:\r\n\r\n" + path, "Error - QTTabBar", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             }
         }
     }
 }
Exemple #14
0
        protected override bool OnShellViewNotify(NMHDR nmhdr, ref Message msg)
        {
            // Process WM.NOTIFY.  These are all notifications from the
            // SysListView32 control.  We will not get ANY of these on
            // Windows 7, which means every single one of them has to
            // have an alternative somewhere for the ItemsView control,
            // or it's not going to happen.
            switch (nmhdr.code)
            {
            case -12:     // NM_CUSTOMDRAW
                // This is for drawing alternating row colors.  I doubt
                // very much we'll find an alternative for this...
                return(HandleCustomDraw(ref msg));

            case LVN.ITEMCHANGED: {
                // There are two things happening here.
                // 1. Notify plugins of selection changing: Handled through
                //    undocumented WM_USER+163 message
                // 2. Redraw for Full Row Select: Not happening

                /*
                 *  // TODO
                 *
                 *  IntPtr ptr;
                 *  if(QTUtility.instanceManager.TryGetButtonBarHandle(this.hwndExplorer, out ptr)) {
                 *      QTUtility2.SendCOPYDATASTRUCT(ptr, (IntPtr)13, null, (IntPtr)GetItemCount());
                 *  }
                 */
                bool       flag        = !QTUtility.IsXP && QTUtility.CheckConfig(Settings.ToggleFullRowSelect);
                NMLISTVIEW nmlistview2 = (NMLISTVIEW)Marshal.PtrToStructure(msg.LParam, typeof(NMLISTVIEW));
                if (nmlistview2.uChanged == 8 /*LVIF_STATE*/)
                {
                    uint num5  = nmlistview2.uNewState & LVIS.SELECTED;
                    uint num6  = nmlistview2.uOldState & LVIS.SELECTED;
                    uint num7  = nmlistview2.uNewState & LVIS.DROPHILITED;
                    uint num8  = nmlistview2.uOldState & LVIS.DROPHILITED;
                    uint num9  = nmlistview2.uNewState & LVIS.CUT;
                    uint num10 = nmlistview2.uOldState & LVIS.CUT;
                    if (flag)
                    {
                        if (nmlistview2.iItem != -1 && ((num5 != num6) || (num7 != num8) || (num9 != num10)) && ShellBrowser.ViewMode == FVM.DETAILS)
                        {
                            PInvoke.SendMessage(nmlistview2.hdr.hwndFrom, LVM.REDRAWITEMS, (IntPtr)nmlistview2.iItem, (IntPtr)nmlistview2.iItem);
                        }
                    }
                    if (num5 != num6)
                    {
                        OnSelectionChanged();
                    }
                }
                break;
            }

            case LVN.INSERTITEM:
            case LVN.DELETEITEM:
                // Handled through undocumented WM_USER+174 message
                if (!QTUtility.CheckConfig(Settings.NoShowSubDirTips))
                {
                    HideSubDirTip(1);
                }
                if (QTUtility.CheckConfig(Settings.AlternateRowColors) && (ShellBrowser.ViewMode == FVM.DETAILS))
                {
                    PInvoke.InvalidateRect(nmhdr.hwndFrom, IntPtr.Zero, true);
                }
                ShellViewController.DefWndProc(ref msg);
                OnItemCountChanged();
                return(true);

            case LVN.BEGINDRAG:
                // This won't be necessary it seems.  On Windows 7, when you
                // start to drag, a MOUSELEAVE message is sent, which hides
                // the SubDirTip anyway.
                ShellViewController.DefWndProc(ref msg);
                HideSubDirTip(0xff);
                return(true);

            case LVN.ITEMACTIVATE: {
                // Handled by catching Double Clicks and Enter keys.  Ugh...
                NMITEMACTIVATE nmitemactivate = (NMITEMACTIVATE)Marshal.PtrToStructure(msg.LParam, typeof(NMITEMACTIVATE));
                Keys           modKeys        =
                    (((nmitemactivate.uKeyFlags & 1) == 1) ? Keys.Alt : Keys.None) |
                    (((nmitemactivate.uKeyFlags & 2) == 2) ? Keys.Control : Keys.None) |
                    (((nmitemactivate.uKeyFlags & 4) == 4) ? Keys.Shift : Keys.None);
                if (OnItemActivated(modKeys))
                {
                    return(true);
                }
                break;
            }

            case LVN.ODSTATECHANGED:
                // FullRowSelect doesn't look possible anyway, so whatever.
                if (!QTUtility.IsXP && QTUtility.CheckConfig(Settings.ToggleFullRowSelect))
                {
                    NMLVODSTATECHANGE nmlvodstatechange = (NMLVODSTATECHANGE)Marshal.PtrToStructure(msg.LParam, typeof(NMLVODSTATECHANGE));
                    if (((nmlvodstatechange.uNewState & 2) == 2) && (ShellBrowser.ViewMode == FVM.DETAILS))
                    {
                        PInvoke.SendMessage(nmlvodstatechange.hdr.hwndFrom, LVM.REDRAWITEMS, (IntPtr)nmlvodstatechange.iFrom, (IntPtr)nmlvodstatechange.iTo);
                    }
                }
                break;

            case LVN.HOTTRACK:
                // Handled through WM_MOUSEMOVE.
                if (QTUtility.CheckConfig(Settings.ShowTooltipPreviews) || !QTUtility.CheckConfig(Settings.NoShowSubDirTips))
                {
                    NMLISTVIEW nmlistview = (NMLISTVIEW)Marshal.PtrToStructure(msg.LParam, typeof(NMLISTVIEW));
                    int        iItem      = nmlistview.iItem;
                    if (QTUtility.IsXP && iItem == -1 && ShellBrowser.ViewMode == FVM.DETAILS)
                    {
                        // HotTrack is inaccurate in this case.
                        iItem = GetHotItem();
                    }
                    if (iHotItem != iItem)
                    {
                        OnHotItemChanged(nmlistview.iItem);
                        iHotItem = nmlistview.iItem;
                    }
                }
                break;

            case LVN.KEYDOWN: {
                // Handled through WM_KEYDOWN.
                NMLVKEYDOWN nmlvkeydown = (NMLVKEYDOWN)Marshal.PtrToStructure(msg.LParam, typeof(NMLVKEYDOWN));
                if (OnKeyDown((Keys)nmlvkeydown.wVKey))
                {
                    msg.Result = (IntPtr)1;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case LVN.GETINFOTIP: {
                // Handled through WM_NOTIFY / TTN_NEEDTEXT
                NMLVGETINFOTIP nmlvgetinfotip = (NMLVGETINFOTIP)Marshal.PtrToStructure(msg.LParam, typeof(NMLVGETINFOTIP));
                return(OnGetInfoTip(nmlvgetinfotip.iItem, GetHotItem() != nmlvgetinfotip.iItem));    // TODO there's got to be a better way.
            }

            case LVN.BEGINLABELEDIT:
                // This is just for file renaming, which there's no need to
                // mess with in Windows 7.
                ShellViewController.DefWndProc(ref msg);
                if (QTUtility.IsXP && !QTUtility.CheckConfig(Settings.ExtWhileRenaming))
                {
                    NMLVDISPINFO nmlvdispinfo = (NMLVDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMLVDISPINFO));
                    if (nmlvdispinfo.item.lParam != IntPtr.Zero)
                    {
                        using (IDLWrapper idl = ShellBrowser.ILAppend(nmlvdispinfo.item.lParam)) {
                            OnFileRename(idl);
                        }
                    }
                }
                break;

            case LVN.ENDLABELEDIT: {
                // TODO
                NMLVDISPINFO nmlvdispinfo2 = (NMLVDISPINFO)Marshal.PtrToStructure(msg.LParam, typeof(NMLVDISPINFO));
                OnEndLabelEdit(nmlvdispinfo2.item);
                break;
            }
            }
            return(false);
        }
Exemple #15
0
        public bool TrySetSelection(Address[] addresses, string pathToFocus, bool fDeselectOthers)
        {
            IShellView shellView = folderView as IShellView;

            if (addresses == null || folderView == null || shellView == null)
            {
                return(false);
            }
            try {
                bool fFirst          = true;
                bool fFocused        = false;
                bool fFocusingNeeded = !string.IsNullOrEmpty(pathToFocus);

                if (fDeselectOthers)
                {
                    folderView.SelectItem(0, SVSIF.DESELECTOTHERS);
                }

                foreach (Address ad in addresses)
                {
                    using (IDLWrapper wrapper = new IDLWrapper(ad)) {
                        if (!wrapper.Available)
                        {
                            continue;
                        }
                        IntPtr pIDLCHILD = PInvoke.ILFindLastID(wrapper.PIDL);
                        SVSIF  svsi      = SVSIF.SELECT;
                        if (fFirst)
                        {
                            svsi |= SVSIF.ENSUREVISIBLE;
                            if (!fFocusingNeeded)
                            {
                                fFocused = true;
                                svsi    |= SVSIF.FOCUSED;
                            }
                            if (fDeselectOthers)
                            {
                                svsi |= SVSIF.DESELECTOTHERS;
                            }
                            fFirst = false;
                        }

                        if (!fFocused && ad.Path == pathToFocus)
                        {
                            fFocused = true;
                            svsi    |= SVSIF.FOCUSED;
                        }

                        shellView.SelectItem(pIDLCHILD, svsi);
                    }
                }

                if (!fFocused && fFocusingNeeded)
                {
                    using (IDLWrapper wrapper = new IDLWrapper(pathToFocus)) {
                        IntPtr pIDLFOCUSCHILD = PInvoke.ILFindLastID(wrapper.PIDL);
                        shellView.SelectItem(pIDLFOCUSCHILD, SVSIF.FOCUSED | SVSIF.ENSUREVISIBLE);
                    }
                }
                return(true);
            }
            catch (Exception ex) {
                QTUtility2.MakeErrorLog(ex);
            }
            return(false);
        }
Exemple #16
0
            public bool ExecuteCommand(Commands command, object arg)
            {
                if (tabBar != null)
                {
                    IntPtr ptr;
                    switch (command)
                    {
                    case Commands.GoBack:
                    case Commands.GoForward:
                        if (arg is int)
                        {
                            return(tabBar.NavigateToIndex(command == Commands.GoBack, (int)arg));
                        }
                        break;

                    case Commands.GoUpOneLevel:
                        tabBar.UpOneLevel();
                        return(true);

                    case Commands.RefreshBrowser:
                        tabBar.Explorer.Refresh();
                        return(true);

                    case Commands.CloseCurrentTab:
                        return(tabBar.CloseTab(tabBar.CurrentTab));

                    case Commands.CloseLeft:
                    case Commands.CloseRight:
                        tabBar.CloseLeftRight(command == Commands.CloseLeft, -1);
                        return(true);

                    case Commands.CloseAllButCurrent:
                        tabBar.CloseAllTabsExcept(tabBar.CurrentTab);
                        return(true);

                    case Commands.CloseAllButOne: {
                        TabWrapper wrapper = arg as TabWrapper;
                        if (wrapper == null)
                        {
                            break;
                        }
                        tabBar.CloseAllTabsExcept(wrapper.Tab);
                        return(true);
                    }

                    case Commands.CloseWindow:     // 关闭窗口 2 indiff
                        /* using (RegistryKey key = Registry.CurrentUser.CreateSubKey(RegConst.Root))
                         * {
                         *   string[] list = (from QTabItem item2 in tabControl1.TabPages
                         *                    where item2.TabLocked
                         *                    select item2.CurrentPath).ToArray();
                         *
                         *   MessageBox.Show(String.Join(",", list));
                         *   QTUtility2.WriteRegBinary(list, "TabsLocked", key);
                         * }*/
                        WindowUtils.CloseExplorer(tabBar.ExplorerHandle, 2);
                        return(true);

                    case Commands.UndoClose:
                        tabBar.RestoreLastClosed();
                        return(true);

                    case Commands.BrowseFolder:
                        tabBar.ChooseNewDirectory();
                        return(true);

                    case Commands.ToggleTopMost:
                        tabBar.ToggleTopMost();
                        TryCallButtonBar(bbar => bbar.RefreshButtons());
                        return(true);

                    case Commands.FocusFileList:
                        tabBar.listView.SetFocus();
                        return(true);

                    case Commands.OpenTabBarOptionDialog:
                        OptionsDialog.Open();
                        return(true);

                    case Commands.OpenButtonBarOptionDialog:
                        OptionsDialog.Open();     // todo: open at bbar page
                        return(true);

                    case Commands.IsFolderTreeVisible:
                        return(tabBar.ShellBrowser.IsFolderTreeVisible());

                    case Commands.IsButtonBarVisible:
                        return(InstanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr));

                    case Commands.ShowFolderTree:
                        if (!QTUtility.IsXP || !(arg is bool))
                        {
                            break;
                        }
                        tabBar.ShowFolderTree((bool)arg);
                        return(true);

                    case Commands.ShowButtonBar:
                        if (!InstanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr))
                        {
                        }
                        break;

                    case Commands.MD5:
                        if (!(arg is string[]))
                        {
                            break;
                        }
                        if (md5Form == null)
                        {
                            md5Form = new FileHashComputerForm();
                        }
                        if (md5Form.InvokeRequired)
                        {
                            md5Form.Invoke(new FormMethodInvoker(ShowMD5FormCore), new object[] { arg });
                        }
                        else
                        {
                            ShowMD5FormCore(arg);
                        }
                        return(true);

                    case Commands.ShowProperties: {
                        if ((arg == null) || !(arg is Address))
                        {
                            break;
                        }
                        Address address = (Address)arg;
                        using (IDLWrapper wrapper = new IDLWrapper(address)) {
                            if (!wrapper.Available)
                            {
                                break;
                            }
                            ShellMethods.ShowProperties(wrapper.IDL, tabBar.ExplorerHandle);
                            return(true);
                        }
                    }

                    case Commands.SetModalState:
                        if (((arg == null) || !(arg is bool)) || !((bool)arg))
                        {
                            tabBar.NowModalDialogShown = false;
                            break;
                        }
                        tabBar.NowModalDialogShown = true;
                        break;

                    case Commands.SetSearchBoxStr:
                        return(arg != null && arg is string &&
                               TryCallButtonBar(bbar => bbar.SetSearchBarText((string)arg)));

                    case Commands.ReorderTabsByName:
                    case Commands.ReorderTabsByPath:
                    case Commands.ReorderTabsByActv:
                    case Commands.ReorderTabsRevers:
                        if (tabBar.tabControl1.TabCount > 1)
                        {
                            bool fDescending = ((arg != null) && (arg is bool)) && ((bool)arg);
                            tabBar.ReorderTab(((int)command) - 0x18, fDescending);
                        }
                        break;
                    }
                }
                return(false);
            }
Exemple #17
0
        public static void Execute(UserApp app, ShellBrowserEx shellBrowser)
        {
            // todo validate app
            string pathCurrent;

            using (IDLWrapper wrapper = shellBrowser.GetShellPath()) {
                pathCurrent = wrapper.Path;
            }
            Address[] selection;
            shellBrowser.TryGetSelection(out selection, false);

            List <string> lstFiles = new List <string>();
            List <string> lstDirs  = new List <string>();

            if (selection != null)
            {
                foreach (Address address in selection)
                {
                    using (IDLWrapper wrapper = new IDLWrapper(address.ITEMIDLIST)) {
                        if (!wrapper.Available || !wrapper.HasPath)
                        {
                            continue;
                        }
                        (wrapper.IsFileSystemFile ? lstFiles : lstDirs).Add(address.Path.TrimEnd('\\').Enquote());
                    }
                }
            }

            string strFiles = lstFiles.StringJoin(" ");
            string strDirs  = lstDirs.StringJoin(" ");
            string strBoth  = (strFiles + " " + strDirs).Trim();

            pathCurrent = Directory.Exists(pathCurrent) ? pathCurrent.TrimEnd('\\').Enquote() : "";
            string args = app.Args;
            string work = app.WorkingDir;
            string path = app.Path;

            string[] variableValues =
            {
                strDirs.Length > 0 ? strDirs : pathCurrent,         // %cd%
                pathCurrent,                                        // %c%
                strDirs,                                            // %d%
                strFiles,                                           // %f%
                strBoth                                             // %s%
            };
            for (int i = 0; i < variableValues.Length; i++)
            {
                args = reVariables[i].Replace(args, variableValues[i]);
            }
            variableValues = new string[] {
                lstDirs.Count > 0 ? lstDirs[0] : pathCurrent,       // %cd%
                pathCurrent,                                        // %c%
                lstDirs.Count > 0 ? lstDirs[0] : "",                // %d%
                "",                                                 // %f%
                lstDirs.Count > 0 ? lstDirs[0] : ""                 // %s%
            };
            for (int i = 0; i < variableValues.Length; i++)
            {
                work = reVariables[i].Replace(work, variableValues[i]);
            }

            const int SW_SHOWNORMAL           = 1;
            const int SEE_MASK_IDLIST         = 0x00000004;
            const int SEE_MASK_DOENVSUBST     = 0x00000200; // Expand any environment variables specified in the string given by the lpDirectory or lpFile
            const int SEE_MASK_ASYNCOK        = 0x00100000;
            const int SEE_MASK_FLAG_LOG_USAGE = 0x04000000;

            // Open NameSpace folder.
            if (path.StartsWith(IDLWrapper.INDICATOR_NAMESPACE))
            {
                using (IDLWrapper idlw = new IDLWrapper(path)) {
                    if (idlw.Available)
                    {
                        SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO {
                            cbSize   = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)),
                            nShow    = SW_SHOWNORMAL,
                            fMask    = SEE_MASK_IDLIST,
                            lpIDList = idlw.PIDL,
                            hwnd     = shellBrowser.GetExplorerHandle()
                        };
                        PInvoke.ShellExecuteEx(ref sei);
                        return;
                    }
                }
            }
            else
            {
                // check whether target exists if link
                using (IDLWrapper idlw = new IDLWrapper(path)) {
                    if (idlw.IsLinkToDeadFolder)
                    {
                        return;
                    }
                }

                SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO {
                    cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)),
                    nShow  = SW_SHOWNORMAL,
                    fMask  = SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_LOG_USAGE | SEE_MASK_ASYNCOK,
                    hwnd   = shellBrowser.GetExplorerHandle()
                };

                try {
                    sei.lpFile = Marshal.StringToCoTaskMemUni(path);

                    // Arguments
                    if (!string.IsNullOrEmpty(args))
                    {
                        sei.lpParameters = Marshal.StringToCoTaskMemUni(args);
                    }

                    // Working directory
                    if (!string.IsNullOrEmpty(work))
                    {
                        work            = work.Trim(new char[] { '"', '\'' });
                        sei.lpDirectory = Marshal.StringToCoTaskMemUni(work);
                    }
                    else
                    {
                        // "::" will cause an exception in Path.GetDirectoryName
                        if (QTUtility2.IsExecutable(Path.GetExtension(path)) &&
                            !path.StartsWith(IDLWrapper.INDICATOR_NAMESPACE))
                        {
                            work = Path.GetDirectoryName(path);
                        }
                        if (!string.IsNullOrEmpty(work))
                        {
                            sei.lpDirectory = Marshal.StringToCoTaskMemUni(work);
                        }
                    }

                    if (PInvoke.ShellExecuteEx(ref sei))
                    {
                        StaticReg.ExecutedPathsList.Add(path);
                        return;
                    }
                }
                finally {
                    if (sei.lpFile != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(sei.lpFile);
                    }
                    if (sei.lpParameters != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(sei.lpParameters);
                    }
                    if (sei.lpDirectory != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(sei.lpDirectory);
                    }
                }
            }

            // Show Error Message.
            if (!String.IsNullOrEmpty(args))
            {
                path += ", " + args;
            }

            if (!String.IsNullOrEmpty(work))
            {
                path += ", " + work;
            }

            MessageBox.Show(
                String.Format(QTUtility.TextResourcesDic["ErrorDialogs"][0], path),
                QTUtility.TextResourcesDic["ErrorDialogs"][1],
                MessageBoxButtons.OK,
                MessageBoxIcon.Error
                );
        }
        /// <summary>
        /// Displays shell shortcut menu.
        /// </summary>
        /// <param name="idlw">IDLWrapper object that specifies shell item</param>
        /// <param name="pntShow">location of the shortcut menu, in screen coordinates.</param>
        /// <param name="hwndParent">Handle of parent control. Parent control will get focus, and receives the messages about drawing 'Send to' submenues.</param>
        /// <param name="fCanRemove">set true to add 'remove this' menu item.</param>
        /// <returns>
        /// 0xFFFF	user selected "Remove this item from menu".
        /// 0xFFFE	user selected "Open containing folder".
        /// 0xFFFD	If the user cancels the menu without making a selection, or if an error occurs
        /// </returns>
        public int Open(IDLWrapper idlw, Point pntShow, IntPtr hwndParent, bool fCanRemove)
        {
            const uint   MF_STRING         = 0x00000000;
            const uint   MF_SEPARATOR      = 0x00000800;
            const uint   CMF_NORMAL        = 0x00000000;
            const uint   CMF_EXTENDEDVERBS = 0x00000100;
            const uint   TPM_RETURNCMD     = 0x0100;
            const uint   S_OK = 0;
            const int    COMMANDID_REMOVEITEM = 0xffff; // todo: move to const class
            const int    COMMANDID_OPENPARENT = 0xfffe;
            const int    COMMANDID_USERCANCEL = 0xfffd;
            IShellFolder shellFolderParent    = null;

            try {
                // get IShellFolder
                IntPtr pIDLRelative;
                if (idlw.Available && S_OK == PInvoke.SHBindToParent(idlw.PIDL, ExplorerGUIDs.IID_IShellFolder, out shellFolderParent, out pIDLRelative) && shellFolderParent != null)
                {
                    // get IContextMenu2
                    IntPtr[] pIDLs    = new IntPtr[] { pIDLRelative };
                    uint     reserved = 0;
                    object   oUnk;

                    if (S_OK == shellFolderParent.GetUIObjectOf(IntPtr.Zero, (uint)pIDLs.Length, pIDLs, ExplorerGUIDs.IID_IContextMenu, ref reserved, out oUnk))
                    {
                        pIContextMenu2 = oUnk as IContextMenu2;
                        if (pIContextMenu2 != null)
                        {
                            using (ContextMenu contextMenu = new ContextMenu()) {
                                int  nResult = -1;
                                uint uFlags  = CMF_NORMAL;
                                if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                                {
                                    uFlags |= CMF_EXTENDEDVERBS;
                                }

                                pIContextMenu2.QueryContextMenu(contextMenu.Handle, 0, 1, 0xffff, uFlags);

                                // append optional menus
                                if (fCanRemove)
                                {
                                    // "Remove this item from menu"
                                    PInvoke.AppendMenu(contextMenu.Handle, MF_SEPARATOR, IntPtr.Zero, null);
                                    PInvoke.AppendMenu(contextMenu.Handle, MF_STRING, new IntPtr(COMMANDID_REMOVEITEM), QTUtility.ResMain[25]);
                                }
                                if (idlw.HasPath && idlw.Path.Length > 3 && idlw.IsFileSystem /*&& ( idlw.IsFileSystemFolder || idlw.IsFileSystemFile )*/)
                                {
                                    // "Open containing folder"
                                    if (!fCanRemove)
                                    {
                                        // separator
                                        PInvoke.AppendMenu(contextMenu.Handle, MF_SEPARATOR, IntPtr.Zero, null);
                                    }
                                    PInvoke.AppendMenu(contextMenu.Handle, MF_STRING, new IntPtr(COMMANDID_OPENPARENT), QTUtility.ResMain[26]);
                                }

                                uint commandID = PInvoke.TrackPopupMenu(contextMenu.Handle, TPM_RETURNCMD, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero);
                                if (commandID != 0)
                                {
                                    if (commandID == COMMANDID_REMOVEITEM)
                                    {
                                        return(COMMANDID_REMOVEITEM);
                                    }
                                    else if (commandID == COMMANDID_OPENPARENT)
                                    {
                                        if (idlw.HasPath)
                                        {
                                            try {
                                                QTTabBarClass tabbar = InstanceManager.GetThreadTabBar();
                                                if (tabbar != null)
                                                {
                                                    using (IDLWrapper idlwParent = idlw.GetParent()) {
                                                        if (idlwParent.Available)
                                                        {
                                                            tabbar.OpenNewTabOrWindow(idlwParent);
                                                        }
                                                    }
                                                }
                                                // DesktopTool will handle it by itself
                                                nResult = COMMANDID_OPENPARENT;
                                            }
                                            catch {
                                                System.Media.SystemSounds.Asterisk.Play();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        CMINVOKECOMMANDINFO cmInfo = new CMINVOKECOMMANDINFO {
                                            cbSize       = Marshal.SizeOf(typeof(CMINVOKECOMMANDINFO)),
                                            fMask        = 0,
                                            hwnd         = hwndParent,
                                            lpVerb       = (IntPtr)((commandID - 1) & 0xFFFF),
                                            lpParameters = IntPtr.Zero,
                                            lpDirectory  = IntPtr.Zero,
                                            nShow        = 1, //SW_SHOWNORMAL;
                                            dwHotKey     = 0,
                                            hIcon        = IntPtr.Zero
                                        };

                                        // returns S_OK if successful, or an error value otherwise.
                                        // E_ABORT when user clicked "Open folder link target exists" of link file...( E_ABORT  _HRESULT_TYPEDEF_(0x80004004L) )
                                        nResult = pIContextMenu2.InvokeCommand(ref cmInfo);
                                    }
                                }
                                else
                                {
                                    // 'if the user cancels the menu without making a selection, or if an error occurs' (MSDN)
                                    nResult = COMMANDID_USERCANCEL;
                                }

                                return(nResult);
                            }
                        }
                    }
                }

                // if failed to create shell context menu, show 'remove this' menu instead
                if (fCanRemove)
                {
                    using (ContextMenu contextMenu = new ContextMenu()) {
                        PInvoke.AppendMenu(contextMenu.Handle, MF_STRING, new IntPtr(COMMANDID_REMOVEITEM), QTUtility.ResMain[25]);

                        if (COMMANDID_REMOVEITEM == PInvoke.TrackPopupMenu(contextMenu.Handle, TPM_RETURNCMD, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero))
                        {
                            return(COMMANDID_REMOVEITEM);
                        }
                    }
                }

                return(COMMANDID_USERCANCEL);
            }
            catch {
            }
            finally {
                if (shellFolderParent != null)
                {
                    Marshal.ReleaseComObject(shellFolderParent);
                }

                if (pIContextMenu2 != null)
                {
                    Marshal.ReleaseComObject(pIContextMenu2);
                    pIContextMenu2 = null;
                }
            }
            return(-1);
        }
 private void subDirTip_MenuItemClicked(object sender, ToolStripItemClickedEventArgs e) {
     QMenuItem clickedItem = (QMenuItem)e.ClickedItem;
     if(clickedItem.Target == MenuTarget.Folder) {
         if(clickedItem.IDLData == null) {
             OpenTab(new object[] { clickedItem.TargetPath, ModifierKeys });
             return;
         }
         using(IDLWrapper wrapper = new IDLWrapper(clickedItem.IDLData)) {
             SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO();
             structure.cbSize = Marshal.SizeOf(structure);
             structure.nShow = 1;
             structure.fMask = 4;
             structure.lpIDList = wrapper.PIDL;
             try {
                 PInvoke.ShellExecuteEx(ref structure);
             }
             catch {
             }
             return;
         }
     }
     try {
         string path = clickedItem.Path;
         ProcessStartInfo startInfo = new ProcessStartInfo(path);
         startInfo.WorkingDirectory = Path.GetDirectoryName(path);
         startInfo.ErrorDialog = true;
         Process.Start(startInfo);
         if(!QTUtility.CheckConfig(Settings.NoRecentFiles)) {
             QTUtility.ExecutedPathsList.Add(path);
         }
     }
     catch {
     }
 }
Exemple #20
0
 private void subDirTip_MenuItemRightClicked(object sender, ItemRightClickedEventArgs e)
 {
     QMenuItem clickedItem = e.ClickedItem as QMenuItem;
     if(clickedItem != null) {
         using(IDLWrapper wrapper = new IDLWrapper(clickedItem.Path)) {
             e.HRESULT = iContextMenu2_Desktop.Open(wrapper, e.IsKey ? e.Point : MousePosition, ((SubDirTipForm)sender).Handle, false);
         }
     }
 }
 private void subDirTip_MenuItemRightClicked(object sender, ItemRightClickedEventArgs e) {
     using(IDLWrapper wrapper = new IDLWrapper(((QMenuItem)e.ClickedItem).Path)) {
         e.HRESULT = ShellMethods.PopUpSystemContextMenu(wrapper, e.IsKey ? e.Point : MousePosition, ref iContextMenu2, ((SubDirTipForm)sender).Handle, false);
     }
 }
Exemple #22
0
        private void subDirTip_MenuItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            // this can run in both desktop and taskbar thread

            IntPtr hwndDialogParent = sender == subDirTip ? hwndListView : hwndShellTray;
                    // desktop thread or taskbar thread

            QMenuItem qmi = (QMenuItem)e.ClickedItem;

            if(qmi.Genre == MenuGenre.SubDirTip_QTGRootItem) {
                Thread thread = new Thread(OpenGroup);
                thread.SetApartmentState(ApartmentState.STA);
                thread.IsBackground = true;
                thread.Start(new object[] {new string[] {qmi.Name}, ModifierKeys});
            }
            else if(qmi.Target == MenuTarget.Folder) {
                using(IDLWrapper idlw = new IDLWrapper(qmi.IDL)) {
                    if(!idlw.IsDeadLink(hwndDialogParent)) {
                        Keys modKey = ModifierKeys;
                        if(!Config.Bool(Scts.ActivateNewTab)) {
                            if(modKey == Keys.Shift) {
                                modKey = Keys.None;
                            }
                            else if(modKey == Keys.None) {
                                modKey = Keys.Shift;
                            }
                        }

                        if(idlw.IsLink) {
                            if(!String.IsNullOrEmpty(qmi.TargetPath) &&
                                    qmi.TargetPath.StartsWith(IDLWrapper.INDICATOR_NETWORK) &&
                                            -1 == qmi.TargetPath.IndexOf(@"\", 2) &&
                                                    !ShellMethods.IsIDLNullOrEmpty(qmi.IDLTarget)) {
                                // link target is network server root ( "\\server" ), prevent opening window
                                OpenTab(new object[] {null, modKey, qmi.IDLTarget});
                                return;
                            }
                        }
                        OpenTab(new object[] {null, modKey, idlw.IDL});
                    }
                }
            }
            else {
                using(IDLWrapper idlw = new IDLWrapper(qmi.IDL)) {
                    if(!idlw.IsDeadLink(hwndDialogParent)) {
                        string work = String.Empty;

                        SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO();
                        sei.cbSize = Marshal.SizeOf(sei);
                        sei.nShow = SHOWWINDOW.SHOWNORMAL;
                        sei.fMask = SEEMASK.IDLIST;
                        sei.lpIDList = idlw.PIDL;
                        sei.hwnd = hwndDialogParent;

                        if(!String.IsNullOrEmpty(qmi.Path)) {
                            work = QTUtility2.MakeDefaultWorkingDirecotryStr(qmi.Path);
                            if(work.Length > 0) {
                                sei.lpDirectory = Marshal.StringToCoTaskMemUni(work);
                            }
                        }

                        try {
                            if(PInvoke.ShellExecuteEx(ref sei)) {
                                QTUtility.AddRecentFiles(
                                        new string[][] {
                                                work.Length > 0
                                                        ? new string[] {qmi.Path, String.Empty, work}
                                                        : new string[] {qmi.Path}
                                        }, hwndThis);
                            }
                        }
                        finally {
                            if(sei.lpDirectory != IntPtr.Zero) {
                                Marshal.FreeCoTaskMem(sei.lpDirectory);
                            }
                        }
                    }
                }
            }
        }
        private void subDirTip_MultipleMenuItemsClicked(object sender, EventArgs e) {
            List<string> executedDirectories = ((SubDirTipForm)sender).ExecutedDirectories;
            if(executedDirectories.Count > 0) {
                List<byte[]> list2 = new List<byte[]>();
                foreach(string str in executedDirectories) {
                    using(IDLWrapper wrapper = new IDLWrapper(str)) {
                        IDLWrapper wrapper2;
                        if(IDLIsFolder(wrapper, out wrapper2)) {
                            if(wrapper2 != null) {
                                list2.Add(wrapper2.IDL);
                                wrapper2.Dispose();
                            }
                            else {
                                list2.Add(wrapper.IDL);
                            }
                        }
                        continue;
                    }
                }
                Keys modifierKeys = ModifierKeys;
                if(!QTUtility.CheckConfig(Settings.ActivateNewTab)) {
                    switch(modifierKeys) {
                        case Keys.Shift:
                            modifierKeys = Keys.None;
                            break;

                        case Keys.None:
                            modifierKeys = Keys.Shift;
                            break;
                    }
                }
                if(list2.Count == 1) {
                    object[] objArray = new object[3];
                    objArray[1] = modifierKeys;
                    objArray[2] = list2[0];
                    OpenTab(objArray);
                }
                else if(list2.Count > 1) {
                    byte[] buffer = list2[0];
                    list2.RemoveAt(0);
                    Thread thread = new Thread(OpenFolders2);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.IsBackground = true;
                    thread.Start(new object[] { buffer, list2, modifierKeys });
                }
            }
        }
Exemple #24
0
        private void subDirTip_MultipleMenuItemsClicked(object sender, EventArgs e)
        {
            // this can run in both desktop and taskbar thread

            SubDirTipForm sdtf = (SubDirTipForm)sender;
            IntPtr hwndDialogParent = sdtf == subDirTip ? hwndListView : hwndShellTray;

            // SubDirTip_QTGRootItem
            string[] arrGrps = sdtf.ExecutedGroups;
            if(arrGrps.Length > 0) {
                Thread thread = new Thread(OpenGroup);
                thread.SetApartmentState(ApartmentState.STA);
                thread.IsBackground = true;
                thread.Start(new object[] {arrGrps, ModifierKeys});
            }

            // folders
            if(sdtf.ExecutedIDLs.Count > 0) {
                List<byte[]> lstIDLs = new List<byte[]>();

                foreach(byte[] idl in sdtf.ExecutedIDLs) {
                    using(IDLWrapper idlw = new IDLWrapper(idl, false)) {
                        if(idlw.IsLink) {
                            IDLWrapper idlwTarget;
                            if(idlw.TryGetLinkTarget(hwndDialogParent, out idlwTarget)) {
                                if(idlwTarget.IsFolder) {
                                    if(idlw.IsFolder) {
                                        lstIDLs.Add(idlw.IDL);
                                    }
                                    else {
                                        lstIDLs.Add(idlwTarget.IDL);
                                    }
                                }
                            }
                        }
                        else {
                            lstIDLs.Add(idlw.IDL);
                        }
                    }
                }

                Keys modKey = ModifierKeys;
                if(!Config.Bool(Scts.ActivateNewTab)) {
                    if(modKey == Keys.Shift) {
                        modKey = Keys.None;
                    }
                    else if(modKey == Keys.None) {
                        modKey = Keys.Shift;
                    }
                }

                if(lstIDLs.Count == 1) {
                    OpenTab(new object[] {null, modKey, lstIDLs[0]});
                }
                else if(lstIDLs.Count > 1) {
                    Thread thread = new Thread(OpenFolders2);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.IsBackground = true;
                    thread.Start(new object[] {lstIDLs, modKey});
                }
            }
        }
        private void DoFileTools(int index) {
            try {
                switch(index) {
                    case 0:
                    case 1: {
                        bool flag = index == 0;
                        string str = ShellBrowser.GetItems()
                                .Select(wrapper2 => flag ? wrapper2.ParseName : wrapper2.DisplayName)
                                .Where(name => name.Length > 0).StringJoin("\r\n");
                        if(str.Length > 0) {
                            QTTabBarClass.SetStringClipboard(str);
                        }
                        break;
                    }

                    case 2:
                    case 3: {
                        string folderPath = string.Empty;
                        if(index == 2) {
                            folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                        }
                        else {
                            byte[] idl = new byte[2];
                            using(IDLWrapper wrapper = new IDLWrapper(idl)) {
                                if(wrapper.Available) {
                                    folderPath = ShellMethods.GetDisplayName(wrapper.PIDL, true);
                                }
                            }
                        }
                        if(folderPath.Length > 0) {
                            QTTabBarClass.SetStringClipboard(folderPath);
                        }
                        break;
                    }

                    case 4: {
                        List<string> list2 = new List<string>();
                        foreach(IDLWrapper wrapper2 in ShellBrowser.GetItems(true)) {
                            if(wrapper2.IsLink) {
                                string linkTargetPath = ShellMethods.GetLinkTargetPath(wrapper2.Path);
                                if(File.Exists(linkTargetPath)) {
                                    list2.Add(linkTargetPath);
                                }
                            }
                            else if(wrapper2.IsFileSystemFile) {
                                list2.Add(wrapper2.Path);
                            }
                        }
                        if(hashForm == null) {
                            hashForm = new FileHashComputerForm();
                        }
                        hashForm.ShowFileHashForm(list2.ToArray());
                        break;
                    }

                    case 5:
                        listView.ShowAndClickSubDirTip();
                        break;
                }
            }
            catch(Exception exception) {
                QTUtility2.MakeErrorLog(exception);
            }
        }
Exemple #26
0
 private static void OpenFolders(List<byte[]> lstIDLs, bool fForceTab = false)
 {
     if(lstIDLs.Count == 0) return;
     if((fForceTab || Config.Window.CaptureNewWindows) && InstanceManager.GetTotalInstanceCount() > 0) {
         InstanceManager.BeginInvokeMain(tabbar => {
             bool first = true;
             foreach(byte[] idl in lstIDLs) {
                 using(var idlw = new IDLWrapper(idl)) {
                     tabbar.OpenNewTab(idlw, !first);
                 }
                 first = false;
                 // todo: bring to front
             }
         });
     }
     else {
         StaticReg.CreateWindowIDLs.Assign(lstIDLs.Skip(1));
         using(IDLWrapper idlw = new IDLWrapper(lstIDLs[0])) {
             OpenWindow(idlw);
         }
     }
 }
 private void dropDownMenues_ItemRightClicked(object sender, ItemRightClickedEventArgs e) {
     QMenuItem clickedItem = e.ClickedItem as QMenuItem;
     if(clickedItem == null) {
         return;
     }
     Point pnt = e.IsKey ? e.Point : MousePosition;
     if(clickedItem.Target == MenuTarget.VirtualFolder) {
         return;
     }
     if(clickedItem.Genre == MenuGenre.Group) {
         fContextmenuedOnMain_Grp = sender == contextMenu;
         string str = MenuUtility.TrackGroupContextMenu(e.ClickedItem.Text, pnt, ((DropDownMenuReorderable)sender).Handle);
         fContextmenuedOnMain_Grp = false;
         if(!string.IsNullOrEmpty(str)) {
             OpenTab(new object[] { str, ModifierKeys });
             return;
         }
         e.HRESULT = 0xfffd;
         return;
     }
     bool fCanRemove = clickedItem.Genre != MenuGenre.Application;
     using(IDLWrapper wrapper = new IDLWrapper(clickedItem.Path)) {
         e.HRESULT = ShellMethods.PopUpSystemContextMenu(wrapper, pnt, ref iContextMenu2, ((DropDownMenuReorderable)sender).Handle, fCanRemove);
     }
     if(e.HRESULT != 0xffff) {
         return;
     }
     if(clickedItem.Genre == MenuGenre.History) {
         QTUtility.ClosedTabHistoryList.Remove(clickedItem.Path);
         UndoClosedItemsList.Remove(clickedItem);
         try {
             using(RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Quizo\QTTabBar")) {
                 QTUtility.SaveRecentlyClosed(key);
             }
             goto Label_019F;
         }
         catch {
             goto Label_019F;
         }
     }
     if(clickedItem.Genre == MenuGenre.RecentFile) {
         QTUtility.ExecutedPathsList.Remove(clickedItem.Path);
         RecentFileItemsList.Remove(clickedItem);
         try {
             using(RegistryKey key2 = Registry.CurrentUser.CreateSubKey(@"Software\Quizo\QTTabBar")) {
                 QTUtility.SaveRecentFiles(key2);
             }
         }
         catch {
         }
     }
 Label_019F:
     clickedItem.Dispose();
 }
Exemple #28
0
        private void directoryMenuItems_DoubleClick(object sender, EventArgs e)
        {
            // DirectoryMenuItem is clicked.
            // It's guaranteed that sender is DirectoryMenuItem.

            string path = ((DirectoryMenuItem)sender).Path;
            if(!Directory.Exists(path)) return;
            try {
                using(var pidl = new IDLWrapper(path)) { // todo: idlize
                    OpenFolder(pidl);
                }
            }
            catch {
                MessageBox.Show(
                    String.Format(QTUtility.TextResourcesDic["ErrorDialogs"][9], path),
                    QTUtility.TextResourcesDic["ErrorDialogs"][4],
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }
 // TODO: figure out what this is
 private bool GetTargetWindow(IDLWrapper idlw, bool fNeedWait, out IntPtr hwndTabBar, out bool fOpened) {
     hwndTabBar = IntPtr.Zero;
     fOpened = false;
     using(RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Quizo\QTTabBar")) {
         if(key != null) {
             hwndTabBar = QTUtility2.ReadRegHandle("Handle", key);
         }
         if((hwndTabBar == IntPtr.Zero) || !PInvoke.IsWindow(hwndTabBar)) {                              // what?! --.
             hwndTabBar = QTUtility.instanceManager.CurrentHandle;                                       //          v
             if((idlw.Available && ((hwndTabBar == IntPtr.Zero) || !PInvoke.IsWindow(hwndTabBar))) && ShellBrowser.Navigate(idlw)  == 0) {
                 fOpened = true;
                 if(fNeedWait) {
                     int num = 0;
                     while(!PInvoke.IsWindow(hwndTabBar)) {
                         Thread.Sleep(100);
                         hwndTabBar = QTUtility2.ReadRegHandle("Handle", key);
                         if(++num > 50) {
                             goto Label_00EB;
                         }
                     }
                 }
                 else {
                     return true;
                 }
             }
         }
     }
 Label_00EB:
     if(hwndTabBar != IntPtr.Zero) {
         return PInvoke.IsWindow(hwndTabBar);
     }
     return false;
 }
Exemple #30
0
        private void dropDowns_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            // since menu is created on taskbar thread
            // this runs on the thread

            TitleMenuItem tmi = e.ClickedItem as TitleMenuItem;
            if(tmi != null) {
                if(tmi.IsOpened) {
                    // Close
                    OnLabelTitleClickedToClose(tmi.Genre);
                }
                else {
                    // Open
                    OnSubMenuTitleClickedToOpen(tmi.Genre);
                }

                return;
            }

            QMenuItem qmi = e.ClickedItem as QMenuItem;
            if(qmi == null) {
                return;
            }

            if(qmi.Genre == MenuGenre.Group) {
                OpenGroup(qmi.Text);
            }
            else if(qmi.Genre == MenuGenre.History) {
                using(IDLWrapper idlw = new IDLWrapper(qmi.IDLData)) {
                    OpenFolder(idlw);
                }
            }
            else if(qmi.Genre == MenuGenre.Application && qmi.Target == MenuTarget.File) {
                // User apps
                AppsManager.Execute(qmi.MenuItemArguments.App, ShellBrowser);
            }
            else if(qmi.Genre == MenuGenre.RecentFile) {
                // Todo: unify
                try {
                    string toolTipText = e.ClickedItem.ToolTipText ?? "";
                    ProcessStartInfo startInfo = new ProcessStartInfo(toolTipText) {
                        WorkingDirectory = Path.GetDirectoryName(toolTipText),
                        ErrorDialog = true,
                        ErrorDialogParentHandle = Handle
                    };
                    Process.Start(startInfo);
                    StaticReg.ExecutedPathsList.Add(toolTipText);
                }
                catch {
                    SystemSounds.Hand.Play();
                }
            }
        }
        private bool HandleTabFolderActions(int index, Keys modKey, bool fEnqExec) {
            if(QTUtility.CheckConfig(Settings.MidClickNewWindow)) {
                if(modKey == Keys.Control) {
                    modKey = Keys.None;
                }
                else if(modKey == Keys.None) {
                    modKey = Keys.Control;
                }
            }
            if(!QTUtility.CheckConfig(Settings.ActivateNewTab)) {
                if((modKey & Keys.Shift) == Keys.Shift) {
                    modKey &= ~Keys.Shift;
                }
                else {
                    modKey |= Keys.Shift;
                }
            }
            
            byte[] idl = null;
            List<byte[]> folderIDLs = new List<byte[]>();
            List<string> execPaths = new List<string>();
            if(index != -1) {
                using(IDLWrapper wrapper = ShellBrowser.GetItem(index)) {
                    IDLWrapper wrapper2;
                    if(wrapper.Available && IDLIsFolder(wrapper, out wrapper2)) {
                        if(wrapper2 != null) {
                            idl = wrapper2.IDL;
                            wrapper2.Dispose();
                        }
                        else {
                            idl = wrapper.IDL;
                        }
                    }
                }
            }
            else {
                foreach(IDLWrapper wrapper in ShellBrowser.GetItems(true)) {
                    IDLWrapper wrapper2;
                    if(IDLIsFolder(wrapper, out wrapper2)) {
                        if(wrapper2 != null) {
                            folderIDLs.Add(wrapper2.IDL);
                            wrapper2.Dispose();
                        }
                        else {
                            folderIDLs.Add(wrapper.IDL);
                        }
                    }
                    else if(fEnqExec && wrapper.IsFileSystemFile) {
                        execPaths.Add(wrapper.Path);
                    }
                }
                if(folderIDLs.Count > 0) {
                    idl = folderIDLs[0];
                    folderIDLs.RemoveAt(0);
                }
                else {
                    if(fEnqExec) {
                        foreach(string str in execPaths) {
                            QTUtility.ExecutedPathsList.Add(str);
                        }
                    }
                }
            }
            
            if(idl == null) return false;

            if(folderIDLs.Count == 0) {
                if(index == -1) {
                    using(IDLWrapper wrapper5 = new IDLWrapper(idl)) {
                        if(wrapper5.IsFileSystemFile) {
                            return false;
                        }
                    }
                }
                OpenTab(new object[] {null, modKey, idl});
            }
            else {
                Thread thread = new Thread(OpenFolders2);
                thread.SetApartmentState(ApartmentState.STA);
                thread.IsBackground = true;
                thread.Start(new object[] {idl, folderIDLs, modKey});
            }
            return true;
        }
 public static string GetDisplayName(string path) {
     using(IDLWrapper wrapper = new IDLWrapper(path)) {
         if(wrapper.Available) {
             return GetDisplayName(wrapper.PIDL, true);
         }
     }
     return path;
 }
 private static bool IDLIsFolder(IDLWrapper idlw, out IDLWrapper idlwLinkTarget) {
     idlwLinkTarget = null;
     if(!idlw.IsLink) {
         return idlw.IsFolder;
     }
     if(idlw.HasPath) {
         idlwLinkTarget = new IDLWrapper(ShellMethods.GetLinkTargetPath(idlw.Path));
         if(idlwLinkTarget.Available && idlwLinkTarget.IsFolder) {
             return true;
         }
         idlwLinkTarget.Dispose();
         idlwLinkTarget = null;
     }
     return false;
 }
 public static void ShowProperties(byte[] idl) {
     SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO();
     structure.cbSize = Marshal.SizeOf(structure);
     structure.fMask = 0x40c;
     structure.lpVerb = Marshal.StringToHGlobalUni("properties");
     try {
         using(IDLWrapper wrapper = new IDLWrapper(idl)) {
             if(wrapper.Available) {
                 structure.lpIDList = wrapper.PIDL;
                 PInvoke.ShellExecuteEx(ref structure);
             }
         }
     }
     finally {
         if(structure.lpVerb != IntPtr.Zero) {
             Marshal.FreeHGlobal(structure.lpVerb);
         }
     }
 }
Exemple #35
0
 private void OpenFolder(IDLWrapper pidl, bool fForceTab = false)
 {
     OpenFolders(new List<byte[]> { pidl.IDL }, fForceTab);
 }
 private void ddmr45_ItemRightClicked(object sender, ItemRightClickedEventArgs e) {
     QMenuItem clickedItem = e.ClickedItem as QMenuItem;
     if(clickedItem != null) {
         bool fCanRemove = sender == ddmrRecentlyClosed;
         using(IDLWrapper wrapper = new IDLWrapper(clickedItem.Path)) {
             e.HRESULT = ShellMethods.PopUpSystemContextMenu(wrapper, e.IsKey ? e.Point : MousePosition, ref iContextMenu2, ((DropDownMenuReorderable)sender).Handle, fCanRemove);
         }
         if(fCanRemove && (e.HRESULT == 0xffff)) {
             QTUtility.ClosedTabHistoryList.Remove(clickedItem.Path);
             clickedItem.Dispose();
         }
     }
 }
        /// <summary>
        /// Displays shell shortcut menu for multiple items. Paths must be sub items of one directory.
        /// </summary>
        /// <param name="lstIDLs"></param>
        /// <param name="pntShow"></param>
        /// <param name="hwndParent"></param>
        /// <returns></returns>
        public int Open(List <byte[]> lstIDLs, Point pntShow, IntPtr hwndParent)
        {
            // All lstIDLs members must share the same parent, for compatibility.
            const uint S_OK = 0;

            if (lstIDLs == null || lstIDLs.Count == 0)
            {
                return(-1);
            }

            IShellFolder  shellFolder  = null;
            List <IntPtr> lstRltvPIDLs = new List <IntPtr>();
            IntPtr        pIDLFirst    = IntPtr.Zero;

            try {
                // build array of relative idls
                for (int i = 0; i < lstIDLs.Count; i++)
                {
                    if (i == 0)
                    {
                        pIDLFirst = ShellMethods.CreateIDL(lstIDLs[0]);
                    }

                    using (IDLWrapper idlw = new IDLWrapper(lstIDLs[i])) {
                        if (!idlw.Available)
                        {
                            continue;
                        }
                        IntPtr p = PInvoke.ILClone(PInvoke.ILFindLastID(idlw.PIDL));
                        if (p != IntPtr.Zero)
                        {
                            lstRltvPIDLs.Add(p);
                        }
                    }
                }
                IntPtr[] apidl = lstRltvPIDLs.ToArray();

                if (apidl.Length > 0)
                {
                    IntPtr pIDLRltv1st;
                    if (S_OK == PInvoke.SHBindToParent(pIDLFirst, ExplorerGUIDs.IID_IShellFolder, out shellFolder, out pIDLRltv1st))
                    {
                        // get IContextMenu2
                        uint   rsv = 0;
                        object oUnk;

                        if (S_OK == shellFolder.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ExplorerGUIDs.IID_IContextMenu, ref rsv, out oUnk))
                        {
                            pIContextMenu2 = oUnk as IContextMenu2;
                            if (pIContextMenu2 != null)
                            {
                                using (ContextMenu contextMenu = new ContextMenu()) {
                                    const uint CMF_EXTENDEDVERBS = 0x00000100;
                                    const uint TPM_RETURNCMD     = 0x0100;

                                    uint uFlags = 0;
                                    if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                                    {
                                        uFlags |= CMF_EXTENDEDVERBS;
                                    }

                                    pIContextMenu2.QueryContextMenu(contextMenu.Handle, 0, 1, 0xffff, uFlags);

                                    uint commandID = PInvoke.TrackPopupMenu(contextMenu.Handle, TPM_RETURNCMD, pntShow.X, pntShow.Y, 0, hwndParent, IntPtr.Zero);
                                    if (commandID != 0)
                                    {
                                        CMINVOKECOMMANDINFO cmInfo = new CMINVOKECOMMANDINFO {
                                            cbSize       = Marshal.SizeOf(typeof(CMINVOKECOMMANDINFO)),
                                            fMask        = 0,
                                            hwnd         = hwndParent,
                                            lpVerb       = (IntPtr)((commandID - 1) & 0xFFFF),
                                            lpParameters = IntPtr.Zero,
                                            lpDirectory  = IntPtr.Zero,
                                            nShow        = 1, //SW_SHOWNORMAL
                                            dwHotKey     = 0,
                                            hIcon        = IntPtr.Zero
                                        };

                                        // this returns E_ABORT when user clicked "Open folder link target exists" of link file...
                                        pIContextMenu2.InvokeCommand(ref cmInfo);
                                        return(0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch {
            }
            finally {
                if (shellFolder != null)
                {
                    Marshal.ReleaseComObject(shellFolder);
                }
                if (pIDLFirst != IntPtr.Zero)
                {
                    PInvoke.CoTaskMemFree(pIDLFirst);
                }
                foreach (IntPtr pIDL in lstRltvPIDLs.Where(pIDL => pIDL != IntPtr.Zero))
                {
                    PInvoke.CoTaskMemFree(pIDL);
                }
                if (pIContextMenu2 != null)
                {
                    Marshal.ReleaseComObject(pIContextMenu2);
                    pIContextMenu2 = null;
                }
            }
            return(-1);
        }