Example #1
0
        internal CommandProcessorBase CreateScriptProcessorForMiniShell(
            ExternalScriptInfo scriptInfo,
            bool useLocalScope)
        {
            CommandDiscovery.VerifyPSVersion(scriptInfo);
            if (string.IsNullOrEmpty(scriptInfo.RequiresApplicationID))
            {
                if (scriptInfo.RequiresPSSnapIns != null && scriptInfo.RequiresPSSnapIns.Count > 0)
                {
                    Collection <string>     psSnapinNames     = this.GetPSSnapinNames(scriptInfo.RequiresPSSnapIns);
                    ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, psSnapinNames, "ScriptRequiresMissingPSSnapIns");
                    CommandDiscovery.tracer.TraceException((Exception)requiresException);
                    throw requiresException;
                }
                return(CommandDiscovery.CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope));
            }
            if (string.Equals(this._context.ShellID, scriptInfo.RequiresApplicationID, StringComparison.OrdinalIgnoreCase))
            {
                return(CommandDiscovery.CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope));
            }
            string pathFromRegistry = CommandDiscovery.GetShellPathFromRegistry(scriptInfo.RequiresApplicationID);
            ScriptRequiresException requiresException1 = new ScriptRequiresException(scriptInfo.Name, scriptInfo.ApplicationIDLineNumber, scriptInfo.RequiresApplicationID, pathFromRegistry, "ScriptRequiresUnmatchedShellId");

            CommandDiscovery.tracer.TraceException((Exception)requiresException1);
            throw requiresException1;
        }
Example #2
0
        private static string GetMshDefaultInstallationPath()
        {
            string shellPathFromRegistry = CommandDiscovery.GetShellPathFromRegistry(Utils.DefaultPowerShellShellID);

            if (shellPathFromRegistry != null)
            {
                shellPathFromRegistry = Path.GetDirectoryName(shellPathFromRegistry);
            }
            return(shellPathFromRegistry);
        }
        /// <summary>
        /// Helper method which returns the default monad installation path based on ShellID
        /// registry key.
        /// </summary>
        /// <returns>string representing path.</returns>
        /// <remarks>
        /// If ShellID is not defined or Path property is not defined returns null.
        /// </remarks>
        private static string GetMshDefaultInstallationPath()
        {
            string returnValue = CommandDiscovery.GetShellPathFromRegistry(Utils.DefaultPowerShellShellID);

            if (returnValue != null)
            {
                returnValue = Path.GetDirectoryName(returnValue);
            }

            // returnValue can be null.
            return(returnValue);
        }
Example #4
0
        private static string GetMessageDllPath(string shellId)
        {
            string directoryName = null;

            if (!string.IsNullOrEmpty(shellId))
            {
                directoryName = Path.GetDirectoryName(CommandDiscovery.GetShellPathFromRegistry(shellId));
            }
            if (string.IsNullOrEmpty(directoryName) && (Assembly.GetEntryAssembly() != null))
            {
                directoryName = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            }
            return(Path.Combine(directoryName, "pwrshmsg.dll"));
        }
Example #5
0
        private CommandProcessorBase CreateScriptProcessorForSingleShell(
            ExternalScriptInfo scriptInfo,
            RunspaceConfigForSingleShell ssRunConfig,
            bool useLocalScope)
        {
            CommandDiscovery.VerifyPSVersion(scriptInfo);
            Collection <PSSnapInNameVersionPair> requiresPsSnapIns = scriptInfo.RequiresPSSnapIns;

            if (requiresPsSnapIns != null)
            {
                Collection <string> missingPSSnapIns = (Collection <string>)null;
                foreach (PSSnapInNameVersionPair PSSnapin in requiresPsSnapIns)
                {
                    Collection <PSSnapInInfo> psSnapIn = ssRunConfig.ConsoleInfo.GetPSSnapIn(PSSnapin.PSSnapInName, false);
                    if (psSnapIn == null || psSnapIn.Count == 0)
                    {
                        if (missingPSSnapIns == null)
                        {
                            missingPSSnapIns = new Collection <string>();
                        }
                        missingPSSnapIns.Add(CommandDiscovery.BuildPSSnapInDisplayName(PSSnapin));
                    }
                    else if (PSSnapin.Version != (Version)null && !CommandDiscovery.AreInstalledRequiresVersionsCompatible(PSSnapin.Version, psSnapIn[0].Version))
                    {
                        if (missingPSSnapIns == null)
                        {
                            missingPSSnapIns = new Collection <string>();
                        }
                        missingPSSnapIns.Add(CommandDiscovery.BuildPSSnapInDisplayName(PSSnapin));
                    }
                }
                if (missingPSSnapIns != null)
                {
                    ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, missingPSSnapIns, "ScriptRequiresMissingPSSnapIns");
                    CommandDiscovery.tracer.TraceException((Exception)requiresException);
                    throw requiresException;
                }
            }
            else if (!string.IsNullOrEmpty(scriptInfo.RequiresApplicationID))
            {
                CommandDiscovery.GetShellPathFromRegistry(scriptInfo.RequiresApplicationID);
                ScriptRequiresException requiresException = new ScriptRequiresException(scriptInfo.Name, scriptInfo.ApplicationIDLineNumber, string.Empty, string.Empty, "RequiresShellIDInvalidForSingleShell");
                CommandDiscovery.tracer.TraceException((Exception)requiresException);
                throw requiresException;
            }
            return(CommandDiscovery.CreateCommandProcessorForScript(scriptInfo, this._context, useLocalScope));
        }
Example #6
0
        internal string GetDefaultShellSearchPath()
        {
            string shellPathFromRegistry = CommandDiscovery.GetShellPathFromRegistry(this.HelpSystem.ExecutionContext.ShellID);

            if (shellPathFromRegistry == null)
            {
                return(Path.GetDirectoryName(PsUtils.GetMainModule(Process.GetCurrentProcess()).FileName));
            }
            if (OSHelper.IsWindows)
            {
                shellPathFromRegistry = Path.GetDirectoryName(shellPathFromRegistry);
            }
            if (!Directory.Exists(shellPathFromRegistry))
            {
                shellPathFromRegistry = Path.GetDirectoryName(PsUtils.GetMainModule(Process.GetCurrentProcess()).FileName);
            }
            return(shellPathFromRegistry);
        }
Example #7
0
        internal string GetDefaultShellSearchPath()
        {
            string shellId          = this.HelpSystem.ExecutionContext.ShellID;
            string pathFromRegistry = CommandDiscovery.GetShellPathFromRegistry(shellId);
            string directoryName;

            if (pathFromRegistry == null)
            {
                directoryName = Path.GetDirectoryName(PsUtils.GetMainModule(Process.GetCurrentProcess()).FileName);
                this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)HelpProvider.tracer.NewArgumentException("DefaultSearchPath", "HelpErrors", "RegistryPathNotFound", (object)Utils.GetRegistryConfigurationPath(shellId), (object)"\\Path", (object)directoryName), "LoadHelpFileForTargetFailed", ErrorCategory.OpenError, (object)null));
            }
            else
            {
                directoryName = Path.GetDirectoryName(pathFromRegistry);
                if (!Directory.Exists(directoryName))
                {
                    directoryName = Path.GetDirectoryName(PsUtils.GetMainModule(Process.GetCurrentProcess()).FileName);
                    this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)HelpProvider.tracer.NewArgumentException("DefaultSearchPath", "HelpErrors", "RegistryPathNotFound", (object)Utils.GetRegistryConfigurationPath(shellId), (object)"\\Path", (object)"\\Path", (object)directoryName), "LoadHelpFileForTargetFailed", ErrorCategory.OpenError, (object)null));
                }
            }
            return(directoryName);
        }
Example #8
0
        /// <summary>
        /// Each Shell ( minishell ) will have its own path specified by the
        /// registry HKLM\software\microsoft\msh\1\ShellIds\&lt;ShellID&gt;\path. Every help
        /// provider should search this path for content.
        /// </summary>
        /// <returns>string representing base directory of the executing shell.</returns>
        internal string GetDefaultShellSearchPath()
        {
            string shellID     = this.HelpSystem.ExecutionContext.ShellID;
            string returnValue = CommandDiscovery.GetShellPathFromRegistry(shellID);

            if (returnValue == null)
            {
                // use executing assemblies location in case registry entry not found
                returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName);
            }
            else
            {
                // Get the directory path of the executing shell
                returnValue = Path.GetDirectoryName(returnValue);
                if (!Directory.Exists(returnValue))
                {
                    // use executing assemblies location in case registry entry not found
                    returnValue = Path.GetDirectoryName(PsUtils.GetMainModule(System.Diagnostics.Process.GetCurrentProcess()).FileName);
                }
            }

            return(returnValue);
        }