|
|
@ -200,21 +200,49 @@ namespace NzbDrone.Common
|
|
|
|
File.SetAccessControl(filename, fs);
|
|
|
|
File.SetAccessControl(filename, fs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual ulong GetAvilableSpace(string path)
|
|
|
|
public virtual long GetAvilableSpace(string path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!FolderExists(path))
|
|
|
|
if (!FolderExists(path))
|
|
|
|
throw new DirectoryNotFoundException(path);
|
|
|
|
throw new DirectoryNotFoundException(path);
|
|
|
|
|
|
|
|
|
|
|
|
ulong freeBytesAvailable;
|
|
|
|
|
|
|
|
ulong totalNumberOfBytes;
|
|
|
|
|
|
|
|
ulong totalNumberOfFreeBytes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool success = GetDiskFreeSpaceEx(path, out freeBytesAvailable, out totalNumberOfBytes,
|
|
|
|
var driveInfo = DriveInfo.GetDrives().SingleOrDefault(c => c.IsReady && c.Name.Equals(Path.GetPathRoot(path), StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
out totalNumberOfFreeBytes);
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
|
|
|
throw new System.ComponentModel.Win32Exception();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return freeBytesAvailable;
|
|
|
|
if (driveInfo == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (EnvironmentProvider.IsLinux)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DriveFreeSpaceEx(path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return driveInfo.AvailableFreeSpace;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static long DriveFreeSpaceEx(string folderName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(folderName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentNullException("folderName");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!folderName.EndsWith("\\"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
folderName += '\\';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ulong free = 0;
|
|
|
|
|
|
|
|
ulong dummy1 = 0;
|
|
|
|
|
|
|
|
ulong dummy2 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GetDiskFreeSpaceEx(folderName, out free, out dummy1, out dummy2))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return (long)free;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual string ReadAllText(string filePath)
|
|
|
|
public virtual string ReadAllText(string filePath)
|
|
|
|