示例#1
0
文件: Shell.cs 项目: levi1994/LitDev
        /// <summary>Gets the value of an extended property for a given file or folder.</summary>
        /// <param name="path">The full file- or folder path.</param>
        /// <param name="infoType">The ID number or name of the property (eg. -1="Infotip"/"", 0="Name", 1="Size", etc.)
        /// ID numbers and names of available properties under s. 'AllDetails'.</param>
        /// <returns>The value of the property if available, else "". "FAILED" on failure (eg. missing path).
        /// Infotip lines separated by lf and ending with crlf.</returns>
        public static Primitive GetDetail(Primitive path, Primitive infoType)
        {
            string fo = Environment.ExpandEnvironmentVariables(path);

            if (!System.IO.File.Exists(fo) && !Directory.Exists(fo))
            {
                return("FAILED");
            }
            char[] charsTrim = { ' ', '\'' };
            fo = fo.Trim(charsTrim);

            string strTyp = infoType;

            if (String.IsNullOrEmpty(strTyp))
            {
                strTyp = "Infotip";
            }
            int    itNo      = -1;
            string strDetail = "";
            string fDir      = Path.GetDirectoryName(fo);
            string fNameExt  = Path.GetFileName(fo);
            string header;

            try
            {
                Shell32.Folder     fold     = GetShell32NameSpace(fDir);
                Shell32.FolderItem foldItem = fold.ParseName(fNameExt);

                if (IsNumber(strTyp))
                {
                    itNo = Convert.ToInt32(strTyp);
                }
                else
                {
                    for (int i = 0; i <= 316; i++)      // 286	(Win7)
                    {
                        header = fold.GetDetailsOf(fold.Items(), i).ToString();
                        if (String.Compare(strTyp, header, true) == 0)
                        {
                            itNo = i;
                            break;
                        }
                    }
                }

                strDetail = fold.GetDetailsOf(foldItem, itNo).ToString();
                strDetail = Regex.Replace(strDetail, @"[\u200E\u200F\u202A\u202C]", string.Empty, RegexOptions.CultureInvariant);
                strDetail = Regex.Replace(strDetail, strItag, string.Empty, RegexOptions.CultureInvariant);
                strDetail = Regex.Replace(strDetail, strAShellSep, string.Empty, RegexOptions.CultureInvariant);
                strDetail = Regex.Replace(strDetail, strAShell, string.Empty, RegexOptions.CultureInvariant);
                return(strDetail);
            }
            catch
            { return(strDetail); }
        }
示例#2
0
文件: Shell.cs 项目: levi1994/LitDev
        /// <summary>Gets the names of all available extended properties for a given file or folder as Array (up to max. 316, w/o -1=Infotip).</summary>
        /// <param name="path">The full file- or folder path.</param>
        /// <param name="step1">Indizes in speps by 1?  "True" or "False" (default, real property ID).</param>
        /// <returns>The names of all available extended properties as Array ("idx=property name;...", w/o Infotip) on success, else "FAILED".</returns>
        public static Primitive GetAllDetailNamesFor(Primitive path, Primitive step1)
        {
            string fo = Environment.ExpandEnvironmentVariables(path);

            if (!System.IO.File.Exists(fo) && !Directory.Exists(fo))
            {
                return("FAILED");
            }
            char[] charsTrim = { ' ', '\'' };
            fo = fo.Trim(charsTrim);

            string    prop;
            string    header;
            Primitive details  = new Primitive();
            string    fDir     = Path.GetDirectoryName(fo);
            string    fNameExt = Path.GetFileName(fo);

            try
            {
                Shell32.Folder     fold     = GetShell32NameSpace(fDir);
                Shell32.FolderItem foldItem = fold.ParseName(fNameExt);

                for (int i = 0; i <= 316; i++)  // 286	(Win7)
                {
                    prop = fold.GetDetailsOf(foldItem, i).ToString();
                    if (!String.IsNullOrEmpty(prop))
                    {
                        header = fold.GetDetailsOf(fold.Items(), i).ToString();
                        if (step1)
                        {
                            details[details.GetItemCount() + 1] = header;
                        }
                        else
                        {
                            details[i] = header;
                        }
                    }
                }
                return(details);
            }
            catch
            { return("FAILED"); }
        }
示例#3
0
文件: Shell.cs 项目: levi1994/LitDev
        /// <summary>Gets all available extended properties for the given file or folder as Array (up to max. 316, without -1=Infotip).</summary>
        /// <param name="path">The full file- or folder path.</param>
        /// <returns>All available extended properties as Array ("property name=value;...", without Infotip) on success, else "FAILED".</returns>
        public static Primitive GetAllDetailsFor(Primitive path)
        {
            string fo = Environment.ExpandEnvironmentVariables(path);

            if (!System.IO.File.Exists(fo) && !Directory.Exists(fo))
            {
                return("FAILED");
            }
            char[] charsTrim = { ' ', '\'' };
            fo = fo.Trim(charsTrim);

            string    prop;
            string    header;
            Primitive details  = new Primitive();
            string    fDir     = Path.GetDirectoryName(fo);
            string    fNameExt = Path.GetFileName(fo);

            try
            {
                Shell32.Folder     fold     = GetShell32NameSpace(fDir);
                Shell32.FolderItem foldItem = fold.ParseName(fNameExt);

                for (int i = 0; i <= 316; i++)  // 286	(Win7)
                {
                    prop = fold.GetDetailsOf(foldItem, i).ToString();
                    if (!String.IsNullOrEmpty(prop))
                    {
                        header          = fold.GetDetailsOf(fold.Items(), i).ToString();
                        prop            = Regex.Replace(prop, @"[\u200E\u200F\u202A\u202C]", string.Empty, RegexOptions.CultureInvariant);
                        details[header] = prop;
                    }
                }
                return(details);
            }
            catch
            { return("FAILED"); }
        }