| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="DriveExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.IO; |
| | | 8 | | |
| | | 9 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 10 | | namespace MyNet.IO; |
| | | 11 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Result codes used by disk drive checks. |
| | | 15 | | /// </summary> |
| | | 16 | | public enum DiskDriveInfo |
| | | 17 | | { |
| | | 18 | | /// <summary>No error detected.</summary> |
| | | 19 | | NoError, |
| | | 20 | | |
| | | 21 | | /// <summary>Drive is not found or not ready.</summary> |
| | | 22 | | DiskNotFound, |
| | | 23 | | |
| | | 24 | | /// <summary>Drive has not enough free space for requested operation.</summary> |
| | | 25 | | InsufficientSpace |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Extension methods for <see cref="DriveInfo"/>. |
| | | 30 | | /// </summary> |
| | | 31 | | public static class DriveExtensions |
| | | 32 | | { |
| | | 33 | | extension(DriveInfo driveInfo) |
| | | 34 | | { |
| | | 35 | | /// <summary> |
| | | 36 | | /// Checks whether the drive has at least the requested amount of free space. |
| | | 37 | | /// </summary> |
| | | 38 | | /// <param name="space">Minimum required free space in bytes.</param> |
| | | 39 | | /// <returns>A <see cref="DiskDriveInfo"/> value describing the result.</returns> |
| | 15 | 40 | | public DiskDriveInfo HasEnoughSpace(double space) => !driveInfo.IsReady |
| | 15 | 41 | | ? DiskDriveInfo.DiskNotFound |
| | 15 | 42 | | : driveInfo.TotalFreeSpace >= space |
| | 15 | 43 | | ? DiskDriveInfo.NoError |
| | 15 | 44 | | : DiskDriveInfo.InsufficientSpace; |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | |