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))
|
||||
return new string[] { };
|
||||
|
||||
var ds = Directory.GetDirectories(directory);
|
||||
|
||||
var paths = ds.SelectMany(d =>
|
||||
var files = new List<string>();
|
||||
var folderQueue = new Queue<string>();
|
||||
folderQueue.Enqueue(directory);
|
||||
do
|
||||
{
|
||||
var currentDirectory = folderQueue.Dequeue();
|
||||
try
|
||||
{
|
||||
var paths_for_suffixes = suffixes.SelectMany(s =>
|
||||
foreach (var suffix in suffixes)
|
||||
{
|
||||
var pattern = $"*.{s}";
|
||||
var ps = Directory.EnumerateFiles(d, pattern, SearchOption.AllDirectories);
|
||||
return ps;
|
||||
});
|
||||
return paths_for_suffixes;
|
||||
files.AddRange(Directory.EnumerateFiles(currentDirectory, $"*.{suffix}", SearchOption.TopDirectoryOnly));
|
||||
}
|
||||
}
|
||||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
|
||||
{
|
||||
Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{directory}>", e);
|
||||
return new List<string>();
|
||||
Log.Exception($"|Program.Win32.ProgramPaths|Don't have permission on <{currentDirectory}>", e);
|
||||
}
|
||||
});
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user