some refactoring
This commit is contained in:
parent
89c3dcb424
commit
bbf905495c
8 changed files with 160 additions and 106 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using MetaforceInstaller.UI.Windows;
|
||||
|
||||
namespace MetaforceInstaller.UI;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="vm:MainWindowViewModel"
|
||||
x:Class="MetaforceInstaller.UI.MainWindow"
|
||||
x:Class="MetaforceInstaller.UI.Windows.MainWindow"
|
||||
Title="MetaforceInstaller">
|
||||
|
||||
<Window.Resources>
|
||||
|
|
@ -22,9 +22,9 @@
|
|||
</ResourceDictionary.ThemeDictionaries>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
|
||||
<Design.DataContext>
|
||||
<vm:MainWindowViewModel/>
|
||||
<vm:MainWindowViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid>
|
||||
|
|
@ -49,9 +49,13 @@
|
|||
<ItemsControl ItemsSource="{Binding Installations}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Expander Header="{Binding Title}" Margin="20, 0" HorizontalAlignment="Stretch">
|
||||
<StackPanel Margin="10">
|
||||
|
||||
<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>
|
||||
|
|
@ -4,7 +4,7 @@ using MetaforceInstaller.Core.Intefaces;
|
|||
using MetaforceInstaller.Core.Services;
|
||||
using MetaforceInstaller.UI.ViewModels;
|
||||
|
||||
namespace MetaforceInstaller.UI;
|
||||
namespace MetaforceInstaller.UI.Windows;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
|
|
@ -16,9 +16,8 @@ public partial class MainWindow : Window
|
|||
InitializeComponent();
|
||||
|
||||
_viewModel = new MainWindowViewModel();
|
||||
DataContext = _viewModel;
|
||||
|
||||
_storageService = new StorageService();
|
||||
DataContext = _viewModel;
|
||||
|
||||
NewInstallationButton.Click += OnNewInstalltionClick;
|
||||
|
||||
|
|
@ -33,7 +32,7 @@ public partial class MainWindow : Window
|
|||
|
||||
public async void OnNewInstalltionClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var newInstallationDialog = new NewInstallationDialog();
|
||||
var newInstallationDialog = new NewInstallationDialog(_storageService);
|
||||
await newInstallationDialog.ShowDialog<NewInstallationDialog>(this);
|
||||
LoadInstallations();
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
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.NewInstallationDialog"
|
||||
x:Class="MetaforceInstaller.UI.Windows.NewInstallationDialog"
|
||||
Title="MetaforceInstaller - Add new installation"
|
||||
SizeToContent="WidthAndHeight"
|
||||
CanResize="False">
|
||||
|
|
@ -8,19 +8,24 @@ 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;
|
||||
namespace MetaforceInstaller.UI.Windows;
|
||||
|
||||
public partial class NewInstallationDialog : Window
|
||||
{
|
||||
private string? _zipPath;
|
||||
private InstallationParts? _installationParts;
|
||||
private readonly IStorageService _storageService;
|
||||
|
||||
public NewInstallationDialog()
|
||||
public NewInstallationDialog(IStorageService storageService)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_storageService = storageService;
|
||||
|
||||
RefreshCheckboxes();
|
||||
CancelButton.Click += OnCancelClick;
|
||||
ChooseZip.Click += OnChooseZipClick;
|
||||
|
|
@ -74,19 +79,35 @@ public partial class NewInstallationDialog : Window
|
|||
{
|
||||
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(() =>
|
||||
ZipScrapper.ExtractZip(archive, Defaults.StoragePath, progress));
|
||||
{
|
||||
extractedPath = ZipScrapper.ExtractZip(
|
||||
archive,
|
||||
Defaults.StoragePath,
|
||||
installationGuid,
|
||||
progress);
|
||||
});
|
||||
|
||||
InstallButton.IsEnabled = false;
|
||||
var storageService = new StorageService();
|
||||
var appData = storageService.Load();
|
||||
|
||||
var appData = _storageService.Load();
|
||||
|
||||
var updatedParts = ZipScrapper.UpdatePathsAfterExtraction(_installationParts, extractedPath);
|
||||
|
||||
var installationData = new InstallationData
|
||||
{
|
||||
Id = installationGuid,
|
||||
Title = title,
|
||||
Parts = _installationParts.ExtendPaths(Defaults.StoragePath + Path.DirectorySeparatorChar)
|
||||
Parts = updatedParts
|
||||
};
|
||||
|
||||
appData.Installations.Add(installationData);
|
||||
storageService.Save(appData);
|
||||
_storageService.Save(appData);
|
||||
Close();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue