Files
jdescopingtool/NEW/src/Utils/JdeScoping.ConfigManager.Ui/ViewModels/Dialogs/UnlockStoreDialogViewModel.cs
T
Joseph Doherty 1fc7792cd1 refactor(configmanager): rename UI project and split test projects
Rename ConfigManager to ConfigManager.Ui to match the Core/CLI/UI project
structure, and split the monolithic test project into Core.Tests,
Cli.Tests, and Ui.Tests to align with the source project organization.
2026-01-28 10:24:36 -05:00

107 lines
3.0 KiB
C#

using System.Windows.Input;
using JdeScoping.ConfigManager.Core.Constants;
namespace JdeScoping.ConfigManager.Ui.ViewModels.Dialogs;
/// <summary>
/// View model for unlocking an existing secure store.
/// </summary>
public class UnlockStoreDialogViewModel : ViewModelBase
{
private readonly string _storePath;
private string _keyFilePath = string.Empty;
/// <summary>
/// Initializes a new instance of the <see cref="UnlockStoreDialogViewModel"/> class.
/// </summary>
/// <param name="storePath">The path to the store file to unlock.</param>
public UnlockStoreDialogViewModel(string storePath)
{
_storePath = storePath ?? throw new ArgumentNullException(nameof(storePath));
BrowseKeyFilePathCommand = new RelayCommand(BrowseKeyFilePath);
}
/// <summary>
/// Gets the path to the store file to unlock (read-only).
/// </summary>
public string StorePath => _storePath;
/// <summary>
/// Gets or sets the path to the key file for decryption.
/// </summary>
public string KeyFilePath
{
get => _keyFilePath;
set
{
if (SetProperty(ref _keyFilePath, value))
NotifyValidationChanged();
}
}
/// <summary>
/// Gets the command to browse for key file path location.
/// </summary>
public ICommand BrowseKeyFilePathCommand { get; }
/// <summary>
/// Gets a value indicating whether the dialog input is valid.
/// </summary>
public bool IsValid
{
get
{
if (string.IsNullOrWhiteSpace(KeyFilePath))
return false;
return System.IO.File.Exists(KeyFilePath);
}
}
/// <summary>
/// Gets the validation error message, or null if valid.
/// </summary>
public string? ValidationError
{
get
{
if (string.IsNullOrWhiteSpace(KeyFilePath))
return SecureStoreStrings.KeyFilePathRequired;
if (!System.IO.File.Exists(KeyFilePath))
return SecureStoreStrings.KeyFileNotFound;
return null;
}
}
/// <summary>
/// Event raised to request open file dialog for key file path.
/// Parameters: title, fileTypeName, pattern
/// Returns: selected file path or null
/// </summary>
public event Func<string, string, string, Task<string?>>? OnShowOpenFileDialog;
private void NotifyValidationChanged()
{
OnPropertyChanged(nameof(IsValid));
OnPropertyChanged(nameof(ValidationError));
}
private async void BrowseKeyFilePath()
{
if (OnShowOpenFileDialog == null)
return;
var path = await OnShowOpenFileDialog(
SecureStoreStrings.SelectKeyFile,
SecureStoreFileExtensions.KeyTypeName,
SecureStoreFileExtensions.KeyPattern);
if (!string.IsNullOrEmpty(path))
{
KeyFilePath = path;
}
}
}