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);
         }
     }
 }
 public static bool TryMakeSubDirTipPath(ref string path) {
     if(!string.IsNullOrEmpty(path)) {
         bool flag;
         if(path.StartsWith("::")) {
             using(IDLWrapper wrapper = new IDLWrapper(path)) {
                 return wrapper.IsFolder;
             }
         }
         if(path.StartsWith(@"a:\", StringComparison.OrdinalIgnoreCase) || path.StartsWith(@"b:\", StringComparison.OrdinalIgnoreCase)) {
             return false;
         }
         if(!Directory.Exists(path)) {
             if(!File.Exists(path) || !Path.GetExtension(path).PathEquals(".lnk")) {
                 return false;
             }
             path = GetLinkTargetPath(path);
             if(!Directory.Exists(path)) {
                 return false;
             }
         }
         FileSystemInfo targetIfFolderLink = GetTargetIfFolderLink(new DirectoryInfo(path), out flag);
         if(flag) {
             bool fSearchHidden = QTUtility.CheckConfig(Settings.SubDirTipsHidden);
             bool fSearchSystem = QTUtility.CheckConfig(Settings.SubDirTipsSystem);
             bool flag4 = QTUtility.CheckConfig(Settings.SubDirTipsFiles);
             path = targetIfFolderLink.FullName;
             using(FindFile file = new FindFile(path, fSearchHidden, fSearchSystem)) {
                 return (file.SubDirectoryExists() || (flag4 && file.SubFileExists()));
             }
         }
     }
     return false;
 }
 public static bool PathIsFolder(string targetPath) {
     if(targetPath.StartsWith("::")) {
         using(IDLWrapper wrapper = new IDLWrapper(targetPath)) {
             return wrapper.IsFolder;
         }
     }
     else {
         return Directory.Exists(targetPath);
     }
 }
        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;
                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);
                }
            }
            return num5;
        }
 public static string GetDisplayName(string path) {
     using(IDLWrapper wrapper = new IDLWrapper(path)) {
         if(wrapper.Available) {
             return GetDisplayName(wrapper.PIDL, true);
         }
     }
     return path;
 }
 public static void ShowProperties(byte[] idl, IntPtr hwnd = default(IntPtr)) {
     using(SafePtr sptr = new SafePtr("properties"))
     using(IDLWrapper wrapper = new IDLWrapper(idl)) {
         if(wrapper.Available) {
             SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO {
                 hwnd = hwnd,
                 fMask = 0x40C,
                 lpVerb = sptr,
                 lpIDList = wrapper.PIDL
             };
             structure.cbSize = Marshal.SizeOf(structure);
             PInvoke.ShellExecuteEx(ref structure);
         }
     }
 }
        public int DragDrop(IDataObject pDataObj, int grfKeyState, Point pt, ref DragDropEffects pdwEffect)
        {
            try {
                if(DragFileOver != null) {
                    DragEventArgs e = new DragEventArgs(null, grfKeyState, pt.X, pt.Y, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll, pdwEffect);
                    DragFileOver(null, e);
                    pdwEffect = e.Effect;
                }
                else {
                    pdwEffect = DragDropEffects.Copy;
                }
                if(pdwEffect != DragDropEffects.None) {
                    if(DragFileDrop != null) {
                        IntPtr ptr;
                        byte[] buffer;
                        switch(DragFileDrop(out ptr, out buffer)) {
                            case -1:
                                return 0;

                            case 0: {
                                    IShellFolder ppv = null;
                                    object obj2 = null;
                                    Guid riid = ExplorerGUIDs.IID_IShellFolder;
                                    Guid guid2 = ExplorerGUIDs.IID_IDropTarget;
                                    using(IDLWrapper wrapper = new IDLWrapper(buffer)) {
                                        if(wrapper.Available && wrapper.IsDropTarget) {
                                            try {
                                                IntPtr ptr2;
                                                if(PInvoke.SHBindToParent(wrapper.PIDL, riid, out ppv, out ptr2) == 0) {
                                                    uint rgfReserved = 0;
                                                    IntPtr[] apidl = new IntPtr[] { ptr2 };
                                                    if(ppv.GetUIObjectOf(ptr, 1, apidl, ref guid2, ref rgfReserved, out obj2) == 0) {
                                                        _IDropTarget target = obj2 as _IDropTarget;
                                                        if(target != null) {
                                                            DragDropEffects effects = pdwEffect;
                                                            if(target.DragEnter(pDataObj, iLastKeyState, pt, ref effects) == 0) {
                                                                effects = pdwEffect;
                                                                if(target.DragOver(iLastKeyState, pt, ref effects) == 0) {
                                                                    if((iLastKeyState & 2) != 0) {
                                                                        pdwEffect = DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy;
                                                                    }
                                                                    return target.DragDrop(pDataObj, iLastKeyState, pt, ref pdwEffect);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            catch {
                                            }
                                            finally {
                                                if(ppv != null) {
                                                    Marshal.ReleaseComObject(ppv);
                                                }
                                                if(obj2 != null) {
                                                    Marshal.ReleaseComObject(obj2);
                                                }
                                                if(DragDropEnd != null) {
                                                    DragDropEnd(this, EventArgs.Empty);
                                                }
                                            }
                                        }
                                    }
                                    return 0;
                                }
                        }
                    }
                    FORMATETC format = new FORMATETC();
                    format.cfFormat = 15;
                    format.ptd = IntPtr.Zero;
                    format.dwAspect = DVASPECT.DVASPECT_CONTENT;
                    format.lindex = -1;
                    format.tymed = TYMED.TYMED_HGLOBAL;
                    STGMEDIUM medium = new STGMEDIUM();
                    try {
                        pDataObj.GetData(ref format, out medium);
                        PInvoke.SendMessage(hwnd, 0x233, medium.unionmember, IntPtr.Zero);
                    }
                    catch {
                    }
                    finally {
                        PInvoke.ReleaseStgMedium(ref medium);
                    }
                }
            }
            finally {
                if(pDataObj != null) {
                    Marshal.FinalReleaseComObject(pDataObj);
                }
            }
            return 0;
        }
        public int DragDrop(IDataObject pDataObj, int grfKeyState, Point pt, ref DragDropEffects pdwEffect)
        {
            try {
                if (DragFileOver != null)
                {
                    DragEventArgs e = new DragEventArgs(null, grfKeyState, pt.X, pt.Y, DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll, pdwEffect);
                    DragFileOver(null, e);
                    pdwEffect = e.Effect;
                }
                else
                {
                    pdwEffect = DragDropEffects.Copy;
                }
                if (pdwEffect != DragDropEffects.None)
                {
                    if (DragFileDrop != null)
                    {
                        IntPtr ptr;
                        byte[] buffer;
                        switch (DragFileDrop(out ptr, out buffer))
                        {
                        case -1:
                            return(0);

                        case 0: {
                            IShellFolder ppv   = null;
                            object       obj2  = null;
                            Guid         riid  = ExplorerGUIDs.IID_IShellFolder;
                            Guid         guid2 = ExplorerGUIDs.IID_IDropTarget;
                            using (IDLWrapper wrapper = new IDLWrapper(buffer)) {
                                if (wrapper.Available && wrapper.IsDropTarget)
                                {
                                    try {
                                        IntPtr ptr2;
                                        if (PInvoke.SHBindToParent(wrapper.PIDL, riid, out ppv, out ptr2) == 0)
                                        {
                                            uint     rgfReserved = 0;
                                            IntPtr[] apidl       = new IntPtr[] { ptr2 };
                                            if (ppv.GetUIObjectOf(ptr, 1, apidl, ref guid2, ref rgfReserved, out obj2) == 0)
                                            {
                                                _IDropTarget target = obj2 as _IDropTarget;
                                                if (target != null)
                                                {
                                                    DragDropEffects effects = pdwEffect;
                                                    if (target.DragEnter(pDataObj, iLastKeyState, pt, ref effects) == 0)
                                                    {
                                                        effects = pdwEffect;
                                                        if (target.DragOver(iLastKeyState, pt, ref effects) == 0)
                                                        {
                                                            if ((iLastKeyState & 2) != 0)
                                                            {
                                                                pdwEffect = DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy;
                                                            }
                                                            return(target.DragDrop(pDataObj, iLastKeyState, pt, ref pdwEffect));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch {
                                    }
                                    finally {
                                        if (ppv != null)
                                        {
                                            Marshal.ReleaseComObject(ppv);
                                        }
                                        if (obj2 != null)
                                        {
                                            Marshal.ReleaseComObject(obj2);
                                        }
                                        if (DragDropEnd != null)
                                        {
                                            DragDropEnd(this, EventArgs.Empty);
                                        }
                                    }
                                }
                            }
                            return(0);
                        }
                        }
                    }
                    FORMATETC format = new FORMATETC();
                    format.cfFormat = 15;
                    format.ptd      = IntPtr.Zero;
                    format.dwAspect = DVASPECT.DVASPECT_CONTENT;
                    format.lindex   = -1;
                    format.tymed    = TYMED.TYMED_HGLOBAL;
                    STGMEDIUM medium = new STGMEDIUM();
                    try {
                        pDataObj.GetData(ref format, out medium);
                        PInvoke.SendMessage(hwnd, 0x233, medium.unionmember, IntPtr.Zero);
                    }
                    catch {
                    }
                    finally {
                        PInvoke.ReleaseStgMedium(ref medium);
                    }
                }
            }
            finally {
                if (pDataObj != null)
                {
                    Marshal.FinalReleaseComObject(pDataObj);
                }
            }
            return(0);
        }
        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);
        }