public async Task OpenTargetFolder(StorageFolder Folder) { if (Folder == null) { throw new ArgumentNullException(nameof(Folder), "Argument could not be null"); } try { if (string.IsNullOrEmpty(Folder.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_CouldNotAccess_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } else { if (AnimationController.Current.IsEnableAnimation) { Frame.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, string[]>(WeakToTabItem, new string[] { Folder.Path }), new DrillInNavigationTransitionInfo()); } else { Frame.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, string[]>(WeakToTabItem, new string[] { Folder.Path }), new SuppressNavigationTransitionInfo()); } } } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when entering device"); } }
private async void Grid_Drop(object sender, DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { IReadOnlyList <IStorageItem> Items = await e.DataView.GetStorageItemsAsync(); if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.Folder))) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaImportFiliter_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.File))) { ActivateLoading(true, true); Cancellation = new CancellationTokenSource(); try { foreach (string OriginFilePath in Items.Select((Item) => Item.Path)) { if (FileSystemStorageItemBase.Open(OriginFilePath, ItemFilters.File) is FileSystemStorageItemBase Item) { if (await Item.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token).ConfigureAwait(true) is SecureAreaStorageItem EncryptedFile) { SecureCollection.Add(EncryptedFile); if (!Item.PermanentDelete()) { LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()), "Delete origin file failed after importing to SecureArea"); } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } } } } catch (TaskCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when importing file"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1000).ConfigureAwait(true); ActivateLoading(false); } } } }
private async void SetAsWallpaper_Click(object sender, RoutedEventArgs e) { try { if (!UserProfilePersonalizationSettings.IsSupported()) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_SetWallpaperNotSupport_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(false); } else { if (Flip.SelectedItem is PhotoDisplaySupport Photo) { if (await Photo.PhotoFile.GetStorageItem().ConfigureAwait(true) is StorageFile File) { StorageFile TempFile = await File.CopyAsync(ApplicationData.Current.LocalFolder, Photo.PhotoFile.Name, NameCollisionOption.GenerateUniqueName); try { if (await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(TempFile)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_SetWallpaperSuccess_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(false); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_SetWallpaperFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(false); } } finally { await TempFile.DeleteAsync(StorageDeleteOption.PermanentDelete); } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_SetWallpaperFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(false); } } } } catch { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_SetWallpaperFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(false); } }
private async Task Initialize(FileSystemStorageItemBase PdfFile) { LoadingControl.IsLoading = true; MainPage.ThisPage.IsAnyTaskRunning = true; PdfCollection = new ObservableCollection <BitmapImage>(); LoadQueue = new Queue <int>(); ExitLocker = new ManualResetEvent(false); Cancellation = new CancellationTokenSource(); Flip.ItemsSource = PdfCollection; MaxLoad = 0; LastPageIndex = 0; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(true)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++) { using (PdfPage Page = Pdf.GetPage(i)) using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream()) { await Page.RenderToStreamAsync(PageStream); BitmapImage DisplayImage = new BitmapImage(); PdfCollection.Add(DisplayImage); await DisplayImage.SetSourceAsync(PageStream); } } } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); Frame.GoBack(); } finally { ExitLocker.Set(); if (!Cancellation.IsCancellationRequested) { Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; } await Task.Delay(1000).ConfigureAwait(true); LoadingControl.IsLoading = false; MainPage.ThisPage.IsAnyTaskRunning = false; } }
private async void QuickStartGridView_ItemClick(object sender, ItemClickEventArgs e) { if (e.ClickedItem is QuickStartItem Item) { if ((sender as GridView).Name == nameof(QuickStartGridView)) { if (Uri.TryCreate(Item.Protocol, UriKind.Absolute, out Uri Ur)) { if (Ur.IsFile) { if (await FileSystemStorageItemBase.CheckExistAsync(Item.Protocol)) { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { try { if (Path.GetExtension(Item.Protocol).ToLower() == ".msc") { await Exclusive.Controller.RunAsync("powershell.exe", string.Empty, WindowState.Normal, false, true, false, "-Command", Item.Protocol); } else { await Exclusive.Controller.RunAsync(Item.Protocol, Path.GetDirectoryName(Item.Protocol)); } } catch (Exception ex) { LogTracer.Log(ex, "Could not execute program in quick start"); } } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_ApplicationNotFound_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } } else { await Launcher.LaunchUriAsync(Ur); } } else { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (!await Exclusive.Controller.LaunchUWPLnkAsync(Item.Protocol)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } } } } else { await Launcher.LaunchUriAsync(new Uri(Item.Protocol)); } } }
private async Task ImportFilesAsync(IEnumerable <StorageFile> FileList) { if (FileList.Any()) { await ActivateLoading(true, DisplayString : Globalization.GetString("Progress_Tip_Importing")); Cancellation = new CancellationTokenSource(); try { ulong TotalSize = 0; ulong CurrentPosition = 0; List <FileSystemStorageFile> NewFileList = new List <FileSystemStorageFile>(); foreach (StorageFile ImportFile in FileList) { FileSystemStorageFile File = await FileSystemStorageItemBase.CreatedByStorageItemAsync(ImportFile); if (File != null) { NewFileList.Add(File); TotalSize += File.SizeRaw; } } foreach (FileSystemStorageFile OriginFile in NewFileList) { string EncryptedFilePath = Path.Combine(SecureFolder.Path, $"{Path.GetFileNameWithoutExtension(OriginFile.Name)}.sle"); if (await FileSystemStorageItemBase.CreateAsync(EncryptedFilePath, StorageItemTypes.File, CreateOption.GenerateUniqueName) is FileSystemStorageFile EncryptedFile) { using (FileStream OriginFStream = await OriginFile.GetFileStreamFromFileAsync(AccessMode.Read)) using (FileStream EncryptFStream = await EncryptedFile.GetFileStreamFromFileAsync(AccessMode.Write)) using (SLEOutputStream SLEStream = new SLEOutputStream(EncryptFStream, OriginFile.Name, AESKey, AESKeySize)) { await OriginFStream.CopyToAsync(SLEStream, OriginFStream.Length, async (s, e) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { ProBar.IsIndeterminate = false; ProBar.Value = Convert.ToInt32((CurrentPosition + Convert.ToUInt64(e.ProgressPercentage / 100d * OriginFile.SizeRaw)) * 100d / TotalSize); }); }, Cancellation.Token); CurrentPosition += OriginFile.SizeRaw; await Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { ProBar.Value = Convert.ToInt32(CurrentPosition * 100d / TotalSize); }); } await EncryptedFile.RefreshAsync(); SecureCollection.Add(EncryptedFile); await OriginFile.DeleteAsync(false); } } } catch (OperationCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An exception was threw when importing file"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } finally { Cancellation.Dispose(); Cancellation = null; await ActivateLoading(false); } } }
public async Task CreateNewTabAndOpenTargetFolder(string Path, int?InsertIndex = null) { int Index = InsertIndex ?? (TabViewControl?.TabItems.Count ?? 0); try { if (string.IsNullOrWhiteSpace(Path)) { if (CreateNewTab() is TabViewItem Item) { //预览版TabView在没有子Item时会崩溃,此方案作为临时解决方案 if (TabViewControl == null) { _ = FindName(nameof(TabViewControl)); } TabViewControl.TabItems.Insert(Index, Item); TabViewControl.UpdateLayout(); TabViewControl.SelectedItem = Item; } } else { if (WIN_Native_API.CheckIfHidden(Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_ItemHidden_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); //预览版TabView在没有子Item时会崩溃,此方案作为临时解决方案 if (TabViewControl == null) { _ = FindName(nameof(TabViewControl)); if (CreateNewTab() is TabViewItem EmptyItem) { TabViewControl.TabItems.Insert(Index, EmptyItem); TabViewControl.UpdateLayout(); TabViewControl.SelectedItem = EmptyItem; } } } else { StorageFolder TargetFolder = await StorageFolder.GetFolderFromPathAsync(Path); if (CreateNewTab(TargetFolder) is TabViewItem Item) { //预览版TabView在没有子Item时会崩溃,此方案作为临时解决方案 if (TabViewControl == null) { _ = FindName(nameof(TabViewControl)); } TabViewControl.TabItems.Insert(Index, Item); TabViewControl.UpdateLayout(); TabViewControl.SelectedItem = Item; } } } } catch (Exception ex) { if (CreateNewTab() is TabViewItem Item) { //预览版TabView在没有子Item时会崩溃,此方案作为临时解决方案 if (TabViewControl == null) { _ = FindName(nameof(TabViewControl)); } TabViewControl.TabItems.Insert(Index, Item); TabViewControl.UpdateLayout(); TabViewControl.SelectedItem = Item; } LogTracer.Log(ex, "Error happened when try to create a new tab"); } }
private async Task Initialize() { try { ExitLocker = new ManualResetEvent(false); Cancellation = new CancellationTokenSource(); LoadQueue = new Queue <int>(); Behavior.Attach(Flip); if (await FileSystemStorageItemBase.OpenAsync(Path.GetDirectoryName(SelectedPhotoFile.Path)) is FileSystemStorageFolder Item) { FileSystemStorageFile[] PictureFileList = (await Item.GetChildItemsAsync(SettingControl.IsDisplayHiddenItem, SettingControl.IsDisplayProtectedSystemItems, Filter: ItemFilters.File, AdvanceFilter: (Name) => { string Extension = Path.GetExtension(Name); return(Extension.Equals(".png", StringComparison.OrdinalIgnoreCase) || Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || Extension.Equals(".bmp", StringComparison.OrdinalIgnoreCase)); })).Cast <FileSystemStorageFile>().ToArray(); if (PictureFileList.Length == 0) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("Queue_Dialog_ImageReadError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync(); Frame.GoBack(); } else { int LastSelectIndex = Array.FindIndex(PictureFileList, (Photo) => Photo.Path.Equals(SelectedPhotoFile.Path, StringComparison.OrdinalIgnoreCase)); if (LastSelectIndex < 0 || LastSelectIndex >= PictureFileList.Length) { LastSelectIndex = 0; } PhotoCollection = new ObservableCollection <PhotoDisplaySupport>(PictureFileList.Select((Item) => new PhotoDisplaySupport(Item))); Flip.ItemsSource = PhotoCollection; if (!await PhotoCollection[LastSelectIndex].ReplaceThumbnailBitmapAsync()) { CouldnotLoadTip.Visibility = Visibility.Visible; } for (int i = LastSelectIndex - 5 > 0 ? LastSelectIndex - 5 : 0; i <= (LastSelectIndex + 5 < PhotoCollection.Count - 1 ? LastSelectIndex + 5 : PhotoCollection.Count - 1) && !Cancellation.IsCancellationRequested; i++) { await PhotoCollection[i].GenerateThumbnailAsync(); } if (!Cancellation.IsCancellationRequested) { Flip.SelectedIndex = LastSelectIndex; Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; EnterAnimation.Begin(); } } } else { throw new FileNotFoundException(); } } catch (Exception ex) { CouldnotLoadTip.Visibility = Visibility.Visible; LogTracer.Log(ex, "An error was threw when initialize PhotoViewer"); } finally { ExitLocker.Set(); } }
private async Task LaunchSelectedItem(FileSystemStorageItemBase Item) { try { switch (Item) { case FileSystemStorageFile File: { if (!await FileSystemStorageItemBase.CheckExistAsync(File.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LocateFileFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); return; } switch (File.Type.ToLower()) { case ".exe": case ".bat": case ".msi": { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (!await Exclusive.Controller.RunAsync(File.Path, Path.GetDirectoryName(File.Path))) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } } break; } case ".msc": { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (!await Exclusive.Controller.RunAsync("powershell.exe", string.Empty, WindowState.Normal, false, true, false, "-Command", File.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } } break; } case ".lnk": { if (File is LinkStorageFile LinkItem) { if (LinkItem.LinkType == ShellLinkType.Normal) { switch (await FileSystemStorageItemBase.OpenAsync(LinkItem.LinkTargetPath)) { case FileSystemStorageFolder: { if (WeakToFileControl.TryGetTarget(out FileControl Control)) { Frame.GoBack(); await Control.CurrentPresenter.DisplayItemsInFolder(LinkItem.LinkTargetPath); await JumpListController.Current.AddItemAsync(JumpListGroup.Recent, LinkItem.LinkTargetPath); if (Control.CurrentPresenter.FileCollection.FirstOrDefault((SItem) => SItem == LinkItem) is FileSystemStorageItemBase Target) { Control.CurrentPresenter.ItemPresenter.ScrollIntoView(Target); Control.CurrentPresenter.SelectedItem = Target; } } break; } case FileSystemStorageFile: { await LinkItem.LaunchAsync(); break; } } } else { await LinkItem.LaunchAsync(); } } break; } case ".url": { if (File is UrlStorageFile UrlItem) { await UrlItem.LaunchAsync(); } break; } default: { string AdminExecutablePath = await SQLite.Current.GetDefaultProgramPickerRecordAsync(File.Type); if (string.IsNullOrEmpty(AdminExecutablePath) || AdminExecutablePath == Package.Current.Id.FamilyName) { if (!TryOpenInternally(File)) { if (await File.GetStorageItemAsync() is StorageFile SFile) { if (!await Launcher.LaunchFileAsync(SFile)) { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (!await Exclusive.Controller.RunAsync(File.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } } } } else { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (!await Exclusive.Controller.RunAsync(File.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } } } } } else { if (Path.IsPathRooted(AdminExecutablePath)) { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (!await Exclusive.Controller.RunAsync(AdminExecutablePath, Path.GetDirectoryName(AdminExecutablePath), Parameters: File.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } } } else { if ((await Launcher.FindFileHandlersAsync(File.Type)).FirstOrDefault((Item) => Item.PackageFamilyName == AdminExecutablePath) is AppInfo Info) { if (await File.GetStorageItemAsync() is StorageFile InnerFile) { if (!await Launcher.LaunchFileAsync(InnerFile, new LauncherOptions { TargetApplicationPackageFamilyName = Info.PackageFamilyName, DisplayApplicationPicker = false })) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LaunchFailed_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnableAccessFile_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } } } } break; } } break; } case FileSystemStorageFolder Folder: { if (await FileSystemStorageItemBase.CheckExistAsync(Folder.Path)) { if (WeakToFileControl.TryGetTarget(out FileControl Control)) { Frame.GoBack(); await Control.CurrentPresenter.DisplayItemsInFolder(Folder); await JumpListController.Current.AddItemAsync(JumpListGroup.Recent, Folder.Path); if (Control.CurrentPresenter.FileCollection.FirstOrDefault((SItem) => SItem == Folder) is FileSystemStorageItemBase Target) { Control.CurrentPresenter.ItemPresenter.ScrollIntoView(Target); Control.CurrentPresenter.SelectedItem = Target; } } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LocateFolderFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } break; } } } catch (Exception ex) { LogTracer.Log(ex, $"An error was threw in {nameof(LaunchSelectedItem)}"); QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LocateFolderFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync(); } }
public async void Refresh_Click(object sender, RoutedEventArgs e) { if (Interlocked.Exchange(ref LockResource, 1) == 0) { try { CommonAccessCollection.HardDeviceList.Clear(); bool AccessError = false; foreach (DriveInfo Drive in DriveInfo.GetDrives().Where((Drives) => Drives.DriveType == DriveType.Fixed || Drives.DriveType == DriveType.Removable) .Where((NewItem) => CommonAccessCollection.HardDeviceList.All((Item) => Item.Folder.Path != NewItem.RootDirectory.FullName))) { try { StorageFolder Device = await StorageFolder.GetFolderFromPathAsync(Drive.RootDirectory.FullName); BasicProperties Properties = await Device.GetBasicPropertiesAsync(); IDictionary <string, object> PropertiesRetrieve = await Properties.RetrievePropertiesAsync(new string[] { "System.Capacity", "System.FreeSpace", "System.Volume.FileSystem" }); CommonAccessCollection.HardDeviceList.Add(new HardDeviceInfo(Device, await Device.GetThumbnailBitmapAsync().ConfigureAwait(true), PropertiesRetrieve, Drive.DriveType)); } catch { AccessError = true; } } foreach (DeviceInformation Device in await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector())) { try { StorageFolder DeviceFolder = StorageDevice.FromId(Device.Id); if (CommonAccessCollection.HardDeviceList.All((Item) => (string.IsNullOrEmpty(Item.Folder.Path) || string.IsNullOrEmpty(DeviceFolder.Path)) ? Item.Folder.Name != DeviceFolder.Name : Item.Folder.Path != DeviceFolder.Path)) { BasicProperties Properties = await DeviceFolder.GetBasicPropertiesAsync(); IDictionary <string, object> PropertiesRetrieve = await Properties.RetrievePropertiesAsync(new string[] { "System.Capacity", "System.FreeSpace", "System.Volume.FileSystem" }); if (PropertiesRetrieve["System.Capacity"] is ulong && PropertiesRetrieve["System.FreeSpace"] is ulong) { CommonAccessCollection.HardDeviceList.Add(new HardDeviceInfo(DeviceFolder, await DeviceFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), PropertiesRetrieve, DriveType.Removable)); } else { IReadOnlyList <IStorageItem> InnerItemList = await DeviceFolder.GetItemsAsync(0, 2); if (InnerItemList.Count == 1 && InnerItemList[0] is StorageFolder InnerFolder) { BasicProperties InnerProperties = await InnerFolder.GetBasicPropertiesAsync(); IDictionary <string, object> InnerPropertiesRetrieve = await InnerProperties.RetrievePropertiesAsync(new string[] { "System.Capacity", "System.FreeSpace", "System.Volume.FileSystem" }); if (InnerPropertiesRetrieve["System.Capacity"] is ulong && InnerPropertiesRetrieve["System.FreeSpace"] is ulong) { CommonAccessCollection.HardDeviceList.Add(new HardDeviceInfo(DeviceFolder, await DeviceFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), InnerPropertiesRetrieve, DriveType.Removable)); } else { CommonAccessCollection.HardDeviceList.Add(new HardDeviceInfo(DeviceFolder, await DeviceFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), PropertiesRetrieve, DriveType.Removable)); } } else { CommonAccessCollection.HardDeviceList.Add(new HardDeviceInfo(DeviceFolder, await DeviceFolder.GetThumbnailBitmapAsync().ConfigureAwait(true), PropertiesRetrieve, DriveType.Removable)); } } } } catch { AccessError = true; } } if (AccessError && !ApplicationData.Current.LocalSettings.Values.ContainsKey("DisableAccessErrorTip")) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_DeviceHideForError_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_DoNotTip"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; if (await dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { ApplicationData.Current.LocalSettings.Values["DisableAccessErrorTip"] = true; } } } finally { _ = Interlocked.Exchange(ref LockResource, 0); } } }
private async void QuickStartGridView_ItemClick(object sender, ItemClickEventArgs e) { if (e.ClickedItem is QuickStartItem Item) { if ((sender as GridView).Name == nameof(QuickStartGridView)) { Uri Ur = new Uri(Item.Protocol); if (Ur.IsFile) { if (WIN_Native_API.CheckExist(Item.Protocol)) { Retry: try { if (Path.GetExtension(Item.Protocol).ToLower() == ".msc") { await FullTrustProcessController.Current.RunAsync(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "WindowsPowerShell\\v1.0\\powershell.exe"), false, true, "-Command", Item.Protocol).ConfigureAwait(true); } else { await FullTrustProcessController.Current.RunAsync(Item.Protocol).ConfigureAwait(true); } } catch (InvalidOperationException) { QueueContentDialog UnauthorizeDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnauthorizedExecute_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_GrantButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await UnauthorizeDialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { if (await FullTrustProcessController.Current.SwitchToAdminMode().ConfigureAwait(true)) { goto Retry; } else { QueueContentDialog ErrorDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DenyElevation_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await ErrorDialog.ShowAsync().ConfigureAwait(true); } } } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_ApplicationNotFound_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } } else { await Launcher.LaunchUriAsync(Ur); } } else { await Launcher.LaunchUriAsync(new Uri(Item.Protocol)); } } }
private async Task Initialize() { if (IsNavigateToCropperPage) { IsNavigateToCropperPage = false; await PhotoCollection[Flip.SelectedIndex].UpdateImage().ConfigureAwait(true); return; } try { ExitLocker = new ManualResetEvent(false); Cancellation = new CancellationTokenSource(); LoadQueue = new Queue <int>(); MainPage.ThisPage.IsAnyTaskRunning = true; Behavior.Attach(Flip); List <FileSystemStorageItemBase> FileList = WIN_Native_API.GetStorageItems(FileControlInstance.CurrentFolder, false, ItemFilters.File).Where((Item) => Item.Type.Equals(".png", StringComparison.OrdinalIgnoreCase) || Item.Type.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || Item.Type.Equals(".bmp", StringComparison.OrdinalIgnoreCase)).ToList(); int LastSelectIndex = FileList.FindIndex((Photo) => Photo.Name == SelectedPhotoName); if (LastSelectIndex < 0 || LastSelectIndex >= FileList.Count) { LastSelectIndex = 0; } if (FileList.Count == 0) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("Queue_Dialog_ImageReadError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); FileControlInstance.Nav.GoBack(); return; } PhotoCollection = new ObservableCollection <PhotoDisplaySupport>(FileList.Select((Item) => new PhotoDisplaySupport(Item))); Flip.ItemsSource = PhotoCollection; if (!await PhotoCollection[LastSelectIndex].ReplaceThumbnailBitmapAsync().ConfigureAwait(true)) { CouldnotLoadTip.Visibility = Visibility.Visible; } for (int i = LastSelectIndex - 5 > 0 ? LastSelectIndex - 5 : 0; i <= (LastSelectIndex + 5 < PhotoCollection.Count - 1 ? LastSelectIndex + 5 : PhotoCollection.Count - 1) && !Cancellation.IsCancellationRequested; i++) { await PhotoCollection[i].GenerateThumbnailAsync().ConfigureAwait(true); } if (!Cancellation.IsCancellationRequested) { Flip.SelectedIndex = LastSelectIndex; Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; await EnterAnimation.BeginAsync().ConfigureAwait(true); } } catch (Exception ex) { ExceptionTracer.RequestBlueScreen(ex); } finally { MainPage.ThisPage.IsAnyTaskRunning = false; ExitLocker.Set(); } }
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; } } }
private async void ExportFile_Click(object sender, RoutedEventArgs e) { FolderPicker Picker = new FolderPicker { SuggestedStartLocation = PickerLocationId.Desktop, ViewMode = PickerViewMode.Thumbnail }; Picker.FileTypeFilter.Add("*"); if ((await Picker.PickSingleFolderAsync()) is StorageFolder Folder) { Cancellation = new CancellationTokenSource(); try { ActivateLoading(true, false); foreach (SecureAreaStorageItem Item in SecureGridView.SelectedItems.ToArray()) { if (await Item.DecryptAsync(Folder.Path, EncryptionAESKey, Cancellation.Token).ConfigureAwait(true) is FileSystemStorageItemBase) { SecureCollection.Remove(Item); if (!Item.PermanentDelete()) { LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()), "Delete encrypted file failed after exporting to SecureArea"); } } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DecryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } } _ = await Launcher.LaunchFolderAsync(Folder); } catch (PasswordErrorException) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DecryptPasswordError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } catch (FileDamagedException) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_FileDamageError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } catch (TaskCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DecryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1000).ConfigureAwait(true); ActivateLoading(false); } } }
private async void AddFile_Click(object sender, RoutedEventArgs e) { FileOpenPicker Picker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.ComputerFolder, ViewMode = PickerViewMode.Thumbnail }; Picker.FileTypeFilter.Add("*"); IReadOnlyList <StorageFile> FileList = await Picker.PickMultipleFilesAsync(); if (FileList.Count > 0) { ActivateLoading(true, true); Cancellation = new CancellationTokenSource(); try { foreach (string OriginFilePath in FileList.Select((Item) => Item.Path)) { if (await FileSystemStorageItemBase.OpenAsync(OriginFilePath) is FileSystemStorageFile File) { if (await File.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token) is FileSystemStorageFile EncryptedFile) { SecureCollection.Add(EncryptedFile); await File.DeleteAsync(false); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } } } } catch (TaskCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An exception was threw when importing file"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1500); ActivateLoading(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()) { if (!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")) { 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 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; } } } } }
private async void Grid_Drop(object sender, DragEventArgs e) { try { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { IReadOnlyList <IStorageItem> Items = await e.DataView.GetStorageItemsAsync(); if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.Folder))) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaImportFiliter_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.File))) { ActivateLoading(true, true); Cancellation = new CancellationTokenSource(); try { foreach (string OriginFilePath in Items.Select((Item) => Item.Path)) { if (await FileSystemStorageItemBase.OpenAsync(OriginFilePath) is FileSystemStorageFile File) { if (await File.EncryptAsync(SecureFolder.Path, EncryptionAESKey, AESKeySize, Cancellation.Token) is FileSystemStorageFile EncryptedFile) { SecureCollection.Add(EncryptedFile); await File.DeleteAsync(false); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } } } } catch (TaskCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when importing file"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1000); ActivateLoading(false); } } } } catch (Exception ex) when(ex.HResult is unchecked ((int)0x80040064)or unchecked ((int)0x8004006A)) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_CopyFromUnsupportedArea_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync(); } catch { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_FailToGetClipboardError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync(); } }
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()) { if (!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")) { 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(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 Task InitializeAsync() { try { using (IRandomAccessStream Stream = await MediaFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { Source = MediaSource.CreateFromStream(Stream, MIMEDictionary[MediaFile.Type.ToLower()]); MediaPlaybackItem Item = new MediaPlaybackItem(Source); switch (MediaFile.Type.ToLower()) { case ".mp3": case ".flac": case ".wma": case ".m4a": { MusicCover.Visibility = Visibility.Visible; MediaItemDisplayProperties Props = Item.GetDisplayProperties(); Props.Type = Windows.Media.MediaPlaybackType.Music; Props.MusicProperties.Title = MediaFile.DisplayName; Props.MusicProperties.AlbumArtist = await GetArtistAsync(); Item.ApplyDisplayProperties(Props); if (await GetMusicCoverAsync() is BitmapImage Thumbnail) { Cover.Source = Thumbnail; Cover.Visibility = Visibility.Visible; } else { Cover.Visibility = Visibility.Collapsed; } Display.Text = $"{Globalization.GetString("Media_Tip_Text")} {MediaFile.DisplayName}"; MVControl.Source = Item; break; } default: { MusicCover.Visibility = Visibility.Collapsed; MediaItemDisplayProperties Props = Item.GetDisplayProperties(); Props.Type = Windows.Media.MediaPlaybackType.Video; Props.VideoProperties.Title = MediaFile.DisplayName; Item.ApplyDisplayProperties(Props); MVControl.Source = Item; break; } } } } catch (Exception ex) { LogTracer.Log(ex, "Could not load media because an exception was threw"); QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_CouldNotLoadMedia_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await Dialog.ShowAsync(); Frame.GoBack(); } }
private async Task Initialize(FileSystemStorageFile PdfFile) { LoadingControl.IsLoading = true; PdfCollection.Clear(); LoadQueue.Clear(); Cancellation = new CancellationTokenSource(); MaxLoad = 0; LastPageIndex = 0; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++) { using (PdfPage Page = Pdf.GetPage(i)) using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream()) { await Page.RenderToStreamAsync(PageStream, new PdfPageRenderOptions { DestinationHeight = Convert.ToUInt32(Page.Size.Height * 1.5), DestinationWidth = Convert.ToUInt32(Page.Size.Width * 1.5) }); BitmapImage DisplayImage = new BitmapImage(); PdfCollection.Add(DisplayImage); await DisplayImage.SetSourceAsync(PageStream); } } } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync(); Frame.GoBack(); } finally { if (!Cancellation.IsCancellationRequested) { Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; } await Task.Delay(1000); LoadingControl.IsLoading = false; } }
private async void TabViewContainer_KeyDown(CoreWindow sender, KeyEventArgs args) { if (!QueueContentDialog.IsRunningOrWaiting && CurrentTabNavigation?.Content is ThisPC PC) { args.Handled = true; switch (args.VirtualKey) { case VirtualKey.Space when SettingControl.IsQuicklookAvailable && SettingControl.IsQuicklookEnable: { if (PC.DeviceGrid.SelectedItem is HardDeviceInfo Device) { await FullTrustProcessController.Current.ViewWithQuicklookAsync(Device.Folder.Path).ConfigureAwait(false); } else if (PC.LibraryGrid.SelectedItem is LibraryFolder Library) { await FullTrustProcessController.Current.ViewWithQuicklookAsync(Library.Folder.Path).ConfigureAwait(false); } break; } case VirtualKey.Enter: { if (PC.DeviceGrid.SelectedItem is HardDeviceInfo Device) { if (string.IsNullOrEmpty(Device.Folder.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_MTP_CouldNotAccess_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_ContinueButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { await Launcher.LaunchFolderAsync(Device.Folder); } } else { if (AnimationController.Current.IsEnableAnimation) { CurrentTabNavigation.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, StorageFolder>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Device.Folder), new DrillInNavigationTransitionInfo()); } else { CurrentTabNavigation.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, StorageFolder>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Device.Folder), new SuppressNavigationTransitionInfo()); } } } else if (PC.LibraryGrid.SelectedItem is LibraryFolder Library) { if (AnimationController.Current.IsEnableAnimation) { CurrentTabNavigation.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, StorageFolder>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Library.Folder), new DrillInNavigationTransitionInfo()); } else { CurrentTabNavigation.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, StorageFolder>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Library.Folder), new SuppressNavigationTransitionInfo()); } } break; } case VirtualKey.F5: { PC.Refresh_Click(null, null); break; } } } }
private async void AddFile_Click(object sender, RoutedEventArgs e) { FileOpenPicker Picker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.ComputerFolder, ViewMode = PickerViewMode.Thumbnail }; Picker.FileTypeFilter.Add("*"); IReadOnlyList <StorageFile> FileList = await Picker.PickMultipleFilesAsync(); if (FileList.Count > 0) { ActivateLoading(true, true); Cancellation = new CancellationTokenSource(); try { foreach (StorageFile File in FileList) { if ((await File.EncryptAsync(SecureFolder, FileEncryptionAesKey, AESKeySize, Cancellation.Token).ConfigureAwait(true)) is StorageFile EncryptedFile) { var Size = await EncryptedFile.GetSizeRawDataAsync().ConfigureAwait(true); var Thumbnail = new BitmapImage(new Uri("ms-appx:///Assets/LockFile.png")); var ModifiedTime = await EncryptedFile.GetModifiedTimeAsync().ConfigureAwait(true); SecureCollection.Add(new FileSystemStorageItemBase(EncryptedFile, Size, Thumbnail, ModifiedTime)); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); break; } } } catch (TaskCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when importing file"); } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1500).ConfigureAwait(true); ActivateLoading(false); } } }
private async void SecureArea_Loaded(object sender, RoutedEventArgs e) { WholeArea.Visibility = Visibility.Collapsed; SecureGridView.AddHandler(PointerPressedEvent, PointerPressedHandler, true); ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false; if (ApplicationData.Current.LocalSettings.Values.ContainsKey("IsFirstEnterSecureArea")) { AESKeySize = Convert.ToInt32(ApplicationData.Current.LocalSettings.Values["SecureAreaAESKeySize"]); if (ApplicationData.Current.LocalSettings.Values["SecureAreaLockMode"] is not string LockMode || LockMode != nameof(CloseLockMode) || IsNewStart) { if (Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"])) { RETRY: switch (await WindowsHelloAuthenticator.VerifyUserAsync()) { case AuthenticatorState.VerifyPassed: { break; } case AuthenticatorState.UnknownError: case AuthenticatorState.VerifyFailed: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_WinHelloAuthFail_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_TryAgain"), SecondaryButtonText = Globalization.GetString("Common_Dialog_UsePassword"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; ContentDialogResult Result = await Dialog.ShowAsync(); if (Result == ContentDialogResult.Primary) { goto RETRY; } else if (Result == ContentDialogResult.Secondary) { if (!await EnterByPassword()) { return; } } else { Frame.GoBack(); return; } break; } case AuthenticatorState.UserNotRegistered: case AuthenticatorState.CredentialNotFound: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_WinHelloCredentialLost_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = false; if (!await EnterByPassword()) { return; } break; } case AuthenticatorState.WindowsHelloUnsupport: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_WinHelloDisable_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_UsePassword"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = false; if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { if (!await EnterByPassword()) { return; } } else { Frame.GoBack(); return; } break; } } } else { if (!await EnterByPassword()) { return; } } } } else { try { await ActivateLoading(true, false, Globalization.GetString("Progress_Tip_CheckingLicense")); if (await MSStoreHelper.Current.CheckPurchaseStatusAsync()) { await Task.Delay(500); } else { SecureAreaIntroDialog IntroDialog = new SecureAreaIntroDialog(); if ((await IntroDialog.ShowAsync()) == ContentDialogResult.Primary) { StorePurchaseStatus Status = await MSStoreHelper.Current.PurchaseAsync(); if (Status == StorePurchaseStatus.AlreadyPurchased || Status == StorePurchaseStatus.Succeeded) { QueueContentDialog SuccessDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaUnlock_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await SuccessDialog.ShowAsync(); } else { Frame.GoBack(); return; } } else { Frame.GoBack(); return; } } } finally { await ActivateLoading(false); } SecureAreaWelcomeDialog Dialog = new SecureAreaWelcomeDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { AESKeySize = Dialog.AESKeySize; UnlockPassword = Dialog.Password; ApplicationData.Current.LocalSettings.Values["SecureAreaAESKeySize"] = Dialog.AESKeySize; ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = Dialog.IsEnableWindowsHello; ApplicationData.Current.LocalSettings.Values["IsFirstEnterSecureArea"] = false; } else { if (Dialog.IsEnableWindowsHello) { await WindowsHelloAuthenticator.DeleteUserAsync(); } Frame.GoBack(); return; } } CoreWindow.GetForCurrentThread().KeyDown += SecureArea_KeyDown; WholeArea.Visibility = Visibility.Visible; SelectionExtention = new ListViewBaseSelectionExtention(SecureGridView, DrawRectangle); await LoadSecureFile(); }
private async void Grid_Drop(object sender, DragEventArgs e) { IReadOnlyList <IStorageItem> Items = await e.DataView.GetStorageItemsAsync(); if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.Folder))) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaImportFiliter_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } if (Items.Any((Item) => Item.IsOfType(StorageItemTypes.File))) { ActivateLoading(true, true); Cancellation = new CancellationTokenSource(); try { foreach (StorageFile Item in Items.OfType <StorageFile>()) { if ((await Item.EncryptAsync(SecureFolder, FileEncryptionAesKey, AESKeySize, Cancellation.Token).ConfigureAwait(true)) is StorageFile EncryptedFile) { var Size = await EncryptedFile.GetSizeRawDataAsync().ConfigureAwait(true); var Thumbnail = new BitmapImage(new Uri("ms-appx:///Assets/LockFile.png")); var ModifiedTime = await EncryptedFile.GetModifiedTimeAsync().ConfigureAwait(true); SecureCollection.Add(new FileSystemStorageItemBase(EncryptedFile, Size, Thumbnail, ModifiedTime)); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_EncryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); break; } } } catch (TaskCanceledException cancelException) { LogTracer.Log(cancelException, "Import items to SecureArea have been cancelled"); } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when importing file"); } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1500).ConfigureAwait(true); ActivateLoading(false); } } }
private async void Location_Click(object sender, RoutedEventArgs e) { if (SearchResultList.SelectedItem is FileSystemStorageItem Item) { if (Item.StorageType == StorageItemTypes.Folder) { try { if (SettingControl.IsDetachTreeViewAndPresenter) { if ((await Item.GetStorageItem().ConfigureAwait(true)) is StorageFolder Folder) { await FileControlInstance.DisplayItemsInFolder(Folder).ConfigureAwait(true); } } else { TreeViewNode TargetNode = await FileControlInstance.FolderTree.RootNodes[0].GetChildNodeAsync(new PathAnalysis(Item.Path, (FileControlInstance.FolderTree.RootNodes[0].Content as TreeViewNodeContent).Path)).ConfigureAwait(true); if (TargetNode != null) { await FileControlInstance.DisplayItemsInFolder(TargetNode).ConfigureAwait(true); } else { throw new Exception(); } } } catch { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LocateFolderFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } else { try { if ((await Item.GetStorageItem().ConfigureAwait(true)) is StorageFile File) { if (SettingControl.IsDetachTreeViewAndPresenter) { await FileControlInstance.DisplayItemsInFolder(await File.GetParentAsync()).ConfigureAwait(true); } else { TreeViewNode CurrentNode = await FileControlInstance.FolderTree.RootNodes[0].GetChildNodeAsync(new PathAnalysis(Path.GetDirectoryName(Item.Path), (FileControlInstance.FolderTree.RootNodes[0].Content as TreeViewNodeContent).Path)).ConfigureAwait(true); await FileControlInstance.DisplayItemsInFolder(CurrentNode).ConfigureAwait(true); } } } catch (FileNotFoundException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_LocateFileFailure_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_RefreshButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } } }
private async void SecureArea_Loaded(object sender, RoutedEventArgs e) { try { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("IsFirstEnterSecureArea")) { UnlockPassword = CredentialProtector.GetPasswordFromProtector("SecureAreaPrimaryPassword"); FileEncryptionAesKey = KeyGenerator.GetMD5FromKey(UnlockPassword, 16); AESKeySize = Convert.ToInt32(ApplicationData.Current.LocalSettings.Values["SecureAreaAESKeySize"]); if (!(ApplicationData.Current.LocalSettings.Values["SecureAreaLockMode"] is string LockMode) || LockMode != nameof(CloseLockMode) || IsNewStart) { if (Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"])) { RETRY: switch (await WindowsHelloAuthenticator.VerifyUserAsync().ConfigureAwait(true)) { case AuthenticatorState.VerifyPassed: { break; } case AuthenticatorState.UnknownError: case AuthenticatorState.VerifyFailed: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_WinHelloAuthFail_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_TryAgain"), SecondaryButtonText = Globalization.GetString("Common_Dialog_UsePassword"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; ContentDialogResult Result = await Dialog.ShowAsync().ConfigureAwait(true); if (Result == ContentDialogResult.Primary) { goto RETRY; } else if (Result == ContentDialogResult.Secondary) { if (!await EnterByPassword().ConfigureAwait(true)) { return; } } else { GoBack(); return; } break; } case AuthenticatorState.UserNotRegistered: case AuthenticatorState.CredentialNotFound: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_WinHelloCredentialLost_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = false; if (!await EnterByPassword().ConfigureAwait(true)) { return; } break; } case AuthenticatorState.WindowsHelloUnsupport: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_WinHelloDisable_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_UsePassword"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = false; if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { if (!await EnterByPassword().ConfigureAwait(true)) { return; } } else { GoBack(); return; } break; } } } else { if (!await EnterByPassword().ConfigureAwait(true)) { return; } } } } else { if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("SecureAreaUsePermission")) { try { LoadingText.Text = Globalization.GetString("Progress_Tip_CheckingLicense"); CancelButton.Visibility = Visibility.Collapsed; LoadingControl.IsLoading = true; MainPage.ThisPage.IsAnyTaskRunning = true; if (await CheckPurchaseStatusAsync().ConfigureAwait(true)) { if (MainPage.ThisPage.Nav.CurrentSourcePageType.Name != nameof(SecureArea)) { GoBack(); return; } ApplicationData.Current.LocalSettings.Values["SecureAreaUsePermission"] = true; await Task.Delay(500).ConfigureAwait(true); } else { if (MainPage.ThisPage.Nav.CurrentSourcePageType.Name != nameof(SecureArea)) { GoBack(); return; } SecureAreaIntroDialog IntroDialog = new SecureAreaIntroDialog(); if ((await IntroDialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { if (await PurchaseAsync().ConfigureAwait(true)) { ApplicationData.Current.LocalSettings.Values["SecureAreaUsePermission"] = true; QueueContentDialog SuccessDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaUnlock_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await SuccessDialog.ShowAsync().ConfigureAwait(true); } else { GoBack(); return; } } else { GoBack(); return; } } } catch (NetworkException) { QueueContentDialog ErrorDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaNetworkUnavailable_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await ErrorDialog.ShowAsync().ConfigureAwait(true); GoBack(); return; } finally { await Task.Delay(500).ConfigureAwait(true); LoadingControl.IsLoading = false; MainPage.ThisPage.IsAnyTaskRunning = false; } } SecureAreaWelcomeDialog Dialog = new SecureAreaWelcomeDialog(); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { AESKeySize = Dialog.AESKeySize; UnlockPassword = Dialog.Password; FileEncryptionAesKey = KeyGenerator.GetMD5FromKey(UnlockPassword, 16); CredentialProtector.RequestProtectPassword("SecureAreaPrimaryPassword", UnlockPassword); ApplicationData.Current.LocalSettings.Values["SecureAreaAESKeySize"] = Dialog.AESKeySize; ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = Dialog.IsEnableWindowsHello; ApplicationData.Current.LocalSettings.Values["IsFirstEnterSecureArea"] = false; } else { if (Dialog.IsEnableWindowsHello) { await WindowsHelloAuthenticator.DeleteUserAsync().ConfigureAwait(true); } GoBack(); return; } } await StartLoadFile().ConfigureAwait(false); } catch (Exception ex) { LogTracer.LeadToBlueScreen(ex); } }
private async void Delete_Click(object sender, RoutedEventArgs e) { if (Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down)) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; Retry: try { await FullTrustProcessController.Current.DeleteAsync(Item.PhotoFile.Path, true).ConfigureAwait(true); PhotoCollection.Remove(Item); Behavior.InitAnimation(InitOption.Full); } catch (FileCaputureException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Item_Captured_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (FileNotFoundException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_RefreshButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (InvalidOperationException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_GrantButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { if (await FullTrustProcessController.Current.SwitchToAdminModeAsync().ConfigureAwait(true)) { goto Retry; } else { QueueContentDialog ErrorDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DenyElevation_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await ErrorDialog.ShowAsync().ConfigureAwait(true); } } } catch (Exception) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } else { DeleteDialog Dialog = new DeleteDialog(Globalization.GetString("QueueDialog_DeleteFile_Content")); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; Retry: try { await FullTrustProcessController.Current.DeleteAsync(Item.PhotoFile.Path, Dialog.IsPermanentDelete).ConfigureAwait(true); PhotoCollection.Remove(Item); Behavior.InitAnimation(InitOption.Full); } catch (FileCaputureException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_Item_Captured_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (FileNotFoundException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_RefreshButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } catch (InvalidOperationException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnauthorizedDelete_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_GrantButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if (await dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary) { if (await FullTrustProcessController.Current.SwitchToAdminModeAsync().ConfigureAwait(true)) { goto Retry; } else { QueueContentDialog ErrorDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DenyElevation_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await ErrorDialog.ShowAsync().ConfigureAwait(true); } } } catch (Exception) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DeleteItemError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); } } } }
private async void ExportFile_Click(object sender, RoutedEventArgs e) { if (SecureGridView.SelectedItem is FileSystemStorageItemBase Item) { FolderPicker Picker = new FolderPicker { SuggestedStartLocation = PickerLocationId.Desktop, ViewMode = PickerViewMode.Thumbnail }; Picker.FileTypeFilter.Add("*"); if ((await Picker.PickSingleFolderAsync()) is StorageFolder Folder) { Cancellation = new CancellationTokenSource(); try { ActivateLoading(true, false); if (await((StorageFile)await Item.GetStorageItem().ConfigureAwait(true)).DecryptAsync(Folder, FileEncryptionAesKey, Cancellation.Token).ConfigureAwait(true) is StorageFile) { await(await Item.GetStorageItem().ConfigureAwait(true)).DeleteAsync(StorageDeleteOption.PermanentDelete); SecureCollection.Remove(Item); _ = await Launcher.LaunchFolderAsync(Folder); } else { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DecryptError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); } } catch (PasswordErrorException) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_DecryptPasswordError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); await Task.Delay(1500).ConfigureAwait(true); ActivateLoading(false); } catch (FileDamagedException) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_FileDamageError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); await Task.Delay(1500).ConfigureAwait(true); ActivateLoading(false); } catch (UnauthorizedAccessException) { QueueContentDialog dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_UnauthorizedCreateDecryptFile_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await dialog.ShowAsync().ConfigureAwait(true); await Task.Delay(1500).ConfigureAwait(true); ActivateLoading(false); } catch (TaskCanceledException) { } catch (CryptographicException) { } finally { Cancellation.Dispose(); Cancellation = null; await Task.Delay(1500).ConfigureAwait(true); ActivateLoading(false); } } } }
private async Task Initialize() { try { ExitLocker = new ManualResetEvent(false); Cancellation = new CancellationTokenSource(); LoadQueue = new Queue <int>(); MainPage.ThisPage.IsAnyTaskRunning = true; Behavior.Attach(Flip); List <FileSystemStorageItemBase> FileList = FileSystemStorageItemBase.Open(Path.GetDirectoryName(SelectedPhotoPath), ItemFilters.Folder).GetChildrenItems(SettingControl.IsDisplayHiddenItem, ItemFilters.File).Where((Item) => Item.Type.Equals(".png", StringComparison.OrdinalIgnoreCase) || Item.Type.Equals(".jpg", StringComparison.OrdinalIgnoreCase) || Item.Type.Equals(".bmp", StringComparison.OrdinalIgnoreCase)).ToList(); if (FileList.Count == 0) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("Queue_Dialog_ImageReadError_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); Frame.GoBack(); } else { int LastSelectIndex = FileList.FindIndex((Photo) => Photo.Path.Equals(SelectedPhotoPath, StringComparison.OrdinalIgnoreCase)); if (LastSelectIndex < 0 || LastSelectIndex >= FileList.Count) { LastSelectIndex = 0; } PhotoCollection = new ObservableCollection <PhotoDisplaySupport>(FileList.Select((Item) => new PhotoDisplaySupport(Item))); Flip.ItemsSource = PhotoCollection; if (!await PhotoCollection[LastSelectIndex].ReplaceThumbnailBitmapAsync().ConfigureAwait(true)) { CouldnotLoadTip.Visibility = Visibility.Visible; } for (int i = LastSelectIndex - 5 > 0 ? LastSelectIndex - 5 : 0; i <= (LastSelectIndex + 5 < PhotoCollection.Count - 1 ? LastSelectIndex + 5 : PhotoCollection.Count - 1) && !Cancellation.IsCancellationRequested; i++) { await PhotoCollection[i].GenerateThumbnailAsync().ConfigureAwait(true); } if (!Cancellation.IsCancellationRequested) { Flip.SelectedIndex = LastSelectIndex; Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; await EnterAnimation.BeginAsync().ConfigureAwait(true); } } } catch (Exception ex) { CouldnotLoadTip.Visibility = Visibility.Visible; LogTracer.Log(ex, "An error was threw when initialize PhotoViewer"); } finally { MainPage.ThisPage.IsAnyTaskRunning = false; ExitLocker.Set(); } }
private async void TabViewContainer_KeyDown(CoreWindow sender, KeyEventArgs args) { if (!QueueContentDialog.IsRunningOrWaiting) { CoreVirtualKeyStates CtrlState = sender.GetKeyState(VirtualKey.Control); switch (args.VirtualKey) { case VirtualKey.W when CtrlState.HasFlag(CoreVirtualKeyStates.Down): { if (TabViewControl.SelectedItem is TabViewItem Tab) { args.Handled = true; await CleanUpAndRemoveTabItem(Tab).ConfigureAwait(true); } return; } } if (CurrentNavigationControl?.Content is ThisPC PC) { switch (args.VirtualKey) { case VirtualKey.T when CtrlState.HasFlag(CoreVirtualKeyStates.Down): { CreateNewTab(null); args.Handled = true; break; } case VirtualKey.Space when SettingControl.IsQuicklookAvailable && SettingControl.IsQuicklookEnable: { using (FullTrustProcessController.ExclusiveUsage Exclusive = await FullTrustProcessController.GetAvailableController()) { if (PC.DeviceGrid.SelectedItem is HardDeviceInfo Device) { await Exclusive.Controller.ViewWithQuicklookAsync(Device.Folder.Path).ConfigureAwait(true); } else if (PC.LibraryGrid.SelectedItem is LibraryFolder Library) { await Exclusive.Controller.ViewWithQuicklookAsync(Library.Folder.Path).ConfigureAwait(true); } } args.Handled = true; break; } case VirtualKey.Enter: { if (PC.DeviceGrid.SelectedItem is HardDeviceInfo Device) { if (string.IsNullOrEmpty(Device.Folder.Path)) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_TipTitle"), Content = Globalization.GetString("QueueDialog_MTP_CouldNotAccess_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_ContinueButton"), CloseButtonText = Globalization.GetString("Common_Dialog_CancelButton") }; if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { await Launcher.LaunchFolderAsync(Device.Folder); } } else { if (AnimationController.Current.IsEnableAnimation) { CurrentNavigationControl.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, string>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Device.Folder.Path), new DrillInNavigationTransitionInfo()); } else { CurrentNavigationControl.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, string>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Device.Folder.Path), new SuppressNavigationTransitionInfo()); } } args.Handled = true; } else if (PC.LibraryGrid.SelectedItem is LibraryFolder Library) { if (AnimationController.Current.IsEnableAnimation) { CurrentNavigationControl.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, string>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Library.Folder.Path), new DrillInNavigationTransitionInfo()); } else { CurrentNavigationControl.Navigate(typeof(FileControl), new Tuple <WeakReference <TabViewItem>, string>(new WeakReference <TabViewItem>(TabViewControl.SelectedItem as TabViewItem), Library.Folder.Path), new SuppressNavigationTransitionInfo()); } args.Handled = true; } break; } case VirtualKey.F5: { PC.Refresh_Click(null, null); args.Handled = true; break; } } } } }