TRX/tools/tr1/installer/Installer/Models/InstallSourceViewModel.cs
2024-10-03 10:36:35 +02:00

66 lines
1.5 KiB
C#

using Installer.Installers;
using Installer.Utils;
using System.Windows.Input;
namespace Installer.Models;
public class InstallSourceViewModel : BaseNotifyPropertyChanged
{
public InstallSourceViewModel(IInstallSource source)
{
InstallSource = source;
foreach (var directory in source.DirectoriesToTry)
{
if (InstallSource.IsGameFound(directory))
{
SourceDirectory = directory;
break;
}
}
}
public ICommand ChooseLocationCommand
{
get
{
return _chooseLocationCommand ??= new RelayCommand(ChooseLocation);
}
}
public IInstallSource InstallSource { get; private set; }
public bool IsAvailable
{
get
{
return SourceDirectory != null && InstallSource.IsGameFound(SourceDirectory);
}
}
public string? SourceDirectory
{
get => _sourceDirectory;
set
{
if (value != _sourceDirectory)
{
_sourceDirectory = value;
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(IsAvailable));
}
}
}
private RelayCommand? _chooseLocationCommand;
private string? _sourceDirectory;
private void ChooseLocation()
{
var result = FileBrowser.Browse(SourceDirectory);
if (result is not null)
{
SourceDirectory = result;
}
}
}