diff --git a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs index 5cb3a171a..97d8c25d3 100644 --- a/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs +++ b/Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs @@ -241,5 +241,22 @@ namespace Flow.Launcher.Plugin.SharedCommands return path; } + + /// + /// Returns if is a sub path of . + /// From https://stackoverflow.com/a/66877016 + /// + /// + /// + /// + public static bool IsSubPathOf(string subPath, string basePath) + { + var rel = Path.GetRelativePath(basePath, subPath); + return rel != "." + && rel != ".." + && !rel.StartsWith("../") + && !rel.StartsWith(@"..\") + && !Path.IsPathRooted(rel); + } } } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 25604cf2f..324832990 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -121,7 +121,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search } results.RemoveWhere(r => Settings.IndexSearchExcludedSubdirectoryPaths.Any( - excludedPath => IsSubPathOf(r.SubTitle, excludedPath.Path))); + excludedPath => FilesFolders.IsSubPathOf(r.SubTitle, excludedPath.Path))); return results.ToList(); } @@ -256,16 +256,5 @@ namespace Flow.Launcher.Plugin.Explorer.Search && search != "%%" && !search.Contains('\\'); } - - // https://stackoverflow.com/a/66877016 - internal static bool IsSubPathOf(string subPath, string basePath) - { - var rel = Path.GetRelativePath(basePath, subPath); - return rel != "." - && rel != ".." - && !rel.StartsWith("../") - && !rel.StartsWith(@"..\") - && !Path.IsPathRooted(rel); - } } } diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index f678b6bc8..28eb9832f 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -471,7 +471,7 @@ namespace Flow.Launcher.Plugin.Program.Programs var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).DistinctBy(p => p.ToLowerInvariant()); - var toFilter = paths.Where(x => commonParents.All(parent => !IsSubPathOf(x, parent))) + var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.IsSubPathOf(x, parent))) .AsParallel() .SelectMany(p => EnumerateProgramsInDir(p, suffixes, recursive: false)); @@ -763,17 +763,6 @@ namespace Flow.Launcher.Plugin.Program.Programs } } - // https://stackoverflow.com/a/66877016 - private static bool IsSubPathOf(string subPath, string basePath) - { - var rel = Path.GetRelativePath(basePath, subPath); - return rel != "." - && rel != ".." - && !rel.StartsWith("../") - && !rel.StartsWith(@"..\") - && !Path.IsPathRooted(rel); - } - private static List GetCommonParents(IEnumerable programSources) { // To avoid unnecessary io @@ -785,7 +774,7 @@ namespace Flow.Launcher.Plugin.Program.Programs HashSet parents = group.ToHashSet(); foreach (var source in group) { - if (parents.Any(p => IsSubPathOf(source.Location, p.Location) && + if (parents.Any(p => FilesFolders.IsSubPathOf(source.Location, p.Location) && source != p)) { parents.Remove(source);