mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
Moved FreeDiskSpace to DiskProvider.
This commit is contained in:
parent
401b3b13e2
commit
95cdc4b78c
6 changed files with 59 additions and 29 deletions
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Ionic.Zip;
|
||||
using NLog;
|
||||
|
||||
|
@ -9,6 +10,13 @@ namespace NzbDrone.Core.Providers.Core
|
|||
{
|
||||
public class DiskProvider
|
||||
{
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
|
||||
out ulong lpFreeBytesAvailable,
|
||||
out ulong lpTotalNumberOfBytes,
|
||||
out ulong lpTotalNumberOfFreeBytes);
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public virtual bool FolderExists(string path)
|
||||
|
@ -96,5 +104,19 @@ namespace NzbDrone.Core.Providers.Core
|
|||
fs.SetAccessRuleProtection(false, false);
|
||||
File.SetAccessControl(filename, fs);
|
||||
}
|
||||
|
||||
public virtual ulong FreeDiskSpace(DirectoryInfo directoryInfo)
|
||||
{
|
||||
ulong freeBytesAvailable;
|
||||
ulong totalNumberOfBytes;
|
||||
ulong totalNumberOfFreeBytes;
|
||||
|
||||
bool success = GetDiskFreeSpaceEx(directoryInfo.FullName, out freeBytesAvailable, out totalNumberOfBytes,
|
||||
out totalNumberOfFreeBytes);
|
||||
if (!success)
|
||||
throw new System.ComponentModel.Win32Exception();
|
||||
|
||||
return freeBytesAvailable;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue