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
7
MetaforceInstaller.Core/Defaults.cs
Normal file
7
MetaforceInstaller.Core/Defaults.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace MetaforceInstaller.Core;
|
||||||
|
|
||||||
|
public static class Defaults
|
||||||
|
{
|
||||||
|
public static readonly string StoragePath =
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "MetaforceInstaller";
|
||||||
|
}
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
public class InstallationData
|
public class InstallationData
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
public string Title { get; set; }
|
public required string Title { get; set; }
|
||||||
public string AndroidPackagePath { get; set; }
|
public required InstallationParts Parts { get; set; }
|
||||||
public string WindowsServerPackagePath { get; set; }
|
|
||||||
public string WindowsAdminPackagePath { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
namespace MetaforceInstaller.Core.Models;
|
namespace MetaforceInstaller.Core.Models;
|
||||||
|
|
||||||
public record InstallationParts
|
public class InstallationParts
|
||||||
{
|
{
|
||||||
public string? OculusClientPath { get; init; }
|
public string? OculusClientPath { get; init; }
|
||||||
public string? PicoClientPath { get; init; }
|
public string? PicoClientPath { get; init; }
|
||||||
|
|
@ -9,4 +9,18 @@ public record InstallationParts
|
||||||
public string? WindowsContentPath { get; init; }
|
public string? WindowsContentPath { get; init; }
|
||||||
public string? WindowsAdminPath { get; init; }
|
public string? WindowsAdminPath { get; init; }
|
||||||
public string? WindowsServerPath { get; init; }
|
public string? WindowsServerPath { get; init; }
|
||||||
|
|
||||||
|
public InstallationParts ExtendPaths(string prefixPath)
|
||||||
|
{
|
||||||
|
return new InstallationParts
|
||||||
|
{
|
||||||
|
OculusClientPath = OculusClientPath is null ? null : Path.Combine(prefixPath, OculusClientPath),
|
||||||
|
PicoClientPath = PicoClientPath is null ? null : Path.Combine(prefixPath, PicoClientPath),
|
||||||
|
AndroidAdminPath = AndroidAdminPath is null ? null : Path.Combine(prefixPath, AndroidAdminPath),
|
||||||
|
AndroidContentPath = AndroidContentPath is null ? null : Path.Combine(prefixPath, AndroidContentPath),
|
||||||
|
WindowsContentPath = WindowsContentPath is null ? null : Path.Combine(prefixPath, WindowsContentPath),
|
||||||
|
WindowsAdminPath = WindowsAdminPath is null ? null : Path.Combine(prefixPath, WindowsAdminPath),
|
||||||
|
WindowsServerPath = WindowsServerPath is null ? null : Path.Combine(prefixPath, WindowsServerPath)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,8 +10,7 @@ public class StorageService : IStorageService
|
||||||
|
|
||||||
public StorageService()
|
public StorageService()
|
||||||
{
|
{
|
||||||
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
var appDirectory = Defaults.StoragePath;
|
||||||
var appDirectory = Path.Combine(appData, "MetaforceInstaller");
|
|
||||||
Directory.CreateDirectory(appDirectory);
|
Directory.CreateDirectory(appDirectory);
|
||||||
_storagePath = Path.Combine(appDirectory, "installations.json");
|
_storagePath = Path.Combine(appDirectory, "installations.json");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,29 @@ public class ZipScrapper
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ExtractZip(ZipArchive archive, string outputPath)
|
public static string ExtractZip(ZipArchive archive, string outputPath, IProgress<double>? progress = null)
|
||||||
{
|
{
|
||||||
archive.ExtractToDirectory(outputPath);
|
var entries = archive.Entries.Where(e => !string.IsNullOrEmpty(e.Name)).ToList();
|
||||||
|
var totalEntries = entries.Count;
|
||||||
|
var processedEntries = 0;
|
||||||
|
|
||||||
|
foreach (var entry in entries)
|
||||||
|
{
|
||||||
|
var destinationPath = Path.Combine(outputPath, entry.FullName);
|
||||||
|
var destinationDir = Path.GetDirectoryName(destinationPath);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(destinationDir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(destinationDir);
|
||||||
|
Console.WriteLine($"Extracting {entry.FullName} to {destinationPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.ExtractToFile(destinationPath, overwrite: true);
|
||||||
|
|
||||||
|
processedEntries++;
|
||||||
|
progress?.Report((double)processedEntries / totalEntries * 100);
|
||||||
|
}
|
||||||
|
|
||||||
return outputPath;
|
return outputPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="200" d:DesignHeight="400"
|
mc:Ignorable="d" d:DesignWidth="200" d:DesignHeight="400"
|
||||||
x:Class="MetaforceInstaller.UI.NewInstallationDialog"
|
x:Class="MetaforceInstaller.UI.NewInstallationDialog"
|
||||||
Title="MetaforceInstaller">
|
Title="MetaforceInstaller - Add new installation"
|
||||||
|
SizeToContent="WidthAndHeight"
|
||||||
|
CanResize="False">
|
||||||
|
|
||||||
<StackPanel Margin="24" Spacing="12">
|
<StackPanel Margin="24" Spacing="12">
|
||||||
<Label FontSize="36">Add new installation</Label>
|
<Label FontSize="36">Add new installation</Label>
|
||||||
<TextBox />
|
<TextBox Name="TitleTextBox" Watermark="Name of new installation"/>
|
||||||
<Button Name="ChooseZip">Choose .zip with installation</Button>
|
<Button Name="ChooseZip">Choose .zip with installation</Button>
|
||||||
<CheckBox Name="ServerCheckBox">Install server</CheckBox>
|
<CheckBox Name="ServerCheckBox">Install server</CheckBox>
|
||||||
<CheckBox Name="PcAdminCheckBox">Install admin</CheckBox>
|
<CheckBox Name="PcAdminCheckBox">Install admin</CheckBox>
|
||||||
|
|
@ -19,6 +21,7 @@
|
||||||
<Button Name="InstallButton">Install</Button>
|
<Button Name="InstallButton">Install</Button>
|
||||||
<Button Name="CancelButton">Cancel</Button>
|
<Button Name="CancelButton">Cancel</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<ProgressBar Name="ProgressBar" Minimum="0" Maximum="100" Value="0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</Window>
|
</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.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
using MetaforceInstaller.Core;
|
||||||
using MetaforceInstaller.Core.Models;
|
using MetaforceInstaller.Core.Models;
|
||||||
using MetaforceInstaller.Core.Services;
|
using MetaforceInstaller.Core.Services;
|
||||||
|
|
||||||
|
|
@ -67,6 +73,21 @@ public partial class NewInstallationDialog : Window
|
||||||
private async void OnInstallClick(object? sender, RoutedEventArgs e)
|
private async void OnInstallClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
using var archive = ZipFile.OpenRead(_zipPath);
|
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()
|
private void UpdateCheckboxes()
|
||||||
|
|
@ -77,6 +98,7 @@ public partial class NewInstallationDialog : Window
|
||||||
var androidAdminCheckbox = AndroidAdminCheckbox;
|
var androidAdminCheckbox = AndroidAdminCheckbox;
|
||||||
var vrClientCheckbox = VrClientCheckbox;
|
var vrClientCheckbox = VrClientCheckbox;
|
||||||
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(_installationParts.WindowsServerPath))
|
if (string.IsNullOrEmpty(_installationParts.WindowsServerPath))
|
||||||
{
|
{
|
||||||
serverCheckbox.IsEnabled = false;
|
serverCheckbox.IsEnabled = false;
|
||||||
|
|
@ -109,6 +131,9 @@ public partial class NewInstallationDialog : Window
|
||||||
vrClientCheckbox.IsEnabled = false;
|
vrClientCheckbox.IsEnabled = false;
|
||||||
vrClientCheckbox.Content += "\nCouldn't find any VR clients";
|
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)
|
private void OnCancelClick(object? sender, RoutedEventArgs e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue