some refactoring
This commit is contained in:
parent
89c3dcb424
commit
bbf905495c
8 changed files with 160 additions and 106 deletions
66
MetaforceInstaller.UI/Windows/MainWindow.axaml
Normal file
66
MetaforceInstaller.UI/Windows/MainWindow.axaml
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:MetaforceInstaller.UI.ViewModels"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="vm:MainWindowViewModel"
|
||||
x:Class="MetaforceInstaller.UI.Windows.MainWindow"
|
||||
Title="MetaforceInstaller">
|
||||
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Light">
|
||||
<SvgImage x:Key="Logo" Source="/Images/logo_red.svg" />
|
||||
</ResourceDictionary>
|
||||
|
||||
<ResourceDictionary x:Key="Dark">
|
||||
<SvgImage x:Key="Logo" Source="/Images/logo_red.svg" />
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
<Design.DataContext>
|
||||
<vm:MainWindowViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="96" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Image Grid.Row="0"
|
||||
Margin="20"
|
||||
VerticalAlignment="Center"
|
||||
Source="{DynamicResource Logo}"
|
||||
HorizontalAlignment="Left">
|
||||
</Image>
|
||||
|
||||
<Button Grid.Row="0" Name="NewInstallationButton" Margin="20" VerticalAlignment="Center"
|
||||
HorizontalAlignment="Right">
|
||||
+ Add new installation
|
||||
</Button>
|
||||
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<ItemsControl ItemsSource="{Binding Installations}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Expander Header="{Binding Title}" Margin="16, 8" HorizontalAlignment="Stretch">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Name="LaunchServerButton">Launch server</Button>
|
||||
<Button Name="LaunchPcAdminButton">Launch PC admin</Button>
|
||||
<Button Name="InstallVrClientButton">Install VR client</Button>
|
||||
<Button Name="InstallAndroidAdminButton">Install Android admin</Button>
|
||||
<Button Name="DeleteButton">Delete</Button>
|
||||
</StackPanel>
|
||||
</Expander>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Window>
|
||||
39
MetaforceInstaller.UI/Windows/MainWindow.axaml.cs
Normal file
39
MetaforceInstaller.UI/Windows/MainWindow.axaml.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using MetaforceInstaller.Core.Intefaces;
|
||||
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;
|
||||
|
||||
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<NewInstallationDialog>(this);
|
||||
LoadInstallations();
|
||||
}
|
||||
}
|
||||
27
MetaforceInstaller.UI/Windows/NewInstallationDialog.axaml
Normal file
27
MetaforceInstaller.UI/Windows/NewInstallationDialog.axaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="200" d:DesignHeight="400"
|
||||
x:Class="MetaforceInstaller.UI.Windows.NewInstallationDialog"
|
||||
Title="MetaforceInstaller - Add new installation"
|
||||
SizeToContent="WidthAndHeight"
|
||||
CanResize="False">
|
||||
|
||||
<StackPanel Margin="24" Spacing="12">
|
||||
<Label FontSize="36">Add new installation</Label>
|
||||
<TextBox Name="TitleTextBox" Watermark="Name of new installation"/>
|
||||
<Button Name="ChooseZip">Choose .zip with installation</Button>
|
||||
<CheckBox Name="ServerCheckBox">Install server</CheckBox>
|
||||
<CheckBox Name="PcAdminCheckBox">Install admin</CheckBox>
|
||||
<CheckBox Name="AndroidAdminCheckbox">Save android admin</CheckBox>
|
||||
<CheckBox Name="VrClientCheckbox">Save VR client</CheckBox>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom" Spacing="8">
|
||||
<Button Name="InstallButton">Install</Button>
|
||||
<Button Name="CancelButton">Cancel</Button>
|
||||
</StackPanel>
|
||||
<ProgressBar Name="ProgressBar" Minimum="0" Maximum="100" Value="0"/>
|
||||
</StackPanel>
|
||||
|
||||
</Window>
|
||||
164
MetaforceInstaller.UI/Windows/NewInstallationDialog.axaml.cs
Normal file
164
MetaforceInstaller.UI/Windows/NewInstallationDialog.axaml.cs
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using MetaforceInstaller.Core;
|
||||
using MetaforceInstaller.Core.Intefaces;
|
||||
using MetaforceInstaller.Core.Models;
|
||||
using MetaforceInstaller.Core.Services;
|
||||
|
||||
namespace MetaforceInstaller.UI.Windows;
|
||||
|
||||
public partial class NewInstallationDialog : Window
|
||||
{
|
||||
private string? _zipPath;
|
||||
private InstallationParts? _installationParts;
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
public NewInstallationDialog(IStorageService storageService)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_storageService = storageService;
|
||||
|
||||
RefreshCheckboxes();
|
||||
CancelButton.Click += OnCancelClick;
|
||||
ChooseZip.Click += OnChooseZipClick;
|
||||
InstallButton.IsEnabled = false;
|
||||
InstallButton.Click += OnInstallClick;
|
||||
}
|
||||
|
||||
private 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);
|
||||
var title = TitleTextBox.Text ?? Path.GetFileNameWithoutExtension(_zipPath);
|
||||
var installationGuid = Guid.NewGuid();
|
||||
|
||||
var progress = new Progress<double>(value => { ProgressBar.Value = value; });
|
||||
|
||||
string extractedPath = null;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
extractedPath = ZipScrapper.ExtractZip(
|
||||
archive,
|
||||
Defaults.StoragePath,
|
||||
installationGuid,
|
||||
progress);
|
||||
});
|
||||
|
||||
InstallButton.IsEnabled = false;
|
||||
|
||||
var appData = _storageService.Load();
|
||||
|
||||
var updatedParts = ZipScrapper.UpdatePathsAfterExtraction(_installationParts, extractedPath);
|
||||
|
||||
var installationData = new InstallationData
|
||||
{
|
||||
Id = installationGuid,
|
||||
Title = title,
|
||||
Parts = updatedParts
|
||||
};
|
||||
|
||||
appData.Installations.Add(installationData);
|
||||
_storageService.Save(appData);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void UpdateCheckboxes()
|
||||
{
|
||||
RefreshCheckboxes();
|
||||
var serverCheckbox = ServerCheckBox;
|
||||
var pcAdminCheckbox = PcAdminCheckBox;
|
||||
var androidAdminCheckbox = AndroidAdminCheckbox;
|
||||
var vrClientCheckbox = VrClientCheckbox;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(_installationParts.WindowsServerPath))
|
||||
{
|
||||
serverCheckbox.IsEnabled = false;
|
||||
serverCheckbox.Content += "\nCouldn't find directory with server";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_installationParts.WindowsAdminPath))
|
||||
{
|
||||
pcAdminCheckbox.IsEnabled = false;
|
||||
pcAdminCheckbox.Content += "\nCouldn't find directory with PC admin";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_installationParts.WindowsContentPath))
|
||||
{
|
||||
pcAdminCheckbox.IsEnabled = false;
|
||||
pcAdminCheckbox.Content += "\nCouldn't find windows content";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_installationParts.AndroidContentPath))
|
||||
{
|
||||
vrClientCheckbox.IsEnabled = false;
|
||||
vrClientCheckbox.Content += "\nCouldn't find android content";
|
||||
androidAdminCheckbox.IsEnabled = false;
|
||||
androidAdminCheckbox.Content += "\nCouldn't find android content";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_installationParts.PicoClientPath) &&
|
||||
string.IsNullOrEmpty(_installationParts.OculusClientPath))
|
||||
{
|
||||
vrClientCheckbox.IsEnabled = false;
|
||||
vrClientCheckbox.Content += "\nCouldn't find any VR clients";
|
||||
}
|
||||
|
||||
InstallButton.IsEnabled = new List<CheckBox?>
|
||||
{ serverCheckbox, pcAdminCheckbox, androidAdminCheckbox, vrClientCheckbox }.Any(x => x?.IsEnabled == true);
|
||||
}
|
||||
|
||||
private void OnCancelClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue