-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add functionality to update help in user scope #6352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
316df13
154685f
f0f1209
4ce5670
86e4992
899f8f0
7410164
7ed20bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.IO; | ||
| using System.Management.Automation; | ||
| using System.Management.Automation.Help; | ||
| using Microsoft.PowerShell.Commands; | ||
|
|
||
| namespace System.Management.Automation | ||
| { | ||
| internal class HelpUtils | ||
| { | ||
| private static string userHomeHelpPath = null; | ||
|
|
||
| /// <summary> | ||
| /// Get the path to $HOME | ||
| /// </summary> | ||
| 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; | ||
|
|
||
| // In case of inbox modules, the help is put under $PSHOME/<current_culture>, | ||
| // since the dlls are not published under individual module folders, but under $PSHome. | ||
| // In case of other modules, the help is under moduleBase/<current_culture> or | ||
| // under moduleBase/<Version>/<current_culture>. | ||
| // The code below creates a similar layout for CurrentUser scope. | ||
| // If the the scope is AllUsers, then the help goes under moduleBase. | ||
|
|
||
| var userHelpPath = GetUserHomeHelpSearchPath(); | ||
| string moduleBaseParent = Directory.GetParent(moduleBase).Name; | ||
|
|
||
| if (moduleBase.EndsWith(moduleName, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| //This module is not an inbox module, so help goes under <userHelpPath>/<moduleName> | ||
| newModuleBase = Path.Combine(userHelpPath, moduleName); | ||
| } | ||
| else if (String.Equals(moduleBaseParent, moduleName, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| //This module has version folder. | ||
| var moduleVersion = Path.GetFileName(moduleBase); | ||
| newModuleBase = Path.Combine(userHelpPath, moduleName, moduleVersion); | ||
| } | ||
| else | ||
| { | ||
| //This module is inbox module, help should be under <userHelpPath> | ||
| newModuleBase = userHelpPath; | ||
| } | ||
|
|
||
| return newModuleBase; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,10 +212,17 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, | |
| UpdatableHelpInfo newHelpInfo = null; | ||
| string helpInfoUri = null; | ||
|
|
||
| string moduleBase = module.ModuleBase; | ||
|
|
||
| if(this.Scope == UpdateHelpScope.CurrentUser) | ||
| { | ||
| moduleBase = HelpUtils.GetModuleBaseForUserHelp(moduleBase, module.ModuleName); | ||
| } | ||
|
|
||
| // reading the xml file even if force is specified | ||
| // Reason: we need the current version for ShouldProcess | ||
| string xml = UpdatableHelpSystem.LoadStringFromPath(this, | ||
| SessionState.Path.Combine(module.ModuleBase, module.GetHelpInfoName()), | ||
| SessionState.Path.Combine(moduleBase, module.GetHelpInfoName()), | ||
| null); | ||
|
|
||
| if (xml != null) | ||
|
|
@@ -230,7 +237,7 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, | |
| } | ||
|
|
||
| // Don't update too frequently | ||
| if (!_alreadyCheckedOncePerDayPerModule && !CheckOncePerDayPerModule(module.ModuleName, module.ModuleBase, module.GetHelpInfoName(), DateTime.UtcNow, _force)) | ||
| if (!_alreadyCheckedOncePerDayPerModule && !CheckOncePerDayPerModule(module.ModuleName, moduleBase, module.GetHelpInfoName(), DateTime.UtcNow, _force)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
@@ -347,7 +354,7 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, | |
| continue; | ||
| } | ||
|
|
||
| if (Utils.IsUnderProductFolder(module.ModuleBase) && (!Utils.IsAdministrator())) | ||
| if (Utils.IsUnderProductFolder(moduleBase) && (!Utils.IsAdministrator())) | ||
| { | ||
| string message = StringUtil.Format(HelpErrors.UpdatableHelpRequiresElevation); | ||
| ProcessException(module.ModuleName, null, new UpdatableHelpSystemException("UpdatableHelpSystemRequiresElevation", | ||
|
|
@@ -375,7 +382,12 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, | |
| // Gather destination paths | ||
| Collection<string> destPaths = new Collection<string>(); | ||
|
|
||
| destPaths.Add(module.ModuleBase); | ||
|
||
| if(!Directory.Exists(moduleBase)) | ||
| { | ||
| Directory.CreateDirectory(moduleBase); | ||
| } | ||
|
|
||
| destPaths.Add(moduleBase); | ||
|
|
||
| #if !CORECLR // Side-By-Side directories are not present in OneCore environments. | ||
| if (IsSystemModule(module.ModuleName) && Environment.Is64BitOperatingSystem) | ||
|
|
@@ -442,7 +454,7 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, | |
| } | ||
|
|
||
| _helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture), | ||
| module.ModuleBase, module.GetHelpInfoName(), _force); | ||
| moduleBase, module.GetHelpInfoName(), _force); | ||
|
|
||
| foreach (string fileInstalled in filesInstalled) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np: Please remove the extra space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.