@page "/{configId:int?}"
@using System.Diagnostics
@using fxl.codes.kisekae.data
@using fxl.codes.kisekae.data.Entities
@inject KisekaeContext Context
@inject IWebHostEnvironment Environment
@rendermode InteractiveServer
Kisekae
@if (ConfigId.HasValue)
{
@Current!.Name
}
else
{
Existing Sets
@foreach (var set in AllConfigurations)
{
- @set.Name
}
}
@code {
[Parameter] public int? ConfigId { get; set; }
private IEnumerable AllConfigurations { get; set; } = ArraySegment.Empty;
private Configuration? Current { get; set; }
protected override Task OnInitializedAsync()
{
if (ConfigId.HasValue)
{
Current = Context.Configurations.Find(ConfigId.Value);
}
else
{
AllConfigurations = Context.Configurations.ToArray();
}
return base.OnInitializedAsync();
}
private async Task Unzip(InputFileChangeEventArgs upload)
{
var path = Path.Combine(Environment.ContentRootPath, "temp");
if (!Directory.Exists(path)) throw new Exception("temp directory doesn't exist");
var filename = Path.Combine(path, upload.File.Name);
var directory = Path.Combine(path, Path.GetFileNameWithoutExtension(upload.File.Name));
if (!File.Exists(filename))
{
await using var stream = new FileStream(filename, FileMode.Create);
await upload.File.OpenReadStream().CopyToAsync(stream);
await stream.FlushAsync();
stream.Close();
}
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
if (!Directory.GetFiles(directory).Any())
{
var processName = OperatingSystem.IsWindows() ? "7z.exe" : OperatingSystem.IsMacOS() ? "7zz" : "7zzl";
var args = $"\"{Path.Combine(".", "Libraries", processName)}\" x {filename} -o\"{directory}\"";
var process = Process.Start(processName, args);
await process.WaitForExitAsync();
}
}
}