From f87651c4a2f977a0be9c062af945c266136d1cde Mon Sep 17 00:00:00 2001 From: David Sungaila Date: Fri, 27 Sep 2024 19:54:15 +0200 Subject: [PATCH] Change a few calls to WinRT --- src/Commands/AddDriveCommands.cs | 9 ++++----- src/Commands/DriveCommands.cs | 5 +++-- src/Commands/MappingCommands.cs | 25 ++++++++----------------- src/Views/SettingsView.xaml.cs | 9 ++++++--- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/Commands/AddDriveCommands.cs b/src/Commands/AddDriveCommands.cs index 40f053d..fdf38e7 100644 --- a/src/Commands/AddDriveCommands.cs +++ b/src/Commands/AddDriveCommands.cs @@ -1,11 +1,13 @@ using CommunityToolkit.Mvvm.Input; using Sungaila.SUBSTitute.ViewModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using Windows.Storage; using Windows.Win32; using Windows.Win32.Storage.FileSystem; @@ -44,7 +46,7 @@ public static class AddDriveCommands parameter.SelectedLetter = parameter.AvailableLetters.FirstOrDefault(); }); - public static readonly IRelayCommand AddVirtualDrive = new RelayCommand(parameter => + public static readonly IRelayCommand AddVirtualDrive = new AsyncRelayCommand(async parameter => { parameter!.CancelClose = false; @@ -53,10 +55,7 @@ public static class AddDriveCommands var selectedPath = Path.GetFullPath(parameter.SelectedPath.Trim('\"')); - if (!Path.Exists(selectedPath) || File.Exists(selectedPath)) - { - throw new DirectoryNotFoundException(); - } + _ = await StorageFolder.GetFolderFromPathAsync(selectedPath); if (parameter.IsPermanent) { diff --git a/src/Commands/DriveCommands.cs b/src/Commands/DriveCommands.cs index 62bd65f..6813c21 100644 --- a/src/Commands/DriveCommands.cs +++ b/src/Commands/DriveCommands.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Input; +using Windows.System; using Windows.Win32; using Windows.Win32.Storage.FileSystem; @@ -16,9 +17,9 @@ namespace Sungaila.SUBSTitute.Commands { public static class DriveCommands { - private static readonly IRelayCommand OpenInternal = new RelayCommand(parameter => + private static readonly IRelayCommand OpenInternal = new AsyncRelayCommand(async parameter => { - Process.Start(new ProcessStartInfo(parameter!.Path) { UseShellExecute = true }); + await Launcher.LaunchFolderPathAsync(parameter!.Path); }); public static readonly ICommand Open = new StandardUICommand(StandardUICommandKind.Open) diff --git a/src/Commands/MappingCommands.cs b/src/Commands/MappingCommands.cs index 5113d3c..6bba23f 100644 --- a/src/Commands/MappingCommands.cs +++ b/src/Commands/MappingCommands.cs @@ -59,29 +59,20 @@ internal static DriveViewModel GetDriveViewModel(MappingViewModel mappingViewMod IsVirtual = IsVirtualDrive(driveInfo.Name) }; - Task.Run(() => + Task.Run(async () => { - // get the disk label + // get the disk label and file system try { - string driveDisplayName = StorageFolder.GetFolderFromPathAsync(driveInfo.Name).GetAwaiter().GetResult().DisplayName; + var folder = await StorageFolder.GetFolderFromPathAsync(driveInfo.Name); + var properties = await folder.GetBasicPropertiesAsync(); + var prop = await properties.RetrievePropertiesAsync(["System.Volume.FileSystem"]); + var filesystem = prop.First().Value as string; App.MainWindow?.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () => { - result.Label = driveDisplayName; - }); - } - catch { } - - // get the disk format - try - { - if (!driveInfo.IsReady) - return; - - App.MainWindow?.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () => - { - result.DriveFormat = driveInfo.DriveFormat; + result.Label = folder.DisplayName; + result.DriveFormat = filesystem ?? string.Empty; }); } catch { } diff --git a/src/Views/SettingsView.xaml.cs b/src/Views/SettingsView.xaml.cs index c5e829f..3d749e9 100644 --- a/src/Views/SettingsView.xaml.cs +++ b/src/Views/SettingsView.xaml.cs @@ -2,9 +2,10 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Sungaila.SUBSTitute.ViewModels; -using System.Diagnostics; +using System; using System.Reflection; using Windows.ApplicationModel; +using Windows.System; namespace Sungaila.SUBSTitute.Views { @@ -47,9 +48,11 @@ private void ComboBox_Loaded(object sender, RoutedEventArgs e) comboBox.SelectionChanged += (_, _) => App.MainWindow?.ShowInfoBar(App.ResourceLoader.GetString("SettingsRestartRequired"), InfoBarSeverity.Warning); } - private void SettingsCard_Click(object sender, RoutedEventArgs e) + private static readonly Uri _githubIssuesUri = new("https://github.com/sungaila/SUBSTitute/issues"); + + private async void SettingsCard_Click(object sender, RoutedEventArgs e) { - Process.Start(new ProcessStartInfo("https://github.com/sungaila/SUBSTitute/issues") { UseShellExecute = true }); + await Launcher.LaunchUriAsync(_githubIssuesUri); } } } \ No newline at end of file