LocalFileSystemProvider now starts at Drive View (#6)
* LocalFileSystemProvider now starts at Drive View. * Resolve conflicts * Formatting, back button fix * Exclude drives that are not ready
This commit is contained in:
Родитель
8a8c3dd8c9
Коммит
469f718b5d
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Camelotia.Services.Interfaces;
|
||||
using Camelotia.Services.Providers;
|
||||
|
@ -34,5 +35,21 @@ namespace Camelotia.Presentation.Tests
|
|||
.GetAttributes(path)
|
||||
.HasFlag(FileAttributes.Directory));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldReturnDrivesFromAnEmptyPath()
|
||||
{
|
||||
var real = await _provider.Get(_provider.InitialPath);
|
||||
var expected = DriveInfo
|
||||
.GetDrives()
|
||||
.Where(p => p.DriveType != DriveType.CDRom && p.IsReady)
|
||||
.ToList();
|
||||
|
||||
foreach (var model in real)
|
||||
expected.Should().Contain(drive =>
|
||||
model.Name == drive.Name &&
|
||||
model.IsFolder == false &&
|
||||
model.IsDrive);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -95,8 +95,7 @@ namespace Camelotia.Presentation.Tests
|
|||
[Fact]
|
||||
public void ShouldBeAbleToOpenSelectedPath() => new TestScheduler().With(scheduler =>
|
||||
{
|
||||
|
||||
var file = new FileModel("foo", Separator + "foo", true, string.Empty);
|
||||
var file = new FileModel("foo", Separator + "foo", true, false, string.Empty);
|
||||
_provider.Get(Separator).Returns(Enumerable.Repeat(file, 1));
|
||||
_authViewModel.IsAuthenticated.Returns(true);
|
||||
_provider.InitialPath.Returns(Separator);
|
||||
|
|
|
@ -66,16 +66,16 @@ namespace Camelotia.Presentation.ViewModels
|
|||
|
||||
var canOpenCurrentPath = this
|
||||
.WhenAnyValue(x => x.SelectedFile)
|
||||
.Select(file => file != null && file.IsFolder)
|
||||
.Select(file => file != null && (file.IsFolder || file.IsDrive))
|
||||
.CombineLatest(_refresh.IsExecuting, (folder, busy) => folder && !busy);
|
||||
|
||||
_open = ReactiveCommand.Create(
|
||||
() => Path.Combine(CurrentPath, SelectedFile.Name),
|
||||
() => Path.Combine(CurrentPath ?? string.Empty, SelectedFile.Name),
|
||||
canOpenCurrentPath, mainThread);
|
||||
|
||||
var canCurrentPathGoBack = this
|
||||
.WhenAnyValue(x => x.CurrentPath)
|
||||
.Select(path => path?.Length > 1)
|
||||
.Select(path => path?.Length > provider.InitialPath.Length)
|
||||
.CombineLatest(_refresh.IsExecuting, (valid, busy) => valid && !busy);
|
||||
|
||||
_back = ReactiveCommand.Create(
|
||||
|
@ -120,7 +120,7 @@ namespace Camelotia.Presentation.ViewModels
|
|||
|
||||
var canDownloadSelectedFile = this
|
||||
.WhenAnyValue(x => x.SelectedFile)
|
||||
.Select(file => file != null && !file.IsFolder)
|
||||
.Select(file => file != null && !file.IsFolder && !file.IsDrive)
|
||||
.DistinctUntilChanged();
|
||||
|
||||
_downloadSelectedFile = ReactiveCommand.CreateFromObservable(
|
||||
|
@ -137,7 +137,7 @@ namespace Camelotia.Presentation.ViewModels
|
|||
.Subscribe(Console.WriteLine);
|
||||
|
||||
this.WhenAnyValue(x => x.SelectedFile)
|
||||
.Where(file => file != null && file.IsFolder)
|
||||
.Where(file => file != null && (file.IsFolder || file.IsDrive))
|
||||
.Buffer(2, 1)
|
||||
.Select(files => (files.First().Path, files.Last().Path))
|
||||
.DistinctUntilChanged()
|
||||
|
|
|
@ -2,20 +2,22 @@ namespace Camelotia.Services.Models
|
|||
{
|
||||
public sealed class FileModel
|
||||
{
|
||||
public FileModel(string name, string path, bool isFolder, string size)
|
||||
public FileModel(string name, string path, bool isFolder, bool isDrive, string size)
|
||||
{
|
||||
Name = name;
|
||||
Path = path;
|
||||
Size = size;
|
||||
IsFolder = isFolder;
|
||||
IsDrive = isDrive;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
public bool IsFolder { get; }
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
|
||||
public string Path { get; }
|
||||
|
||||
|
||||
public bool IsFolder { get; }
|
||||
|
||||
public bool IsDrive { get; }
|
||||
|
||||
public string Size { get; }
|
||||
}
|
||||
}
|
|
@ -17,14 +17,14 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public string Description => "Provides access to files stored locally.";
|
||||
|
||||
public string InitialPath { get; } = Path.DirectorySeparatorChar.ToString();
|
||||
|
||||
public IObservable<bool> IsAuthorized { get; } = Observable.Return(true);
|
||||
|
||||
public bool SupportsDirectAuth => false;
|
||||
|
||||
public bool SupportsOAuth => false;
|
||||
|
||||
public string InitialPath => string.Empty;
|
||||
|
||||
public Task OAuth() => Task.CompletedTask;
|
||||
|
||||
public Task Logout() => Task.CompletedTask;
|
||||
|
@ -33,13 +33,24 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public Task<IEnumerable<FileModel>> Get(string path) => Task.Run(() =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
var driveQuery = from entity in GetAllDrives()
|
||||
where entity.IsReady
|
||||
let size = ByteConverter.BytesToString(entity.AvailableFreeSpace)
|
||||
select new FileModel(entity.Name, entity.Name, false, true, size);
|
||||
return driveQuery
|
||||
.ToList()
|
||||
.AsEnumerable();
|
||||
}
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
throw new ArgumentException("Directory doesn't exist.");
|
||||
|
||||
var query = from entity in Directory.GetFileSystemEntries(path)
|
||||
let isDirectory = IsDirectory(entity)
|
||||
let size = isDirectory ? "*" : ByteConverter.BytesToString(new FileInfo(entity).Length)
|
||||
select new FileModel(Path.GetFileName(entity), entity, isDirectory, size);
|
||||
select new FileModel(Path.GetFileName(entity), entity, isDirectory, false, size);
|
||||
|
||||
return query
|
||||
.ToList()
|
||||
|
@ -79,18 +90,26 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
private static string GetSizeOnAllDisks()
|
||||
{
|
||||
var totalBytes = DriveInfo
|
||||
.GetDrives()
|
||||
.Where(p => p.DriveType != DriveType.CDRom)
|
||||
var totalBytes = GetAllDrives()
|
||||
.Select(x => x.AvailableFreeSpace)
|
||||
.Sum();
|
||||
|
||||
return ByteConverter.BytesToString(totalBytes);
|
||||
}
|
||||
|
||||
private static IEnumerable<DriveInfo> GetAllDrives()
|
||||
{
|
||||
var drives = DriveInfo
|
||||
.GetDrives()
|
||||
.Where(p => p.DriveType != DriveType.CDRom);
|
||||
|
||||
return drives;
|
||||
}
|
||||
|
||||
private static bool IsDirectory(string path)
|
||||
{
|
||||
var attributes = File.GetAttributes(path);
|
||||
|
||||
return attributes.HasFlag(FileAttributes.Directory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,14 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public string Description => "Vkontakte documents provider";
|
||||
|
||||
public string InitialPath { get; } = "Documents";
|
||||
|
||||
public IObservable<bool> IsAuthorized => _isAuthorized;
|
||||
|
||||
public bool SupportsDirectAuth => true;
|
||||
|
||||
public bool SupportsOAuth => false;
|
||||
|
||||
public string InitialPath => Path.DirectorySeparatorChar.ToString();
|
||||
|
||||
public Task OAuth() => Task.CompletedTask;
|
||||
|
||||
public async Task DirectAuth(string login, string password)
|
||||
|
@ -76,7 +76,7 @@ namespace Camelotia.Services.Providers
|
|||
var size = string.Empty;
|
||||
if (document.Size.HasValue)
|
||||
size = ByteConverter.BytesToString(document.Size.Value);
|
||||
return new FileModel(document.Title, document.Uri, false, size);
|
||||
return new FileModel(document.Title, document.Uri, false, false, size);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -33,14 +33,14 @@ namespace Camelotia.Services.Providers
|
|||
|
||||
public string Description => "Yandex Disk file provider";
|
||||
|
||||
public string InitialPath { get; } = Path.DirectorySeparatorChar.ToString();
|
||||
|
||||
public IObservable<bool> IsAuthorized => _isAuthorized;
|
||||
|
||||
public bool SupportsDirectAuth => false;
|
||||
|
||||
public bool SupportsOAuth => true;
|
||||
|
||||
|
||||
public string InitialPath => Path.DirectorySeparatorChar.ToString();
|
||||
|
||||
public Task DirectAuth(string login, string password) => Task.CompletedTask;
|
||||
|
||||
public async Task<IEnumerable<FileModel>> Get(string path)
|
||||
|
@ -61,6 +61,7 @@ namespace Camelotia.Services.Providers
|
|||
file.Name,
|
||||
file.Path.Replace("disk:", ""),
|
||||
file.Type == "dir",
|
||||
false,
|
||||
ByteConverter.BytesToString(file.Size)));
|
||||
|
||||
return models;
|
||||
|
|
Загрузка…
Ссылка в новой задаче