Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Fixed: GetDriveWithHighestFreeSpace() doesn't work with optical dri…
Browse files Browse the repository at this point in the history
…ves (#350)
  • Loading branch information
lpeyr committed Aug 3, 2022
1 parent b3f79a9 commit 1523450
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions LeoCorpLibrary.Core/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,23 @@ public static bool IsDirectoryHasPermission(string filePath)
/// Gets the drive with the higest free space available.
/// </summary>
/// <returns>A <see cref="DriveInfo"/> value, which contains the information of the drive.</returns>
public static DriveInfo GetDriveWithHighestFreeSpace() => DriveInfo.GetDrives().OrderBy(d => d.TotalFreeSpace).Last();
public static DriveInfo GetDriveWithHighestFreeSpace()
{
var drives = DriveInfo.GetDrives(); // Get all drives
drives = drives.Where(x => x.DriveType != DriveType.CDRom).ToArray(); // Remove CD-ROM
return drives.OrderByDescending(x => x.TotalFreeSpace).First(); // Return the drive with the highest free space
}

/// <summary>
/// Gets the drive with the lowest free space available.
/// </summary>
/// <returns>A <see cref="DriveInfo"/> value, which contains the information of the drive.</returns>
public static DriveInfo GetDriveWithLowestFreeSpace() => DriveInfo.GetDrives().OrderBy(d => d.TotalFreeSpace).First();
public static DriveInfo GetDriveWithLowestFreeSpace()
{
var drives = DriveInfo.GetDrives(); // Get all drives
drives = drives.Where(x => x.DriveType != DriveType.CDRom).ToArray(); // Remove CD-ROM
return drives.OrderBy(x => x.TotalFreeSpace).First(); // Return the drive with the lowest free space
}

/// <summary>
/// Gets the appropriate <see cref="UnitType"/> to use depending of the total size of the drive.
Expand Down

0 comments on commit 1523450

Please sign in to comment.