Пример #1
0
        public string GetCurrentDirectory(string path = null)
        {
            string volume = path == null ? lastVolume : extendedFileService.GetCanonicalRoot(fileService, path);

            string directory;

            if (this.volumeDirectories.TryGetValue(volume, out directory))
            {
                AddEntry(directory, volume);
                return(directory);
            }
            else
            {
                // Try to get the hidden environment variable (e.g. "=C:") for the given drive if available
                string driveLetter = extendedFileService.GetDriveLetter(fileService, path);
                if (driveLetter != null)
                {
                    string environmentPath = NativeMethods.GetEnvironmentVariable("=" + driveLetter.Substring(0, 2));
                    if (environmentPath != null)
                    {
                        AddEntry(environmentPath);
                        return(environmentPath);
                    }
                }

                // Nothing is set yet, assume the root
                string root = Paths.GetRoot(path);
                AddEntry(root);
                return(root);
            }
        }
Пример #2
0
        /// <summary>
        /// Get the current directory for the volume of the given path. If no path is given, returns the volume for the last
        /// set current directory.
        /// </summary>
        public string GetCurrentDirectory(string path = null)
        {
            // Find the path's volume or use the last set volume if there is no path
            string volume = path == null ? _lastVolume : _extendedFileService.GetCanonicalRoot(_fileService, path);

            string directory;

            if (_volumeDirectories.TryGetValue(volume, out directory))
            {
                // We have a current directory from this volume
                AddEntry(directory, volume);
                return(directory);
            }
            else
            {
                // No current directory yet for this volume

                // Try to get the hidden environment variable (e.g. "=C:") for the given drive if available
                string driveLetter = _extendedFileService.GetDriveLetter(_fileService, path);
                if (!string.IsNullOrEmpty(driveLetter))
                {
                    string environmentPath = Processes.GetEnvironmentVariable("=" + driveLetter.Substring(0, 2));
                    if (environmentPath != null)
                    {
                        AddEntry(environmentPath);
                        return(environmentPath);
                    }
                }

                // No stashed environment variable, add the root of the path as our current directory
                string root = Paths.GetRoot(path);
                AddEntry(root);
                return(root);
            }
        }