2014-03-19 02:06:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.System
|
|
|
|
|
{
|
|
|
|
|
public class FileSystemProgramSource : AbstractProgramSource
|
|
|
|
|
{
|
|
|
|
|
public string BaseDirectory;
|
|
|
|
|
public List<string> Suffixes = new List<string>() { "lnk", "exe" };
|
|
|
|
|
|
|
|
|
|
public FileSystemProgramSource(string baseDirectory)
|
|
|
|
|
{
|
|
|
|
|
BaseDirectory = baseDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FileSystemProgramSource(string baseDirectory, List<string> suffixes)
|
|
|
|
|
: this(baseDirectory)
|
|
|
|
|
{
|
|
|
|
|
Suffixes = suffixes;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-19 04:05:27 +08:00
|
|
|
|
public FileSystemProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
|
|
|
|
|
: this(source.Location)
|
|
|
|
|
{
|
2014-03-19 20:16:20 +08:00
|
|
|
|
this.BonusPoints = source.BonusPoints;
|
2014-03-19 04:05:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-19 02:06:51 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-19 20:16:20 +08:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return typeof(FileSystemProgramSource).Name + ":" + this.BaseDirectory;
|
|
|
|
|
}
|
2014-03-19 02:06:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|