Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
HelpUtils.cs70 linesDownload Raw Back to help
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.IO;5using System.Management.Automation;6using System.Management.Automation.Help;7 8using Microsoft.PowerShell.Commands;9 10namespace System.Management.Automation11{12    internal static class HelpUtils13    {14        private static string userHomeHelpPath = null;15 16        /// <summary>17        /// Get the path to $HOME.18        /// </summary>19        internal static string GetUserHomeHelpSearchPath()20        {21            if (userHomeHelpPath == null)22            {23#if UNIX24                var userModuleFolder = Platform.SelectProductNameForDirectory(Platform.XDG_Type.USER_MODULES);25                string userScopeRootPath = System.IO.Path.GetDirectoryName(userModuleFolder);26#else27                string userScopeRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PowerShell");28#endif29                userHomeHelpPath = Path.Combine(userScopeRootPath, "Help");30            }31 32            return userHomeHelpPath;33        }34 35        internal static string GetModuleBaseForUserHelp(string moduleBase, string moduleName)36        {37            string newModuleBase = moduleBase;38 39            // In case of inbox modules, the help is put under $PSHOME/<current_culture>,40            // since the dlls are not published under individual module folders, but under $PSHome.41            // In case of other modules, the help is under moduleBase/<current_culture> or42            // under moduleBase/<Version>/<current_culture>.43            // The code below creates a similar layout for CurrentUser scope.44            // If the scope is AllUsers, then the help goes under moduleBase.45 46            var userHelpPath = GetUserHomeHelpSearchPath();47            string moduleBaseParent = Directory.GetParent(moduleBase).Name;48 49            if (moduleBase.EndsWith(moduleName, StringComparison.OrdinalIgnoreCase))50            {51                // This module is not an inbox module, so help goes under <userHelpPath>/<moduleName>52                newModuleBase = Path.Combine(userHelpPath, moduleName);53            }54            else if (string.Equals(moduleBaseParent, moduleName, StringComparison.OrdinalIgnoreCase))55            {56                // This module has version folder.57                var moduleVersion = Path.GetFileName(moduleBase);58                newModuleBase = Path.Combine(userHelpPath, moduleName, moduleVersion);59            }60            else61            {62                // This module is inbox module, help should be under <userHelpPath>63                newModuleBase = userHelpPath;64            }65 66            return newModuleBase;67        }68    }69}70