Exemplo n.º 1
0
        /// <summary>
        /// Return whether PIDL match fileMask ( * and ? supported)
        /// </summary>
        /// <param name="pidl"></param>
        /// <param name="fileMask"></param>
        /// <returns></returns>
        public static bool MatchFileMask(PIDL pidl, string fileMask)
        {
            string path = FileSystemInfoEx.PIDLToPath(pidl);
            string name = PathEx.GetFileName(path);

            return(MatchFileMask(name, fileMask));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copy directory or file, take full path of source and dest as parameter.
        /// </summary>
        public static void Copy(string source, string dest)
        {
            DirectoryInfoEx fromDir, toDir;

            fromDir = new DirectoryInfoEx(PathEx.GetDirectoryName(source));
            toDir   = new DirectoryInfoEx(PathEx.GetDirectoryName(dest));


            if (fromDir.Storage == null)
            {
                throw new IOException("Source directory does not support IStorage");
            }
            if (toDir.Storage == null)
            {
                throw new IOException("Destination directory does not support IStorage");
            }


            int hr = fromDir.Storage.MoveElementTo(PathEx.GetFileName(source), toDir.Storage,
                                                   Path.GetFileName(dest), ShellAPI.STGMOVE.COPY);

            if (hr != ShellAPI.S_OK)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get relative path of a entry based on baseDirectory.
 /// e.g. C:\Temp\AbC\1.txt (entry), C:\Temp\ (baseDirectory) will return ABC\1.txt
 /// </summary>
 /// <param name="entry"></param>
 /// <param name="baseDirectory"></param>
 /// <returns></returns>
 public static string GetRelativePath(string name, DirectoryInfoEx baseDirectory)
 {
     if (name.IndexOf(baseDirectory.FullName, StringComparison.InvariantCultureIgnoreCase) == -1)
     {
         if (Debugger.IsAttached)
         {
             Debugger.Break();
         }
         return(PathEx.GetFileName(name));
     }
     else
     {
         return(name.Substring(baseDirectory.FullName.Length + 1));
     }
 }
Exemplo n.º 4
0
        protected virtual void refresh(IShellFolder2 parentShellFolder, PIDL relPIDL, PIDL fullPIDL, RefreshModeEnum mode)
        {
            if (parentShellFolder != null && fullPIDL != null && relPIDL != null)
            {
                Attributes = loadAttributes(parentShellFolder, fullPIDL, relPIDL);
                string parseName = loadName(parentShellFolder, relPIDL, ShellAPI.SHGNO.FORPARSING);
                FullName = "";

                //Console.WriteLine("relPIDL.size = {0}", relPIDL.Size);
                //Console.WriteLine("PIDL.size = {0}", _pidl.Size);


                if (relPIDL.Size == 0)
                {
                    FullName = IOTools.IID_Desktop;
                }
                else
                //0.12: Fixed Fullname of User/Shared directory under desktop is now it's GUID instead of it's file path.
                //0.13: Fixed All subdirectory under User/Shared directory uses GUID now.
                {
                    if (DirectoryInfoEx.CurrentUserDirectory != null)
                    {
                        if (parseName == DirectoryInfoEx.CurrentUserDirectory.FullName &&
                            loadName(parentShellFolder, ShellAPI.SHGNO.FORPARSING) == Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
                        {
                            FullName = IOTools.IID_UserFiles;
                        }
                        //else if (
                        //    (parseName.StartsWith(DirectoryInfoEx.CurrentUserDirectory.FullName) &&
                        //    _parent != null && _parent.FullName.StartsWith(IOTools.IID_UserFiles))
                        //    ||
                        //    (OriginalPath != null && OriginalPath.StartsWith(IOTools.IID_UserFiles))
                        //    )
                        //{
                        //    FullName = parseName.Replace(DirectoryInfoEx.CurrentUserDirectory.FullName, IOTools.IID_UserFiles);
                        //}
                    }

                    if (DirectoryInfoEx.SharedDirectory != null)
                    {
                        if (parseName == DirectoryInfoEx.SharedDirectory.FullName &&
                            loadName(parentShellFolder, ShellAPI.SHGNO.FORPARSING) == Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
                        {
                            FullName = IOTools.IID_Public;
                        }
                        //else if (
                        //    (parseName.StartsWith(DirectoryInfoEx.SharedDirectory.FullName) &&
                        //    _parent != null && _parent.FullName.StartsWith(IOTools.IID_Public))
                        //    ||
                        //    (OriginalPath != null && OriginalPath.StartsWith(IOTools.IID_Public))
                        //    )
                        //    FullName = parseName.Replace(DirectoryInfoEx.SharedDirectory.FullName, IOTools.IID_Public);
                    }

                    //if (_parent != null && _parent.FullName.StartsWith(IOTools.IID_Library)
                    //    && !parseName.StartsWith(IOTools.IID_Library))
                    //    FullName = PathEx.Combine(_parent.FullName, PathEx.GetFileName(parseName));

                    if (FullName == "")
                    {
                        FullName = parseName;
                    }
                }
                //if (DirectoryInfoEx.CurrentUserDirectory != null && parseName == DirectoryInfoEx.CurrentUserDirectory.FullName &&
                //loadName(parentShellFolder, ShellAPI.SHGNO.FORPARSING) == Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
                //    FullName = IOTools.IID_UserFiles;
                //else

                //if (DirectoryInfoEx.SharedDirectory != null && parseName == DirectoryInfoEx.SharedDirectory.FullName &&
                //    loadName(parentShellFolder, ShellAPI.SHGNO.FORPARSING) == Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
                //    FullName = IOTools.IID_Public;
                //else


                if (OriginalPath == null)
                {
                    OriginalPath = FullName;
                }
                if (parseName.StartsWith("::")) //Guid
                {
                    parseName = loadName(parentShellFolder, relPIDL, ShellAPI.SHGNO.NORMAL);
                }

                _name = FullName.EndsWith("\\") ? FullName : PathEx.GetFileName(FullName);
                Label = loadName(parentShellFolder, relPIDL, ShellAPI.SHGNO.NORMAL);
            }
            else
            {
                if (OriginalPath != null)
                {
                    string origPath = Helper.RemoveSlash(OriginalPath);
                    _name    = Path.GetFileName(origPath);
                    Label    = _name;
                    FullName = origPath;
                }
            }
        }