diff --git a/MetaforceInstaller.UI/MainWindow.axaml b/MetaforceInstaller.UI/MainWindow.axaml index 61a426d..7b8c85a 100644 --- a/MetaforceInstaller.UI/MainWindow.axaml +++ b/MetaforceInstaller.UI/MainWindow.axaml @@ -10,11 +10,11 @@ - + - + - + @@ -22,49 +22,44 @@ + - - - - - - - + + - - - - + Install server + Install admin + Save android admin + Save VR client + + + + + + + + \ No newline at end of file diff --git a/MetaforceInstaller.UI/NewInstallationDialog.axaml.cs b/MetaforceInstaller.UI/NewInstallationDialog.axaml.cs new file mode 100644 index 0000000..85d5f28 --- /dev/null +++ b/MetaforceInstaller.UI/NewInstallationDialog.axaml.cs @@ -0,0 +1,118 @@ +using System.IO.Compression; +using Avalonia.Controls; +using Avalonia.Interactivity; +using Avalonia.Platform.Storage; +using MetaforceInstaller.Core.Models; +using MetaforceInstaller.Core.Services; + +namespace MetaforceInstaller.UI; + +public partial class NewInstallationDialog : Window +{ + private string? _zipPath; + private InstallationParts? _installationParts; + + public NewInstallationDialog() + { + InitializeComponent(); + RefreshCheckboxes(); + CancelButton.Click += OnCancelClick; + ChooseZip.Click += OnChooseZipClick; + InstallButton.IsEnabled = false; + InstallButton.Click += OnInstallClick; + } + + private async void RefreshCheckboxes() + { + var serverCheckbox = ServerCheckBox; + var pcAdminCheckbox = PcAdminCheckBox; + var androidAdminCheckbox = AndroidAdminCheckbox; + var vrClientCheckbox = VrClientCheckbox; + serverCheckbox.Content = TextDefaults.InstallServer; + serverCheckbox.IsEnabled = true; + pcAdminCheckbox.Content = TextDefaults.InstallAdmin; + pcAdminCheckbox.IsEnabled = true; + androidAdminCheckbox.Content = TextDefaults.SaveAndroidAdmin; + androidAdminCheckbox.IsEnabled = true; + vrClientCheckbox.Content = TextDefaults.SaveVRClient; + vrClientCheckbox.IsEnabled = true; + } + + private async void OnChooseZipClick(object? sender, RoutedEventArgs e) + { + var topLevel = GetTopLevel(this); + var files = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = "Выберите архив с контентом", + AllowMultiple = false, + FileTypeFilter = + [ + new FilePickerFileType("ZIP Files") + { + Patterns = ["*.zip"] + } + ] + }); + + if (files.Count >= 1) + { + _zipPath = files[0].Path.LocalPath; + using var archive = ZipFile.OpenRead(_zipPath); + _installationParts = ZipScrapper.PeekFiles(archive); + UpdateCheckboxes(); + archive.Dispose(); + } + } + + private async void OnInstallClick(object? sender, RoutedEventArgs e) + { + using var archive = ZipFile.OpenRead(_zipPath); + + } + + private void UpdateCheckboxes() + { + RefreshCheckboxes(); + var serverCheckbox = ServerCheckBox; + var pcAdminCheckbox = PcAdminCheckBox; + var androidAdminCheckbox = AndroidAdminCheckbox; + var vrClientCheckbox = VrClientCheckbox; + + if (!_installationParts.WindowsServerExists) + { + serverCheckbox.IsEnabled = false; + serverCheckbox.Content += "\nCouldn't find directory with server"; + } + + if (!_installationParts.WindowsAdminExists) + { + pcAdminCheckbox.IsEnabled = false; + pcAdminCheckbox.Content += "\nCouldn't find directory with PC admin"; + } + + if (!_installationParts.WindowsContentExists) + { + pcAdminCheckbox.IsEnabled = false; + pcAdminCheckbox.Content += "\nCouldn't find windows content"; + } + + if (!_installationParts.AndroidContentExists) + { + vrClientCheckbox.IsEnabled = false; + vrClientCheckbox.Content += "\nCouldn't find android content"; + androidAdminCheckbox.IsEnabled = false; + androidAdminCheckbox.Content += "\nCouldn't find android content"; + } + + if (!_installationParts.PicoClientExists && !_installationParts.OculusClientExists) + { + vrClientCheckbox.IsEnabled = false; + vrClientCheckbox.Content += "\nCouldn't find any VR clients"; + } + } + + private void OnCancelClick(object? sender, RoutedEventArgs e) + { + Close(); + } +} \ No newline at end of file diff --git a/MetaforceInstaller.UI/TextDefaults.cs b/MetaforceInstaller.UI/TextDefaults.cs new file mode 100644 index 0000000..176e1f6 --- /dev/null +++ b/MetaforceInstaller.UI/TextDefaults.cs @@ -0,0 +1,9 @@ +namespace MetaforceInstaller.UI; + +public static class TextDefaults +{ + public static readonly string InstallServer = "Install Server"; + public static readonly string InstallAdmin = "Install Admin"; + public static readonly string SaveAndroidAdmin = "Save Android admin"; + public static readonly string SaveVRClient = "Save VR client"; +} \ No newline at end of file