mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 12:11:09 +01:00
fix #46 Reload index cache when the file changed in index directories
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
@@ -7,15 +9,14 @@ namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
{
|
||||
public class FileSystemProgramSource : AbstractProgramSource
|
||||
{
|
||||
public string BaseDirectory;
|
||||
private string baseDirectory;
|
||||
|
||||
public FileSystemProgramSource(string baseDirectory)
|
||||
{
|
||||
BaseDirectory = baseDirectory;
|
||||
this.baseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
public FileSystemProgramSource(ProgramSource source)
|
||||
: this(source.Location)
|
||||
public FileSystemProgramSource(ProgramSource source):this(source.Location)
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
@@ -23,33 +24,41 @@ namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
List<Program> list = new List<Program>();
|
||||
if (Directory.Exists(BaseDirectory))
|
||||
if (Directory.Exists(baseDirectory))
|
||||
{
|
||||
GetAppFromDirectory(BaseDirectory, list);
|
||||
GetAppFromDirectory(baseDirectory, list);
|
||||
FileChangeWatcher.AddWatch(baseDirectory);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void GetAppFromDirectory(string path, List<Program> list)
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
try
|
||||
{
|
||||
if (UserSettingStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
{
|
||||
Program p = CreateEntry(file);
|
||||
list.Add(p);
|
||||
if (UserSettingStorage.Instance.ProgramSuffixes.Split(';').Any(o => file.EndsWith("." + o)))
|
||||
{
|
||||
Program p = CreateEntry(file);
|
||||
list.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subDirectory in Directory.GetDirectories(path))
|
||||
{
|
||||
GetAppFromDirectory(subDirectory, list);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subDirectory in Directory.GetDirectories(path))
|
||||
catch (UnauthorizedAccessException e)
|
||||
{
|
||||
GetAppFromDirectory(subDirectory, list);
|
||||
Debug.WriteLine(string.Format("Can't access to directory {0}",path),"WoxDebug");
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(FileSystemProgramSource).Name + ":" + this.BaseDirectory;
|
||||
return typeof(FileSystemProgramSource).Name + ":" + this.baseDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user