using System.IO;
using System.Threading.Tasks;
using FubarDev.FtpServer.FileSystem;
namespace ShadowEditor.Server.Remote.FileSystem
{
///
/// A implementation that uses
/// the standard .NET functionality to provide file system access.
///
public class RemoteFileSystemProvider : IFileSystemClassFactory
{
private readonly string _rootPath;
private readonly bool _useUserIdAsSubFolder;
///
/// Initializes a new instance of the class.
///
/// The root path for all users
public RemoteFileSystemProvider(string rootPath)
: this(rootPath, false)
{
}
///
/// Initializes a new instance of the class.
///
/// The root path for all users
/// Use the user id as subfolder?
public RemoteFileSystemProvider(string rootPath, bool useUserIdAsSubFolder)
{
_rootPath = rootPath;
_useUserIdAsSubFolder = useUserIdAsSubFolder;
}
///
/// Gets or sets a value indicating whether deletion of non-empty directories is allowed.
///
public bool AllowNonEmptyDirectoryDelete { get; set; }
///
public Task Create(string userId, bool isAnonymous)
{
var path = _rootPath;
if (_useUserIdAsSubFolder)
{
if (isAnonymous)
userId = "anonymous";
path = Path.Combine(path, userId);
}
return Task.FromResult(new RemoteFileSystem(path, AllowNonEmptyDirectoryDelete));
}
}
}