示例#1
0
        protected override string GetChildName(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new NullReferenceException("Path can't be null");
            }

            path = PathIntrinsics.NormalizePath(path);
            path = path.TrimEnd('\\');

            int num = path.LastIndexOf('\\');

            if (num == -1)
            {
                return(MakeSlashedPath(path));
            }
            return(path.Substring(num + 1));
        }
        protected virtual string GetChildName(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new NullReferenceException("Path can't be null");
            }

            path = PathIntrinsics.NormalizePath(path);
            path = path.TrimEnd(PathIntrinsics.CorrectSlash);

            int iLastSlash = path.LastIndexOf('\\');

            if (iLastSlash == -1)
            {
                return(path);
            }

            return(path.Substring(iLastSlash + 1));
        }
示例#3
0
        internal PathInfo SetLocation(string path, ProviderRuntime providerRuntime)
        {
            // TODO: deal with paths starting with ".\"

            if (path == null)
            {
                throw new NullReferenceException("Path can't be null");
            }

            path = PathIntrinsics.NormalizePath(path);

            ProviderInfo provider  = null;
            string       driveName = null;

            string      str          = path;
            string      providerId   = null;
            PSDriveInfo currentDrive = CurrentDrive;

            // If path doesn't start with a drive name
            if (path.StartsWith(PathIntrinsics.CorrectSlash.ToString()))
            {
                provider = CurrentLocation.Provider;
            }
            else if (PathIntrinsics.IsAbsolutePath(path, out driveName))
            {
                _currentDrive = GetDrive(driveName, null);

                path = PathIntrinsics.NormalizePath(PathIntrinsics.RemoveDriveName(path));
            }

            _currentDrive.CurrentLocation = path;

            _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive;

            SetVariable("PWD", CurrentLocation);
            return(CurrentLocation);


            PSDriveInfo drive = CurrentDrive;

            SetLocation(path);
        }
        protected virtual string GetParentPath(string path, string root)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new NullReferenceException("Path can't be empty");
            }

            if ((root == null) && (PSDriveInfo != null))
            {
                root = PSDriveInfo.Root;
            }

            path = PathIntrinsics.NormalizePath(path);
            path = path.TrimEnd(PathIntrinsics.CorrectSlash);

            if (root != null)
            {
                if (string.Equals(path, root, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(string.Empty);
                }
            }

            int iLastSlash = path.LastIndexOf(PathIntrinsics.CorrectSlash);

            if (iLastSlash > 0)
            {
                return(path.Substring(0, iLastSlash));
            }

            if (iLastSlash == 1)
            {
                return(PathIntrinsics.CorrectSlash.ToString());
            }

            return(string.Empty);
        }
        // internals
        //internal string GetChildName(string path, System.Management.Automation.CmdletProviderContext context);
        //internal string GetParentPath(string path, string root, System.Management.Automation.CmdletProviderContext context);
        //internal bool IsItemContainer(string path, System.Management.Automation.CmdletProviderContext context);
        //internal string MakePath(string parent, string child, System.Management.Automation.CmdletProviderContext context);
        //internal void MoveItem(string path, string destination, System.Management.Automation.CmdletProviderContext context);
        //internal object MoveItemDynamicParameters(string path, string destination, System.Management.Automation.CmdletProviderContext context);
        //internal string NormalizeRelativePath(string path, string basePath, System.Management.Automation.CmdletProviderContext context);

        internal static string NormalizePath(string path)
        {
            return(PathIntrinsics.NormalizePath(path));
        }
示例#6
0
        // internals
        //internal string GetChildName(Path path, System.Management.Automation.CmdletProviderContext context);
        //internal string GetParentPath(Path path, string root, System.Management.Automation.CmdletProviderContext context);
        //internal bool IsItemContainer(Path path, System.Management.Automation.CmdletProviderContext context);
        //internal string MakePath(string parent, string child, System.Management.Automation.CmdletProviderContext context);
        //internal void MoveItem(Path path, string destination, System.Management.Automation.CmdletProviderContext context);
        //internal object MoveItemDynamicParameters(Path path, string destination, System.Management.Automation.CmdletProviderContext context);
        //internal string NormalizeRelativePath(Path path, string basePath, System.Management.Automation.CmdletProviderContext context);

        internal static Path NormalizePath(Path path)
        {
            return(PathIntrinsics.NormalizePath(path));
        }