Exemple #1
0
 public bool ExpandANode(CShItem newItem)
 {
     bool returnValue;
     returnValue = false; //assume failure
     System.Windows.Forms.TreeNode baseNode = Root;
     tv1.BeginUpdate();
     baseNode.Expand(); //Ensure base is filled in
     //do the drill down -- Node to expand must be included in tree
     TreeNode testNode;
     int lim = CShItem.PidlCount(newItem.PIDL) - CShItem.PidlCount((baseNode.Tag as CShItem).PIDL);
     //TODO: Test ExpandARow again on XP to ensure that the CP problem ix fixed
     while (lim > 0)
     {
         foreach (TreeNode tempLoopVar_testNode in baseNode.Nodes)
         {
             testNode = tempLoopVar_testNode;
             if (CShItem.IsAncestorOf(testNode.Tag as CShItem, newItem, false))
             {
                 baseNode = testNode;
                 RefreshNode(baseNode); //ensure up-to-date
                 baseNode.Expand();
                 lim--;
                 goto NEXLEV;
             }
         }
         goto XIT; //on falling thru For, we can't find it, so get out
     NEXLEV:
         1.GetHashCode() ; //nop
     }
     //after falling thru here, we have found & expanded the node
     this.tv1.HideSelection = false;
     this.Select();
     this.tv1.SelectedNode = baseNode;
     returnValue = true;
     XIT:
     tv1.EndUpdate();
     return returnValue;
 }
Exemple #2
0
        private void expTree1_ExpTreeNodeSelected(string SelPath, CShItem CSI)
        {
            ImageList imgList = new ImageList();
            imgList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
            imgList.ImageSize = new System.Drawing.Size(130, 130);
            lv.BeginUpdate();
            lv.Items.Clear();

            ArrayList dirList = new ArrayList();
            ArrayList fileList = new ArrayList();

            if (CSI.DisplayName.Equals(CShItem.strMyComputer))
            {
                dirList = CSI.GetDirectories(true);
            }
            else
            {
                dirList = CSI.GetDirectories(true);
                fileList = CSI.GetFiles();
            }

            
           try {
            foreach (CShItem file in fileList)
            {
                if (file.Path.ToLower().EndsWith(".jpg") || file.Path.ToLower().EndsWith(".png") || file.Path.ToLower().EndsWith(".bmp"))
                {
                    try { 
                        Image thumb = Image.FromFile(file.Path);
                        imgList.Images.Add(thumb);
                        ListViewItem lvi = lv.Items.Add(file.GetFileName());
                        lvi.ImageIndex = lvi.Index;
                        lvi.Tag = file.Path;
                    }
                    catch (Exception Ex) {
                    }
                }
            }
            lv.LargeImageList = imgList;
            lv.EndUpdate();
            }
           catch (Exception Exc) { MessageBox.Show(Exc.ToString()); }
        }
        /// <summary>
        /// Summary of GetIconIndex.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="GetOpenIcon"></param>
        ///
        public static int GetIconIndex(CShItem item, bool GetOpenIcon, bool GetSelectedIcon)
        {
            int rVal; //The returned Index
            if (dcAttrIndexCache.TryGetValue((int)item.Attributes, out rVal))
                return rVal;

            Initializer();
            bool HasOverlay = false; //true if it's an overlay
            //int rVal; //The returned Index

            int dwflag = (int)(ExpTreeLib.ShellDll.SHGFI.SYSICONINDEX | ExpTreeLib.ShellDll.SHGFI.PIDL | ExpTreeLib.ShellDll.SHGFI.ICON);
            int dwAttr = 0;
            //build Key into HashTable for this Item
            int Key = ! GetOpenIcon ? item.IconIndexNormal * 256 : item.IconIndexOpen * 256;
            CShItem with_1 = item;
            if (with_1.IsLink)
            {
                Key = Key | 1;
                dwflag = dwflag | (int)ExpTreeLib.ShellDll.SHGFI.LINKOVERLAY;
                HasOverlay = true;
            }
            if (with_1.IsShared)
            {
                Key = Key | 2;
                dwflag = dwflag | (int)ExpTreeLib.ShellDll.SHGFI.ADDOVERLAYS;
                HasOverlay = true;
            }
            if (GetSelectedIcon)
            {
                Key = Key | 4;
                dwflag = dwflag | (int)ExpTreeLib.ShellDll.SHGFI.SELECTED;
                HasOverlay = true; //not really an overlay, but handled the same
            }
            if (m_Table.ContainsKey(Key))
            {
                rVal = (int)m_Table[Key];
                mCnt++;
            }
            else if (! HasOverlay) //for non-overlay icons, we already have
            {
                rVal = Key / 256; //  the right index -- put in table
                m_Table[Key] = rVal;
                bCnt++;
            }
            else //don't have iconindex for an overlay, get it.
            {
                //This is the tricky part -- add overlaid Icon to systemimagelist
                //  use of SmallImageList from Calum McLellan
                //ExpTreeLib.ShellDll.SHFILEINFO shfi = new ExpTreeLib.ShellDll.SHFILEINFO();
                ExpTreeLib.ShellDll.SHFILEINFO shfi_small = new ExpTreeLib.ShellDll.SHFILEINFO();
                //IntPtr HR;
                IntPtr HR_SMALL;
                if (with_1.IsFileSystem && ! with_1.IsDisk && ! with_1.IsFolder)
                {
                    dwflag = dwflag | (int)ExpTreeLib.ShellDll.SHGFI.USEFILEATTRIBUTES;
                    dwAttr = ExpTreeLib.ShellDll.FILE_ATTRIBUTE_NORMAL;
                }
                //HR = ExpTreeLib.ShellDll.SHGetFileInfo(with_1.PIDL, dwAttr, ref shfi, ExpTreeLib.ShellDll.cbFileInfo, dwflag);
                HR_SMALL = ExpTreeLib.ShellDll.SHGetFileInfo(with_1.PIDL, dwAttr, ref shfi_small, ExpTreeLib.ShellDll.cbFileInfo, dwflag | (int)ExpTreeLib.ShellDll.SHGFI.SMALLICON);
                m_Mutex.WaitOne();
                rVal = ExpTreeLib.ShellDll.ImageList_ReplaceIcon(m_smImgList, - 1, shfi_small.hIcon);
                Debug.Assert(rVal > - 1, "Failed to add overlaid small icon");
                /*int rVal2;
                rVal2 = ExpTreeLib.ShellDll.ImageList_ReplaceIcon(m_lgImgList, - 1, shfi.hIcon);
                Debug.Assert(rVal2 > - 1, "Failed to add overlaid large icon");
                Debug.Assert(rVal == rVal2, "Small & Large IconIndices are Different");*/
                m_Mutex.ReleaseMutex();
                //ExpTreeLib.ShellDll.DestroyIcon(shfi.hIcon);
                ExpTreeLib.ShellDll.DestroyIcon(shfi_small.hIcon);
                if (rVal < 0/* || rVal != rVal2*/)
                {
                    throw (new ApplicationException("Failed to add Icon for " + item.DisplayName));
                }
                m_Table[Key] = rVal;
            }

            if (item.IsFileSystem && item.IsFolder)
            {
                dcAttrIndexCache[(int)item.Attributes] = rVal;
            }

            return rVal;
        }
Exemple #4
0
 public static CShItem GetCShItem(ExpTreeLib.ShellDll.CSIDL ID)
 {
     CShItem returnValue;
     returnValue = null; //avoid VB2005 Warning
     if (ID == ExpTreeLib.ShellDll.CSIDL.DESKTOP)
     {
         return GetDeskTop();
     }
     int HR;
     IntPtr tmpPidl = IntPtr.Zero;
     if (ID == ExpTreeLib.ShellDll.CSIDL.MYDOCUMENTS)
     {
         int pchEaten = 0;
         int pdwAttributes = 0;
         HR = GetDeskTop().Folder.ParseDisplayName(0, IntPtr.Zero, "::{450d8fba-ad25-11d0-98a8-0800361b1103}", ref pchEaten, ref tmpPidl, ref pdwAttributes);
     }
     else
     {
         HR = ExpTreeLib.ShellDll.SHGetSpecialFolderLocation(0, (int)ID, ref tmpPidl);
     }
     if (HR == ExpTreeLib.ShellDll.NOERROR)
     {
         returnValue = FindCShItem(tmpPidl);
         if (returnValue == null)
         {
             try
             {
                 returnValue = new CShItem(ID);
             }
             catch
             {
                 returnValue = null;
             }
         }
     }
     if (! tmpPidl.Equals(IntPtr.Zero))
     {
         Marshal.FreeCoTaskMem(tmpPidl);
     }
     return returnValue;
 }
