HardDisk类添加异常捕获

croire 3 years ago
parent 6c8a738e02
commit f93306509d

@ -1,4 +1,6 @@
using System.IO;
using DownKyi.Core.Logging;
using System;
using System.IO;
namespace DownKyi.Core.Utils
{
@ -11,7 +13,10 @@ namespace DownKyi.Core.Utils
/// <returns></returns>
public static long GetHardDiskSpace(string hardDiskName)
{
long totalSize = new long();
long totalSize = 0;
try
{
hardDiskName = $"{hardDiskName}:\\";
DriveInfo[] drives = DriveInfo.GetDrives();
@ -22,6 +27,12 @@ namespace DownKyi.Core.Utils
totalSize = drive.TotalSize;
}
}
}
catch (Exception e)
{
Debugging.Console.PrintLine("GetHardDiskSpace()发生异常: {0}", e);
LogManager.Error("HardDisk", e);
}
return totalSize;
}
@ -33,7 +44,9 @@ namespace DownKyi.Core.Utils
/// <returns></returns>
public static long GetHardDiskFreeSpace(string hardDiskName)
{
long freeSpace = new long();
long freeSpace = 0;
try
{
hardDiskName = $"{hardDiskName}:\\";
DriveInfo[] drives = DriveInfo.GetDrives();
@ -44,6 +57,12 @@ namespace DownKyi.Core.Utils
freeSpace = drive.TotalFreeSpace;
}
}
}
catch (Exception e)
{
Debugging.Console.PrintLine("GetHardDiskFreeSpace()发生异常: {0}", e);
LogManager.Error("HardDisk", e);
}
return freeSpace;
}

Loading…
Cancel
Save