private async void SecureArea_Loaded(object sender, RoutedEventArgs e) { WholeArea.Visibility = Visibility.Collapsed; SecureGridView.AddHandler(PointerPressedEvent, PointerPressedHandler, true); ApplicationView.GetForCurrentView().IsScreenCaptureEnabled = false; if (ApplicationData.Current.LocalSettings.Values.ContainsKey("IsFirstEnterSecureArea")) { AESKeySize = Convert.ToInt32(ApplicationData.Current.LocalSettings.Values["SecureAreaAESKeySize"]); if (ApplicationData.Current.LocalSettings.Values["SecureAreaLockMode"] is not string LockMode || LockMode != nameof(CloseLockMode) || IsNewStart) { if (Convert.ToBoolean(ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"])) { RETRY: switch (await WindowsHelloAuthenticator.VerifyUserAsync()) { case AuthenticatorState.VerifyPassed: { break; } case AuthenticatorState.UnknownError: case AuthenticatorState.VerifyFailed: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_WinHelloAuthFail_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_TryAgain"), SecondaryButtonText = Globalization.GetString("Common_Dialog_UsePassword"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; ContentDialogResult Result = await Dialog.ShowAsync(); if (Result == ContentDialogResult.Primary) { goto RETRY; } else if (Result == ContentDialogResult.Secondary) { if (!await EnterByPassword()) { return; } } else { Frame.GoBack(); return; } break; } case AuthenticatorState.UserNotRegistered: case AuthenticatorState.CredentialNotFound: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_WinHelloCredentialLost_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; _ = await Dialog.ShowAsync(); ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = false; if (!await EnterByPassword()) { return; } break; } case AuthenticatorState.WindowsHelloUnsupport: { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_WinHelloDisable_Content"), PrimaryButtonText = Globalization.GetString("Common_Dialog_UsePassword"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = false; if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { if (!await EnterByPassword()) { return; } } else { Frame.GoBack(); return; } break; } } } else { if (!await EnterByPassword()) { return; } } } } else { try { await ActivateLoading(true, false, Globalization.GetString("Progress_Tip_CheckingLicense")); if (await MSStoreHelper.Current.CheckPurchaseStatusAsync()) { await Task.Delay(500); } else { SecureAreaIntroDialog IntroDialog = new SecureAreaIntroDialog(); if ((await IntroDialog.ShowAsync()) == ContentDialogResult.Primary) { StorePurchaseStatus Status = await MSStoreHelper.Current.PurchaseAsync(); if (Status == StorePurchaseStatus.AlreadyPurchased || Status == StorePurchaseStatus.Succeeded) { QueueContentDialog SuccessDialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_SecureAreaUnlock_Content"), CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton") }; await SuccessDialog.ShowAsync(); } else { Frame.GoBack(); return; } } else { Frame.GoBack(); return; } } } finally { await ActivateLoading(false); } SecureAreaWelcomeDialog Dialog = new SecureAreaWelcomeDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { AESKeySize = Dialog.AESKeySize; UnlockPassword = Dialog.Password; ApplicationData.Current.LocalSettings.Values["SecureAreaAESKeySize"] = Dialog.AESKeySize; ApplicationData.Current.LocalSettings.Values["SecureAreaEnableWindowsHello"] = Dialog.IsEnableWindowsHello; ApplicationData.Current.LocalSettings.Values["IsFirstEnterSecureArea"] = false; } else { if (Dialog.IsEnableWindowsHello) { await WindowsHelloAuthenticator.DeleteUserAsync(); } Frame.GoBack(); return; } } CoreWindow.GetForCurrentThread().KeyDown += SecureArea_KeyDown; WholeArea.Visibility = Visibility.Visible; SelectionExtention = new ListViewBaseSelectionExtention(SecureGridView, DrawRectangle); await LoadSecureFile(); }
private async void 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); } }