Exemple #5
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            ImageList imgList = new ImageList();
            imgList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
            imgList.ImageSize = new System.Drawing.Size(130, 130);
            
            lvIncludedBG.BeginUpdate();
            lvIncludedBG.Items.Clear();

            ArrayList dirList = new ArrayList();
            ArrayList fileList = new ArrayList();

            if (!Directory.Exists(Application.StartupPath + "\\Backgrounds")) return;

            CShItem CSI = new CShItem(Application.StartupPath + "\\Backgrounds");
            dirList = CSI.GetDirectories(true);
            fileList = CSI.GetFiles();


            try
            {
                foreach (CShItem file in fileList)
                {
                    if (file.Path.ToLower().EndsWith(".jpg") || file.Path.ToLower().EndsWith(".png") || file.Path.ToLower().EndsWith(".bmp"))
                    {
                        try
                        {
                            Image thumb = Image.FromFile(file.Path);
                            imgList.Images.Add(thumb);

                            ListViewItem lvi = lvIncludedBG.Items.Add(String.Empty);
                            lvi.ImageIndex = lvi.Index;
                            lvi.Tag = file.Path;
                        }
                        catch (Exception Ex)
                        {
                        }
                    }
                }
                lvIncludedBG.LargeImageList = imgList;
                lvIncludedBG.EndUpdate();
            }
            catch (Exception Exc) { MessageBox.Show(Exc.ToString()); }
        }
Exemple #6
0
 private TreeNode MakeNode(CShItem item)
 {
     TreeNode newNode = new TreeNode(item.DisplayName);
     newNode.Tag = item;
     newNode.ImageIndex = SystemImageListManager.GetIconIndex(item, false, false);
     newNode.SelectedImageIndex = SystemImageListManager.GetIconIndex(item, true, false);
     //The following code, from Calum implements the following logic
     // Allow/disallow the showing of Hidden folders based on ShowHidden Propert
     // For Removable disks, always show + (allow expansion) - avoids floppy access
     // For all others, add + based on HasSubFolders
     //  Except - If showing Hidden dirs, do extra check to  allow for
     //  the case of all hidden items in the Dir which will cause
     //  HasSubFolders to be always left unset
     if (item.IsRemovable) //Calum's fix to hidden file fix
     {
         newNode.Nodes.Add(new TreeNode(" : "));
     }
     else if (item.HasSubFolders)
     {
         newNode.Nodes.Add(new TreeNode(" : "));
         //Begin Calum's change so Hidden dirs with all hidden content are expandable
     }
     else if (item.GetDirectories(true).Count > 0) //Added Code
     {
         newNode.Nodes.Add(new TreeNode(" : ")); //Added Code
         //End Calum's change
     }
     return newNode;
 }
Exemple #7
0
        private void expTree1_ExpTreeNodeSelected(string pathName, CShItem CSI)
        {
            if (SelectedPathChanged != null)
                SelectedPathChanged(this, EventArgs.Empty);

            if (browseMode == BrowseModes.FolderBrowser) return;

            List<CShItem> dirList = new List<CShItem>();
            List<CShItem> fileList = new List<CShItem>();

            int TotalItems;

            if (CSI.DisplayName.Equals(CShItem.strMyComputer))
                //avoid re-query since only has dirs
                dirList = CSI.GetDirectories(true);
            else
            {
                dirList = CSI.GetDirectories(true);
                fileList = (this.DesignMode || SelectedFilter == "*.*")? CSI.GetFiles() : CSI.GetFiles(SelectedFilter);
            }

            TotalItems = dirList.Count + fileList.Count;

            if (TotalItems > 0)
            {
                dirList.Sort();
                fileList.Sort();

                browseStatusBar.Text = dirList.Count + " Directories " +
                            fileList.Count + " Files";

                ArrayList combList = new ArrayList(TotalItems);

                combList.AddRange(dirList);
                combList.AddRange(fileList);

                //Build the ListViewItems & add to lv1
                explorerLV.BeginUpdate();
                explorerLV.Items.Clear();

                foreach (CShItem item in combList)
                {
                    ListViewItem lvi = new ListViewItem(item.DisplayName);
                    /*if (!item.IsDisk && item.IsFileSystem)
                    {
                        FileAttributes attr = File.GetAttributes(item.Path);
                        StringBuilder SB = new StringBuilder();

                        if ((attr & FileAttributes.System) == FileAttributes.System) SB.Append("S");
                        if ((attr & FileAttributes.Hidden) == FileAttributes.Hidden) SB.Append("H");
                        if ((attr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) SB.Append("R");
                        if ((attr & FileAttributes.Archive) == FileAttributes.Archive) SB.Append("A");

                        lvi.SubItems.Add(SB.ToString());
                    }
                    else
                        lvi.SubItems.Add("");

                    if ((!item.IsDisk) && item.IsFileSystem && (!item.IsFolder))
                    {
                        if (item.Length > 1024)
                            lvi.SubItems.Add(string.Format("{0:#,###} KB", item.Length / 1024));
                        else
                            lvi.SubItems.Add(string.Format("{0:##0} Bytes", item.Length));
                    }
                    else
                        lvi.SubItems.Add("");

                    lvi.SubItems.Add(item.TypeName);
                    if (item.IsDisk)
                        lvi.SubItems.Add("");*/

                    lvi.Tag = item;
                    CShItem refItem = item;
                    lvi.ImageIndex = SystemImageListManager.GetIconIndex(refItem, false, false);
                    explorerLV.Items.Add(lvi);
                }

                explorerLV.EndUpdate();
                //LoadLV1Images();
            }
            else
            {
                explorerLV.Items.Clear();
                browseStatusBar.Text = "No Items";
            }

            pathTextBox.Text = (CSI.IsFileSystem) ? pathName : "";
        }
Exemple #8
0
        /// <summary>Create a new CShItem based on a Path Must be a valid FileSystem Path</summary>
        /// <param name="path"></param>
        ///
        public CShItem(string path)
        {
            if (DesktopBase == null)
            {
                DesktopBase = new CShItem(); //This initializes the Desktop folder
            }
            //Removal of following code allows Path(GUID) of Special FOlders to serve
            //  as a valid Path for CShItem creation (part of Calum's refresh code needs this
            //If Not Directory.Exists(path) AndAlso Not File.Exists(path) Then
            //    Throw New Exception("CShItem -- Invalid Path specified")
            //End If
            int HR;
            int pchEaten = 0;
            int pdwAttributes = 0;
            HR = DesktopBase.m_Folder.ParseDisplayName(0, IntPtr.Zero, path, ref pchEaten, ref m_Pidl, ref pdwAttributes);
            if (HR != ExpTreeLib.ShellDll.NOERROR)
            {
                Marshal.ThrowExceptionForHR(HR);
            }
            ShellDll.IShellFolder pParent;
            IntPtr relPidl = IntPtr.Zero;

            pParent = GetParentOf(m_Pidl, ref relPidl);

            //Get the Attributes
            SetUpAttributes(pParent, relPidl);
            //Set unfetched value for IconIndex....
            m_IconIndexNormal = - 1;
            m_IconIndexOpen = - 1;
            //finally, set up my Folder
            if (m_IsFolder)
            {
                HR = pParent.BindToObject(relPidl, IntPtr.Zero, ref ExpTreeLib.ShellDll.IID_IShellFolder, ref m_Folder);
                if (HR != ExpTreeLib.ShellDll.NOERROR)
                {
                    Marshal.ThrowExceptionForHR(HR);
                }
            }
            Marshal.ReleaseComObject(pParent);
            //if PidlCount(m_Pidl) = 1 then relPidl is same as m_Pidl, don't release
            if (PidlCount(m_Pidl) > 1)
            {
                Marshal.FreeCoTaskMem(relPidl);
            }
        }
Exemple #9
0
        ///<Summary>Given a Byte() containing the Pidl of the parent
        /// folder and another Byte() containing the Pidl of the Item,
        /// relative to the Folder, Create a CShItem for the Item.
        /// This is of primary use in dealing with "Shell IDList Array"
        /// formatted info passed in a Drag Operation
        /// </Summary>
        public CShItem(byte[] FoldBytes, byte[] ItemBytes)
        {
            Debug.WriteLine("CShItem.New(FoldBytes,ItemBytes) Fold len= " + FoldBytes.Length + " Item Len = " + ItemBytes.Length);
            if (DesktopBase == null)
            {
                DesktopBase = new CShItem(); //This initializes the Desktop folder
            }
            ShellDll.IShellFolder pParent = MakeFolderFromBytes(FoldBytes);

            IntPtr ipParent = IntPtr.Zero;
            IntPtr ipItem = IntPtr.Zero;

            if (pParent == null)
            {
                goto XIT; //m_PIDL will = IntPtr.Zero for really bad CShitem
            }
            ipParent = cPidl.BytesToPidl(FoldBytes);
            ipItem = cPidl.BytesToPidl(ItemBytes);
            if (ipParent.Equals(IntPtr.Zero) || ipItem.Equals(IntPtr.Zero))
            {
                goto XIT;
            }
            // Now process just like sub new(folder,pidl,parent) version
            m_Pidl = concatPidls(ipParent, ipItem);

            //Get some attributes
            SetUpAttributes(pParent, ipItem);

            //Set unfetched value for IconIndex....
            m_IconIndexNormal = - 1;
            m_IconIndexOpen = - 1;
            //finally, set up my Folder
            if (m_IsFolder)
            {
                int HR;
                HR = pParent.BindToObject(ipItem, IntPtr.Zero, ref ExpTreeLib.ShellDll.IID_IShellFolder, ref m_Folder);
                #if DEBUG
                if (HR != ExpTreeLib.ShellDll.NOERROR)
                {
                    Marshal.ThrowExceptionForHR(HR);
                }
                #endif
            }
            XIT: //On any kind of exit, free the allocated memory
            #if DEBUG
            if (m_Pidl.Equals(IntPtr.Zero))
            {
                Debug.WriteLine("CShItem.New(FoldBytes,ItemBytes) Failed");
            }
            else
            {
                Debug.WriteLine("CShItem.New(FoldBytes,ItemBytes) Created " + this.Path);
            }
            #endif

            if (! ipParent.Equals(IntPtr.Zero))
            {
                Marshal.FreeCoTaskMem(ipParent);
            }
            if (! ipItem.Equals(IntPtr.Zero))
            {
                Marshal.FreeCoTaskMem(ipItem);
            }
        }
Exemple #10
0
        private bool m_XtrInfo; //= False

        #endregion Fields

        #region Constructors

        /// <summary>Create instance based on a non-desktop CSIDL.
        /// Will create based on any CSIDL Except the DeskTop CSIDL</summary>
        /// <param name="ID">Value from CSIDL enumeration denoting the folder to create this CShItem of.</param>
        ///
        public CShItem(ExpTreeLib.ShellDll.CSIDL ID)
        {
            if (DesktopBase == null)
            {
                DesktopBase = new CShItem(); //This initializes the Desktop folder
            }
            int HR;
            if (ID == ExpTreeLib.ShellDll.CSIDL.MYDOCUMENTS)
            {
                int pchEaten = 0;
                int pdwAttributes = 0;
                HR = DesktopBase.m_Folder.ParseDisplayName(0, IntPtr.Zero, "::{450d8fba-ad25-11d0-98a8-0800361b1103}", ref pchEaten, ref m_Pidl, ref pdwAttributes);
            }
            else
            {
                HR = ExpTreeLib.ShellDll.SHGetSpecialFolderLocation(0, (int)ID, ref m_Pidl);
            }
            if (HR == ExpTreeLib.ShellDll.NOERROR)
            {
                ShellDll.IShellFolder pParent;
                IntPtr relPidl = IntPtr.Zero;

                pParent = GetParentOf(m_Pidl, ref relPidl);
                //Get the Attributes
                SetUpAttributes(pParent, relPidl);
                //Set unfetched value for IconIndex....
                m_IconIndexNormal = - 1;
                m_IconIndexOpen = - 1;
                //finally, set up my Folder
                if (m_IsFolder)
                {
                    HR = pParent.BindToObject(relPidl, IntPtr.Zero, ref ExpTreeLib.ShellDll.IID_IShellFolder, ref m_Folder);
                    if (HR != ExpTreeLib.ShellDll.NOERROR)
                    {
                        Marshal.ThrowExceptionForHR(HR);
                    }
                }
                Marshal.ReleaseComObject(pParent);
                //if PidlCount(m_Pidl) = 1 then relPidl is same as m_Pidl, don't release
                if (PidlCount(m_Pidl) > 1)
                {
                    Marshal.FreeCoTaskMem(relPidl);
                }
            }
            else
            {
                Marshal.ThrowExceptionForHR(HR);
            }
        }
Exemple #11
0
 public bool Equals(CShItem other)
 {
     bool returnValue;
     returnValue = this.Path.Equals(other.Path);
     return returnValue;
 }
Exemple #12
0
 ///<Summary>IsAncestorOf returns True if CShItem ancestor is an ancestor of CShItem current
 /// if OS is Win2K or above, uses the ILIsParent API, otherwise uses the
 /// cPidl function StartsWith.  This is necessary since ILIsParent in only available
 /// in Win2K or above systems AND StartsWith fails on some folders on XP systems (most
 /// obviously some Network Folder Shortcuts, but also Control Panel. Note, StartsWith
 /// always works on systems prior to XP.
 /// NOTE: if ancestor and current reference the same Item, both
 /// methods return True</Summary>
 public static bool IsAncestorOf(CShItem ancestor, CShItem current, bool fParent)
 {
     return IsAncestorOf(ancestor.PIDL, current.PIDL, fParent);
 }
Exemple #13
0
 /// <summary>
 /// If not initialized, then build DesktopBase
 /// once done, or if initialized already,
 /// </summary>
 ///<returns>The DesktopBase CShItem representing the desktop</returns>
 ///
 public static CShItem GetDeskTop()
 {
     if (DesktopBase == null)
     {
         DesktopBase = new CShItem();
     }
     return DesktopBase;
 }
Exemple #14
0
        public static CShItem GetCShItem(byte[] FoldBytes, byte[] ItemBytes)
        {
            CShItem returnValue;
            returnValue = null; //assume failure
            byte[] b = cPidl.JoinPidlBytes(FoldBytes, ItemBytes);
            if (b == null)
            {
                return returnValue; //can do no more with invalid pidls
            }
            //otherwise do like below, skipping unnecessary validation check
            IntPtr thisPidl = Marshal.AllocCoTaskMem(b.Length);
            if (thisPidl.Equals(IntPtr.Zero))
            {
                return null;
            }
            Marshal.Copy(b, 0, thisPidl, b.Length);
            returnValue = FindCShItem(thisPidl);
            Marshal.FreeCoTaskMem(thisPidl);
            if (returnValue == null) //didn't find it, make new
            {
                try
                {
                    returnValue = new CShItem(FoldBytes, ItemBytes);
                }
                catch
                {

                }
            }
            if (returnValue.PIDL.Equals(IntPtr.Zero))
            {
                returnValue = null;
            }
            return returnValue;
        }
Exemple #15
0
        public void RefreshTree(CShItem rootCSI)
        {
            //Modified to use ExpandANode(CShItem) rather than ExpandANode(path)
            //Set refresh variable for BeforeExpand method
            EnableEventPost = false;
            //Begin Calum's change -- With some modification
            TreeNode Selnode;
            if (this.tv1.SelectedNode == null)
            {
                Selnode = this.Root;
            }
            else
            {
                Selnode = this.tv1.SelectedNode;
            }
            //End Calum's change
            try
            {
                this.tv1.BeginUpdate();
                CShItem SelCSI = Selnode.Tag as CShItem;
                //Set root node
                if (rootCSI == null)
                {
                    this.RootItem = this.RootItem;
                }
                else
                {
                    this.RootItem = rootCSI;
                }
                //Try to expand the node
                if (! this.ExpandANode(SelCSI))
                {
                    ArrayList nodeList = new ArrayList();
                    while (Selnode.Parent != null)
                    {
                        nodeList.Add(Selnode.Parent);
                        Selnode = Selnode.Parent;
                    }

                    foreach (TreeNode tempLoopVar_Selnode in nodeList)
                    {
                        Selnode = tempLoopVar_Selnode;
                        if (this.ExpandANode((CShItem) Selnode.Tag))
                        {
                            goto endOfForLoop;
                        }
                    }
            endOfForLoop:
                    1.GetHashCode() ; //nop
                }
                //Reset refresh variable for BeforeExpand method
            }
            finally
            {
                this.tv1.EndUpdate();
            }
            EnableEventPost = true;
            //We suppressed EventPosting during refresh, so give it one now
            tv1_AfterSelect(this, new TreeViewEventArgs(tv1.SelectedNode));
        }
Exemple #16
0
        /// <summary>
        /// Private Constructor, creates new CShItem from the item's parent folder and
        ///  the item's PIDL relative to that folder.</summary>
        /// <param name="folder">the folder interface of the parent</param>
        /// <param name="pidl">the Relative PIDL of this item</param>
        /// <param name="parent">the CShitem of the parent</param>
        ///
        private CShItem(ExpTreeLib.ShellDll.IShellFolder folder, IntPtr pidl, CShItem parent)
        {
            if (DesktopBase == null)
            {
                DesktopBase = new CShItem(); //This initializes the Desktop folder
            }
            m_Parent = parent;
            m_Pidl = concatPidls(parent.PIDL, pidl);

            //Get some attributes
            SetUpAttributes(folder, pidl);

            //Set unfetched value for IconIndex....
            m_IconIndexNormal = - 1;
            m_IconIndexOpen = - 1;
            //finally, set up my Folder
            if (m_IsFolder)
            {
                int HR;
                HR = folder.BindToObject(pidl, IntPtr.Zero, ref ExpTreeLib.ShellDll.IID_IShellFolder, ref m_Folder);
                if (HR != ExpTreeLib.ShellDll.NOERROR)
                {
                    Marshal.ThrowExceptionForHR(HR);
                }
            }
        }
Exemple #17
0
 ///<Summary>Given a CShItem, find the TreeNode that belongs to the
 /// equivalent (matching PIDL) CShItem's most immediate surviving ancestor.
 ///  Note: referential comparison might not work since there is no guarantee
 /// that the exact same CShItem is stored in the tree.</Summary>
 ///<returns> Me.Root if not found, otherwise the Treenode whose .Tag is
 /// equivalent to the input CShItem's most immediate surviving ancestor </returns>
 private TreeNode FindAncestorNode(CShItem CSI)
 {
     TreeNode returnValue;
     returnValue = null;
     if (! CSI.IsFolder)
     {
         return returnValue; //only folders in tree
     }
     System.Windows.Forms.TreeNode baseNode = Root;
     //Dim cp As cPidl = CSI.clsPidl     'the cPidl rep of the PIDL to be found
     TreeNode testNode;
     int lim = ExpTreeLib.CShItem.PidlCount(CSI.PIDL) - ExpTreeLib.CShItem.PidlCount((baseNode.Tag as CShItem).PIDL);
     while (lim > 1)
     {
         foreach (TreeNode tempLoopVar_testNode in baseNode.Nodes)
         {
             testNode = tempLoopVar_testNode;
             if (CShItem.IsAncestorOf(testNode.Tag as CShItem, CSI, false))
             {
                 baseNode = testNode;
                 baseNode.Expand();
                 lim--;
                 goto NEXTLEV;
             }
         }
         //CSI's Ancestor may have moved or been deleted, return the last one
         // found (if none, will return Me.Root)
         return baseNode;
     NEXTLEV:
         1.GetHashCode() ; //nop
     }
     //on fall thru, we have it
     return baseNode;
 }
Exemple #18
0
        //only used when desktopfolder has not been intialized
        /// <summary>
        /// Private Constructor. Creates CShItem of the Desktop
        /// </summary>
        ///
        private CShItem()
        {
            if (DesktopBase != null)
            {
                throw (new Exception("Attempt to initialize CShItem for second time"));
            }

            int HR;
            //firstly determine what the local machine calls a "System Folder" and "My Computer"
            IntPtr tmpPidl = IntPtr.Zero;
            HR = ExpTreeLib.ShellDll.SHGetSpecialFolderLocation(0, (int)ExpTreeLib.ShellDll.CSIDL.DRIVES, ref tmpPidl);
            ExpTreeLib.ShellDll.SHFILEINFO shfi = new ExpTreeLib.ShellDll.SHFILEINFO();
            int dwflag = (int)(ExpTreeLib.ShellDll.SHGFI.DISPLAYNAME | ExpTreeLib.ShellDll.SHGFI.TYPENAME | ExpTreeLib.ShellDll.SHGFI.PIDL);
            int dwAttr = 0;
            ExpTreeLib.ShellDll.SHGetFileInfo(tmpPidl, dwAttr, ref shfi, ExpTreeLib.ShellDll.cbFileInfo, dwflag);
            m_strSystemFolder = shfi.szTypeName;
            m_strMyComputer = shfi.szDisplayName;
            Marshal.FreeCoTaskMem(tmpPidl);
            //set OS version info
            XPorAbove = ShellDll.IsXpOrAbove();
            Win2KOrAbove = ShellDll.Is2KOrAbove();

            //With That done, now set up Desktop CShItem
            m_Path = "::{" + ExpTreeLib.ShellDll.DesktopGUID.ToString() + "}";
            m_IsFolder = true;
            m_HasSubFolders = true;
            m_IsBrowsable = false;
            HR = ExpTreeLib.ShellDll.SHGetDesktopFolder(ref m_Folder);
            m_Pidl = ShellDll.GetSpecialFolderLocation(IntPtr.Zero, (int)ExpTreeLib.ShellDll.CSIDL.DESKTOP);
            dwflag = (int)(ExpTreeLib.ShellDll.SHGFI.DISPLAYNAME | ExpTreeLib.ShellDll.SHGFI.TYPENAME | ExpTreeLib.ShellDll.SHGFI.SYSICONINDEX | ExpTreeLib.ShellDll.SHGFI.PIDL);
            dwAttr = 0;
            IntPtr H = ExpTreeLib.ShellDll.SHGetFileInfo(m_Pidl, dwAttr, ref shfi, ExpTreeLib.ShellDll.cbFileInfo, dwflag);
            m_DisplayName = shfi.szDisplayName;
            m_TypeName = strSystemFolder; //not returned correctly by SHGetFileInfo
            m_IconIndexNormal = shfi.iIcon;
            m_IconIndexOpen = shfi.iIcon;
            m_HasDispType = true;
            m_IsDropTarget = true;
            m_IsReadOnly = false;
            m_IsReadOnlySetup = true;

            //also get local name for "My Documents"
            int pchEaten = 0;
            tmpPidl = IntPtr.Zero;
            int pdwAttributes = 0;
            HR = m_Folder.ParseDisplayName(0, IntPtr.Zero, "::{450d8fba-ad25-11d0-98a8-0800361b1103}", ref pchEaten, ref tmpPidl, ref pdwAttributes);
            shfi = new ExpTreeLib.ShellDll.SHFILEINFO();
            dwflag = (int)(ExpTreeLib.ShellDll.SHGFI.DISPLAYNAME | ExpTreeLib.ShellDll.SHGFI.TYPENAME | ExpTreeLib.ShellDll.SHGFI.PIDL);
            dwAttr = 0;
            ExpTreeLib.ShellDll.SHGetFileInfo(tmpPidl, dwAttr, ref shfi, ExpTreeLib.ShellDll.cbFileInfo, dwflag);
            m_strMyDocuments = shfi.szDisplayName;
            Marshal.FreeCoTaskMem(tmpPidl);
            //this must be done after getting "My Documents" string
            m_SortFlag = ComputeSortFlag();
            //Set DesktopBase
            DesktopBase = this;
            // Lastly, get the Path and CShItem of the DesktopDirectory -- useful for DragDrop
            m_DeskTopDirectory = new CShItem(ExpTreeLib.ShellDll.CSIDL.DESKTOPDIRECTORY);
        }
Exemple #19
0
        private void explorerLV_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.Label == null)
            {
                e.CancelEdit = true;
                return;
            }

            CShItem item = explorerLV.Items[e.Item].Tag as CShItem;
            try
            {
                if (item.IsFolder)
                    Directory.Move(item.Path, item.Parent.Path + "\\" + e.Label);
                else
                    System.IO.File.Move(item.Path, item.Parent.Path + "\\" + e.Label);

                CShItem newItem = new CShItem(item.Parent.Path + "\\" + e.Label);
                explorerLV.Items[e.Item].Tag = newItem;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                e.CancelEdit = true;
                return;
            }
        }
Exemple #20
0
 ///<Summary>
 /// AllFolderWalk recursively walks down directories from cStart, calling its
 ///   callback routine, WalkAllCallBack, for each Directory and File encountered, including those in
 ///   cStart.  UserLevel is incremented by 1 for each level of dirs that DirWalker
 ///  recurses thru.  Tag in an Integer that is simply passed, unmodified to the
 ///  callback, with each CShItem encountered, both File and Directory CShItems.
 /// </Summary>
 /// <param name="cStart"></param>
 /// <param name="cback"></param>
 /// <param name="UserLevel"></param>
 /// <param name="Tag"></param>
 ///
 public static bool AllFolderWalk(CShItem cStart, WalkAllCallBack cback, int UserLevel, int Tag)
 {
     if (cStart != null&& cStart.IsFolder)
     {
         CShItem cItem;
         //first processes all files in this directory
         foreach (CShItem tempLoopVar_cItem in cStart.GetFiles())
         {
             cItem = tempLoopVar_cItem;
             if (! cback(cItem, UserLevel, Tag))
             {
                 return false; //user said stop
             }
         }
         //then process all dirs in this directory, recursively
         foreach (CShItem tempLoopVar_cItem in cStart.GetDirectories(true))
         {
             cItem = tempLoopVar_cItem;
             if (! cback(cItem, UserLevel + 1, Tag))
             {
                 return false; //user said stop
             }
             else
             {
                 if (! AllFolderWalk(cItem, cback, UserLevel + 1, Tag))
                 {
                     return false;
                 }
             }
         }
         return true;
     }
     else //Invalid call
     {
         throw (new ApplicationException("AllFolderWalk -- Invalid Start Directory"));
     }
 }
Exemple #21
0
        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDataObject data = Clipboard.GetDataObject();
            if (!data.GetDataPresent(DataFormats.FileDrop))
                return;

            string[] files = (string[])data.GetData(DataFormats.FileDrop);
            MemoryStream stream = (MemoryStream)data.GetData("Preferred DropEffect", true);
            int flag = stream.ReadByte();
            if (flag != 2 && flag != 5)
                return;
            bool cut = (flag == 2);
            foreach (string file in files)
            {
                string dest = this.SelectedPath + "\\" + Path.GetFileName(file);
                try
                {
                    if (cut)
                        System.IO.File.Move(file, dest);
                    else
                        System.IO.File.Copy(file, dest, false);

                    ListViewItem lvi = new ListViewItem(Path.GetFileName(dest));
                    CShItem item = new CShItem(dest);
                    lvi.Tag = item;
                    lvi.ImageIndex = SystemImageListManager.GetIconIndex(item, false, false);
                    explorerLV.Items.Add(lvi);
                }
                catch (IOException ex)
                {
                    MessageBox.Show(this, "Failed to perform the specified operation:\n\n" + ex.Message, "File operation failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }
Exemple #22
0
 public static CShItem GetCShItem(string path)
 {
     CShItem returnValue;
     returnValue = null; //assume failure
     int HR;
     IntPtr tmpPidl = IntPtr.Zero;
     int pchEaten = 0;
     int pdwAttributes = 0;
     HR = GetDeskTop().Folder.ParseDisplayName(0, IntPtr.Zero, path, ref pchEaten, ref tmpPidl, ref pdwAttributes);
     if (HR == 0)
     {
         returnValue = FindCShItem(tmpPidl);
         if (returnValue == null)
         {
             try
             {
                 returnValue = new CShItem(path);
             }
             catch
             {
                 returnValue = null;
             }
         }
     }
     if (! tmpPidl.Equals(IntPtr.Zero))
     {
         Marshal.FreeCoTaskMem(tmpPidl);
     }
     return returnValue;
 }