private void ProcessSingleModuleObject(PSModuleInfo module, ExecutionContext context, Dictionary <Tuple <string, Version>, UpdatableHelpModuleInfo> helpModules, bool noErrors) { if (InitialSessionState.IsEngineModule(module.Name) && !InitialSessionState.IsNestedEngineModule(module.Name)) { WriteDebug(StringUtil.Format("Found engine module: {0}, {1}.", module.Name, module.Guid)); var keyTuple = new Tuple <string, Version>(module.Name, module.Version); if (!helpModules.ContainsKey(keyTuple)) { helpModules.Add(keyTuple, new UpdatableHelpModuleInfo(module.Name, module.Guid, Utils.GetApplicationBase(context.ShellID), s_metadataCache[module.Name])); } return; } else if (InitialSessionState.IsNestedEngineModule(module.Name)) { return; } if (string.IsNullOrEmpty(module.HelpInfoUri)) { if (!noErrors) { ProcessException(module.Name, null, new UpdatableHelpSystemException( "HelpInfoUriNotFound", StringUtil.Format(HelpDisplayStrings.HelpInfoUriNotFound), ErrorCategory.NotSpecified, new Uri("HelpInfoUri", UriKind.Relative), null)); } return; } if (!(module.HelpInfoUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || module.HelpInfoUri.StartsWith("https://", StringComparison.OrdinalIgnoreCase))) { if (!noErrors) { ProcessException(module.Name, null, new UpdatableHelpSystemException( "InvalidHelpInfoUriFormat", StringUtil.Format(HelpDisplayStrings.InvalidHelpInfoUriFormat, module.HelpInfoUri), ErrorCategory.NotSpecified, new Uri("HelpInfoUri", UriKind.Relative), null)); } return; } var keyTuple2 = new Tuple <string, Version>(module.Name, module.Version); if (!helpModules.ContainsKey(keyTuple2)) { helpModules.Add(keyTuple2, new UpdatableHelpModuleInfo(module.Name, module.Guid, module.ModuleBase, module.HelpInfoUri)); } }
internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, string culture) { if (((InitialSessionState.IsEngineModule(module.ModuleName) || InitialSessionState.IsNestedEngineModule(module.ModuleName)) || module.ModuleName.Equals(InitialSessionState.CoreSnapin, StringComparison.OrdinalIgnoreCase)) && !UpdatableHelpSystem.IsAdministrator()) { string message = StringUtil.Format(HelpErrors.UpdatableHelpRequiresElevation, new object[0]); base.ProcessException(module.ModuleName, null, new UpdatableHelpSystemException("UpdatableHelpSystemRequiresElevation", message, ErrorCategory.InvalidOperation, null, null)); return(false); } UpdatableHelpInfo currentHelpInfo = null; UpdatableHelpInfo newHelpInfo = null; string str2 = null; string xml = UpdatableHelpSystem.LoadStringFromPath(this, base.SessionState.Path.Combine(module.ModuleBase, module.GetHelpInfoName()), null); if (xml != null) { currentHelpInfo = base._helpSystem.CreateHelpInfo(xml, module.ModuleName, module.ModuleGuid, null, null, false); } if (!this.alreadyCheckedOncePerDayPerModule && !base.CheckOncePerDayPerModule(module.ModuleName, module.ModuleBase, module.GetHelpInfoName(), DateTime.UtcNow, base._force)) { return(true); } this.alreadyCheckedOncePerDayPerModule = true; if (this._path != null) { //using (null) { try { Collection <string> collection = new Collection <string>(); foreach (string str4 in this._path) { if (string.IsNullOrEmpty(str4)) { PSArgumentException exception = new PSArgumentException(StringUtil.Format(HelpDisplayStrings.PathNullOrEmpty, new object[0])); base.WriteError(exception.ErrorRecord); return(false); } try { string path = str4; if (base._credential != null) { UpdatableHelpSystemDrive drive2 = new UpdatableHelpSystemDrive(this, str4, base._credential); path = drive2.DriveName; } foreach (string str6 in base.ResolvePath(path, this._recurse, this.isLiteralPath)) { collection.Add(str6); } } catch (System.Management.Automation.DriveNotFoundException exception2) { this.ThrowPathMustBeValidContainersException(str4, exception2); } catch (ItemNotFoundException exception3) { this.ThrowPathMustBeValidContainersException(str4, exception3); } } if (collection.Count == 0) { return(true); } foreach (string str7 in collection) { string str8 = base.SessionState.Path.Combine(str7, module.GetHelpInfoName()); xml = UpdatableHelpSystem.LoadStringFromPath(this, str8, base._credential); if (xml != null) { newHelpInfo = base._helpSystem.CreateHelpInfo(xml, module.ModuleName, module.ModuleGuid, culture, str7, false); str2 = str7; goto Label_02DD; } } } catch (Exception exception4) { CommandProcessorBase.CheckForSevereException(exception4); throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml", StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture), ErrorCategory.ResourceUnavailable, null, exception4); } goto Label_02DD; } } string str9 = base._helpSystem.GetHelpInfoUri(module, null).ResolvedUri + module.GetHelpInfoName(); newHelpInfo = base._helpSystem.GetHelpInfo(UpdatableHelpCommandType.UpdateHelpCommand, str9, module.ModuleName, module.ModuleGuid, culture); Label_02DD: if (newHelpInfo == null) { throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml", StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture), ErrorCategory.ResourceUnavailable, null, null); } bool flag = false; foreach (UpdatableHelpUri uri in newHelpInfo.HelpContentUriCollection) { if (!base.IsUpdateNecessary(module, currentHelpInfo, newHelpInfo, uri.Culture, base._force)) { base.WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, new object[] { module.ModuleName, HelpDisplayStrings.NewestContentAlreadyInstalled, uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture) })); flag = true; } else { try { Collection <string> collection3; string resolvedUri = uri.ResolvedUri; string xsdPath = base.SessionState.Path.Combine(Utils.GetApplicationBase(base.Context.ShellID), @"Schemas\PSMaml\maml.xsd"); Collection <string> destPaths = new Collection <string> { module.ModuleBase }; if (UpdatableHelpCommandBase.IsSystemModule(module.ModuleName) && Environment.Is64BitOperatingSystem) { string item = Utils.GetApplicationBase(Utils.DefaultPowerShellShellID).Replace("System32", "SysWOW64"); destPaths.Add(item); } if (Directory.Exists(resolvedUri)) { if (base._credential != null) { string helpContentName = module.GetHelpContentName(uri.Culture); string str14 = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); try { using (UpdatableHelpSystemDrive drive3 = new UpdatableHelpSystemDrive(this, resolvedUri, base._credential)) { if (!Directory.Exists(str14)) { Directory.CreateDirectory(str14); } base.InvokeProvider.Item.Copy(new string[] { Path.Combine(drive3.DriveName, helpContentName) }, Path.Combine(str14, helpContentName), false, CopyContainers.CopyTargetContainer, true, true); base._helpSystem.InstallHelpContent(UpdatableHelpCommandType.UpdateHelpCommand, base.Context, str14, destPaths, module.GetHelpContentName(uri.Culture), Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())), uri.Culture, xsdPath, out collection3); } goto Label_0593; } catch (Exception exception5) { CommandProcessorBase.CheckForSevereException(exception5); throw new UpdatableHelpSystemException("HelpContentNotFound", StringUtil.Format(HelpDisplayStrings.HelpContentNotFound, new object[0]), ErrorCategory.ResourceUnavailable, null, exception5); } } base._helpSystem.InstallHelpContent(UpdatableHelpCommandType.UpdateHelpCommand, base.Context, resolvedUri, destPaths, module.GetHelpContentName(uri.Culture), Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())), uri.Culture, xsdPath, out collection3); } else if (!base._helpSystem.DownloadAndInstallHelpContent(UpdatableHelpCommandType.UpdateHelpCommand, base.Context, destPaths, module.GetHelpContentName(uri.Culture), uri.Culture, resolvedUri, xsdPath, out collection3)) { flag = false; goto Label_069B; } Label_0593: base._helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture), module.ModuleBase, module.GetHelpInfoName(), base._force); foreach (string str15 in collection3) { base.WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, new object[] { module.ModuleName, StringUtil.Format(HelpDisplayStrings.UpdatedHelpContent, str15), uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture) })); } base.LogMessage(StringUtil.Format(HelpDisplayStrings.UpdateHelpCompleted, new object[0])); flag = true; } catch (Exception exception6) { CommandProcessorBase.CheckForSevereException(exception6); base.ProcessException(module.ModuleName, uri.Culture.Name, exception6); } Label_069B :; } } return(flag); }
private Dictionary <string, UpdatableHelpModuleInfo> GetModuleInfo(System.Management.Automation.ExecutionContext context, string pattern, bool loaded, bool noErrors) { List <PSModuleInfo> modules = context.Modules.GetModules(new string[] { pattern }, false); Dictionary <string, UpdatableHelpModuleInfo> dictionary = new Dictionary <string, UpdatableHelpModuleInfo>(); if (modules.Count != 0) { base.WriteDebug(StringUtil.Format("Found {0} loaded modules.", modules.Count)); foreach (PSModuleInfo info in modules) { if (InitialSessionState.IsEngineModule(info.Name) && !InitialSessionState.IsNestedEngineModule(info.Name)) { base.WriteDebug(StringUtil.Format("Found engine module: {0}, {1}.", info.Name, info.Guid)); if (!dictionary.ContainsKey(info.Name)) { dictionary.Add(info.Name, new UpdatableHelpModuleInfo(info.Name, info.Guid, Utils.GetApplicationBase(context.ShellID), metadataCache[info.Name])); } } else if (!InitialSessionState.IsNestedEngineModule(info.Name)) { if (string.IsNullOrEmpty(info.HelpInfoUri)) { if (!noErrors) { this.ProcessException(info.Name, null, new UpdatableHelpSystemException("HelpInfoUriNotFound", StringUtil.Format(HelpDisplayStrings.HelpInfoUriNotFound, new object[0]), ErrorCategory.NotSpecified, new Uri("HelpInfoUri", UriKind.Relative), null)); } } else if (!info.HelpInfoUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { if (!noErrors) { this.ProcessException(info.Name, null, new UpdatableHelpSystemException("InvalidHelpInfoUriFormat", StringUtil.Format(HelpDisplayStrings.InvalidHelpInfoUriFormat, info.HelpInfoUri), ErrorCategory.NotSpecified, new Uri("HelpInfoUri", UriKind.Relative), null)); } } else if (!dictionary.ContainsKey(info.Name)) { dictionary.Add(info.Name, new UpdatableHelpModuleInfo(info.Name, info.Guid, info.ModuleBase, info.HelpInfoUri)); } } } } WildcardOptions options = WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase; IEnumerable <WildcardPattern> patterns = SessionStateUtilities.CreateWildcardsFromStrings(new string[] { pattern }, options); if (!loaded) { Collection <PSObject> collection = base.InvokeCommand.InvokeScript("Get-Module -ListAvailable"); Collection <PSModuleInfo> collection2 = new Collection <PSModuleInfo>(); if (collection != null) { foreach (PSObject obj2 in collection) { try { collection2.Add((PSModuleInfo)LanguagePrimitives.ConvertTo(obj2, typeof(PSModuleInfo), CultureInfo.InvariantCulture)); } catch (PSInvalidCastException) { } } } base.WriteDebug(StringUtil.Format("Found {0} available (Get-Module -ListAvailable) modules.", collection2.Count)); foreach (PSModuleInfo info2 in collection2) { if (SessionStateUtilities.MatchesAnyWildcardPattern(info2.Name, patterns, true)) { if (InitialSessionState.IsEngineModule(info2.Name) && !InitialSessionState.IsNestedEngineModule(info2.Name)) { base.WriteDebug(StringUtil.Format("Found engine module: {0}, {1}.", info2.Name, info2.Guid)); if (!dictionary.ContainsKey(info2.Name)) { dictionary.Add(info2.Name, new UpdatableHelpModuleInfo(info2.Name, info2.Guid, Utils.GetApplicationBase(context.ShellID), metadataCache[info2.Name])); } } else if (!InitialSessionState.IsNestedEngineModule(info2.Name)) { if (string.IsNullOrEmpty(info2.HelpInfoUri)) { if (!noErrors) { this.ProcessException(info2.Name, null, new UpdatableHelpSystemException("HelpInfoUriNotFound", StringUtil.Format(HelpDisplayStrings.HelpInfoUriNotFound, new object[0]), ErrorCategory.NotSpecified, new Uri("HelpInfoUri", UriKind.Relative), null)); } } else if (!info2.HelpInfoUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { if (!noErrors) { this.ProcessException(info2.Name, null, new UpdatableHelpSystemException("InvalidHelpInfoUriFormat", StringUtil.Format(HelpDisplayStrings.InvalidHelpInfoUriFormat, info2.HelpInfoUri), ErrorCategory.NotSpecified, new Uri("HelpInfoUri", UriKind.Relative), null)); } } else if (!dictionary.ContainsKey(info2.Name)) { dictionary.Add(info2.Name, new UpdatableHelpModuleInfo(info2.Name, info2.Guid, info2.ModuleBase, info2.HelpInfoUri)); } } } } } foreach (KeyValuePair <string, string> pair in metadataCache) { if (SessionStateUtilities.MatchesAnyWildcardPattern(pair.Key, patterns, true)) { if (!pair.Key.Equals(InitialSessionState.CoreSnapin, StringComparison.OrdinalIgnoreCase)) { Collection <PSObject> collection3 = base.InvokeCommand.InvokeScript(StringUtil.Format("Get-Module {0} -ListAvailable", pair.Key)); Collection <PSModuleInfo> collection4 = new Collection <PSModuleInfo>(); if (collection3 != null) { foreach (PSObject obj3 in collection3) { try { collection4.Add((PSModuleInfo)LanguagePrimitives.ConvertTo(obj3, typeof(PSModuleInfo), CultureInfo.InvariantCulture)); } catch (PSInvalidCastException) { } } } foreach (PSModuleInfo info3 in collection4) { if (!dictionary.ContainsKey(info3.Name)) { base.WriteDebug(StringUtil.Format("Found engine module: {0}, {1}.", info3.Name, info3.Guid)); dictionary.Add(pair.Key, new UpdatableHelpModuleInfo(info3.Name, info3.Guid, Utils.GetApplicationBase(context.ShellID), metadataCache[info3.Name])); } } } else if (!dictionary.ContainsKey(pair.Key)) { dictionary.Add(pair.Key, new UpdatableHelpModuleInfo(pair.Key, Guid.Empty, Utils.GetApplicationBase(context.ShellID), pair.Value)); } } } return(dictionary); }