Exemple #1
0
        public void EditWithEditWindow(DecryptedPasswordFile file)
        {
            Helpers.AssertOnUiThread();

            using (var window = new EditWindow(file.RelativePath, file.Content, ConfigManager.Config.PasswordStore.PasswordGeneration))
            {
                if (!window.ShowDialog() ?? true)
                {
                    return;
                }

                try
                {
                    var newFile = new DecryptedPasswordFile(file.PasswordStore, file.FullPath, window.PasswordContent.Text);
                    passwordManager.EncryptPassword(newFile, true);

                    syncService?.EditPassword(newFile.RelativePath);
                    if (ConfigManager.Config.Notifications.Types.PasswordUpdated)
                    {
                        notificationService.Raise($"Password file \"{newFile.FileNameWithoutExtension}\" has been updated.", Severity.Info);
                    }
                }
                catch (Exception e)
                {
                    notificationService.ShowErrorWindow($"Unable to save your password (encryption failed): {e.Message}");
                    // TODO: do we want to show the edit window again here?
                }
            }
        }
        private void EditWithEditWindow(DecryptedPasswordFile file)
        {
            Helpers.AssertOnUiThread();

            using (var window = new EditWindow(pathDisplayHelper.GetDisplayPath(file), file.Content, ConfigManager.Config.PasswordStore.PasswordGeneration))
            {
                if (!window.ShowDialog() ?? true)
                {
                    return;
                }

                var newFile = new DecryptedPasswordFile(file, window.PasswordContent.Text);
                try
                {
                    passwordManager.EncryptPassword(newFile);

                    syncService?.EditPassword(newFile.FullPath);
                    if (ConfigManager.Config.Notifications.Types.PasswordUpdated)
                    {
                        notificationService.Raise($"Password file \"{newFile.FileNameWithoutExtension}\" has been updated.", Severity.Info);
                    }
                }
                catch (GitException e)
                {
                    notificationService.ShowErrorWindow($"Unable to commit your changes: {e.Message}");
                    EditWithEditWindow(newFile);
                }
                catch (Exception e)
                {
                    notificationService.ShowErrorWindow($"Unable to save your password (encryption failed): {e.Message}");
                    EditWithEditWindow(newFile);
                }
            }
        }