Beispiel #1
0
        public static async Task <List <Program> > GetExecutablesFromFolder(string path, SearchOption searchOption, CancellationTokenSource cancelToken = null)
        {
            return(await Task.Run(() =>
            {
                var execs = new List <Program>();
                var files = new SafeFileEnumerator(path, "*.exe", SearchOption.AllDirectories);

                foreach (var file in files)
                {
                    if (cancelToken?.IsCancellationRequested == true)
                    {
                        return null;
                    }

                    var versionInfo = FileVersionInfo.GetVersionInfo(file.FullName);
                    var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(Path.GetDirectoryName(file.FullName)).Name;

                    execs.Add(new Program()
                    {
                        Path = file.FullName,
                        Icon = file.FullName,
                        WorkDir = Path.GetDirectoryName(file.FullName),
                        Name = programName
                    });
                }

                return execs;
            }));
        }
Beispiel #2
0
        public static List <Program> GetExecutablesFromFolder(string path, SearchOption searchOption)
        {
            var execs = new List <Program>();
            var files = new SafeFileEnumerator(path, "*.exe", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                execs.Add(new Program()
                {
                    Path    = file.FullName,
                    Icon    = file.FullName,
                    WorkDir = Path.GetDirectoryName(file.FullName),
                    Name    = new DirectoryInfo(Path.GetDirectoryName(file.FullName)).Name
                });
            }

            return(execs);
        }
Beispiel #3
0
        public static List <Program> GetExecutablesFromFolder(string path, SearchOption searchOption)
        {
            var execs = new List <Program>();
            var files = new SafeFileEnumerator(path, "*.exe", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var versionInfo = FileVersionInfo.GetVersionInfo(file.FullName);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(Path.GetDirectoryName(file.FullName)).Name;

                execs.Add(new Program()
                {
                    Path    = file.FullName,
                    Icon    = file.FullName,
                    WorkDir = Path.GetDirectoryName(file.FullName),
                    Name    = programName
                });
            }

            return(execs);
        }
Beispiel #4
0
        public static async Task <List <Program> > GetShortcutProgramsFromFolder(string path, CancellationTokenSource cancelToken = null)
        {
            return(await Task.Run(() =>
            {
                var folderExceptions = new string[]
                {
                    @"\Accessibility\",
                    @"\Accessories\",
                    @"\Administrative Tools\",
                    @"\Maintenance\",
                    @"\StartUp\",
                    @"\Windows ",
                    @"\Microsoft ",
                };

                var nameExceptions = new string[]
                {
                    "uninstall",
                    "setup"
                };

                var pathExceptions = new string[]
                {
                    @"\system32\",
                    @"\windows\",
                };

                var shell = new WshShell();
                var apps = new List <Program>();
                var shortucts = new SafeFileEnumerator(path, "*.lnk", SearchOption.AllDirectories);

                foreach (var shortcut in shortucts)
                {
                    if (cancelToken?.IsCancellationRequested == true)
                    {
                        return null;
                    }

                    var fileName = shortcut.Name;
                    var Directory = Path.GetDirectoryName(shortcut.FullName);

                    if (folderExceptions.FirstOrDefault(a => shortcut.FullName.IndexOf(a, StringComparison.OrdinalIgnoreCase) >= 0) != null)
                    {
                        continue;
                    }

                    if (nameExceptions.FirstOrDefault(a => shortcut.FullName.IndexOf(a, StringComparison.OrdinalIgnoreCase) >= 0) != null)
                    {
                        continue;
                    }

                    var link = (IWshShortcut)shell.CreateShortcut(shortcut.FullName);
                    var target = link.TargetPath;

                    if (pathExceptions.FirstOrDefault(a => target.IndexOf(a, StringComparison.OrdinalIgnoreCase) >= 0) != null)
                    {
                        continue;
                    }

                    // Ignore duplicates
                    if (apps.FirstOrDefault(a => a.Path == target) != null)
                    {
                        continue;
                    }

                    // Ignore non-application links
                    if (Path.GetExtension(target) != ".exe")
                    {
                        continue;
                    }

                    var app = new Program()
                    {
                        Path = target,
                        Icon = link.IconLocation,
                        Name = Path.GetFileNameWithoutExtension(shortcut.Name),
                        WorkDir = link.WorkingDirectory
                    };

                    apps.Add(app);
                }

                return apps;
            }));
        }