Display a big database size warning

Auto rename additional field when it matches standard
Treated all fields as new Field class
Added the Is Protected property
This commit is contained in:
Geoffroy BONNEVILLE
2020-05-12 17:14:30 +02:00
parent d6dc6a74a3
commit f8f7c19f65
34 changed files with 300 additions and 159 deletions

View File

@@ -5,5 +5,6 @@
public string OldName { get; set; }
public string NewName { get; set; }
public string Value { get; set; }
public bool IsProtected { get; set; }
}
}

View File

@@ -4,5 +4,6 @@
{
public string FieldName { get; set; }
public string FieldValue { get; set; }
public bool IsProtected { get; set; }
}
}

View File

@@ -0,0 +1,51 @@
using System.Linq;
using GalaSoft.MvvmLight;
using Messages;
using ModernKeePass.Domain.Enums;
namespace ModernKeePass.ViewModels.ListItems
{
public class EntryFieldVm: ViewModelBase
{
private string _name;
private string _value;
private bool _isProtected;
public string Name
{
get { return _name; }
set
{
var newName = EntryFieldName.StandardFieldNames.Contains(value) ? $"{value}_1" : value;
MessengerInstance.Send(new EntryFieldNameChangedMessage { OldName = Name, NewName = newName, Value = Value, IsProtected = IsProtected});
Set(nameof(Name), ref _name, newName);
}
}
public string Value
{
get { return _value; }
set
{
MessengerInstance.Send(new EntryFieldValueChangedMessage { FieldName = Name, FieldValue = value, IsProtected = IsProtected });
Set(nameof(Value), ref _value, value);
}
}
public bool IsProtected
{
get { return _isProtected; }
set
{
MessengerInstance.Send(new EntryFieldValueChangedMessage { FieldName = Name, FieldValue = Value, IsProtected = value });
Set(nameof(IsProtected), ref _isProtected, value);
}
}
public EntryFieldVm(string fieldName, string fieldValue, bool isProtected)
{
_name = fieldName;
_value = fieldValue;
_isProtected = isProtected;
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Messages;
using ModernKeePass.Application.Common.Interfaces;
@@ -93,6 +94,7 @@ namespace ModernKeePass.ViewModels
private readonly IResourceProxy _resource;
private readonly INotificationService _notification;
private readonly IFileProxy _file;
private readonly IDialogService _dialog;
private bool _hasPassword;
private bool _hasKeyFile;
private bool _isOpening;
@@ -102,12 +104,13 @@ namespace ModernKeePass.ViewModels
private string _keyFileText;
private bool _isError;
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, INotificationService notification, IFileProxy file)
public OpenDatabaseControlVm(IMediator mediator, IResourceProxy resource, INotificationService notification, IFileProxy file, IDialogService dialog)
{
_mediator = mediator;
_resource = resource;
_notification = notification;
_file = file;
_dialog = dialog;
OpenKeyFileCommand = new RelayCommand(async () => await OpenKeyFile());
OpenDatabaseCommand = new RelayCommand<string>(async databaseFilePath => await TryOpenDatabase(databaseFilePath), _ => IsValid);
_keyFileText = _resource.GetResourceValue("CompositeKeyDefaultKeyFile");
@@ -130,7 +133,7 @@ namespace ModernKeePass.ViewModels
if (database.IsDirty)
{
MessengerInstance.Register<DatabaseClosedMessage>(this, async message => await OpenDatabase(message.Parameter as string));
MessengerInstance.Send(new DatabaseAlreadyOpenedMessage {Parameter = databaseFilePath});
MessengerInstance.Send(new DatabaseAlreadyOpenedMessage { Parameter = databaseFilePath });
}
else await OpenDatabase(databaseFilePath);
}
@@ -146,9 +149,11 @@ namespace ModernKeePass.ViewModels
KeyFilePath = HasKeyFile ? KeyFilePath : null,
Password = HasPassword ? Password : null,
});
var rootGroupId = (await _mediator.Send(new GetDatabaseQuery())).RootGroupId;
var database = await _mediator.Send(new GetDatabaseQuery());
MessengerInstance.Send(new DatabaseOpenedMessage { RootGroupId = rootGroupId });
if (database.Size > Common.Constants.File.OneMegaByte)
await _dialog.ShowMessage(_resource.GetResourceValue("DatabaseTooBigDescription"), _resource.GetResourceValue("DatabaseTooBigTitle"));
MessengerInstance.Send(new DatabaseOpenedMessage { RootGroupId = database.RootGroupId });
}
catch (ArgumentException)
{

View File

@@ -42,7 +42,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Messages\NavigateToPageMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\SaveErrorMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\AboutVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\FieldVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\EntryFieldVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\ViewModelLocatorCommon.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\ListMenuItemVm.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\Items\MainMenuItemVm.cs" />