Updated Utilities

This commit is contained in:
Tal Aloni 2018-11-30 14:38:05 +02:00
parent 41474b87ac
commit 73b6c288a4
2 changed files with 38 additions and 0 deletions

View file

@ -22,6 +22,17 @@ namespace Utilities
return ListEntriesInDirectory(@"\"); return ListEntriesInDirectory(@"\");
} }
public virtual List<KeyValuePair<string, ulong>> ListDataStreams(string path)
{
FileSystemEntry entry = GetEntry(path);
List<KeyValuePair<string, ulong>> result = new List<KeyValuePair<string, ulong>>();
if (!entry.IsDirectory)
{
result.Add(new KeyValuePair<string, ulong>("::$DATA", entry.Size));
}
return result;
}
public Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share) public Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share)
{ {
return OpenFile(path, mode, access, share, FileOptions.None); return OpenFile(path, mode, access, share, FileOptions.None);
@ -59,6 +70,24 @@ namespace Utilities
destinationStream.Close(); destinationStream.Close();
} }
public virtual bool Exists(string path)
{
try
{
GetEntry(path);
}
catch (FileNotFoundException)
{
return false;
}
catch (DirectoryNotFoundException)
{
return false;
}
return true;
}
public abstract string Name public abstract string Name
{ {
get; get;

View file

@ -7,6 +7,8 @@ namespace Utilities
public interface IFileSystem public interface IFileSystem
{ {
/// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.ArgumentException"></exception>
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
/// <exception cref="System.IO.FileNotFoundException"></exception>
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="System.IO.IOException"></exception>
/// <exception cref="System.UnauthorizedAccessException"></exception> /// <exception cref="System.UnauthorizedAccessException"></exception>
FileSystemEntry GetEntry(string path); FileSystemEntry GetEntry(string path);
@ -43,6 +45,13 @@ namespace Utilities
/// <exception cref="System.UnauthorizedAccessException"></exception> /// <exception cref="System.UnauthorizedAccessException"></exception>
List<FileSystemEntry> ListEntriesInDirectory(string path); List<FileSystemEntry> ListEntriesInDirectory(string path);
/// <exception cref="System.ArgumentException"></exception>
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
/// <exception cref="System.IO.FileNotFoundException"></exception>
/// <exception cref="System.IO.IOException"></exception>
/// <exception cref="System.UnauthorizedAccessException"></exception>
List<KeyValuePair<string, ulong>> ListDataStreams(string path);
/// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.ArgumentException"></exception>
/// <exception cref="System.IO.DirectoryNotFoundException"></exception> /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
/// <exception cref="System.IO.FileNotFoundException"></exception> /// <exception cref="System.IO.FileNotFoundException"></exception>