mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Add max depth and suffixes per program source
This commit is contained in:
@@ -10,14 +10,21 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
public class FileSystemProgramSource : AbstractProgramSource
|
||||
{
|
||||
private string baseDirectory;
|
||||
private int maxDepth;
|
||||
private string suffixes;
|
||||
|
||||
public FileSystemProgramSource(string baseDirectory)
|
||||
public FileSystemProgramSource(string baseDirectory, int maxDepth, string suffixes)
|
||||
{
|
||||
this.baseDirectory = baseDirectory;
|
||||
this.maxDepth = maxDepth;
|
||||
this.suffixes = suffixes;
|
||||
}
|
||||
|
||||
public FileSystemProgramSource(string baseDirectory)
|
||||
: this(baseDirectory, -1, "") {}
|
||||
|
||||
public FileSystemProgramSource(ProgramSource source)
|
||||
: this(source.Location)
|
||||
: this(source.Location, source.MaxDepth, source.Suffixes)
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
@@ -35,11 +42,21 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
|
||||
private void GetAppFromDirectory(string path, List<Program> list)
|
||||
{
|
||||
GetAppFromDirectory(path, list, 0);
|
||||
}
|
||||
|
||||
private void GetAppFromDirectory(string path, List<Program> list, int depth)
|
||||
{
|
||||
if(maxDepth != -1 && depth > maxDepth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
{
|
||||
if (ProgramStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
|
||||
if (ProgramStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)) ||
|
||||
suffixes.Split(';').Any(o => file.EndsWith("." + o)))
|
||||
{
|
||||
Program p = CreateEntry(file);
|
||||
list.Add(p);
|
||||
@@ -48,7 +65,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
|
||||
foreach (var subDirectory in Directory.GetDirectories(path))
|
||||
{
|
||||
GetAppFromDirectory(subDirectory, list);
|
||||
GetAppFromDirectory(subDirectory, list, depth + 1);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user