csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.4 KiB
70 lines
2.4 KiB
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Platform.Storage;
|
|
using Avalonia.Platform.Storage.FileIO;
|
|
|
|
namespace Avalonia.Native;
|
|
|
|
internal sealed class StorageProviderImpl(TopLevelImpl topLevel, StorageProviderApi native) : IStorageProvider
|
|
{
|
|
public bool CanOpen => true;
|
|
|
|
public bool CanSave => true;
|
|
|
|
public bool CanPickFolder => true;
|
|
|
|
public Task<IReadOnlyList<IStorageFile>> OpenFilePickerAsync(FilePickerOpenOptions options)
|
|
{
|
|
return native.OpenFileDialog(topLevel, options);
|
|
}
|
|
|
|
public async Task<IStorageFile?> SaveFilePickerAsync(FilePickerSaveOptions options)
|
|
{
|
|
var (file, _) = await native.SaveFileDialog(topLevel, options).ConfigureAwait(false);
|
|
return file;
|
|
}
|
|
|
|
public async Task<SaveFilePickerResult> SaveFilePickerWithResultAsync(FilePickerSaveOptions options)
|
|
{
|
|
var (file, selectedType) = await native.SaveFileDialog(topLevel, options).ConfigureAwait(false);
|
|
return new SaveFilePickerResult(file) { SelectedFileType = selectedType };
|
|
}
|
|
|
|
public Task<IReadOnlyList<IStorageFolder>> OpenFolderPickerAsync(FolderPickerOpenOptions options)
|
|
{
|
|
return native.SelectFolderDialog(topLevel, options);
|
|
}
|
|
|
|
public Task<IStorageBookmarkFile?> OpenFileBookmarkAsync(string bookmark)
|
|
{
|
|
return Task.FromResult(native.TryGetStorageItem(native.ReadBookmark(bookmark, false)) as IStorageBookmarkFile);
|
|
}
|
|
|
|
public Task<IStorageBookmarkFolder?> OpenFolderBookmarkAsync(string bookmark)
|
|
{
|
|
return Task.FromResult(native.TryGetStorageItem(native.ReadBookmark(bookmark, true)) as IStorageBookmarkFolder);
|
|
}
|
|
|
|
public Task<IStorageFile?> TryGetFileFromPathAsync(Uri fileUri)
|
|
{
|
|
return Task.FromResult(native.TryGetStorageItem(fileUri) as IStorageFile);
|
|
}
|
|
|
|
public Task<IStorageFolder?> TryGetFolderFromPathAsync(Uri folderPath)
|
|
{
|
|
return Task.FromResult(native.TryGetStorageItem(folderPath) as IStorageFolder);
|
|
}
|
|
|
|
public Task<IStorageFolder?> TryGetWellKnownFolderAsync(WellKnownFolder wellKnownFolder)
|
|
{
|
|
if (BclStorageProvider.TryGetWellKnownFolderCore(wellKnownFolder) is { } directoryInfo)
|
|
{
|
|
return Task.FromResult<IStorageFolder?>(new BclStorageFolder(directoryInfo));
|
|
}
|
|
|
|
return Task.FromResult<IStorageFolder?>(null);
|
|
}
|
|
}
|
|
|