/// <summary> /// Process a single module with a given culture. /// </summary> /// <param name="module">Module to process.</param> /// <param name="culture">Culture to use.</param> /// <returns>True if the module has been processed, false if not.</returns> internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, string culture) { UpdatableHelpInfo currentHelpInfo = null; 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(moduleBase, module.GetHelpInfoName()), null); if (xml != null) { // constructing the helpinfo object from previous update help log xml.. // no need to resolve the uri's in this case. currentHelpInfo = _helpSystem.CreateHelpInfo(xml, module.ModuleName, module.ModuleGuid, currentCulture: null, pathOverride: null, verbose: false, shouldResolveUri: false, // ignore validation exception if _force is true ignoreValidationException: _force); } // Don't update too frequently if (!_alreadyCheckedOncePerDayPerModule && !CheckOncePerDayPerModule(module.ModuleName, moduleBase, module.GetHelpInfoName(), DateTime.UtcNow, _force)) { return(true); } _alreadyCheckedOncePerDayPerModule = true; if (_path != null) { UpdatableHelpSystemDrive helpInfoDrive = null; try { Collection <string> resolvedPaths = new Collection <string>(); // Search for the HelpInfo XML foreach (string path in _path) { if (string.IsNullOrEmpty(path)) { PSArgumentException e = new PSArgumentException(StringUtil.Format(HelpDisplayStrings.PathNullOrEmpty)); WriteError(e.ErrorRecord); return(false); } try { string sourcePath = path; if (_credential != null) { UpdatableHelpSystemDrive drive = new UpdatableHelpSystemDrive(this, path, _credential); sourcePath = drive.DriveName; } // Expand wildcard characters foreach (string tempPath in ResolvePath(sourcePath, _recurse, _isLiteralPath)) { resolvedPaths.Add(tempPath); } } catch (System.Management.Automation.DriveNotFoundException e) { ThrowPathMustBeValidContainersException(path, e); } catch (ItemNotFoundException e) { ThrowPathMustBeValidContainersException(path, e); } } if (resolvedPaths.Count == 0) { return(true); } // Everything in resolvedPaths is a container foreach (string resolvedPath in resolvedPaths) { string literalPath = SessionState.Path.Combine(resolvedPath, module.GetHelpInfoName()); xml = UpdatableHelpSystem.LoadStringFromPath(this, literalPath, _credential); if (xml != null) { newHelpInfo = _helpSystem.CreateHelpInfo(xml, module.ModuleName, module.ModuleGuid, culture, resolvedPath, verbose: false, shouldResolveUri: true, ignoreValidationException: false); helpInfoUri = resolvedPath; break; } } } catch (Exception e) { throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml", StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture), ErrorCategory.ResourceUnavailable, null, e); } finally { if (helpInfoDrive != null) { helpInfoDrive.Dispose(); } } } else { // Form the actual HelpInfo.xml uri helpInfoUri = _helpSystem.GetHelpInfoUri(module, null).ResolvedUri; string uri = helpInfoUri + module.GetHelpInfoName(); newHelpInfo = _helpSystem.GetHelpInfo(UpdatableHelpCommandType.UpdateHelpCommand, uri, module.ModuleName, module.ModuleGuid, culture); } if (newHelpInfo == null) { throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml", StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture), ErrorCategory.ResourceUnavailable, null, null); } bool installed = false; foreach (UpdatableHelpUri contentUri in newHelpInfo.HelpContentUriCollection) { Version currentHelpVersion = (currentHelpInfo != null) ? currentHelpInfo.GetCultureVersion(contentUri.Culture) : null; string updateHelpShouldProcessAction = string.Format(CultureInfo.InvariantCulture, HelpDisplayStrings.UpdateHelpShouldProcessActionMessage, module.ModuleName, (currentHelpVersion != null) ? currentHelpVersion.ToString() : "0.0.0.0", newHelpInfo.GetCultureVersion(contentUri.Culture), contentUri.Culture); if (!this.ShouldProcess(updateHelpShouldProcessAction, "Update-Help")) { continue; } if (Utils.IsUnderProductFolder(moduleBase) && (!Utils.IsAdministrator())) { string message = StringUtil.Format(HelpErrors.UpdatableHelpRequiresElevation); ProcessException(module.ModuleName, null, new UpdatableHelpSystemException("UpdatableHelpSystemRequiresElevation", message, ErrorCategory.InvalidOperation, null, null)); return(false); } if (!IsUpdateNecessary(module, _force ? null : currentHelpInfo, newHelpInfo, contentUri.Culture, _force)) { WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, module.ModuleName, HelpDisplayStrings.NewestContentAlreadyInstalled, contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture))); installed = true; continue; } else { try { Debug.Assert(helpInfoUri != null, "If we are here, helpInfoUri must not be null"); string helpContentUri = contentUri.ResolvedUri; string xsdPath = SessionState.Path.Combine(Utils.GetApplicationBase(Context.ShellID), "Schemas\\PSMaml\\maml.xsd"); // TODO: Edit the maml XSDs and change this // Gather destination paths Collection <string> destPaths = new Collection <string>(); 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) { string path = Utils.DefaultPowerShellAppBase.Replace("System32", "SysWOW64"); destPaths.Add(path); } #endif Collection <string> filesInstalled; if (Directory.Exists(helpContentUri)) { if (_credential != null) { string helpContentName = module.GetHelpContentName(contentUri.Culture); string tempContentPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())); try { using (UpdatableHelpSystemDrive drive = new UpdatableHelpSystemDrive(this, helpContentUri, _credential)) { if (!Directory.Exists(tempContentPath)) { Directory.CreateDirectory(tempContentPath); } InvokeProvider.Item.Copy(new string[1] { Path.Combine(drive.DriveName, helpContentName) }, Path.Combine(tempContentPath, helpContentName), false, CopyContainers.CopyTargetContainer, true, true); // Local _helpSystem.InstallHelpContent(UpdatableHelpCommandType.UpdateHelpCommand, Context, tempContentPath, destPaths, module.GetHelpContentName(contentUri.Culture), Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())), contentUri.Culture, xsdPath, out filesInstalled); } } catch (Exception e) { throw new UpdatableHelpSystemException("HelpContentNotFound", StringUtil.Format(HelpDisplayStrings.HelpContentNotFound), ErrorCategory.ResourceUnavailable, null, e); } } else { _helpSystem.InstallHelpContent(UpdatableHelpCommandType.UpdateHelpCommand, Context, helpContentUri, destPaths, module.GetHelpContentName(contentUri.Culture), Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())), contentUri.Culture, xsdPath, out filesInstalled); } } else { // Remote // Download and install help content if (!_helpSystem.DownloadAndInstallHelpContent(UpdatableHelpCommandType.UpdateHelpCommand, Context, destPaths, module.GetHelpContentName(contentUri.Culture), contentUri.Culture, helpContentUri, xsdPath, out filesInstalled)) { installed = false; continue; } } _helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture), moduleBase, module.GetHelpInfoName(), _force); foreach (string fileInstalled in filesInstalled) { WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, module.ModuleName, StringUtil.Format(HelpDisplayStrings.UpdatedHelpContent, fileInstalled), contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture))); } LogMessage(StringUtil.Format(HelpDisplayStrings.UpdateHelpCompleted)); installed = true; } catch (Exception e) { ProcessException(module.ModuleName, contentUri.Culture.Name, e); } } } return(installed); }
/// <summary> /// Process a single module with a given culture /// </summary> /// <param name="module">module to process</param> /// <param name="culture">culture to use</param> /// <returns>true if the module has been processed, false if not</returns> internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, string culture) { Collection <string> resolvedPaths = new Collection <string>(); // Search for the HelpInfo XML foreach (string path in _path) { UpdatableHelpSystemDrive helpInfoDrive = null; try { if (String.IsNullOrEmpty(path)) { PSArgumentException e = new PSArgumentException(StringUtil.Format(HelpDisplayStrings.PathNullOrEmpty)); WriteError(e.ErrorRecord); return(false); } string destPath = path; if (_credential != null) { if (path.Contains("*")) { // Deal with wildcards int index = path.IndexOf("*", StringComparison.OrdinalIgnoreCase); if (index == 0) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, path), ErrorCategory.InvalidArgument, null, new ItemNotFoundException()); } else { int i = index; for (; i >= 0; i--) { if (path[i].Equals('/') || path[i].Equals('\\')) { break; } } if (i == 0) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, path), ErrorCategory.InvalidArgument, null, new ItemNotFoundException()); } helpInfoDrive = new UpdatableHelpSystemDrive(this, path.Substring(0, i), _credential); destPath = Path.Combine(helpInfoDrive.DriveName, path.Substring(i + 1, path.Length - (i + 1))); } } else { helpInfoDrive = new UpdatableHelpSystemDrive(this, path, _credential); destPath = helpInfoDrive.DriveName; } } if (_isLiteralPath) { string destinationPath = GetUnresolvedProviderPathFromPSPath(destPath); if (!Directory.Exists(destinationPath)) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, path), ErrorCategory.InvalidArgument, null, new ItemNotFoundException()); } resolvedPaths.Add(destinationPath); } else { try { // Expand wildcard characters foreach (string tempPath in ResolvePath(destPath, false, false)) { resolvedPaths.Add(tempPath); } } catch (ItemNotFoundException e) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, path), ErrorCategory.InvalidArgument, null, e); } } } finally { if (helpInfoDrive != null) { helpInfoDrive.Dispose(); } } } if (resolvedPaths.Count == 0) { return(true); } bool installed = false; foreach (string path in resolvedPaths) { UpdatableHelpInfo currentHelpInfo = null; UpdatableHelpInfo newHelpInfo = null; string helpInfoUri = null; // if -force is specified, no need to read from the current HelpInfo.xml file // because it won't be used for checking "IsUpdateNecessary" string xml = _force ? null : UpdatableHelpSystem.LoadStringFromPath(this, SessionState.Path.Combine(path, module.GetHelpInfoName()), _credential); if (xml != null) { // constructing the helpinfo object from previous update help log xml.. // no need to resolve the uri's in this case. currentHelpInfo = _helpSystem.CreateHelpInfo(xml, module.ModuleName, module.ModuleGuid, currentCulture: null, pathOverride: null, verbose: false, shouldResolveUri: false, ignoreValidationException: false); } // Don't update too frequently if (!_alreadyCheckedOncePerDayPerModule && !CheckOncePerDayPerModule(module.ModuleName, path, module.GetHelpInfoName(), DateTime.UtcNow, _force)) { return(true); } _alreadyCheckedOncePerDayPerModule = true; // Form the actual HelpInfo.xml uri helpInfoUri = _helpSystem.GetHelpInfoUri(module, null).ResolvedUri; string uri = helpInfoUri + module.GetHelpInfoName(); newHelpInfo = _helpSystem.GetHelpInfo(_commandType, uri, module.ModuleName, module.ModuleGuid, culture); if (newHelpInfo == null) { throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml", StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture), ErrorCategory.ResourceUnavailable, null, null); } string tempPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetTempFileName())); foreach (UpdatableHelpUri contentUri in newHelpInfo.HelpContentUriCollection) { if (!IsUpdateNecessary(module, currentHelpInfo, newHelpInfo, contentUri.Culture, _force)) { WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, module.ModuleName, HelpDisplayStrings.NewestContentAlreadyDownloaded, contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture))); installed = true; continue; } else { Debug.Assert(helpInfoUri != null, "If we are here, helpInfoUri must not be null"); string helpContentUri = contentUri.ResolvedUri; string helpContentName = module.GetHelpContentName(contentUri.Culture); UpdatableHelpSystemDrive helpContentDrive = null; try { if (Directory.Exists(helpContentUri)) { File.Copy(SessionState.Path.Combine(helpContentUri, helpContentName), SessionState.Path.Combine(path, helpContentName), true); } else { // Remote if (_credential != null) { try { helpContentDrive = new UpdatableHelpSystemDrive(this, path, _credential); if (!_helpSystem.DownloadHelpContent(_commandType, tempPath, helpContentUri, helpContentName, culture)) { installed = false; continue; } InvokeProvider.Item.Copy(new string[1] { tempPath }, helpContentDrive.DriveName, true, CopyContainers.CopyChildrenOfTargetContainer, true, true); } catch (Exception e) { CommandProcessorBase.CheckForSevereException(e); ProcessException(module.ModuleName, contentUri.Culture.Name, e); installed = false; continue; } } else { if (!_helpSystem.DownloadHelpContent(_commandType, path, helpContentUri, helpContentName, culture)) { installed = false; continue; } } } if (_credential != null) { _helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture), tempPath, module.GetHelpInfoName(), _force); InvokeProvider.Item.Copy(new string[1] { Path.Combine(tempPath, module.GetHelpInfoName()) }, Path.Combine(helpContentDrive.DriveName, module.GetHelpInfoName()), false, CopyContainers.CopyTargetContainer, true, true); } else { _helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture), path, module.GetHelpInfoName(), _force); } WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, module.ModuleName, StringUtil.Format(HelpDisplayStrings.SavedHelpContent, System.IO.Path.Combine(path, helpContentName)), contentUri.Culture.Name, newHelpInfo.GetCultureVersion(contentUri.Culture))); LogMessage(StringUtil.Format(HelpDisplayStrings.SaveHelpCompleted, path)); } catch (Exception e) { CommandProcessorBase.CheckForSevereException(e); ProcessException(module.ModuleName, contentUri.Culture.Name, e); } finally { if (helpContentDrive != null) { helpContentDrive.Dispose(); } } } } installed = true; } return(installed); }
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); }
internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, string culture) { Collection <string> collection = new Collection <string>(); foreach (string str in this._path) { UpdatableHelpSystemDrive drive = null; using (drive) { if (string.IsNullOrEmpty(str)) { PSArgumentException exception = new PSArgumentException(StringUtil.Format(HelpDisplayStrings.PathNullOrEmpty, new object[0])); base.WriteError(exception.ErrorRecord); return(false); } string path = str; if (base._credential != null) { if (str.Contains("*")) { int index = str.IndexOf("*", StringComparison.OrdinalIgnoreCase); if (index == 0) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, str), ErrorCategory.InvalidArgument, null, new ItemNotFoundException()); } int length = index; while (length >= 0) { char ch = str[length]; if (ch.Equals('/')) { break; } char ch2 = str[length]; if (ch2.Equals('\\')) { break; } length--; } if (length == 0) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, str), ErrorCategory.InvalidArgument, null, new ItemNotFoundException()); } drive = new UpdatableHelpSystemDrive(this, str.Substring(0, length), base._credential); path = Path.Combine(drive.DriveName, str.Substring(length + 1, str.Length - (length + 1))); } else { drive = new UpdatableHelpSystemDrive(this, str, base._credential); path = drive.DriveName; } } if (this.isLiteralPath) { string unresolvedProviderPathFromPSPath = base.GetUnresolvedProviderPathFromPSPath(path); if (!Directory.Exists(unresolvedProviderPathFromPSPath)) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, str), ErrorCategory.InvalidArgument, null, new ItemNotFoundException()); } collection.Add(unresolvedProviderPathFromPSPath); } else { try { foreach (string str4 in base.ResolvePath(path, false, false)) { collection.Add(str4); } } catch (ItemNotFoundException exception2) { throw new UpdatableHelpSystemException("PathMustBeValidContainers", StringUtil.Format(HelpDisplayStrings.PathMustBeValidContainers, str), ErrorCategory.InvalidArgument, null, exception2); } } } } if (collection.Count == 0) { return(true); } bool flag = false; foreach (string str5 in collection) { UpdatableHelpInfo currentHelpInfo = null; UpdatableHelpInfo newHelpInfo = null; string xml = UpdatableHelpSystem.LoadStringFromPath(this, base.SessionState.Path.Combine(str5, module.GetHelpInfoName()), base._credential); if (xml != null) { currentHelpInfo = base._helpSystem.CreateHelpInfo(xml, module.ModuleName, module.ModuleGuid, null, null, false); } if (!this.alreadyCheckedOncePerDayPerModule && !base.CheckOncePerDayPerModule(module.ModuleName, str5, module.GetHelpInfoName(), DateTime.UtcNow, base._force)) { return(true); } this.alreadyCheckedOncePerDayPerModule = true; string str8 = base._helpSystem.GetHelpInfoUri(module, null).ResolvedUri + module.GetHelpInfoName(); newHelpInfo = base._helpSystem.GetHelpInfo(base._commandType, str8, module.ModuleName, module.ModuleGuid, culture); if (newHelpInfo == null) { throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml", StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture), ErrorCategory.ResourceUnavailable, null, null); } 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.NewestContentAlreadyDownloaded, uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture) })); flag = true; } else { string resolvedUri = uri.ResolvedUri; string helpContentName = module.GetHelpContentName(uri.Culture); string str11 = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetTempFileName())); UpdatableHelpSystemDrive drive2 = null; using (drive2) { try { if (Directory.Exists(resolvedUri)) { File.Copy(base.SessionState.Path.Combine(resolvedUri, helpContentName), base.SessionState.Path.Combine(str5, helpContentName), true); } else { if (base._credential != null) { try { drive2 = new UpdatableHelpSystemDrive(this, str5, base._credential); if (!base._helpSystem.DownloadHelpContent(base._commandType, str11, resolvedUri, helpContentName, culture)) { flag = false; goto Label_0641; } base.InvokeProvider.Item.Copy(new string[] { str11 }, drive2.DriveName, true, CopyContainers.CopyChildrenOfTargetContainer, true, true); goto Label_04C2; } catch (Exception exception3) { CommandProcessorBase.CheckForSevereException(exception3); base.ProcessException(module.ModuleName, uri.Culture.Name, exception3); flag = false; goto Label_0641; } } if (!base._helpSystem.DownloadHelpContent(base._commandType, str5, resolvedUri, helpContentName, culture)) { flag = false; goto Label_0641; } } Label_04C2: if (base._credential != null) { base._helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture), str11, module.GetHelpInfoName(), base._force); base.InvokeProvider.Item.Copy(new string[] { Path.Combine(str11, module.GetHelpInfoName()) }, Path.Combine(drive2.DriveName, module.GetHelpInfoName()), false, CopyContainers.CopyTargetContainer, true, true); } else { base._helpSystem.GenerateHelpInfo(module.ModuleName, module.ModuleGuid, newHelpInfo.UnresolvedUri, uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture), str5, module.GetHelpInfoName(), base._force); } base.WriteVerbose(StringUtil.Format(HelpDisplayStrings.SuccessfullyUpdatedHelpContent, new object[] { module.ModuleName, StringUtil.Format(HelpDisplayStrings.SavedHelpContent, Path.Combine(str5, helpContentName)), uri.Culture.Name, newHelpInfo.GetCultureVersion(uri.Culture) })); base.LogMessage(StringUtil.Format(HelpDisplayStrings.SaveHelpCompleted, str5)); } catch (Exception exception4) { CommandProcessorBase.CheckForSevereException(exception4); base.ProcessException(module.ModuleName, uri.Culture.Name, exception4); } } Label_0641 :; } } flag = true; } return(flag); }