2020-05-04 12:48:27 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.Common;
|
|
|
|
|
using ModernKeePass.Domain.Dtos;
|
2017-10-10 15:00:31 +02:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2020-04-23 19:00:38 +02:00
|
|
|
|
public class OpenVm: ViewModelBase
|
2017-10-10 15:00:31 +02:00
|
|
|
|
{
|
2020-05-04 12:48:27 +02:00
|
|
|
|
private readonly IFileProxy _file;
|
2020-04-07 12:48:18 +02:00
|
|
|
|
private string _name;
|
|
|
|
|
private string _path;
|
|
|
|
|
private string _token;
|
2020-04-30 19:40:48 +02:00
|
|
|
|
public bool IsFileSelected => !string.IsNullOrEmpty(Token);
|
2017-10-10 15:00:31 +02:00
|
|
|
|
|
2020-04-07 12:48:18 +02:00
|
|
|
|
public string Token
|
|
|
|
|
{
|
|
|
|
|
get { return _token; }
|
2020-04-30 19:40:48 +02:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Set(() => Token, ref _token, value);
|
|
|
|
|
RaisePropertyChanged(nameof(IsFileSelected));
|
|
|
|
|
}
|
2020-04-07 12:48:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return _name; }
|
2020-04-30 19:40:48 +02:00
|
|
|
|
set { Set(() => Name, ref _name, value); }
|
2020-04-07 12:48:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Path
|
|
|
|
|
{
|
|
|
|
|
get { return _path; }
|
2020-04-30 19:40:48 +02:00
|
|
|
|
set { Set(() => Path, ref _path, value); }
|
2017-10-10 15:00:31 +02:00
|
|
|
|
}
|
2020-05-04 12:48:27 +02:00
|
|
|
|
|
|
|
|
|
public RelayCommand OpenDatabaseFileCommand { get; }
|
|
|
|
|
|
|
|
|
|
public OpenVm(IFileProxy file)
|
|
|
|
|
{
|
|
|
|
|
_file = file;
|
|
|
|
|
OpenDatabaseFileCommand = new RelayCommand(async () => await OpenDatabaseFile());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetFileInformation(FileInfo file)
|
|
|
|
|
{
|
|
|
|
|
if (file == null) return;
|
|
|
|
|
Token = file.Id;
|
|
|
|
|
Path = file.Path;
|
|
|
|
|
Name = file.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OpenDatabaseFile()
|
|
|
|
|
{
|
|
|
|
|
var file = await _file.OpenFile(string.Empty, Constants.Extensions.Kdbx, true);
|
|
|
|
|
SetFileInformation(file);
|
|
|
|
|
}
|
2017-10-10 15:00:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|