Exemplo n.º 1
0
        /// <summary>Gets all items in a special system/shell folder (upper level only).</summary>
        /// <param name="csidl">The CSIDL number of the system folder (0 to 47, constants and names of available folders under s. SpecialFolderConstants).</param>
        /// <returns>The names of all objects in the system folder as Array (only upper level) on success, else "FAILED".</returns>
        /// <example>http://msdn.microsoft.com/library/bb774096.aspx
        /// eg. CSIDL for:
        ///  3 Control panel
        ///  5 my documents
        ///  8 Recent
        ///  9 SendTo
        /// 10 RecBin
        /// 16 Desktop folder
        /// 17 Computer
        /// 20 Fonts
        /// 32 Temp Inet Files</example>
        public static Primitive SpecialFolderList(Primitive csidl)
        {
            int nFold = csidl;

            if (nFold < 0 || nFold > 47)
            {
                return("FAILED");
            }
            string    itemName;
            Primitive content = new Primitive();

            try
            {
                Shell32.Folder      fold      = GetShell32NameSpace(nFold);
                Shell32.FolderItems foldItems = fold.Items();

                foreach (Shell32.FolderItem item in foldItems)
                {
                    itemName = item.Name;       //Path;
                    if (Path.GetExtension(itemName) == "")
                    {
                        itemName += Path.GetExtension(item.Path);
                    }
                    // //Necessary for systems with hidden file extensions.
                    content[content.GetItemCount() + 1] = itemName;
                }
                return(content);
            }
            catch
            { return("FAILED"); }
        }
Exemplo n.º 2
0
        /// <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); }
        }
Exemplo n.º 3
0
        /// <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"); }
        }
Exemplo n.º 4
0
        /// <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"); }
        }