Skip to content

Commit

Permalink
Change a few calls to WinRT
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Sep 27, 2024
1 parent fe43591 commit f87651c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
9 changes: 4 additions & 5 deletions src/Commands/AddDriveCommands.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -44,7 +46,7 @@ public static class AddDriveCommands
parameter.SelectedLetter = parameter.AvailableLetters.FirstOrDefault();
});

public static readonly IRelayCommand<AddDriveViewModel> AddVirtualDrive = new RelayCommand<AddDriveViewModel>(parameter =>
public static readonly IRelayCommand<AddDriveViewModel> AddVirtualDrive = new AsyncRelayCommand<AddDriveViewModel>(async parameter =>
{
parameter!.CancelClose = false;

Expand All @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/DriveCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Input;
using Windows.System;
using Windows.Win32;
using Windows.Win32.Storage.FileSystem;

namespace Sungaila.SUBSTitute.Commands
{
public static class DriveCommands
{
private static readonly IRelayCommand<DriveViewModel> OpenInternal = new RelayCommand<DriveViewModel>(parameter =>
private static readonly IRelayCommand<DriveViewModel> OpenInternal = new AsyncRelayCommand<DriveViewModel>(async parameter =>
{
Process.Start(new ProcessStartInfo(parameter!.Path) { UseShellExecute = true });
await Launcher.LaunchFolderPathAsync(parameter!.Path);
});

public static readonly ICommand Open = new StandardUICommand(StandardUICommandKind.Open)
Expand Down
25 changes: 8 additions & 17 deletions src/Commands/MappingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Expand Down
9 changes: 6 additions & 3 deletions src/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit f87651c

Please sign in to comment.