bloxstrap/Bloxstrap/UI/ViewModels/Menu/InstallationViewModel.cs
2023-07-15 11:01:14 +01:00

49 lines
1.5 KiB
C#

using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
namespace Bloxstrap.UI.ViewModels.Menu
{
public class InstallationViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
public void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
private string _originalInstallLocation = App.BaseDirectory;
public ICommand BrowseInstallLocationCommand => new RelayCommand(BrowseInstallLocation);
public ICommand ResetInstallLocationCommand => new RelayCommand(ResetInstallLocation);
public ICommand OpenFolderCommand => new RelayCommand(OpenFolder);
private void BrowseInstallLocation()
{
using var dialog = new System.Windows.Forms.FolderBrowserDialog();
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
InstallLocation = dialog.SelectedPath;
OnPropertyChanged(nameof(InstallLocation));
}
private void ResetInstallLocation()
{
InstallLocation = _originalInstallLocation;
OnPropertyChanged(nameof(InstallLocation));
}
private void OpenFolder()
{
Process.Start("explorer.exe", Directories.Base);
}
public string InstallLocation
{
get => App.BaseDirectory;
set => App.BaseDirectory = value;
}
}
}