Skip to content

Commit beb1449

Browse files
Rename method and add option to allow equality
1 parent ac92b93 commit beb1449

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4-
using System.Windows;
54

65
namespace Flow.Launcher.Plugin.SharedCommands
76
{
@@ -243,16 +242,17 @@ public static string ReturnPreviousDirectoryIfIncompleteString(string path)
243242
}
244243

245244
/// <summary>
246-
/// Returns if <paramref name="subPath"/> is a sub path of <paramref name="basePath"/>.
245+
/// Returns if <paramref name="parentPath"/> contains <paramref name="subPath"/>.
247246
/// From https://stackoverflow.com/a/66877016
248247
/// </summary>
249-
/// <param name="subPath"></param>
250-
/// <param name="basePath"></param>
248+
/// <param name="parentPath">Parent path</param>
249+
/// <param name="subPath">Sub path</param>
250+
/// <param name="allowEqual">If <see langword="true"/>, when <paramref name="parentPath"/> and <paramref name="subPath"/> are equal, returns <see langword="true"/></param>
251251
/// <returns></returns>
252-
public static bool IsSubPathOf(string subPath, string basePath)
252+
public static bool PathContains(string parentPath, string subPath, bool allowEqual = false)
253253
{
254-
var rel = Path.GetRelativePath(basePath, subPath);
255-
return rel != "."
254+
var rel = Path.GetRelativePath(parentPath, subPath);
255+
return (rel != "." || allowEqual)
256256
&& rel != ".."
257257
&& !rel.StartsWith("../")
258258
&& !rel.StartsWith(@"..\")

Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ when ActionKeywordMatch(query, Settings.ActionKeyword.IndexSearchActionKeyword)
121121
}
122122

123123
results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any(
124-
excludedPath => FilesFolders.IsSubPathOf(r.SubTitle, excludedPath.Path)));
124+
excludedPath => FilesFolders.PathContains(excludedPath.Path, r.SubTitle)));
125125

126126
return results.ToList();
127127
}

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ private static IEnumerable<Win32> PATHPrograms(string[] suffixes, string[] proto
470470
}
471471

472472
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).DistinctBy(p => p.ToLowerInvariant());
473-
474-
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.IsSubPathOf(x, parent)))
473+
474+
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.PathContains(parent, x)))
475475
.AsParallel()
476476
.SelectMany(p => EnumerateProgramsInDir(p, suffixes, recursive: false));
477477

@@ -774,8 +774,7 @@ private static List<string> GetCommonParents(IEnumerable<ProgramSource> programS
774774
HashSet<ProgramSource> parents = group.ToHashSet();
775775
foreach (var source in group)
776776
{
777-
if (parents.Any(p => FilesFolders.IsSubPathOf(source.Location, p.Location) &&
778-
source != p))
777+
if (parents.Any(p => FilesFolders.PathContains(p.Location, source.Location)))
779778
{
780779
parents.Remove(source);
781780
}

0 commit comments

Comments
 (0)