mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 11:09:28 +08:00
* ProgramPaths now searches for files on a per-folder basis using a Queue instead of calling EnumerateFiles. This allows us to escape permission errors. Issue #1779 is fixed because of this too.
This commit is contained in:
parent
e251c59da1
commit
1c10ee106e
@ -206,28 +206,37 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
{
|
{
|
||||||
if (!Directory.Exists(directory))
|
if (!Directory.Exists(directory))
|
||||||
return new string[] { };
|
return new string[] { };
|
||||||
|
var files = new List<string>();
|
||||||
var ds = Directory.GetDirectories(directory);
|
var folderQueue = new Queue<string>();
|
||||||
|
folderQueue.Enqueue(directory);
|
||||||
var paths = ds.SelectMany(d =>
|
do
|
||||||
{
|
{
|
||||||
|
var currentDirectory = folderQueue.Dequeue();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var paths_for_suffixes = suffixes.SelectMany(s =>
|
foreach (var suffix in suffixes)
|
||||||
{
|
{
|
||||||
var pattern = $"*.{s}";
|
files.AddRange(Directory.EnumerateFiles(currentDirectory, $"*.{suffix}", SearchOption.TopDirectoryOnly));
|
||||||
var ps = Directory.EnumerateFiles(d, pattern, SearchOption.AllDirectories);
|
}
|
||||||
return ps;
|
|
||||||
});
|
|
||||||
return paths_for_suffixes;
|
|
||||||
}
|
}
|
||||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{directory}>", e);
|
Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{currentDirectory}>", e);
|
||||||
return new List<string>();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return paths;
|
try
|
||||||
|
{
|
||||||
|
foreach (var childDirectory in Directory.EnumerateDirectories(currentDirectory, "*", SearchOption.TopDirectoryOnly))
|
||||||
|
{
|
||||||
|
folderQueue.Enqueue(childDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{currentDirectory}>", e);
|
||||||
|
}
|
||||||
|
} while (folderQueue.Any());
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string Extension(string path)
|
private static string Extension(string path)
|
||||||
|
Loading…
Reference in New Issue
Block a user