mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-16 04:29:16 +08:00
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Wox.Infrastructure.Storage.UserSettings;
|
|
|
|
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
|
{
|
|
public class FileSystemProgramSource : AbstractProgramSource
|
|
{
|
|
public string BaseDirectory;
|
|
public List<string> Suffixes = new List<string>() { "lnk", "exe", "appref-ms" };
|
|
|
|
public FileSystemProgramSource(string baseDirectory)
|
|
{
|
|
BaseDirectory = baseDirectory;
|
|
}
|
|
|
|
public FileSystemProgramSource(string baseDirectory, List<string> suffixes)
|
|
: this(baseDirectory)
|
|
{
|
|
Suffixes = suffixes;
|
|
}
|
|
|
|
public FileSystemProgramSource(ProgramSource source)
|
|
: this(source.Location)
|
|
{
|
|
this.BonusPoints = source.BonusPoints;
|
|
}
|
|
|
|
public override List<Program> LoadPrograms()
|
|
{
|
|
List<Program> list = new List<Program>();
|
|
GetAppFromDirectory(BaseDirectory, list);
|
|
|
|
return list;
|
|
}
|
|
|
|
private void GetAppFromDirectory(string path, List<Program> 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;
|
|
}
|
|
}
|
|
}
|