private async void DeviceGrid_ItemClick(object sender, ItemClickEventArgs e) { LibraryGrid.SelectedIndex = -1; if (!SettingControl.IsDoubleClickEnable && e.ClickedItem is HardDeviceInfo Device) { if (Device.IsLockedByBitlocker) { Retry: BitlockerPasswordDialog Dialog = new BitlockerPasswordDialog(); if (await Dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { await Exclusive.Controller.RunAsync("powershell.exe", true, true, true, "-Command", $"$BitlockerSecureString = ConvertTo-SecureString '{Dialog.Password}' -AsPlainText -Force;", $"Unlock-BitLocker -MountPoint '{Device.Folder.Path}' -Password $BitlockerSecureString").ConfigureAwait(true); } StorageFolder DeviceFolder = await StorageFolder.GetFolderFromPathAsync(Device.Folder.Path); BasicProperties Properties = await DeviceFolder.GetBasicPropertiesAsync(); IDictionary <string, object> PropertiesRetrieve = await Properties.RetrievePropertiesAsync(new string[] { "System.Capacity", "System.FreeSpace", "System.Volume.FileSystem", "System.Volume.BitLockerProtection" }); HardDeviceInfo NewDevice = new HardDeviceInfo(DeviceFolder, await DeviceFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), PropertiesRetrieve, Device.DriveType); if (!NewDevice.IsLockedByBitlocker) { int Index = CommonAccessCollection.HardDeviceList.IndexOf(Device); CommonAccessCollection.HardDeviceList.Remove(Device); CommonAccessCollection.HardDeviceList.Insert(Index, NewDevice); } else { QueueContentDialog UnlockFailedDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnlockBitlockerFailed_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_RetryButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await UnlockFailedDialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { goto Retry; } } } } else { await OpenTargetFolder(Device.Folder).ConfigureAwait(false); } } }
private async void DeviceGrid_ItemClick(object sender, ItemClickEventArgs e) { LibraryGrid.SelectedIndex = -1; if (!SettingControl.IsDoubleClickEnable && e.ClickedItem is DriveRelatedData Device) { if (Device.IsLockedByBitlocker) { Retry: BitlockerPasswordDialog Dialog = new BitlockerPasswordDialog(); if (await Dialog.ShowAsync() == ContentDialogResult.Primary) { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { await Exclusive.Controller.RunAsync("powershell.exe", string.Empty, WindowState.Normal, true, true, true, "-Command", $"$BitlockerSecureString = ConvertTo-SecureString '{Dialog.Password}' -AsPlainText -Force;", $"Unlock-BitLocker -MountPoint '{Device.Folder.Path}' -Password $BitlockerSecureString"); } StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Device.Folder.Path); DriveRelatedData NewDevice = await DriveRelatedData.CreateAsync(DriveFolder, Device.DriveType); if (!NewDevice.IsLockedByBitlocker) { int Index = CommonAccessCollection.DriveList.IndexOf(Device); CommonAccessCollection.DriveList.Remove(Device); CommonAccessCollection.DriveList.Insert(Index, NewDevice); } else { QueueContentDialog UnlockFailedDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnlockBitlockerFailed_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_RetryButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await UnlockFailedDialog.ShowAsync() == ContentDialogResult.Primary) { goto Retry; } } } } else { await OpenTargetFolder(Device.Folder).ConfigureAwait(false); } } }
private async void UnlockBitlocker_Click(object sender, RoutedEventArgs e) { if (DeviceGrid.SelectedItem is DriveRelatedData Device) { Retry: BitlockerPasswordDialog Dialog = new BitlockerPasswordDialog(); if (await Dialog.ShowAsync() == ContentDialogResult.Primary) { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { await Exclusive.Controller.RunAsync("powershell.exe", string.Empty, WindowState.Normal, true, true, true, "-Command", $"$BitlockerSecureString = ConvertTo-SecureString '{Dialog.Password}' -AsPlainText -Force;", $"Unlock-BitLocker -MountPoint '{Device.Folder.Path}' -Password $BitlockerSecureString"); } StorageFolder DeviceFolder = await StorageFolder.GetFolderFromPathAsync(Device.Folder.Path); BasicProperties Properties = await DeviceFolder.GetBasicPropertiesAsync(); IDictionary <string, object> PropertiesRetrieve = await Properties.RetrievePropertiesAsync(new string[] { "System.Capacity", "System.FreeSpace", "System.Volume.FileSystem", "System.Volume.BitLockerProtection" }); DriveRelatedData NewDevice = await DriveRelatedData.CreateAsync(DeviceFolder, Device.DriveType); if (!NewDevice.IsLockedByBitlocker) { int Index = CommonAccessCollection.DriveList.IndexOf(Device); CommonAccessCollection.DriveList.Remove(Device); CommonAccessCollection.DriveList.Insert(Index, NewDevice); } else { QueueContentDialog UnlockFailedDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnlockBitlockerFailed_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_RetryButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await UnlockFailedDialog.ShowAsync() == ContentDialogResult.Primary) { goto Retry; } } } } }
public async Task OpenTargetDriveAsync(DriveDataBase Drive) { switch (Drive) { case LockedDriveData LockedDrive: { Retry: BitlockerPasswordDialog Dialog = new BitlockerPasswordDialog(); if (await Dialog.ShowAsync() == ContentDialogResult.Primary) { if (!await LockedDrive.UnlockAsync(Dialog.Password)) { QueueContentDialog UnlockFailedDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnlockBitlockerFailed_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_RetryButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await UnlockFailedDialog.ShowAsync() == ContentDialogResult.Primary) { goto Retry; } else { return; } } StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(LockedDrive.Path); DriveDataBase NewDrive = await DriveDataBase.CreateAsync(DriveFolder, LockedDrive.DriveType); if (NewDrive is LockedDriveData) { QueueContentDialog UnlockFailedDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnlockBitlockerFailed_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_RetryButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await UnlockFailedDialog.ShowAsync() == ContentDialogResult.Primary) { goto Retry; } } else { int Index = CommonAccessCollection.DriveList.IndexOf(LockedDrive); if (Index >= 0) { CommonAccessCollection.DriveList.Remove(LockedDrive); CommonAccessCollection.DriveList.Insert(Index, NewDrive); } else { CommonAccessCollection.DriveList.Add(NewDrive); } } } break; } case WslDriveData: case NormalDriveData: { await OpenTargetFolder(Drive.DriveFolder).ConfigureAwait(false); break; } } }