@ -1,5 +1,4 @@
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Runtime.InteropServices ;
@ -18,25 +17,21 @@ namespace NzbDrone.Common
bool FileExists ( string path ) ;
string [ ] GetDirectories ( string path ) ;
string [ ] GetFiles ( string path , SearchOption searchOption ) ;
long Get Directory Size( string path ) ;
long Get Folder Size( string path ) ;
long GetFileSize ( string path ) ;
String CreateFolder ( string path ) ;
void Copy Directory ( string source , string target ) ;
void Move Directory ( string source , string destination ) ;
void Copy Folder ( string source , string target ) ;
void Move Folder ( string source , string destination ) ;
void DeleteFile ( string path ) ;
void MoveFile ( string source , string destination ) ;
void DeleteFolder ( string path , bool recursive ) ;
DateTime DirectoryDateCreated ( string path ) ;
IEnumerable < FileInfo > GetFileInfos ( string path , string pattern , SearchOption searchOption ) ;
void InheritFolderPermissions ( string filename ) ;
long GetAvilableSpace ( string path ) ;
string ReadAllText ( string filePath ) ;
void WriteAllText ( string filename , string contents ) ;
void FileSetLastWriteTimeUtc ( string path , DateTime dateTime ) ;
void DirectorySetLastWriteTimeUtc ( string path , DateTime dateTime ) ;
bool IsFolderLocked ( string path ) ;
void FolderSetLastWriteTimeUtc ( string path , DateTime dateTime ) ;
bool IsFileLocked ( FileInfo file ) ;
bool IsChildOfPath ( string child , string parent ) ;
string GetPathRoot ( string path ) ;
}
@ -125,7 +120,7 @@ namespace NzbDrone.Common
return Directory . GetFiles ( path , "*.*" , searchOption ) ;
}
public virtual long Get Directory Size( string path )
public virtual long Get Folder Size( string path )
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
@ -150,22 +145,22 @@ namespace NzbDrone.Common
return Directory . CreateDirectory ( path ) . FullName ;
}
public virtual void Copy Directory ( string source , string target )
public virtual void Copy Folder ( string source , string target )
{
Ensure . That ( ( ) = > source ) . IsValidPath ( ) ;
Ensure . That ( ( ) = > target ) . IsValidPath ( ) ;
Transfer Directory ( source , target , TransferAction . Copy ) ;
Transfer Folder ( source , target , TransferAction . Copy ) ;
}
public virtual void Move Directory ( string source , string destination )
public virtual void Move Folder ( string source , string destination )
{
Ensure . That ( ( ) = > source ) . IsValidPath ( ) ;
Ensure . That ( ( ) = > destination ) . IsValidPath ( ) ;
try
{
Transfer Directory ( source , destination , TransferAction . Move ) ;
Transfer Folder ( source , destination , TransferAction . Move ) ;
Directory . Delete ( source , true ) ;
}
catch ( Exception e )
@ -176,7 +171,7 @@ namespace NzbDrone.Common
}
}
private void Transfer Directory ( string source , string target , TransferAction transferAction )
private void Transfer Folder ( string source , string target , TransferAction transferAction )
{
Ensure . That ( ( ) = > source ) . IsValidPath ( ) ;
Ensure . That ( ( ) = > target ) . IsValidPath ( ) ;
@ -193,7 +188,7 @@ namespace NzbDrone.Common
foreach ( var subDir in sourceFolder . GetDirectories ( ) )
{
Transfer Directory ( subDir . FullName , Path . Combine ( target , subDir . Name ) , transferAction ) ;
Transfer Folder ( subDir . FullName , Path . Combine ( target , subDir . Name ) , transferAction ) ;
}
foreach ( var sourceFile in sourceFolder . GetFiles ( "*.*" , SearchOption . TopDirectoryOnly ) )
@ -251,20 +246,6 @@ namespace NzbDrone.Common
Directory . Delete ( path , recursive ) ;
}
public virtual DateTime DirectoryDateCreated ( string path )
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
return Directory . GetCreationTime ( path ) ;
}
public virtual IEnumerable < FileInfo > GetFileInfos ( string path , string pattern , SearchOption searchOption )
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
return new DirectoryInfo ( path ) . EnumerateFiles ( pattern , searchOption ) ;
}
public virtual void InheritFolderPermissions ( string filename )
{
Ensure . That ( ( ) = > filename ) . IsValidPath ( ) ;
@ -350,28 +331,13 @@ namespace NzbDrone.Common
File . SetLastWriteTimeUtc ( path , dateTime ) ;
}
public virtual void Directory SetLastWriteTimeUtc( string path , DateTime dateTime )
public virtual void Folder SetLastWriteTimeUtc( string path , DateTime dateTime )
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
Directory . SetLastWriteTimeUtc ( path , dateTime ) ;
}
public virtual bool IsFolderLocked ( string path )
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;
var files = GetFileInfos ( path , "*.*" , SearchOption . AllDirectories ) ;
foreach ( var fileInfo in files )
{
if ( IsFileLocked ( fileInfo ) )
return true ;
}
return false ;
}
public virtual bool IsFileLocked ( FileInfo file )
{
FileStream stream = null ;
@ -394,17 +360,6 @@ namespace NzbDrone.Common
return false ;
}
public virtual bool IsChildOfPath ( string child , string parent )
{
Ensure . That ( ( ) = > child ) . IsValidPath ( ) ;
Ensure . That ( ( ) = > parent ) . IsValidPath ( ) ;
if ( Path . GetFullPath ( child ) . StartsWith ( Path . GetFullPath ( parent ) ) )
return true ;
return false ;
}
public virtual string GetPathRoot ( string path )
{
Ensure . That ( ( ) = > path ) . IsValidPath ( ) ;