Exemple #1
0
        private void OpenVault_Click(object sender, RoutedEventArgs e)
        {
            if (_viewModel.SelectedItemIndex == -1)
            {
                MessageBox.Show((string)FindResource("NoVaultSelected"), "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (Password.SecurePassword.Empty())
            {
                MessageBox.Show((string)FindResource("NoPasswordGiven"), "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Debug.Assert(_viewModel.SelectedVaultPath != string.Empty, "SelectedPath != Empty");
            if (!File.Exists(_viewModel.SelectedVaultPath))
            {
                var result = MessageBox.Show((string)FindResource("VaultNotFound"), "Error",
                                             MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes &&
                    _viewModel.RemoveLocationCommand.CanExecute(null))
                {
                    _viewModel.RemoveLocationCommand.Execute(null);
                }

                _viewModel.SelectedItemIndex = -1;
                Password.Clear();

                return;
            }

            try {
                var cmd = (ExecuteCommand <SecureString, BindableObject>)_viewModel.OpenVaultCommand;
                if (!cmd.CanExecute(Password.SecurePassword))
                {
                    return;
                }

                cmd.Execute(Password.SecurePassword);
                Debug.Assert(cmd.Result != null, "cmd.Result != null");
                var vaultViewer = new VaultViewWindow(cmd.Result);
                vaultViewer.Show();
                Close();
            } catch (IncorrectPassword ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Password.Clear();
            } catch (DataCorruptedException ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
        private void NewVault_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new Win32.SaveFileDialog {
                DefaultExt = ".ekp",
                Filter     = "EasyKeeper vault (*.ekp)|*.ekp"
            };

            bool?result = dlg.ShowDialog();

            if (result != true)
            {
                return;
            }

            var newVaultPath = dlg.FileName;

            var vm     = new SetupPasswordViewModel();
            var dialog = new InputPasswordDialog {
                DataContext = vm
            };

            result = dialog.ShowDialog();
            if (result != true)
            {
                return;
            }

            var newVaultSecurePwd = vm.NewVaultPassword;

            var cmd = (ExecuteCommand <Tuple <string, SecureString>,
                                       BindableObject>)_viewModel.NewVaultCommand;
            var info = Tuple.Create(newVaultPath, newVaultSecurePwd);

            if (!_viewModel.NewVaultCommand.CanExecute(info))
            {
                return;
            }

            _viewModel.NewVaultCommand.Execute(info);
            Debug.Assert(cmd.Result != null, "cmd.Result != null");
            var vaultViewer = new VaultViewWindow(cmd.Result);

            vaultViewer.Show();
            Close();
        }