示例#1
0
        private async void DeviceGrid_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
        {
            try
            {
                if (SettingControl.IsInputFromPrimaryButton && (e.OriginalSource as FrameworkElement)?.DataContext 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)
                        {
                            Nav.Navigate(typeof(FileControl), new Tuple <TabViewItem, StorageFolder, ThisPC>(TabItem, Device.Folder, this), new DrillInNavigationTransitionInfo());
                        }
                        else
                        {
                            Nav.Navigate(typeof(FileControl), new Tuple <TabViewItem, StorageFolder, ThisPC>(TabItem, Device.Folder, this), new SuppressNavigationTransitionInfo());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionTracer.RequestBlueScreen(ex);
            }
        }
示例#2
0
        private async void MainPage_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
        {
            Deferral Deferral = e.GetDeferral();

            if (IsAnyTaskRunning || GeneralTransformer.IsAnyTransformTaskRunning || FullTrustExcutorController.Current.IsNowHasAnyActionExcuting)
            {
                QueueContentDialog Dialog = new QueueContentDialog
                {
                    Title             = Globalization.GetString("Common_Dialog_WarningTitle"),
                    Content           = Globalization.GetString("QueueDialog_WaitUntilFinish_Content"),
                    PrimaryButtonText = Globalization.GetString("QueueDialog_WaitUntilFinish_PrimaryButton"),
                    CloseButtonText   = Globalization.GetString("QueueDialog_WaitUntilFinish_CloseButton")
                };

                if ((await Dialog.ShowAsync().ConfigureAwait(true)) != ContentDialogResult.Primary)
                {
                    e.Handled = true;
                }
                else
                {
                    IsAnyTaskRunning = false;
                    GeneralTransformer.IsAnyTransformTaskRunning = false;
                    ToastNotificationManager.History.Clear();
                }
            }

            try
            {
                if (!e.Handled && Clipboard.GetContent().Contains(StandardDataFormats.StorageItems))
                {
                    Clipboard.Flush();
                }
            }
            catch
            {
            }

            Deferral.Complete();
        }
        private async void ClearRecycleBin_Click(object sender, RoutedEventArgs e)
        {
            QueueContentDialog Dialog = new QueueContentDialog
            {
                Title             = Globalization.GetString("Common_Dialog_WarningTitle"),
                Content           = Globalization.GetString("QueueDialog_EmptyRecycleBin_Content"),
                PrimaryButtonText = Globalization.GetString("Common_Dialog_ContinueButton"),
                CloseButtonText   = Globalization.GetString("Common_Dialog_CancelButton")
            };

            if (await Dialog.ShowAsync().ConfigureAwait(true) == ContentDialogResult.Primary)
            {
                await ActivateLoading(true, Globalization.GetString("RecycleBinEmptyingText")).ConfigureAwait(true);

                if (await FullTrustProcessController.Current.EmptyRecycleBinAsync().ConfigureAwait(true))
                {
                    await ActivateLoading(false).ConfigureAwait(true);

                    FileCollection.Clear();

                    HasFile.Visibility        = Visibility.Visible;
                    ClearRecycleBin.IsEnabled = false;
                }
                else
                {
                    QueueContentDialog dialog = new QueueContentDialog
                    {
                        Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                        Content         = Globalization.GetString("QueueDialog_RecycleBinEmptyError_Content"),
                        CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                    };

                    _ = await dialog.ShowAsync().ConfigureAwait(true);

                    await ActivateLoading(false).ConfigureAwait(true);
                }
            }
        }
示例#4
0
        private async void Location_Click(object sender, RoutedEventArgs e)
        {
            if (SearchResultList.SelectedItem is FileSystemStorageItemBase Item)
            {
                try
                {
                    StorageFolder ParentFolder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(Item.Path));

                    if (WeakToFileControl.TryGetTarget(out FileControl Control))
                    {
                        Frame.GoBack();

                        await Control.OpenTargetFolder(ParentFolder).ConfigureAwait(true);

                        await JumpListController.Current.AddItem(JumpListGroup.Recent, ParentFolder).ConfigureAwait(true);

                        if (Control.Presenter.FileCollection.FirstOrDefault((SItem) => SItem.Path == Item.Path) is FileSystemStorageItemBase Target)
                        {
                            Control.Presenter.ItemPresenter.ScrollIntoView(Target);
                            Control.Presenter.SelectedItem = Target;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, $"An error was threw in {nameof(Location_Click)}");

                    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);
                }
            }
        }
