mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
dec085142b
...UnauthorizedAccessException (particularly when the search all starts from the root directory of an NTFS drive.)
72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace LibHac
|
|
{
|
|
public class FileSystem : IFileSystem
|
|
{
|
|
public string Root { get; }
|
|
|
|
public FileSystem(string rootDir)
|
|
{
|
|
Root = Path.GetFullPath(rootDir);
|
|
}
|
|
|
|
public bool FileExists(string path)
|
|
{
|
|
return File.Exists(Path.Combine(Root, path));
|
|
}
|
|
|
|
public bool DirectoryExists(string path)
|
|
{
|
|
return Directory.Exists(Path.Combine(Root, path));
|
|
}
|
|
|
|
public Stream OpenFile(string path, FileMode mode)
|
|
{
|
|
return new FileStream(Path.Combine(Root, path), mode);
|
|
}
|
|
|
|
public Stream OpenFile(string path, FileMode mode, FileAccess access)
|
|
{
|
|
return new FileStream(Path.Combine(Root, path), mode, access);
|
|
}
|
|
|
|
public string[] GetFileSystemEntries(string path, string searchPattern)
|
|
{
|
|
return Directory.GetFileSystemEntries(Path.Combine(Root, path), searchPattern);
|
|
}
|
|
|
|
public string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)
|
|
{
|
|
//return Directory.GetFileSystemEntries(Path.Combine(Root, path), searchPattern, searchOption);
|
|
var result = new List<string>();
|
|
|
|
try
|
|
{
|
|
result.AddRange(GetFileSystemEntries(Path.Combine(Root, path), searchPattern));
|
|
}
|
|
catch { /**/ }
|
|
|
|
if (searchOption == SearchOption.TopDirectoryOnly)
|
|
return result.ToArray();
|
|
|
|
var searchDirectories = Directory.GetDirectories(Path.Combine(Root, path));
|
|
foreach (var search in searchDirectories)
|
|
{
|
|
try
|
|
{
|
|
result.AddRange(GetFileSystemEntries(search, searchPattern, searchOption));
|
|
}
|
|
catch { /**/ }
|
|
}
|
|
|
|
return result.ToArray();
|
|
}
|
|
|
|
public string GetFullPath(string path)
|
|
{
|
|
return Path.Combine(Root, path);
|
|
}
|
|
}
|
|
}
|