This commit is contained in:
2020-05-22 18:17:33 +00:00
parent a26d849dd6
commit 00bf436b53

View File

@@ -102,7 +102,7 @@ namespace AyaNova.Util
public class BackupFileInfo
{
public long length { get; set; }
public string length { get; set; }
public string Name { get; set; }
public DateTime Created { get; set; }
@@ -110,11 +110,11 @@ namespace AyaNova.Util
public class BackupStatus
{
public long AvailableFreeSpace { get; set; }
public string AvailableFreeSpace { get; set; }
public List<BackupFileInfo> BackupFiles { get; set; }
public BackupStatus()
{
AvailableFreeSpace = 0;
AvailableFreeSpace = null;
BackupFiles = new List<BackupFileInfo>();
}
}
@@ -129,11 +129,11 @@ namespace AyaNova.Util
BackupStatus statusReport = new BackupStatus();
try
{
statusReport.AvailableFreeSpace = new System.IO.DriveInfo(Path.GetPathRoot(UtilityFilesFolder)).AvailableFreeSpace;
statusReport.AvailableFreeSpace = GetBytesReadable(new System.IO.DriveInfo(Path.GetPathRoot(UtilityFilesFolder)).AvailableFreeSpace);
}
catch (Exception ex)
{
statusReport.AvailableFreeSpace = -1;
statusReport.AvailableFreeSpace = "ERROR";
ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("FileUtil::BackupStatus");
log.LogError(ex, "FileUtil::BackupStatusReport error getting available space");
}
@@ -146,7 +146,7 @@ namespace AyaNova.Util
statusReport.BackupFiles.Add(new BackupFileInfo()
{
Name = Path.GetFileName(file),
length = fi.Length,
length = GetBytesReadable(fi.Length),
Created = fi.CreationTimeUtc
});
}
@@ -529,6 +529,57 @@ namespace AyaNova.Util
#region General utilities
//https://stackoverflow.com/a/11124118/8939
// Returns the human-readable file size for an arbitrary, 64-bit file size
// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB"
public static string GetBytesReadable(long i)
{
// Get absolute value
long absolute_i = (i < 0 ? -i : i);
// Determine the suffix and readable value
string suffix;
double readable;
if (absolute_i >= 0x1000000000000000) // Exabyte
{
suffix = "EB";
readable = (i >> 50);
}
else if (absolute_i >= 0x4000000000000) // Petabyte
{
suffix = "PB";
readable = (i >> 40);
}
else if (absolute_i >= 0x10000000000) // Terabyte
{
suffix = "TB";
readable = (i >> 30);
}
else if (absolute_i >= 0x40000000) // Gigabyte
{
suffix = "GB";
readable = (i >> 20);
}
else if (absolute_i >= 0x100000) // Megabyte
{
suffix = "MB";
readable = (i >> 10);
}
else if (absolute_i >= 0x400) // Kilobyte
{
suffix = "KB";
readable = i;
}
else
{
return i.ToString("0 B"); // Byte
}
// Divide by 1024 to get fractional value
readable = (readable / 1024);
// Return formatted number with suffix
return readable.ToString("0.### ") + suffix;
}
/// <summary>
/// Attachments / user files folder size info
/// </summary>