Beispiel #1
0
 private void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
 {
     if (!e.IsTerminating && e.ExceptionObject is Exception ex)
     {
         LogTracer.LeadToBlueScreen(ex);
     }
 }
Beispiel #2
0
        private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
        {
            SQLite.Current.Dispose();

            LogTracer.LeadToBlueScreen(e.Exception);
            e.Handled = true;
        }
Beispiel #3
0
        private async void SecureArea_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                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
                                {
                                    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
                                {
                                    GoBack();
                                    return;
                                }

                                break;
                            }
                            }
                        }
                        else
                        {
                            if (!await EnterByPassword())
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    try
                    {
                        LoadingText.Text         = Globalization.GetString("Progress_Tip_CheckingLicense");
                        CancelButton.Visibility  = Visibility.Collapsed;
                        LoadingControl.IsLoading = true;

                        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
                                {
                                    GoBack();
                                    return;
                                }
                            }
                            else
                            {
                                GoBack();
                                return;
                            }
                        }
                    }
                    finally
                    {
                        await Task.Delay(500);

                        LoadingControl.IsLoading = 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();
                        }

                        GoBack();
                        return;
                    }
                }

                CoreWindow.GetForCurrentThread().KeyDown += SecureArea_KeyDown;

                WholeArea.Visibility = Visibility.Visible;

                SelectionExtention = new ListViewBaseSelectionExtention(SecureGridView, DrawRectangle);

                await LoadSecureFile();
            }
            catch (Exception ex)
            {
                LogTracer.LeadToBlueScreen(ex);
            }
        }
        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);
            }
        }