예제 #1
0
        /// <summary>
        /// Gets the metro targets.
        /// </summary>
        /// <returns></returns>
        private IEnumerable<Target> GetMetroTargets()
        {
            if (this._includeMetro && this.HasMetroSupport)
            {
                return MetroManager.GetApplications()
                    .Select(
                        app =>
                            {
                                var target = new Target()
                                {
                                    Name = app.Name,
                                    Description = app.Description,
                                    Path = app.AppUserModelId,
                                    Icon = app.Icon,
                                    Platform = TargetType.Metro,
                                };

                                target.AddAlias(target.Name);

                                var abbreviation = target.Name.GetAbbreviation();
                                if (abbreviation.Length > 1)
                                {
                                    target.AddAlias(abbreviation);
                                }

                                return target;
                            });
            }

            return new List<Target>();
        }
예제 #2
0
        /// <summary>
        /// Gets the URL target.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns></returns>
        private static Target GetUrlTarget(FileInfo file)
        {
            using (var streamReader = new StreamReader(file.FullName))
            {
                var url = string.Empty;
                var iconPath = file.FullName;
                int? iconIndex = null;

                bool foundHeader = false;

                string line = null;
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (!foundHeader)
                    {
                        foundHeader = (line == "[InternetShortcut]");
                    }
                    else
                    {
                        if (line.StartsWith("["))
                        {
                            break;
                        }

                        var firstEquals = line.IndexOf('=');
                        if (firstEquals >= 0)
                        {
                            var key = line.Substring(0, firstEquals);
                            var value = line.Substring(firstEquals + 1);

                            switch (key)
                            {
                                case "URL":
                                    url = value;
                                    break;
                                case "IconIndex":
                                    int parsedIconIndex = 0;
                                    if (int.TryParse(value, out parsedIconIndex))
                                    {
                                        iconIndex = parsedIconIndex;
                                    }
                                    break;
                                case "IconFile":
                                    iconPath = value;
                                    break;
                            }
                        }
                    }
                }

                var icon = IconExtractor.GetIcon(iconPath, iconIndex);

                var target = new Target()
                {
                    Name = file.Name.Replace(file.Extension, string.Empty),
                    Description = url,
                    Path = url,
                    Icon = icon,
                    Platform = TargetType.File
                };

                return target;
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the desktop targets.
        /// </summary>
        /// <param name="directories">The directories.</param>
        /// <returns></returns>
        private IEnumerable<Target> GetDesktopTargets()
        {
            var targets = new List<Target>();

            foreach (var directory in this._directories)
            {
                if (Directory.Exists(directory))
                {
                    // Find all links that point to an executable, and add them to the list of targets.
                    foreach (var file in new DirectoryInfo(directory).GetFiles("*.*", SearchOption.AllDirectories))
                    {
                        var target = default(Target);

                        switch (file.Extension.ToUpperInvariant())
                        {
                            case ".LNK":
                                target = GetLnkTarget(file);
                                break;
                            case ".URL":
                                target = GetUrlTarget(file);
                                break;
                            default:
                                {
                                    target = new Target()
                                    {
                                        Name = file.Name.Replace(file.Extension, string.Empty),
                                        Description = GetFileDescription(file.FullName),
                                        Path = file.FullName,
                                        Icon = IconExtractor.GetIcon(file.FullName),
                                        Platform = GetFilePlatformType(file.FullName)
                                    };
                                }
                                break;
                        }

                        if (target != null)
                        {
                            // Add generic alias information
                            target.AddAlias(target.Name);

                            // Add abbreviated alias information. E.g.: "Visual Studio 2012" becomes "VS2"
                            var abbr = target.Name.GetAbbreviation(true);
                            if (abbr.Length > 1)
                            {
                                target.AddAlias(abbr);
                            }

                            // Add abbreviated alias information, with whole numbers. E.g.: "Visual Studio 2012" becomes "VS2012"
                            var abbrWholeNumbers = target.Name.GetAbbreviation(false);
                            if (abbrWholeNumbers.Length > 1)
                            {
                                target.AddAlias(abbrWholeNumbers);
                            }

                            target.AddAlias(GetPathAliasText(target.Path));

                            // Add this new target to our collection
                            targets.Add(target);
                        }
                    }
                }
            }

            return targets;
        }
예제 #4
0
        /// <summary>
        /// Gets the LNK target.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns></returns>
        private static Target GetLnkTarget(FileInfo file)
        {
            var lnkInfo = new LnkInfo(file.FullName);

            var target = new Target()
                {
                    Name = lnkInfo.Name,
                    Description = GetFileDescription(lnkInfo.TargetPath),
                    Path = file.FullName,
                    Icon = lnkInfo.Icon,
                    Platform = GetFilePlatformType(lnkInfo.TargetPath)
                };

            target.AddAlias(GetPathAliasText(lnkInfo.TargetPath));

            return target;
        }