using System; using System.Management; using System.Text; namespace Trigger.Classes.Device { /// /// A partition of a disk /// public class Partition { #region Properties /// The name of the public string Name { get; internal set; } /// Gets the available free space on the disk, specified in bytes. public ulong FreeSpace { get; internal set; } /// Gets the name of this disk. This is the Windows identifier, drive letter. public char DriveLetter { get; internal set; } /// Gets the total size of the disk, specified in bytes. public ulong Size { get; internal set; } #endregion #region Constructors /// /// /// public Partition(ManagementObject mo) { if (mo["VolumeName"] != null) this.Name = mo["VolumeName"].ToString(); this.DriveLetter = mo["DeviceID"].ToString()[0]; if (mo["FreeSpace"] != null) this.FreeSpace = Convert.ToUInt64(mo["FreeSpace"]); if (mo["Size"] != null) this.Size = Convert.ToUInt64(mo["Size"]); } #endregion #region Methods /// /// Pretty print the disk. /// /// public override string ToString() { StringBuilder builder = new StringBuilder(); builder.Append(this.DriveLetter); builder.Append(": "); builder.Append(this.Name); builder.Append(" ("); builder.Append(StorageDisk.FormatByte(this.FreeSpace)); builder.Append(" free of "); builder.Append(StorageDisk.FormatByte(this.Size)); builder.Append(")"); return builder.ToString(); } #endregion } }