mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-22 22:15:17 -04:00
Added Disk space information to system.
(cherry picked from commit 91625019378247b1c6ab85afaee23f2855e3298b)
This commit is contained in:
committed by
Mark McDowall
parent
4510ca8fa1
commit
041e767f3d
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Api.DiskSpace
|
||||
{
|
||||
public class DiskSpaceModule :NzbDroneRestModule<DiskSpaceResource>
|
||||
{
|
||||
public DiskSpaceModule():base("diskspace")
|
||||
{
|
||||
GetResourceAll = GetFreeSpace;
|
||||
}
|
||||
public List<DiskSpaceResource> GetFreeSpace()
|
||||
{
|
||||
return (DriveInfo.GetDrives()
|
||||
.Where(driveInfo => driveInfo.DriveType == DriveType.Fixed)
|
||||
.Select(
|
||||
driveInfo =>
|
||||
new DiskSpaceResource()
|
||||
{
|
||||
DriveLetter = driveInfo.Name,
|
||||
FreeSpace = SizeSuffix(driveInfo.TotalFreeSpace),
|
||||
TotalSpace = SizeSuffix(driveInfo.TotalSize)
|
||||
})).ToList();
|
||||
}
|
||||
|
||||
static string SizeSuffix(Int64 value)
|
||||
{
|
||||
string[] suffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||
int i = 0;
|
||||
decimal dValue = (decimal)value;
|
||||
while (Math.Round(dValue / 1024) >= 1)
|
||||
{
|
||||
dValue /= 1024;
|
||||
i++;
|
||||
}
|
||||
|
||||
return string.Format("{0:n1}{1}", dValue, suffixes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user