Пример #1
0
        private static CanDoPathLookupResult CanDoPathLookup(string possiblePath)
        {
            CanDoPathLookupResult yes = CanDoPathLookupResult.Yes;

            if (WildcardPattern.ContainsWildcardCharacters(possiblePath))
            {
                return(CanDoPathLookupResult.WildcardCharacters);
            }
            try
            {
                if (!string.IsNullOrEmpty(possiblePath))
                {
                    if (Path.IsPathRooted(possiblePath.Replace("\"", "")))
                    {
                        return(CanDoPathLookupResult.PathIsRooted);
                    }
                }
            }
            catch (ArgumentException)
            {
                return(CanDoPathLookupResult.IllegalCharacters);
            }
            if (possiblePath.IndexOfAny(Utils.DirectorySeparators) != -1)
            {
                return(CanDoPathLookupResult.DirectorySeparator);
            }
            if (possiblePath.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                yes = CanDoPathLookupResult.IllegalCharacters;
            }
            return(yes);
        }
Пример #2
0
 private void setupPathSearcher()
 {
     if (this.pathSearcher == null)
     {
         HashSet <string> allowedExtensions = new HashSet <string>();
         allowedExtensions = this._context.CommandDiscovery.GetAllowedExtensionsFromPathExt();
         allowedExtensions.Add(".ps1");
         if ((this.commandResolutionOptions & SearchResolutionOptions.CommandNameIsPattern) != SearchResolutionOptions.None)
         {
             this.canDoPathLookup       = true;
             this.canDoPathLookupResult = CanDoPathLookupResult.Yes;
             Collection <string> patterns = new Collection <string> {
                 this.commandName
             };
             this.pathSearcher = new CommandPathSearch(patterns, this._context.CommandDiscovery.GetLookupDirectoryPaths(), allowedExtensions, false, this._context);
         }
         else
         {
             this.canDoPathLookupResult = CanDoPathLookup(this.commandName);
             if (this.canDoPathLookupResult == CanDoPathLookupResult.Yes)
             {
                 this.canDoPathLookup = true;
                 this.pathSearcher    = new CommandPathSearch(this.ConstructSearchPatternsFromName(this.commandName), this._context.CommandDiscovery.GetLookupDirectoryPaths(), allowedExtensions, false, this._context);
             }
             else if (this.canDoPathLookupResult == CanDoPathLookupResult.PathIsRooted)
             {
                 this.canDoPathLookup = true;
                 string directoryName            = Path.GetDirectoryName(this.commandName);
                 Collection <string> lookupPaths = new Collection <string> {
                     directoryName
                 };
                 CommandDiscovery.discoveryTracer.WriteLine("The path is rooted, so only doing the lookup in the specified directory: {0}", new object[] { directoryName });
                 string fileName = Path.GetFileName(this.commandName);
                 if (!string.IsNullOrEmpty(fileName))
                 {
                     this.pathSearcher = new CommandPathSearch(this.ConstructSearchPatternsFromName(fileName), lookupPaths, allowedExtensions, false, this._context);
                 }
                 else
                 {
                     this.canDoPathLookup = false;
                 }
             }
             else if (this.canDoPathLookupResult == CanDoPathLookupResult.DirectorySeparator)
             {
                 this.canDoPathLookup = true;
                 string path = Path.GetDirectoryName(this.commandName);
                 path = this.ResolvePSPath(path);
                 CommandDiscovery.discoveryTracer.WriteLine("The path is relative, so only doing the lookup in the specified directory: {0}", new object[] { path });
                 if (path == null)
                 {
                     this.canDoPathLookup = false;
                 }
                 else
                 {
                     Collection <string> collection5 = new Collection <string> {
                         path
                     };
                     string str4 = Path.GetFileName(this.commandName);
                     if (!string.IsNullOrEmpty(str4))
                     {
                         this.pathSearcher = new CommandPathSearch(this.ConstructSearchPatternsFromName(str4), collection5, allowedExtensions, false, this._context);
                     }
                     else
                     {
                         this.canDoPathLookup = false;
                     }
                 }
             }
         }
     }
 }