-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathFileExplorerService.cs
72 lines (62 loc) · 2.52 KB
/
FileExplorerService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Avalonia.Platform.Storage;
using SecureFolderFS.AvaloniaUI.Helpers;
using SecureFolderFS.AvaloniaUI.WindowViews;
using SecureFolderFS.Sdk.Services;
using SecureFolderFS.Sdk.Storage;
using SecureFolderFS.Sdk.Storage.LocatableStorage;
using SecureFolderFS.Shared.Extensions;
using SecureFolderFS.UI.Storage.NativeStorage;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
namespace SecureFolderFS.AvaloniaUI.ServiceImplementation
{
/// <inheritdoc cref="IFileExplorerService"/>
internal sealed class FileExplorerService : IFileExplorerService
{
/// <inheritdoc/>
public Task OpenAppFolderAsync(CancellationToken cancellationToken = default)
{
LauncherHelpers.Launch(App.AppDirectory);
return Task.CompletedTask;
}
/// <inheritdoc/>
public Task OpenInFileExplorerAsync(IFolder folder, CancellationToken cancellationToken = default)
{
if (folder is not ILocatableFolder locatableFolder)
return Task.CompletedTask;
LauncherHelpers.Launch(locatableFolder.Path);
return Task.CompletedTask;
}
/// <inheritdoc/>
public async Task<ILocatableFile?> PickSingleFileAsync(IEnumerable<string>? filter, CancellationToken cancellationToken = default)
{
var file = (await MainWindow.Instance.StorageProvider.OpenFilePickerAsync(new()
{
AllowMultiple = false,
FileTypeFilter = filter is null
? new List<FilePickerFileType>(new[] { new FilePickerFileType("*") }).AsReadOnly()
: filter.Select(x => new FilePickerFileType(x)).ToList().AsReadOnly()
})).FirstOrDefault();
if (file is null)
return null;
return new NativeFile(HttpUtility.UrlDecode(file.Path.AbsolutePath));
}
/// <inheritdoc/>
public async Task<ILocatableFolder?> PickSingleFolderAsync(CancellationToken cancellationToken = default)
{
var folder = await MainWindow.Instance.StorageProvider.OpenFolderPickerAsync(new()
{
AllowMultiple = false
});
if (folder.IsEmpty())
return null;
var firstFolder = folder.FirstOrDefault();
if (firstFolder is null)
return null;
return new NativeFolder(HttpUtility.UrlDecode(firstFolder.Path.AbsolutePath));
}
}
}