mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Rename method and add option to allow equality
This commit is contained in:
parent
ac92b93f66
commit
beb144956c
3 changed files with 11 additions and 12 deletions
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace Flow.Launcher.Plugin.SharedCommands
|
||||
{
|
||||
|
|
@ -243,16 +242,17 @@ namespace Flow.Launcher.Plugin.SharedCommands
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if <paramref name="subPath"/> is a sub path of <paramref name="basePath"/>.
|
||||
/// Returns if <paramref name="parentPath"/> contains <paramref name="subPath"/>.
|
||||
/// From https://stackoverflow.com/a/66877016
|
||||
/// </summary>
|
||||
/// <param name="subPath"></param>
|
||||
/// <param name="basePath"></param>
|
||||
/// <param name="parentPath">Parent path</param>
|
||||
/// <param name="subPath">Sub path</param>
|
||||
/// <param name="allowEqual">If <see langword="true"/>, when <paramref name="parentPath"/> and <paramref name="subPath"/> are equal, returns <see langword="true"/></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsSubPathOf(string subPath, string basePath)
|
||||
public static bool PathContains(string parentPath, string subPath, bool allowEqual = false)
|
||||
{
|
||||
var rel = Path.GetRelativePath(basePath, subPath);
|
||||
return rel != "."
|
||||
var rel = Path.GetRelativePath(parentPath, subPath);
|
||||
return (rel != "." || allowEqual)
|
||||
&& rel != ".."
|
||||
&& !rel.StartsWith("../")
|
||||
&& !rel.StartsWith(@"..\")
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
}
|
||||
|
||||
results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any(
|
||||
excludedPath => FilesFolders.IsSubPathOf(r.SubTitle, excludedPath.Path)));
|
||||
excludedPath => FilesFolders.PathContains(excludedPath.Path, r.SubTitle)));
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -470,8 +470,8 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
}
|
||||
|
||||
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).DistinctBy(p => p.ToLowerInvariant());
|
||||
|
||||
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.IsSubPathOf(x, parent)))
|
||||
|
||||
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.PathContains(parent, x)))
|
||||
.AsParallel()
|
||||
.SelectMany(p => EnumerateProgramsInDir(p, suffixes, recursive: false));
|
||||
|
||||
|
|
@ -774,8 +774,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
HashSet<ProgramSource> parents = group.ToHashSet();
|
||||
foreach (var source in group)
|
||||
{
|
||||
if (parents.Any(p => FilesFolders.IsSubPathOf(source.Location, p.Location) &&
|
||||
source != p))
|
||||
if (parents.Any(p => FilesFolders.PathContains(p.Location, source.Location)))
|
||||
{
|
||||
parents.Remove(source);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue