2017-10-30 18:34:38 +01:00
|
|
|
|
using System;
|
2017-11-02 11:30:03 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
using ModernKeePass.Common;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
2017-11-02 11:30:03 +01:00
|
|
|
|
using ModernKeePassLib;
|
|
|
|
|
using ModernKeePassLib.Cryptography.Cipher;
|
2017-11-03 15:48:55 +01:00
|
|
|
|
using ModernKeePassLib.Cryptography.KeyDerivation;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-12-01 17:59:38 +01:00
|
|
|
|
// TODO: implement Kdf settings
|
2017-10-30 18:34:38 +01:00
|
|
|
|
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
|
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
private readonly IDatabase _database;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
private GroupVm _selectedItem;
|
|
|
|
|
|
|
|
|
|
public bool HasRecycleBin
|
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
get { return _database.RecycleBinEnabled; }
|
2017-10-30 18:34:38 +01:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
_database.RecycleBinEnabled = value;
|
2017-11-29 19:13:38 +01:00
|
|
|
|
OnPropertyChanged("HasRecycleBin");
|
2017-10-30 18:34:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<GroupVm> Groups { get; set; }
|
|
|
|
|
|
2017-11-02 11:30:03 +01:00
|
|
|
|
public IEnumerable<string> Ciphers
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
for (var inx = 0; inx < CipherPool.GlobalPool.EngineCount; inx++)
|
|
|
|
|
{
|
|
|
|
|
yield return CipherPool.GlobalPool[inx].DisplayName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int CipherIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
for (var inx = 0; inx < CipherPool.GlobalPool.EngineCount; ++inx)
|
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
if (CipherPool.GlobalPool[inx].CipherUuid.Equals(_database.DataCipher)) return inx;
|
2017-11-02 11:30:03 +01:00
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2017-11-23 15:26:57 +01:00
|
|
|
|
set { _database.DataCipher = CipherPool.GlobalPool[value].CipherUuid; }
|
2017-11-02 11:30:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<string> Compressions => Enum.GetNames(typeof(PwCompressionAlgorithm)).Take((int)PwCompressionAlgorithm.Count);
|
|
|
|
|
|
|
|
|
|
public string CompressionName
|
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
get { return Enum.GetName(typeof(PwCompressionAlgorithm), _database.CompressionAlgorithm); }
|
|
|
|
|
set { _database.CompressionAlgorithm = (PwCompressionAlgorithm)Enum.Parse(typeof(PwCompressionAlgorithm), value); }
|
2017-11-02 11:30:03 +01:00
|
|
|
|
}
|
2017-11-03 15:48:55 +01:00
|
|
|
|
public IEnumerable<string> KeyDerivations => KdfPool.Engines.Select(e => e.Name);
|
|
|
|
|
|
|
|
|
|
public string KeyDerivationName
|
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
get { return KdfPool.Get(_database.KeyDerivation.KdfUuid).Name; }
|
|
|
|
|
set { _database.KeyDerivation = KdfPool.Engines.FirstOrDefault(e => e.Name == value)?.GetDefaultParameters(); }
|
2017-11-03 15:48:55 +01:00
|
|
|
|
}
|
2017-11-02 11:30:03 +01:00
|
|
|
|
|
2017-10-30 18:34:38 +01:00
|
|
|
|
public ISelectableModel SelectedItem
|
|
|
|
|
{
|
|
|
|
|
get { return Groups.FirstOrDefault(g => g.IsSelected); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_selectedItem == value) return;
|
|
|
|
|
if (_selectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
_selectedItem.IsSelected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetProperty(ref _selectedItem, (GroupVm)value);
|
|
|
|
|
|
|
|
|
|
if (_selectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
_selectedItem.IsSelected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 15:26:57 +01:00
|
|
|
|
public SettingsDatabaseVm() : this((Application.Current as App)?.Database) { }
|
|
|
|
|
|
|
|
|
|
public SettingsDatabaseVm(IDatabase database)
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
2017-11-23 15:26:57 +01:00
|
|
|
|
_database = database;
|
|
|
|
|
Groups = _database.RootGroup.Groups;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|