Beispiel #1
0
        private static string DosDeviceToDosPath(string dosDevice, string deviceReplacement)
        {
            if (Utils.IsNullOrWhiteSpace(dosDevice))
            {
                return(string.Empty);
            }

            foreach (string drive in Directory.EnumerateLogicalDrivesCore(false, false).Select(drv => drv.Name))
            {
                try
                {
                    string path = RemoveTrailingDirectorySeparator(drive, false);
                    foreach (string devNt in Volume.QueryDosDevice(path).Where(dosDevice.StartsWith))
                    {
                        return(dosDevice.Replace(devNt, deviceReplacement ?? path));
                    }
                }
                catch
                {
                }
            }
            return(string.Empty);
        }
Beispiel #2
0
        private object GetDeviceInfo(int type, int mode)
        {
            try
            {
                switch (type)
                {
                    #region Volume

                // VolumeInfo properties.
                case 0:
                    if (Utils.IsNullOrWhiteSpace(_volumeInfo.FullPath))
                    {
                        _volumeInfo.Refresh();
                    }

                    switch (mode)
                    {
                    case 0:
                        // IsVolume, VolumeInfo
                        return(_volumeInfo);

                    case 1:
                        // DriveFormat
                        return(_volumeInfo == null?DriveType.Unknown.ToString() : _volumeInfo.FileSystemName ?? DriveType.Unknown.ToString());

                    case 2:
                        // VolumeLabel
                        return(_volumeInfo == null ? string.Empty : _volumeInfo.Name ?? string.Empty);
                    }
                    break;

                // Volume related.
                case 1:
                    switch (mode)
                    {
                    case 0:
                        // DosDeviceName

                        // Do not use ?? expression here.
                        if (_dosDeviceName == null)
                        {
                            _dosDeviceName = Volume.QueryDosDevice(Name).FirstOrDefault();
                        }

                        return(_dosDeviceName);
                    }
                    break;

                    #endregion // Volume

                    #region Drive

                // Drive related.
                case 2:
                    switch (mode)
                    {
                    case 0:
                        // DriveType
                        // Do not use ?? expression here.
                        if (_driveType == null)
                        {
                            _driveType = Volume.GetDriveType(Name);
                        }

                        return(_driveType);

                    case 1:
                        // RootDirectory

                        // Do not use ?? expression here.
                        if (_rootDirectory == null)
                        {
                            _rootDirectory = new DirectoryInfo(null, Name, PathFormat.RelativePath);
                        }

                        return(_rootDirectory);
                    }
                    break;

                // DiskSpaceInfo related.
                case 3:
                    switch (mode)
                    {
                    case 0:
                        // AvailableFreeSpace, TotalFreeSpace, TotalSize, DiskSpaceInfo
                        if (!_initDsie)
                        {
                            _dsi.Refresh();
                            _initDsie = true;
                        }
                        break;
                    }
                    break;

                    #endregion // Drive
                }
            }
            catch
            {
            }

            return(type == 0 && mode > 0 ? string.Empty : null);
        }