diff --git a/Src/Denovo/App.axaml.cs b/Src/Denovo/App.axaml.cs index db0a802..9b7724d 100644 --- a/Src/Denovo/App.axaml.cs +++ b/Src/Denovo/App.axaml.cs @@ -57,6 +57,7 @@ public override void OnFrameworkInitializationCompleted() DataContext = vm }; vm.Clipboard = desktop.MainWindow.Clipboard; + vm.StorageProvider = desktop.MainWindow.StorageProvider; } base.OnFrameworkInitializationCompleted(); diff --git a/Src/Denovo/ViewModels/ConfigurationViewModel.cs b/Src/Denovo/ViewModels/ConfigurationViewModel.cs index f1f7c24..455c6d1 100644 --- a/Src/Denovo/ViewModels/ConfigurationViewModel.cs +++ b/Src/Denovo/ViewModels/ConfigurationViewModel.cs @@ -4,13 +4,12 @@ // file LICENCE or http://www.opensource.org/licenses/mit-license.php. using Autarkysoft.Bitcoin; -using Avalonia; -using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Platform.Storage; using Denovo.Models; using Denovo.MVVM; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; namespace Denovo.ViewModels { @@ -77,16 +76,19 @@ public bool HasPendingChanges } public bool IsChanged { get; private set; } - + public IStorageProvider StorageProvider { get; set; } public async void SetBlockchainDir() { - var open = new OpenFolderDialog(); - var lf = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime; - string dir = await open.ShowAsync(lf.MainWindow); - if (!string.IsNullOrEmpty(dir)) + FolderPickerOpenOptions opts = new() + { + AllowMultiple = false, + Title = "Blockchain directory" + }; + IReadOnlyList dir = await StorageProvider.OpenFolderPickerAsync(opts); + if (dir != null && dir.Count > 0) { - Config.BlockchainPath = dir; + Config.BlockchainPath= dir.ElementAt(0).Path.LocalPath; } } diff --git a/Src/Denovo/ViewModels/MainWindowViewModel.cs b/Src/Denovo/ViewModels/MainWindowViewModel.cs index e443665..d37dd7e 100644 --- a/Src/Denovo/ViewModels/MainWindowViewModel.cs +++ b/Src/Denovo/ViewModels/MainWindowViewModel.cs @@ -8,6 +8,7 @@ using Autarkysoft.Bitcoin.P2PNetwork; using Autarkysoft.Bitcoin.P2PNetwork.Messages; using Avalonia.Input.Platform; +using Avalonia.Platform.Storage; using Denovo.Models; using Denovo.MVVM; using Denovo.Services; @@ -56,6 +57,7 @@ public MainWindowViewModel(NetworkType network) public NodePool AllNodes { get; set; } public IClipboard Clipboard { get; set; } + public IStorageProvider StorageProvider { get; set; } public IWindowManager WinMan { get; set; } public IDenovoFileManager FileMan { get; set; } public bool IsInitialized { get; } @@ -112,7 +114,10 @@ public async void OpenConfig() config = new Configuration(Network) { IsDefault = true }; } - ConfigurationViewModel vm = new(config); + ConfigurationViewModel vm = new(config) + { + StorageProvider = StorageProvider + }; await WinMan.ShowDialog(vm); if (vm.IsChanged) @@ -214,7 +219,7 @@ public string Result public bool CanDisconnect() => SelectedNode != null; public void Disconnect() { - if (!(SelectedNode is null)) + if (SelectedNode is not null) { AllNodes.Remove(SelectedNode); }