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().ConfigureAwait(true) == 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").ConfigureAwait(true); } StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Device.Folder.Path); DriveRelatedData NewDevice = await DriveRelatedData.CreateAsync(DriveFolder, Device.DriveType).ConfigureAwait(true); 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().ConfigureAwait(true) == 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 void Refresh_Click(object sender, RoutedEventArgs e) { if (Interlocked.Exchange(ref LockResource, 1) == 0) { try { CommonAccessCollection.DriveList.Clear(); foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable || Drives.DriveType == DriveType.Network) .Where((NewItem) => CommonAccessCollection.DriveList.All((Item) => Item.Folder.Path != NewItem.RootDirectory.FullName))) { try { StorageFolder DriveFolder = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); CommonAccessCollection.DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, Drive.DriveType)); } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Drive.RootDirectory.FullName}\" for error"); } } foreach (DeviceInformation Device in await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector())) { try { StorageFolder DriveFolder = StorageDevice.FromId(Device.Id); if (CommonAccessCollection.DriveList.All((Item) => (string.IsNullOrEmpty(Item.Folder.Path) || string.IsNullOrEmpty(DriveFolder.Path)) ? Item.Folder.Name != DriveFolder.Name : Item.Folder.Path != DriveFolder.Path)) { CommonAccessCollection.DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, DriveType.Removable)); } } catch (Exception ex) { LogTracer.Log(ex, $"Hide the device \"{Device.Name}\" for error"); } } } finally { _ = Interlocked.Exchange(ref LockResource, 0); } } }
private async void AddDevice_Click(object sender, RoutedEventArgs e) { FolderPicker Picker = new FolderPicker { SuggestedStartLocation = PickerLocationId.ComputerFolder, ViewMode = PickerViewMode.Thumbnail }; Picker.FileTypeFilter.Add("*"); StorageFolder DriveFolder = await Picker.PickSingleFolderAsync(); if (DriveFolder != null) { if (DriveFolder.Path.Equals(Path.GetPathRoot(DriveFolder.Path), StringComparison.OrdinalIgnoreCase) && DriveInfo.GetDrives().Where((Drive) => Drive.DriveType == DriveType.Fixed || Drive.DriveType == DriveType.Removable || Drive.DriveType == DriveType.Network).Any((Item) => Item.RootDirectory.FullName == DriveFolder.Path)) { if (CommonAccessCollection.DriveList.All((Item) => Item.Folder.Path != DriveFolder.Path)) { CommonAccessCollection.DriveList.Add(await DriveRelatedData.CreateAsync(DriveFolder, new DriveInfo(DriveFolder.Path).DriveType)); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_DeviceExist_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_DeviceSelectError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_TipTitle") }; _ = await Dialog.ShowAsync(); } } }