mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Refactoring start menu source
1. refactoriong start menu source 2. fix depth problems involved in last commit
This commit is contained in:
@@ -8,18 +8,16 @@ using Wox.Infrastructure.Logger;
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
[Serializable]
|
||||
public class FileSystemProgramSource : ProgramSource
|
||||
public class FileSystemProgramSource : Win32
|
||||
{
|
||||
public string Location { get; set; } = "";
|
||||
public int MaxDepth { get; set; } = -1;
|
||||
internal string[] Suffixes { get; set; } = { "" };
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
if (Directory.Exists(Location) && MaxDepth >= -1)
|
||||
{
|
||||
var apps = new List<Program>();
|
||||
GetAppFromDirectory(apps, Location, 0);
|
||||
GetAppFromDirectory(apps, Location, MaxDepth);
|
||||
return apps;
|
||||
}
|
||||
else
|
||||
@@ -27,36 +25,5 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
return new List<Program>();
|
||||
}
|
||||
}
|
||||
|
||||
private void GetAppFromDirectory(List<Program> apps, string path, int depth)
|
||||
{
|
||||
if (MaxDepth != depth)
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(path))
|
||||
{
|
||||
if (Suffixes.Any(o => file.EndsWith("." + o)))
|
||||
{
|
||||
Program p;
|
||||
try
|
||||
{
|
||||
p = CreateEntry(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var woxPluginException = new WoxPluginException("Program",
|
||||
$"GetAppFromDirectory failed: {path}", e);
|
||||
Log.Exception(woxPluginException);
|
||||
continue;
|
||||
}
|
||||
p.Source = this;
|
||||
apps.Add(p);
|
||||
}
|
||||
}
|
||||
foreach (var d in Directory.GetDirectories(path))
|
||||
{
|
||||
GetAppFromDirectory(apps, d, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user