diff --git a/PeyrSharp.Env/FileSys.cs b/PeyrSharp.Env/FileSys.cs index 9e5b003..c2d5193 100644 --- a/PeyrSharp.Env/FileSys.cs +++ b/PeyrSharp.Env/FileSys.cs @@ -208,5 +208,38 @@ public static DriveInfo DriveWithHighestFreeSpace /// /// if the drive is an optical drive; if it isn't. public static bool IsDriveOpticalDrive(DriveInfo driveInfo) => driveInfo.DriveType == DriveType.CDRom; + + /// + /// Gets the appropriate to use depending of the total size of the drive. + /// + /// The drive to get the unit of. + /// The appropriate unit of the specified drive. + public static StorageUnits GetDriveStorageUnit(DriveInfo driveInfo) + { + if (driveInfo.TotalSize >= Math.Pow(1024, 5)) + { + return StorageUnits.Petabyte; + } + else if (driveInfo.TotalSize >= Math.Pow(1024, 4)) + { + return StorageUnits.Terabyte; + } + else if (driveInfo.TotalSize >= 1073741824) + { + return StorageUnits.Gigabyte; + } + else if (driveInfo.TotalSize >= 1048576) + { + return StorageUnits.Megabyte; + } + else if (driveInfo.TotalSize >= 1024) + { + return StorageUnits.Kilobyte; + } + else + { + return StorageUnits.Byte; + } + } } }