Skip to content

Commit ac92b93

Browse files
Move IsSubPathOf to SharedCommands
1 parent 3226889 commit ac92b93

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,22 @@ public static string ReturnPreviousDirectoryIfIncompleteString(string path)
241241

242242
return path;
243243
}
244+
245+
/// <summary>
246+
/// Returns if <paramref name="subPath"/> is a sub path of <paramref name="basePath"/>.
247+
/// From https://stackoverflow.com/a/66877016
248+
/// </summary>
249+
/// <param name="subPath"></param>
250+
/// <param name="basePath"></param>
251+
/// <returns></returns>
252+
public static bool IsSubPathOf(string subPath, string basePath)
253+
{
254+
var rel = Path.GetRelativePath(basePath, subPath);
255+
return rel != "."
256+
&& rel != ".."
257+
&& !rel.StartsWith("../")
258+
&& !rel.StartsWith(@"..\")
259+
&& !Path.IsPathRooted(rel);
260+
}
244261
}
245262
}

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

Lines changed: 1 addition & 12 deletions
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 => IsSubPathOf(r.SubTitle, excludedPath.Path)));
124+
excludedPath => FilesFolders.IsSubPathOf(r.SubTitle, excludedPath.Path)));
125125

126126
return results.ToList();
127127
}
@@ -256,16 +256,5 @@ internal static bool IsEnvironmentVariableSearch(string search)
256256
&& search != "%%"
257257
&& !search.Contains('\\');
258258
}
259-
260-
// https://stackoverflow.com/a/66877016
261-
internal static bool IsSubPathOf(string subPath, string basePath)
262-
{
263-
var rel = Path.GetRelativePath(basePath, subPath);
264-
return rel != "."
265-
&& rel != ".."
266-
&& !rel.StartsWith("../")
267-
&& !rel.StartsWith(@"..\")
268-
&& !Path.IsPathRooted(rel);
269-
}
270259
}
271260
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ private static IEnumerable<Win32> PATHPrograms(string[] suffixes, string[] proto
471471

472472
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).DistinctBy(p => p.ToLowerInvariant());
473473

474-
var toFilter = paths.Where(x => commonParents.All(parent => !IsSubPathOf(x, parent)))
474+
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.IsSubPathOf(x, parent)))
475475
.AsParallel()
476476
.SelectMany(p => EnumerateProgramsInDir(p, suffixes, recursive: false));
477477

@@ -763,17 +763,6 @@ public static void Dispose()
763763
}
764764
}
765765

766-
// https://stackoverflow.com/a/66877016
767-
private static bool IsSubPathOf(string subPath, string basePath)
768-
{
769-
var rel = Path.GetRelativePath(basePath, subPath);
770-
return rel != "."
771-
&& rel != ".."
772-
&& !rel.StartsWith("../")
773-
&& !rel.StartsWith(@"..\")
774-
&& !Path.IsPathRooted(rel);
775-
}
776-
777766
private static List<string> GetCommonParents(IEnumerable<ProgramSource> programSources)
778767
{
779768
// To avoid unnecessary io
@@ -785,7 +774,7 @@ private static List<string> GetCommonParents(IEnumerable<ProgramSource> programS
785774
HashSet<ProgramSource> parents = group.ToHashSet();
786775
foreach (var source in group)
787776
{
788-
if (parents.Any(p => IsSubPathOf(source.Location, p.Location) &&
777+
if (parents.Any(p => FilesFolders.IsSubPathOf(source.Location, p.Location) &&
789778
source != p))
790779
{
791780
parents.Remove(source);

0 commit comments

Comments
 (0)