using System; using System.Diagnostics; using System.Reflection; using Avalonia.Controls; using Avalonia.Interactivity; using MetaforceInstaller.Core.Intefaces; using MetaforceInstaller.Core.Models; using MetaforceInstaller.Core.Services; using MetaforceInstaller.UI.ViewModels; namespace MetaforceInstaller.UI.Windows; public partial class MainWindow : Window { private MainWindowViewModel _viewModel; private IStorageService _storageService; public MainWindow() { InitializeComponent(); _viewModel = new MainWindowViewModel(); _storageService = new StorageService(); DataContext = _viewModel; VersionLabel.Content = Assembly.GetExecutingAssembly() .GetCustomAttribute()?.Version; NewInstallationButton.Click += OnNewInstalltionClick; LoadInstallations(); } private void LoadInstallations() { var appData = _storageService.Load(); _viewModel.LoadInstallations(appData.Installations); } public async void OnNewInstalltionClick(object? sender, RoutedEventArgs e) { var newInstallationDialog = new NewInstallationDialog(_storageService); await newInstallationDialog.ShowDialog(this); LoadInstallations(); } public async void OnDeleteInstallationClick(object? sender, RoutedEventArgs e) { if (sender is Button button && button.DataContext is InstallationData installationData) { var name = installationData.Title; Console.WriteLine($"Delete {name}"); } } public async void OnLaunchServerClick(object? sender, RoutedEventArgs e) { if (sender is Button button && button.DataContext is InstallationData installationData) { var exePath = installationData.Parts.WindowsServerPath; var processInfo = new ProcessStartInfo { FileName = exePath, UseShellExecute = false, }; Process.Start(processInfo); } } public async void OnLaunchAdminClick(object? sender, RoutedEventArgs e) { if (sender is Button button && button.DataContext is InstallationData installationData) { var exePath = installationData.Parts.WindowsAdminPath; var processInfo = new ProcessStartInfo { FileName = exePath, UseShellExecute = false, }; Process.Start(processInfo); } } }