Beispiel #1
0
        /// <summary>Creates a new lnk/url shortcut (Shell32). Further editing with 'LinkSetProperty'.</summary>
        /// <param name="shortcut">The full path for the new lnk/url shortcut file.</param>
        /// <param name="target">The full path of the target file/-folder resp. URL address.</param>
        /// <returns>The full file path of the created shortcut on success, else "FAILED".</returns>
        public static Primitive LinkCreate(Primitive shortcut, Primitive target)
        {
            if (String.IsNullOrEmpty(target))
            {
                return("FAILED");
            }
            string scPath = Environment.ExpandEnvironmentVariables(shortcut);
            string scDir  = Path.GetDirectoryName(scPath);

            if (!Directory.Exists(scDir))
            {
                return("FAILED");
            }
            string scFNameExt = Path.GetFileName(scPath);

            try
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(scPath, false);
                sw.Close();

                Shell32.Folder          fold     = GetShell32NameSpace(scDir);
                Shell32.FolderItem      foldItem = fold.ParseName(scFNameExt);
                Shell32.ShellLinkObject link     = (Shell32.ShellLinkObject)foldItem.GetLink;

                link.Path = target;
                link.Save(scPath);
                return(scPath);
            }
            catch
            { return("FAILED"); }
        }
Beispiel #2
0
        /// <summary>Gets all available Verbs (contextmenu items) for a given filetype or folder as Array.
        /// Applying of a Verb on file/folder under see 'ApplyVerbOn'.</summary>
        /// <param name="path">The full file- or folder path.</param>
        /// <returns>All available Verbs as Array ("idx=verb;...", w/o '&amp;') on success, else "FAILED".</returns>
        public static Primitive GetAllVerbsFor(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    fDir     = Path.GetDirectoryName(fo);
            string    fNameExt = Path.GetFileName(fo);
            Primitive result   = new Primitive();

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

                for (int i = 0; i < verbs.Count; i++)
                {
                    Shell32.FolderItemVerb vrb = verbs.Item(i);
                    string verbName            = vrb.Name.Replace(@"&", string.Empty);
                    if (verbName.Length > 0)
                    {
                        result[result.GetItemCount() + 1] = verbName;
                    }
                }
                return(result);
            }
            catch
            { return("FAILED"); }
        }
Beispiel #3
0
        /// <summary>Modifies properties of an existing lnk/url shortcut link, like target path, arguments etc. (* for Urls).</summary>
        /// <param name="shortcut">The full path of an existing lnk/url shortcut link file.</param>
        /// <param name="target">* The full path of the target file/-folder resp. URL address.</param>
        /// <param name="args">Startparameter when launching the shortcut or "" (for url).</param>
        /// <param name="folder">The full path of the start folder or "" (for url).</param>
        /// <param name="desc">* Comment or description for the shortcut or "".</param>
        /// <param name="icoPath">* Full path of the icon file for the shortcut or "".</param>
        /// <param name="icoIdx">* Index of the icon in the icon file (default: 0, for .ico).</param>
        /// <param name="hotkey">* keys combination to launch the shortcut link (default: 0).</param>
        /// <param name="style">* Window style when launching the shortcut (default: 1 normal, 3 max, 7 min).</param>
        /// <returns>The full file path of the modified shortcut on success, else "FAILED".</returns>
        public static Primitive LinkSetProperty(Primitive shortcut, Primitive target, Primitive args, Primitive folder, Primitive desc, Primitive icoPath, Primitive icoIdx, Primitive hotkey, Primitive style)
        {
            string scPath = Environment.ExpandEnvironmentVariables(shortcut);

            if (!System.IO.File.Exists(scPath))
            {
                return("FAILED");
            }
            else
            {
                string scDir      = Path.GetDirectoryName(scPath);
                string scFNameExt = Path.GetFileName(scPath);

                Shell32.Folder     fold     = GetShell32NameSpace(scDir);
                Shell32.FolderItem foldItem = fold.ParseName(scFNameExt);
                try
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)foldItem.GetLink;
                    link.Path             = target;
                    link.Arguments        = args;
                    link.WorkingDirectory = folder;
                    link.Description      = desc;
                    link.Hotkey           = hotkey;
                    link.ShowCommand      = style;
                    link.SetIconLocation(icoPath, icoIdx);
                    link.Save(scPath);
                    return(scPath);
                }
                catch
                { return("FAILED"); }
            }
        }
Beispiel #4
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); }
        }
Beispiel #5
0
        /// <summary>Gets properties of a lnk/url shortcut link, like target pfad, arguments etc.</summary>
        /// <param name="shortcut">The full path of the lnk/url shortcut link file.</param>
        /// <param name="property">The property to get (case independent, * for Urls) like:
        /// "Target"  target path *
        /// "Args"    arguments
        /// "Folder"  working directory
        /// "Desc"    comment *
        /// "HotKey"  shortcut key comb * (default: 0)
        /// "Style"   window style * (1 normal, 3 max, 7 min)
        /// "Icon"    icon path</param>
        /// <returns>The value of the property if available or "". "FAILED" on failure.</returns>
        public static Primitive LinkGetProperty(Primitive shortcut, Primitive property)
        {
            string scPath = Environment.ExpandEnvironmentVariables(shortcut);

            if (!System.IO.File.Exists(scPath))
            {
                return("FAILED");
            }
            string prop = property;
            string nIcon;
            int    icoIdx     = 0;
            string scDir      = Path.GetDirectoryName(scPath);
            string scFNameExt = Path.GetFileName(scPath);

            try
            {
                Shell32.Folder          fold     = GetShell32NameSpace(scDir);
                Shell32.FolderItem      foldItem = fold.ParseName(scFNameExt);
                Shell32.ShellLinkObject link     = (Shell32.ShellLinkObject)foldItem.GetLink;
                switch (prop.ToUpper())
                {
                case "TARGET": return(link.Path);

                case "ARGS": return(link.Arguments);

                case "FOLDER": return(link.WorkingDirectory);

                case "DESC": return(link.Description);

                case "HOTKEY": return(link.Hotkey);

                case "STYLE": return(link.ShowCommand);

                case "ICON":
                {
                    icoIdx = link.GetIconLocation(out nIcon);
                    return(nIcon + "," + icoIdx.ToString());
                }

                default: return("FAILED");
                }
            }
            catch
            { return("FAILED"); }
        }
Beispiel #6
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"); }
        }
Beispiel #7
0
        /// <summary>Apply the given Verb (contextmenu item) for the given file or folder.
        /// List of available Verbs (for a filetype or folder) under 'GetAllVerbsFor'.</summary>
        /// <param name="path">The full file- or folder path.</param>
        /// <param name="verb">The Verb to apply (case- and '&amp;' insensitive).</param>
        /// <returns>"SUCCESS" on success, else "FAILED".</returns>
        public static Primitive ApplyVerbOn(Primitive path, Primitive verb)
        {
            string vUse = verb;

            if (vUse.Length == 0)
            {
                return("FAILED");
            }
            vUse = vUse.Replace(@"&", string.Empty).ToLower();
            string fo = Environment.ExpandEnvironmentVariables(path);

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

            string fDir     = Path.GetDirectoryName(fo);
            string fNameExt = Path.GetFileName(fo);

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

                for (int i = 0; i < verbs.Count; i++)
                {
                    Shell32.FolderItemVerb vrb = verbs.Item(i);
                    string verbName            = vrb.Name.Replace(@"&", string.Empty).ToLower();
                    if (verbName.Equals(vUse))
                    {
                        vrb.DoIt();
                        return("SUCCESS");
                    }
                }
                return("FAILED");
            }
            catch { return("FAILED"); }
        }
Beispiel #8
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"); }
        }