using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Wox.Infrastructure.Storage.UserSettings; namespace Wox.Plugin.SystemPlugins.ProgramSources { public class FileSystemProgramSource : AbstractProgramSource { public string BaseDirectory; public List Suffixes = new List() { "lnk", "exe", "appref-ms" }; public FileSystemProgramSource(string baseDirectory) { BaseDirectory = baseDirectory; } public FileSystemProgramSource(string baseDirectory, List suffixes) : this(baseDirectory) { Suffixes = suffixes; } public FileSystemProgramSource(ProgramSource source) : this(source.Location) { this.BonusPoints = source.BonusPoints; } public override List LoadPrograms() { List list = new List(); GetAppFromDirectory(BaseDirectory, list); return list; } private void GetAppFromDirectory(string path, List list) { foreach (string file in Directory.GetFiles(path)) { if (Suffixes.Any(o => file.EndsWith("." + o))) { Program p = CreateEntry(file); list.Add(p); } } foreach (var subDirectory in Directory.GetDirectories(path)) { GetAppFromDirectory(subDirectory, list); } } public override string ToString() { return typeof(FileSystemProgramSource).Name + ":" + this.BaseDirectory; } } }