Add max depth and suffixes per program source

This commit is contained in:
Devin Stiert
2015-04-20 20:32:10 -04:00
parent 6b6ab5e752
commit 4c5a046bc0
7 changed files with 284 additions and 165 deletions

View File

@@ -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)