make zip unpacking and saving data to storage
This commit is contained in:
parent
c6a0b39ded
commit
297a784956
7 changed files with 78 additions and 12 deletions
|
|
@ -4,11 +4,13 @@
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="200" d:DesignHeight="400"
|
||||
x:Class="MetaforceInstaller.UI.NewInstallationDialog"
|
||||
Title="MetaforceInstaller">
|
||||
Title="MetaforceInstaller - Add new installation"
|
||||
SizeToContent="WidthAndHeight"
|
||||
CanResize="False">
|
||||
|
||||
<StackPanel Margin="24" Spacing="12">
|
||||
<Label FontSize="36">Add new installation</Label>
|
||||
<TextBox />
|
||||
<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>
|
||||
|
|
@ -19,6 +21,7 @@
|
|||
<Button Name="InstallButton">Install</Button>
|
||||
<Button Name="CancelButton">Cancel</Button>
|
||||
</StackPanel>
|
||||
<ProgressBar Name="ProgressBar" Minimum="0" Maximum="100" Value="0"/>
|
||||
</StackPanel>
|
||||
|
||||
</Window>
|
||||
|
|
@ -1,7 +1,13 @@
|
|||
using System.IO.Compression;
|
||||
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.Models;
|
||||
using MetaforceInstaller.Core.Services;
|
||||
|
||||
|
|
@ -67,6 +73,21 @@ public partial class NewInstallationDialog : Window
|
|||
private async void OnInstallClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
using var archive = ZipFile.OpenRead(_zipPath);
|
||||
var title = TitleTextBox.Text ?? Path.GetFileNameWithoutExtension(_zipPath);
|
||||
var progress = new Progress<double>(value => { ProgressBar.Value = value; });
|
||||
await Task.Run(() =>
|
||||
ZipScrapper.ExtractZip(archive, Defaults.StoragePath, progress));
|
||||
InstallButton.IsEnabled = false;
|
||||
var storageService = new StorageService();
|
||||
var appData = storageService.Load();
|
||||
var installationData = new InstallationData
|
||||
{
|
||||
Title = title,
|
||||
Parts = _installationParts.ExtendPaths(Defaults.StoragePath + Path.DirectorySeparatorChar)
|
||||
};
|
||||
appData.Installations.Add(installationData);
|
||||
storageService.Save(appData);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void UpdateCheckboxes()
|
||||
|
|
@ -77,6 +98,7 @@ public partial class NewInstallationDialog : Window
|
|||
var androidAdminCheckbox = AndroidAdminCheckbox;
|
||||
var vrClientCheckbox = VrClientCheckbox;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(_installationParts.WindowsServerPath))
|
||||
{
|
||||
serverCheckbox.IsEnabled = false;
|
||||
|
|
@ -109,6 +131,9 @@ public partial class NewInstallationDialog : Window
|
|||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue