Beispiel #1
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="copyThis"></param>
        public DirectoryBrowser(DirectoryBrowser copyThis)
        {
            if (copyThis == null)
            {
                return;
            }

            _ItemTypeIsInitialized = copyThis._ItemTypeIsInitialized;
            _ItemType = copyThis._ItemType;

            _KnownFolderIsInitialized = copyThis._KnownFolderIsInitialized;
            _KnownFolder = copyThis._KnownFolder;

            _IconResourceIdInitialized = copyThis._IconResourceIdInitialized;
            _IconResourceId            = copyThis._IconResourceId;

            Name      = copyThis.Name;
            ParseName = copyThis.ParseName;
            Label     = copyThis.Label;
            PathRAW   = copyThis.PathRAW;
            PathShell = copyThis.PathShell;

            _PIDLs_Initialized = copyThis._PIDLs_Initialized;
            _ChildIdList       = copyThis._ChildIdList;
            _ParentIdList      = copyThis._ParentIdList;

            SpecialPathId      = copyThis.SpecialPathId;
            IsSpecialParseItem = copyThis.IsSpecialParseItem;

            PathFileSystem = copyThis.PathFileSystem;

            FullName = copyThis.FullName;
        }
Beispiel #2
0
        /// <summary>
        /// Resolves remaining properties if <see cref="IsFullyInitialized"/> indicates
        /// missing values (useful for lazy initialization).
        /// </summary>
        public void LoadProperties()
        {
            lock (resolvePropsLock)
            {
                if (_KnownFolderIsInitialized == false)
                {
                    _KnownFolderIsInitialized = true;
                    _KnownFolder = LoadKnownFolder();
                }

                if (_ItemTypeIsInitialized == false)
                {
                    _ItemTypeIsInitialized = true;
                    _ItemType = LoadItemType();
                }

                if (_IconResourceIdInitialized == false)
                {
                    _IconResourceIdInitialized = true;
                    _IconResourceId            = LoadIconResourceId();
                }
            }
        }
Beispiel #3
0
        private DirectoryItemFlags LoadItemType()
        {
            DirectoryItemFlags itemType = DirectoryItemFlags.Unknown;

            if (string.IsNullOrEmpty(PathFileSystem) == false)
            {
                var pathIsTypeOf = Browser.IsTypeOf(PathFileSystem);

                if (pathIsTypeOf == Enums.PathType.FileSystemPath)
                {
                    // TODO XXX Always evaluate on NormPath???
                    try
                    {
                        bool pathExists = false;
                        try
                        {
                            pathExists = System.IO.File.Exists(PathFileSystem);
                        }
                        catch
                        {
                            // Catch tis just in case it happens...
                        }

                        if (pathExists)
                        {
                            itemType |= DirectoryItemFlags.FileSystemFile;

                            if (PathFileSystem.EndsWith(".zip"))
                            {
                                itemType |= DirectoryItemFlags.DataFileContainer;
                            }
                        }
                    }
                    catch
                    {
                        // Catch tis just in case it happens...
                    }

                    // See if this is a directory if it was not a file...
                    if ((itemType & DirectoryItemFlags.FileSystemFile) == 0)
                    {
                        // Does this directory exist in file system ?
                        try
                        {
                            bool pathExists = false;
                            try
                            {
                                pathExists = System.IO.Directory.Exists(PathFileSystem);
                            }
                            catch
                            {
                                // Catch this in case string contains blah blah blah :-)
                            }

                            if (pathExists == true)
                            {
                                itemType |= DirectoryItemFlags.FileSystemDirectory;

                                // This could be a reference to a drive
                                DirectoryInfo d = new DirectoryInfo(PathFileSystem);
                                if (d.Parent == null)
                                {
                                    itemType |= DirectoryItemFlags.Drive;
                                }
                            }
                            else
                            {
                                // Neither a regular directory nor a regular file
                                // -> Most likely a folder inside a zip file data container
                                if (PathFileSystem.Contains(".zip"))
                                {
                                    itemType |= DirectoryItemFlags.DataFileContainerFolder;
                                }

                                // -> Lets get its name for display if its more than empty
                                // string displayName = System.IO.Path.GetFileName(PathFileSystem);
                            }
                        }
                        catch (Exception exp)
                        {
                            // Catch and output this in debug in case we've missed a trivial check
                            Debug.WriteLine(exp.Message);
                        }
                    }
                }
            }

            if (KnownFolder != null)
            {
                if (KnownFolder.Category == FolderCategory.Virtual)
                {
                    itemType |= DirectoryItemFlags.Virtual;
                }
            }

            if (IsSpecialParseItem)
            {
                itemType |= DirectoryItemFlags.Special;

                // Check for very common known special directory reference
                if (KF_IID.ID_FOLDERID_Desktop.Equals(SpecialPathId, StringComparison.InvariantCultureIgnoreCase))
                {
                    itemType |= DirectoryItemFlags.Desktop;
                }
                else
                if (KF_IID.ID_FOLDERID_Documents.Equals(SpecialPathId, StringComparison.InvariantCultureIgnoreCase))
                {
                    itemType |= DirectoryItemFlags.Documents;
                }
                else
                if (KF_IID.ID_FOLDERID_Downloads.Equals(SpecialPathId, StringComparison.InvariantCultureIgnoreCase))
                {
                    itemType |= DirectoryItemFlags.Downloads;
                }
                else
                if (KF_IID.ID_FOLDERID_Music.Equals(SpecialPathId, StringComparison.InvariantCultureIgnoreCase))
                {
                    itemType |= DirectoryItemFlags.Music;
                }
                else
                if (KF_IID.ID_FOLDERID_Pictures.Equals(SpecialPathId, StringComparison.InvariantCultureIgnoreCase))
                {
                    itemType |= DirectoryItemFlags.Pictures;
                }
                else
                if (KF_IID.ID_FOLDERID_Videos.Equals(SpecialPathId, StringComparison.InvariantCultureIgnoreCase))
                {
                    itemType |= DirectoryItemFlags.Videos;
                }
            }


            return(itemType);
        }