Пример #1
0
        public void KnownFolder_GetId()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Windows);

            folder.GetId().Should().Be(KNOWNFOLDERID.Windows);
        }
Пример #2
0
        public void GetTextAssociation_AppId()
        {
            Action action = () => ShellMethods.AssocQueryString(AssociationFlags.NoUserSettings, AssociationString.AppId, ".txt", null);

            // No application is associated with the specified file for this operation.
            action.Should().Throw <WInteropIOException>().And.HResult.Should().Be(unchecked ((int)0x80070483));
        }
Пример #3
0
        public void KnownFolder_GetCategory()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KnownFolderIds.Windows);

            folder.GetCategory().Should().Be(KnownFolderCategory.Fixed);
        }
Пример #4
0
        public void KnownFolderManager_GetKnownFolder()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KnownFolderIds.Windows);

            folder.Should().NotBeNull();
        }
Пример #5
0
        public void KnownFolder_GetCategory()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Windows);

            folder.GetCategory().Should().Be(KF_CATEGORY.FIXED);
        }
Пример #6
0
 public IDLWrapper(string path, bool fMsgModal)
 {
     this.attributes = 0xfffffff0;
     if (!string.IsNullOrEmpty(path))
     {
         this.path = path;
         if (path.Contains("???") && dicCacheIDLs.TryGetValue(path, out this.idl))
         {
             this.pIDL = ShellMethods.CreateIDL(this.idl);
         }
         else
         {
             this.pIDL = TranslateLocation(path);
             if (this.pIDL == IntPtr.Zero)
             {
                 if (PathIsNetwork(this.path) && TryPing(this.path))
                 {
                     Application.DoEvents();
                     MessageForm.Show(IntPtr.Zero, "Timed out:    \"" + this.path + "\"", "Timed Out", MessageBoxIcon.Hand, 0x2710, fMsgModal);
                 }
                 else
                 {
                     this.pIDL = PInvoke.ILCreateFromPath(path);
                 }
             }
             else
             {
                 this.fSpecial = true;
             }
         }
     }
 }
Пример #7
0
        public void GetTextAssociation_OpenCommand()
        {
            string value = ShellMethods.AssocQueryString(ASSOCF.None, ASSOCSTR.Command, ".txt", "open");

            // Example: "C:\Program Files (x86)\Notepad++\notepad++.exe" "%1"
            value.Should().EndWith("\"%1\"");
        }
Пример #8
0
        public void GetTextAssociation_OpenCommand()
        {
            string value = ShellMethods.AssocQueryString(AssociationFlags.None, AssociationString.Command, ".txt", "open");

            // Example: "C:\Program Files (x86)\Notepad++\notepad++.exe" "%1"
            value.Should().Contain("%1");
        }
Пример #9
0
        public void DeleteSelection(bool fNuke)
        {
            List <string> lstPaths = new List <string>();

            foreach (var idlw in GetItems(true))
            {
                if (idlw.HasPath /* && idlw.CanDelete */)   // todo
                {
                    lstPaths.Add(idlw.Path);
                }
                else
                {
                    // not deletable object found, cancel
                    System.Media.SystemSounds.Beep.Play();
                    return;
                }
            }

            if (lstPaths.Count > 0)
            {
                IntPtr handle;
                shellBrowser.GetWindow(out handle);
                ShellMethods.DeleteFile(lstPaths, fNuke, handle);
            }
            else
            {
                // no item selected
                System.Media.SystemSounds.Beep.Play();
            }
        }
        private void DeleteFiles(bool fShiftKey)
        {
            List <string>          lstPaths = new List <string>();
            DropDownMenuDropTarget root     = GetRoot(this);

            if (root != null)
            {
                GetCheckedItem(root, lstPaths, false, false);
                if (lstPaths.Count == 0)
                {
                    foreach (ToolStripItem item in this.DisplayedItems)
                    {
                        if (item.Selected)
                        {
                            QMenuItem item2 = item as QMenuItem;
                            if ((item2 != null) && !string.IsNullOrEmpty(item2.Path))
                            {
                                lstPaths.Add(item2.Path);
                            }
                            break;
                        }
                    }
                }
                ShellMethods.DeleteFile(lstPaths, fShiftKey, this.hwndDialogParent);
                if (!QTUtility.IsVista)
                {
                    root.Close(ToolStripDropDownCloseReason.ItemClicked);
                }
            }
        }
 private int dropTargetWrapper_DragFileDrop(out IntPtr hwnd, out byte[] idlReal)
 {
     base.fRespondModKeys = this.fRespondModKeysTemp;
     base.fEnableShiftKey = this.fEnableShiftKeyTemp;
     hwnd    = IntPtr.Zero;
     idlReal = null;
     try {
         if ((this.itemHover != null) && !string.IsNullOrEmpty(this.strTargetPath))
         {
             byte[] iDLData = ShellMethods.GetIDLData(this.strTargetPath);
             if ((iDLData != null) && (iDLData.Length > 0))
             {
                 idlReal = iDLData;
                 base.CancelClosingAncestors(true, false);
                 base.ShowItemToolTips = false;
                 return(0);
             }
         }
     }
     finally {
         this.strDraggingDrive     = null;
         this.strDraggingStartPath = null;
         this.strTargetPath        = null;
         this.itemHover            = null;
     }
     return(-1);
 }