示例#5
0
        private async void SearchResultList_DoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
        {
            if ((e.OriginalSource as FrameworkElement).DataContext is FileSystemStorageItemBase Item)
            {
                try
                {
                    string ParentFolderPath = Path.GetDirectoryName(Item.Path);

                    if (WeakToFileControl.TryGetTarget(out FileControl Control))
                    {
                        Frame.GoBack();

                        await Control.CurrentPresenter.DisplayItemsInFolder(ParentFolderPath).ConfigureAwait(true);

                        await JumpListController.Current.AddItemAsync(JumpListGroup.Recent, ParentFolderPath).ConfigureAwait(true);

                        if (Control.CurrentPresenter.FileCollection.FirstOrDefault((SItem) => SItem == Item) is FileSystemStorageItemBase Target)
                        {
                            Control.CurrentPresenter.ItemPresenter.ScrollIntoView(Target);
                            Control.CurrentPresenter.SelectedItem = Target;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, $"An error was threw in {nameof(Location_Click)}");

                    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);
                }
            }
        }
示例#6
0
        private async void EjectButton_Click(object sender, RoutedEventArgs e)
        {
            if (DeviceGrid.SelectedItem is HardDeviceInfo Item)
            {
                if (string.IsNullOrEmpty(Item.Folder.Path))
                {
                    QueueContentDialog Dialog = new QueueContentDialog
                    {
                        Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                        Content         = Globalization.GetString("QueueContentDialog_UnableToEject_Content"),
                        CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                    };
                    _ = await Dialog.ShowAsync().ConfigureAwait(false);
                }
                else
                {
                    foreach (TabViewItem Tab in TabViewContainer.ThisPage.TabViewControl.TabItems.Select((Obj) => Obj as TabViewItem).Where((Tab) => Tab.Content is Frame frame && CommonAccessCollection.FrameFileControlDic.ContainsKey(frame) && Path.GetPathRoot(CommonAccessCollection.FrameFileControlDic[frame].CurrentFolder?.Path) == Item.Folder.Path).ToArray())
                    {
                        await TabViewContainer.ThisPage.CleanUpAndRemoveTabItem(Tab).ConfigureAwait(true);
                    }

                    if (await FullTrustProcessController.Current.EjectPortableDevice(Item.Folder.Path).ConfigureAwait(true))
                    {
                        ShowEjectNotification();
                    }
                    else
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueContentDialog_UnableToEject_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };
                        _ = await Dialog.ShowAsync().ConfigureAwait(false);
                    }
                }
            }
        }
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (CurrentEncoding != null)
                {
                    try
                    {
                        using (FileStream Stream = FileSystemStorageItemBase.Create(TextFile.Path, StorageItemTypes.File, CreateOption.ReplaceExisting).GetFileStreamFromFile(AccessMode.Write))
                            using (StreamWriter Writer = new StreamWriter(Stream, CurrentEncoding))
                            {
                                await Writer.WriteAsync(Text.Text).ConfigureAwait(true);
                            }
                    }
                    catch
                    {
                        QueueContentDialog Dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("QueueDialog_CouldReadWriteFile_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };

                        await Dialog.ShowAsync().ConfigureAwait(true);
                    }

                    Frame.GoBack();
                }
                else
                {
                    InvalidTip.IsOpen = true;
                }
            }
            catch
            {
                InvalidTip.IsOpen = true;
            }
        }
示例#8
0
        private async void DeleteFile_Click(object sender, RoutedEventArgs e)
        {
            QueueContentDialog Dialog = new QueueContentDialog
            {
                Title             = Globalization.GetString("Common_Dialog_WarningTitle"),
                PrimaryButtonText = Globalization.GetString("Common_Dialog_ContinueButton"),
                Content           = Globalization.GetString("QueueDialog_DeleteFile_Content"),
                CloseButtonText   = Globalization.GetString("Common_Dialog_CancelButton")
            };

            if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary)
            {
                foreach (SecureAreaStorageItem Item in SecureGridView.SelectedItems.ToArray())
                {
                    SecureCollection.Remove(Item);

                    if (!Item.PermanentDelete())
                    {
                        LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error()), "Delete encrypted file failed");
                    }
                }
            }
        }
示例#9
0
        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");
            }
        }
示例#10
0
        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();
        }
示例#11
0
        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);
            }
        }
示例#12
0
        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;
                }
                }
            }
        }
示例#13
0
        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);
                }
            }
        }
        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();
            }
        }
示例#15
0
        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");
            }
        }
示例#16
0
        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;
                        }
                    }
                }
            }
        }
示例#17
0
        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 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);
            }
        }
示例#19
0
        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);
                }
            }
        }
示例#20
0
        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;
            }
        }
示例#21
0
        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));
                }
            }
        }
示例#22
0
        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);
                }
            }
        }
示例#23
0
        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);
                }
            }
        }
示例#24
0
        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;
            }
        }
示例#25
0
        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);
                    }
                }
            }
        }
示例#26
0
        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 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);
                    }
                }
            }
        }
示例#28
0
        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 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();
            }
        }
示例#30
0
        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();
            }
        }