Beispiel #1
0
        /// <summary>
        /// Constructor for the desktop shell item.
        /// </summary>
        /// <param name="explorer">
        /// Explorer class that uses the shell item.
        /// </param>
        /// <param name="pidl">
        /// Pointer to the desktop PIDL.
        /// </param>
        /// <param name="folderPtr">
        /// Pointer to the IShellFolder interface for the desktop.
        /// </param>
        internal ShellItem(ShellExplorer explorer, IntPtr pidl, IntPtr folderPtr)
        {
            this.explorer  = explorer;
            parent         = null;
            this.folderPtr = folderPtr;
            // get managed object
            this.folder =
                (IShellFolder)Marshal.GetTypedObjectForIUnknown(folderPtr, typeof(IShellFolder));
            subFiles   = new ShellItemList(this);
            subFolders = new ShellItemList(this);
            relPidl    = new PIDL(pidl, false);

            text = "Desktop";
            path = "Desktop";
            SetDesktopAttributes();

            ShellAPI.SHFILEINFO info = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGetFileInfo(relPidl.Ptr,
                                   0,
                                   ref info,
                                   ShellAPI.cbFileInfo,
                                   ShellAPI.SHGFI.PIDL |
                                   ShellAPI.SHGFI.TYPENAME |
                                   ShellAPI.SHGFI.SYSICONINDEX);
            type = info.szTypeName;

            ShellImageList.SetIconIndex(this, info.iIcon, false);
            ShellImageList.SetIconIndex(this, info.iIcon, true);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor for a folder item.
 /// </summary>
 /// <param name="explorer">
 /// Explorer class that uses the shell item.
 /// </param>
 /// <param name="parent">
 /// Parent shell item for this item.
 /// </param>
 /// <param name="pidl">
 /// Pointer to the folder PIDL.
 /// </param>
 /// <param name="folderPtr">
 /// Pointer to the IShellFolder interface for the folder.
 /// </param>
 internal ShellItem(ShellExplorer explorer, ShellItem parent, IntPtr pidl, IntPtr folderPtr)
 {
     this.explorer  = explorer;
     this.parent    = parent;
     this.folderPtr = folderPtr;
     folder         = (IShellFolder)Marshal.GetTypedObjectForIUnknown(folderPtr, typeof(IShellFolder));
     subFiles       = new ShellItemList(this);
     subFolders     = new ShellItemList(this);
     relPidl        = new PIDL(pidl, false);
     SetText();
     SetPath();
     SetInfo();
     SetFolderAttributes();
 }
Beispiel #3
0
 /// <summary>
 /// Constructor for a file item.
 /// </summary>
 /// <param name="explorer">
 /// Explorer class that uses the shell item.
 /// </param>
 /// <param name="parent">
 /// Parent shell item for this item.
 /// </param>
 /// <param name="pidl">
 /// Pointer to the file PIDL.
 /// </param>
 internal ShellItem(ShellExplorer explorer, ShellItem parent, IntPtr pidl)
 {
     this.explorer = explorer;
     this.parent   = parent;
     folderPtr     = IntPtr.Zero;
     folder        = null;
     subFiles      = null;
     subFolders    = null;
     relPidl       = new PIDL(pidl, false);
     SetText();
     SetPath();
     SetInfo();
     SetFileAttributes();
 }
Beispiel #4
0
        /// <summary>
        /// Identifies and gathers ShellBag items from raw binary registry data.
        /// </summary>
        /// <returns>a list of different variety ShellBag items</returns>
        public static List <IShellItem> GetShellItems(IRegistryReader registryReader)
        {
            List <IShellItem> shellItems = new List <IShellItem>();
            Dictionary <RegistryKeyWrapper, IShellItem> keyShellMappings = new Dictionary <RegistryKeyWrapper, IShellItem>();

            foreach (RegistryKeyWrapper keyWrapper in registryReader.GetRegistryKeys())
            {
                if (keyWrapper.Value != null) // Some Registry Keys are null
                {
                    ShellItemList shellItemList = new ShellItemList(keyWrapper.Value);
                    foreach (IShellItem shellItem in shellItemList.Items())
                    {
                        IShellItem parentShellItem = null;
                        //obtain the parent shellitem from the parent registry key (if it exists)
                        if (keyWrapper.Parent != null)
                        {
                            if (keyShellMappings.TryGetValue(keyWrapper.Parent, out IShellItem pShellItem))
                            {
                                parentShellItem = pShellItem;
                            }
                        }

                        RegistryShellItemDecorator decoratedShellItem = new RegistryShellItemDecorator(shellItem, keyWrapper, parentShellItem);
                        try
                        {
                            keyShellMappings.Add(keyWrapper, decoratedShellItem);
                        }
                        catch (ArgumentException ex)
                        {
                            //*should* never happen, if it does Absolute Path finding need to be reworked. Potentially should be a fatal exception
                            // as now the shellbags involved are misleading. (contain incomplete data)
                            logger.Error(ex, $"Registry Item {keyWrapper.RegistryPath} already had an associated Shellbag ({keyShellMappings[keyWrapper].Name}), Absolute Path's are no longer accurate.");
                        }

                        shellItems.Add(decoratedShellItem);
                    }
                }
            }
            return(shellItems);
        }