Пример #12
0
        private bool ShowSubDirTip(int iItem, bool fByKey, bool fSkipForegroundCheck)
        {
            string str;

            if ((fSkipForegroundCheck || (hwndExplorer == PInvoke.GetForegroundWindow())) && ShellBrowser.TryGetHotTrackPath(iItem, out str))
            {
                bool flag = false;
                try {
                    if (!ShellMethods.TryMakeSubDirTipPath(ref str))
                    {
                        return(false);
                    }
                    Point pnt = GetSubDirTipPoint(fByKey);
                    if (subDirTip == null)
                    {
                        subDirTip                                = new SubDirTipForm(hwndSubDirTipMessageReflect, true, this);
                        subDirTip.MenuClosed                    += subDirTip_MenuClosed;
                        subDirTip.MenuItemClicked               += subDirTip_MenuItemClicked;
                        subDirTip.MultipleMenuItemsClicked      += subDirTip_MultipleMenuItemsClicked;
                        subDirTip.MenuItemRightClicked          += subDirTip_MenuItemRightClicked;
                        subDirTip.MultipleMenuItemsRightClicked += subDirTip_MultipleMenuItemsRightClicked;
                        if (dropTargetPassthrough != null)
                        {
                            PInvoke.RegisterDragDrop(subDirTip.Handle, dropTargetPassthrough);
                        }
                    }
                    subDirTip.ShowSubDirTip(str, null, pnt);
                    flag = true;
                }
                catch {
                }
                return(flag);
            }
            return(false);
        }
        private void CopyCutFiles(bool fCut)
        {
            List <string>          lstPaths = new List <string>();
            DropDownMenuDropTarget root     = GetRoot(this);

            if (root != null)
            {
                GetCheckedItem(root, lstPaths, fCut, true);
                if (lstPaths.Count == 0)
                {
                    foreach (ToolStripItem item in this.DisplayedItems)
                    {
                        if (item.Selected)
                        {
                            QMenuItem item2 = item as QMenuItem;
                            if ((item2 != null) && !string.IsNullOrEmpty(item2.Path))
                            {
                                item2.IsCut = fCut;
                                lstPaths.Add(item2.Path);
                            }
                            break;
                        }
                    }
                }
                if (ShellMethods.SetClipboardFileDropPaths(lstPaths, fCut, this.hwndDialogParent))
                {
                    fContainsFileDropList = true;
                }
            }
        }
Пример #14
0
        public void KnownFolder_GetRedirectionCaps()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Libraries);

            folder.GetRedirectionCapabilities().Should().Be(KF_REDIRECTION_CAPABILITIES.REDIRECTABLE);
        }
Пример #15
0
 private void InitFromPath(string path, bool fMsgModal = false)
 {
     this.path = path;
     if (path.Contains("???") && dicCacheIDLs.TryGetValue(path, out idl))
     {
         pIDL = ShellMethods.CreateIDL(idl);
     }
     else
     {
         pIDL = TranslateLocation(path);
         if (pIDL == IntPtr.Zero)
         {
             if (PathIsNetwork(this.path) && TryPing(this.path))
             {
                 Application.DoEvents();
                 MessageForm.Show(IntPtr.Zero, "Timed out:    \"" + this.path + "\"", "Timed Out", MessageBoxIcon.Hand, 0x2710, fMsgModal);
             }
             else
             {
                 pIDL = PInvoke.ILCreateFromPath(path);
             }
         }
         else
         {
             fSpecial = true;
         }
     }
 }
Пример #16
0
        public void GetTextAssociation_OpenCommandExecutable()
        {
            string value = ShellMethods.AssocQueryString(AssociationFlags.None, AssociationString.Executable, ".txt", "open");

            // Example: C:\Program Files (x86)\Notepad++\notepad++.exe
            value.Should().EndWithEquivalent(".exe");
        }
Пример #17
0
        private static bool PathIsExecutable(string path, out bool fLinkTargetIsNotDropTarget)
        {
            fLinkTargetIsNotDropTarget = false;
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }
            string extension = System.IO.Path.GetExtension(path);

            if (string.IsNullOrEmpty(extension))
            {
                return(false);
            }
            if (strExtExecutable == null)
            {
                strExtExecutable = Environment.GetEnvironmentVariable("PATHEXT") ??
                                   ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC";
            }
            if (!extension.PathEquals(".lnk"))
            {
                return(strExtExecutable.IndexOf(extension, StringComparison.OrdinalIgnoreCase) != -1);
            }
            string linkTargetPath = ShellMethods.GetLinkTargetPath(path);

            if (File.Exists(linkTargetPath))
            {
                string str3 = System.IO.Path.GetExtension(linkTargetPath);
                if (strExtExecutable.IndexOf(str3, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    return(true);
                }
            }
            fLinkTargetIsNotDropTarget = true;
            return(true);
        }
Пример #18
0
 public void GetKnownFolderId_Basic()
 {
     using (var id = ShellMethods.GetKnownFolderId(KNOWNFOLDERID.ProgramData))
     {
         id.IsInvalid.Should().BeFalse();
     }
 }
Пример #19
0
        public void KnownFolder_GetRedirectionCaps()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KnownFolderIds.Libraries);

            folder.GetRedirectionCapabilities().Should().Be(KnownFolderRedirectionCapabilities.Redirectable);
        }
Пример #20
0
 public void ExpandEnvironmentVariablesForUser()
 {
     ShellMethods.ExpandEnvironmentVariablesForUser(
         AuthorizationMethods.OpenProcessToken(AccessTokenRights.Impersonate | AccessTokenRights.Query | AccessTokenRights.Duplicate),
         @"%USERNAME%").
     Should().Be(Environment.GetEnvironmentVariable("USERNAME"));
 }
Пример #21
0
        public void GetTextAssociation_FriendlyAppName()
        {
            string value = ShellMethods.AssocQueryString(AssociationFlags.None, AssociationString.FriendlyAppName, ".txt", null);

            // Example: Notepad++ : a free (GNU) source code editor
            value.Should().StartWith("Notepad");
        }
Пример #22
0
        public void GetTextAssociation_ProgID()
        {
            string value = ShellMethods.AssocQueryString(ASSOCF.NoUserSettings, ASSOCSTR.ProgId, ".txt", null);

            // Example: Applications\notepad++.exe
            value.Should().StartWith("Applications\\").And.EndWith(".exe");
        }
Пример #23
0
 public static bool TargetIsInNoCapture(IntPtr pIDL, string path)
 {
     if (pIDL != IntPtr.Zero)
     {
         path = ShellMethods.GetPath(pIDL);
     }
     return(!String.IsNullOrEmpty(path) && QTUtility.NoCapturePathsList.Any(path2 => path.PathEquals(path2)));
 }
Пример #24
0
 public void GetIdName_Basic()
 {
     using (var id = ShellMethods.GetKnownFolderId(KNOWNFOLDERID.Windows))
     {
         id.IsInvalid.Should().BeFalse();
         ShellMethods.GetNameFromId(id, SIGDN.PARENTRELATIVE).Should().Be("Windows");
     }
 }
Пример #25
0
        public void ShellItem_GetDisplayName()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Windows);
            IShellItem          item    = folder.GetShellItem(0, new Guid(InterfaceIds.IID_IShellItem));

            item.GetDisplayName(SIGDN.NORMALDISPLAY).Should().Be("Windows");
        }
Пример #26
0
 public void GetIdName_Basic()
 {
     using (var id = ShellMethods.GetKnownFolderId(KnownFolderIds.Windows))
     {
         id.IsInvalid.Should().BeFalse();
         ShellMethods.GetNameFromId(id, ShellItemDisplayNames.ParentRelative).Should().Be("Windows");
     }
 }
Пример #27
0
        public void KnownFolder_GetFolderType()
        {
            // Most known folders don't have a FolderType associated and will throw a COMException with E_FAIL.
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KNOWNFOLDERID.Contacts);

            folder.GetFolderType().Should().Be(FOLDERTYPEID.Contacts);
        }
Пример #28
0
        public void ShellItem_GetDisplayName()
        {
            IKnownFolderManager manager = ShellMethods.GetKnownFolderManager();
            IKnownFolder        folder  = manager.GetFolder(KnownFolderIds.Windows);
            IShellItem          item    = folder.GetShellItem(0, new Guid(InterfaceIds.IID_IShellItem));

            item.GetDisplayName(ShellItemDisplayNames.NormalDisplay).Should().Be("Windows");
        }
Пример #29
0
        public void GetTextAssociation_ShellExecClassKey()
        {
            RegistryKeyHandle key = ShellMethods.AssocQueryKey(ASSOCF.None, ASSOCKEY.ShellExecClass, ".txt", null);

            // \REGISTRY\USER\S-1-5-21-2477298427-4111324449-2912218533-1001_Classes\Applications\notepad++.exe
            string name = RegistryMethods.QueryKeyName(key);

            name.Should().StartWith(@"\REGISTRY\USER\S-").And.EndWith(".exe");
        }
Пример #30
0
        public void GetTextAssociation_BaseClassKey()
        {
            RegistryKeyHandle key = ShellMethods.AssocQueryKey(AssociationFlags.None, AssociationKey.BaseClass, ".txt", null);

            string name = Registry.QueryKeyName(key);

            // \REGISTRY\USER\S-1-5-21-2477298427-4111324449-2912218533-1001_Classes\*
            name.Should().StartWith(@"\REGISTRY\USER\S-").And.EndWith(@"_Classes\*");
        }