mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
* Merge pull request #1205 from Flow-Launcher/fix_cmd_command_with_blank Fix shell cmd command with quote and space * Bump NuGet.CommandLine from 5.4.0 to 5.7.2 (#1241) * Merge pull request #1098 from Flow-Launcher/ScrollToSelectedPlugin Scroll to selected item when expanded or size changed * fix RemoveOldQueryResults NullPointerException (#1204) * Merge pull request #1005 from Flow-Launcher/KillProcess Use Cancellation Token to avoid potential race tracing issue * Merge pull request #1187 from Flow-Launcher/update_python_download_mirrors Update Python download mirrors * Merge pull request #1108 from Flow-Launcher/CalculatorDecimalSeparator Respect Decimal Separator for query not just result * Merge pull request #1087 from Flow-Launcher/turnoff_replace_win_r_shell Set Shell plugin's default replace Win R hotkey to off * Merge pull request #1077 from Flow-Launcher/fix_explorer_button_visibility Fix incorrect button visibility in Explorer's expander control * Merge pull request #1076 from Flow-Launcher/fix_path_search_with_index Fix the use of index in path search * Merge pull request #1071 from medlir/fix-browser-bookmarks-plugin-exception avoid exception in ChromiumBookmarkLoader.cs * Merge pull request #1056 from Flow-Launcher/fix_context_menu_typo Fix typo for plugin title in context menu and WindowsSettings name * Merge pull request #1119 from onesounds/antialising Remove All Cleartype Rendering * Version bump * Remove Calculator plugin CopyText feature for 1.9.4 release
97 lines
No EOL
3.7 KiB
C#
97 lines
No EOL
3.7 KiB
C#
using Flow.Launcher.Infrastructure.Logger;
|
|
using Flow.Launcher.Plugin.SharedCommands;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
|
|
namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo
|
|
{
|
|
public static class DirectoryInfoSearch
|
|
{
|
|
internal static List<Result> TopLevelDirectorySearch(Query query, string search, CancellationToken token)
|
|
{
|
|
var criteria = ConstructSearchCriteria(search);
|
|
|
|
if (search.LastIndexOf(Constants.AllFilesFolderSearchWildcard) >
|
|
search.LastIndexOf(Constants.DirectorySeperator))
|
|
return DirectorySearch(new EnumerationOptions
|
|
{
|
|
RecurseSubdirectories = true
|
|
}, query, search, criteria, token);
|
|
|
|
return DirectorySearch(new EnumerationOptions(), query, search, criteria,
|
|
token); // null will be passed as default
|
|
}
|
|
|
|
public static string ConstructSearchCriteria(string search)
|
|
{
|
|
string incompleteName = "";
|
|
|
|
if (!search.EndsWith(Constants.DirectorySeperator))
|
|
{
|
|
var indexOfSeparator = search.LastIndexOf(Constants.DirectorySeperator);
|
|
|
|
incompleteName = search.Substring(indexOfSeparator + 1).ToLower();
|
|
|
|
if (incompleteName.StartsWith(Constants.AllFilesFolderSearchWildcard))
|
|
incompleteName = "*" + incompleteName.Substring(1);
|
|
}
|
|
|
|
incompleteName += "*";
|
|
|
|
return incompleteName;
|
|
}
|
|
|
|
private static List<Result> DirectorySearch(EnumerationOptions enumerationOption, Query query, string search,
|
|
string searchCriteria, CancellationToken token)
|
|
{
|
|
var results = new List<Result>();
|
|
|
|
var path = FilesFolders.ReturnPreviousDirectoryIfIncompleteString(search);
|
|
|
|
var folderList = new List<Result>();
|
|
var fileList = new List<Result>();
|
|
|
|
try
|
|
{
|
|
var directoryInfo = new System.IO.DirectoryInfo(path);
|
|
|
|
foreach (var fileSystemInfo in directoryInfo.EnumerateFileSystemInfos(searchCriteria, enumerationOption))
|
|
{
|
|
if (fileSystemInfo is System.IO.DirectoryInfo)
|
|
{
|
|
folderList.Add(ResultManager.CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName,
|
|
fileSystemInfo.FullName, query, 0, true, false));
|
|
}
|
|
else
|
|
{
|
|
fileList.Add(ResultManager.CreateFileResult(fileSystemInfo.FullName, query, 0, true, false));
|
|
}
|
|
|
|
token.ThrowIfCancellationRequested();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Exception(nameof(DirectoryInfoSearch), "Error occured while searching path", e);
|
|
|
|
results.Add(
|
|
new Result
|
|
{
|
|
Title = string.Format(SearchManager.Context.API.GetTranslation(
|
|
"plugin_explorer_directoryinfosearch_error"),
|
|
e.Message),
|
|
Score = 501,
|
|
IcoPath = Constants.ExplorerIconImagePath
|
|
});
|
|
|
|
return results;
|
|
}
|
|
|
|
// Initial ordering, this order can be updated later by UpdateResultView.MainViewModel based on history of user selection.
|
|
return results.Concat(folderList.OrderBy(x => x.Title)).Concat(fileList.OrderBy(x => x.Title)).ToList();
|
|
}
|
|
}
|
|
} |