Merge pull request #2834 from Flow-Launcher/fix_env_variable_path

Fix partial env variable path search
This commit is contained in:
Jeremy Wu 2024-07-14 02:03:51 +10:00 committed by GitHub
commit ec17b3dea7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -68,7 +68,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search
IAsyncEnumerable<SearchResult> searchResults;
bool isPathSearch = query.Search.IsLocationPathString() || IsEnvironmentVariableSearch(query.Search);
bool isPathSearch = query.Search.IsLocationPathString()
|| EnvironmentVariables.IsEnvironmentVariableSearch(query.Search)
|| EnvironmentVariables.HasEnvironmentVar(query.Search);
string engineName;
@ -178,16 +180,16 @@ namespace Flow.Launcher.Plugin.Explorer.Search
// Query is a location path with a full environment variable, eg. %appdata%\somefolder\, c:\users\%USERNAME%\downloads
var needToExpand = EnvironmentVariables.HasEnvironmentVar(querySearch);
var locationPath = needToExpand ? Environment.ExpandEnvironmentVariables(querySearch) : querySearch;
var path = needToExpand ? Environment.ExpandEnvironmentVariables(querySearch) : querySearch;
// Check that actual location exists, otherwise directory search will throw directory not found exception
if (!FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath).LocationExists())
if (!FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path).LocationExists())
return results.ToList();
var useIndexSearch = Settings.IndexSearchEngine is Settings.IndexSearchEngineOption.WindowsIndex
&& UseWindowsIndexForDirectorySearch(locationPath);
&& UseWindowsIndexForDirectorySearch(path);
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(locationPath);
var retrievedDirectoryPath = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path);
results.Add(retrievedDirectoryPath.EndsWith(":\\")
? ResultManager.CreateDriveSpaceDisplayResult(retrievedDirectoryPath, query.ActionKeyword, useIndexSearch)
@ -198,21 +200,21 @@ namespace Flow.Launcher.Plugin.Explorer.Search
IAsyncEnumerable<SearchResult> directoryResult;
var recursiveIndicatorIndex = query.Search.IndexOf('>');
var recursiveIndicatorIndex = path.IndexOf('>');
if (recursiveIndicatorIndex > 0 && Settings.PathEnumerationEngine != Settings.PathEnumerationEngineOption.DirectEnumeration)
{
directoryResult =
Settings.PathEnumerator.EnumerateAsync(
query.Search[..recursiveIndicatorIndex].Trim(),
query.Search[(recursiveIndicatorIndex + 1)..],
path[..recursiveIndicatorIndex].Trim(),
path[(recursiveIndicatorIndex + 1)..],
true,
token);
}
else
{
directoryResult = DirectoryInfoSearch.TopLevelDirectorySearch(query, query.Search, token).ToAsyncEnumerable();
directoryResult = DirectoryInfoSearch.TopLevelDirectorySearch(query, path, token).ToAsyncEnumerable();
}
if (token.IsCancellationRequested)
@ -245,12 +247,5 @@ namespace Flow.Launcher.Plugin.Explorer.Search
x => FilesFolders.ReturnPreviousDirectoryIfIncompleteString(pathToDirectory).StartsWith(x.Path, StringComparison.OrdinalIgnoreCase))
&& WindowsIndex.WindowsIndex.PathIsIndexed(pathToDirectory);
}
internal static bool IsEnvironmentVariableSearch(string search)
{
return search.StartsWith("%")
&& search != "%%"
&& !search.Contains('\\');
}
}
}