/// <summary> /// Gets the extended search paths for about_topics help. To be able to get about_topics help from unloaded modules, /// we will add $pshome and the folders under PS module paths to the collection of paths to search. /// </summary> /// <returns>A collection of string representing locations.</returns> internal Collection <string> GetExtendedSearchPaths() { Collection <string> searchPaths = GetSearchPaths(); // Add $pshome at the top of the list string defaultShellSearchPath = GetDefaultShellSearchPath(); int index = searchPaths.IndexOf(defaultShellSearchPath); if (index != 0) { if (index > 0) { searchPaths.RemoveAt(index); } searchPaths.Insert(0, defaultShellSearchPath); } // Add the CurrentUser help path. searchPaths.Add(HelpUtils.GetUserHomeHelpSearchPath()); // Add modules that are not loaded. Since using 'get-module -listavailable' is very expensive, // we load all the directories (which are not empty) under the module path. foreach (string psModulePath in ModuleIntrinsics.GetModulePath(false, this.HelpSystem.ExecutionContext)) { if (Directory.Exists(psModulePath)) { try { // Get all the directories under the module path // * and SearchOption.AllDirectories gets all the version directories. string[] directories = Directory.GetDirectories(psModulePath, "*", SearchOption.AllDirectories); var possibleModuleDirectories = directories.Where(static directory => !ModuleUtils.IsPossibleResourceDirectory(directory));
/// <summary> /// Gets the extended search paths for about_topics help. To be able to get about_topics help from unloaded modules, /// we will add $pshome and the folders under PS module paths to the collection of paths to search. /// </summary> /// <returns>A collection of string representing locations.</returns> internal Collection <string> GetExtendedSearchPaths() { Collection <string> searchPaths = GetSearchPaths(); // Add $pshome at the top of the list string defaultShellSearchPath = GetDefaultShellSearchPath(); int index = searchPaths.IndexOf(defaultShellSearchPath); if (index != 0) { if (index > 0) { searchPaths.RemoveAt(index); } searchPaths.Insert(0, defaultShellSearchPath); } // Add the CurrentUser help path. searchPaths.Add(HelpUtils.GetUserHomeHelpSearchPath()); // Add modules that are not loaded. Since using 'get-module -listavailable' is very expensive, // we load all the directories (which are not empty) under the module path. foreach (string psModulePath in ModuleIntrinsics.GetModulePath(false, this.HelpSystem.ExecutionContext)) { if (Directory.Exists(psModulePath)) { try { // Get all the directories under the module path // * and SearchOption.AllDirectories gets all the version directories. string[] directories = Directory.GetDirectories(psModulePath, "*", SearchOption.AllDirectories); var possibleModuleDirectories = directories.Where(directory => !ModuleUtils.IsPossibleResourceDirectory(directory)); foreach (string directory in possibleModuleDirectories) { // Add only directories that are not empty if (Directory.EnumerateFiles(directory).Any()) { if (!searchPaths.Contains(directory)) { searchPaths.Add(directory); } } } } // Absorb any exception related to enumerating directories catch (System.ArgumentException) { } catch (System.IO.IOException) { } catch (System.UnauthorizedAccessException) { } catch (System.Security.SecurityException) { } } } return(searchPaths); }