Пример #1
0
        private static void AddDrives(StringBuilder builder)
        {
            var values = new List <string[]>();

            foreach (var d in DriveInfo.GetDrives())
            {
                var row = new string[7];
                row[0] = d.Name;
                row[1] = d.DriveType.ToString();

                var    dashString = Dash.ToString();
                string driveFormat = dashString, volumeLabel = dashString;
                double capacity = 0, free = 0, available = 0;

                if (d.IsReady)
                {
                    driveFormat = d.DriveFormat;
                    volumeLabel = d.VolumeLabel;
                    capacity    = UnitConverter.BytesToGigaBytes(d.TotalSize);
                    free        = UnitConverter.BytesToGigaBytes(d.TotalFreeSpace);
                    available   = UnitConverter.BytesToGigaBytes(d.AvailableFreeSpace);
                }

                row[2] = driveFormat;
                row[3] = volumeLabel;
                row[4] = capacity.ToString("N0");
                row[5] = free.ToString("N0");
                row[6] = available.ToString("N0");

                values.Add(row);
            }

            WrapInTable(builder, DrivesHeaders, values);
        }
Пример #2
0
        private static DriveDetails[] GetDriveDetails(DiagnosticReportType type)
        {
            if (!IsReportEnabled(type, DiagnosticReportType.Drives))
            {
                return(null);
            }

            return(DriveInfo.GetDrives()
                   .Select(d =>
            {
                var dashString = Dash.ToString();
                string driveFormat = string.Empty, volumeLabel = string.Empty;
                double capacity = 0, free = 0, available = 0;

                if (d.IsReady)
                {
                    // ReSharper disable once ConstantNullCoalescingCondition
                    driveFormat = d.DriveFormat ?? dashString;
                    volumeLabel = d.VolumeLabel ?? dashString;
                    capacity = UnitConverter.BytesToGigaBytes(d.TotalSize);
                    free = UnitConverter.BytesToGigaBytes(d.TotalFreeSpace);
                    available = UnitConverter.BytesToGigaBytes(d.AvailableFreeSpace);
                }

                return new DriveDetails
                {
                    Name = d.Name,
                    Type = d.DriveType.ToString(),
                    Format = driveFormat,
                    Label = volumeLabel,
                    TotalCapacityInGigaBytes = capacity,
                    FreeCapacityInGigaBytes = free,
                    AvailableCapacityInGigaBytes = available
                };
            })
                   .ToArray());
        }