| |
| |
|
|
| using System.IO; |
| using System.Management.Automation; |
| using System.Management.Automation.Help; |
|
|
| using Microsoft.PowerShell.Commands; |
|
|
| namespace System.Management.Automation |
| { |
| internal static class HelpUtils |
| { |
| private static string userHomeHelpPath = null; |
|
|
| |
| |
| |
| internal static string GetUserHomeHelpSearchPath() |
| { |
| if (userHomeHelpPath == null) |
| { |
| #if UNIX |
| var userModuleFolder = Platform.SelectProductNameForDirectory(Platform.XDG_Type.USER_MODULES); |
| string userScopeRootPath = System.IO.Path.GetDirectoryName(userModuleFolder); |
| #else |
| string userScopeRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PowerShell"); |
| #endif |
| userHomeHelpPath = Path.Combine(userScopeRootPath, "Help"); |
| } |
|
|
| return userHomeHelpPath; |
| } |
|
|
| internal static string GetModuleBaseForUserHelp(string moduleBase, string moduleName) |
| { |
| string newModuleBase = moduleBase; |
|
|
| |
| |
| |
| |
| |
| |
|
|
| var userHelpPath = GetUserHomeHelpSearchPath(); |
| string moduleBaseParent = Directory.GetParent(moduleBase).Name; |
|
|
| if (moduleBase.EndsWith(moduleName, StringComparison.OrdinalIgnoreCase)) |
| { |
| |
| newModuleBase = Path.Combine(userHelpPath, moduleName); |
| } |
| else if (string.Equals(moduleBaseParent, moduleName, StringComparison.OrdinalIgnoreCase)) |
| { |
| |
| var moduleVersion = Path.GetFileName(moduleBase); |
| newModuleBase = Path.Combine(userHelpPath, moduleName, moduleVersion); |
| } |
| else |
| { |
| |
| newModuleBase = userHelpPath; |
| } |
|
|
| return newModuleBase; |
| } |
| } |
| } |
|
|