diff --git a/LANCommander/Components/ArchiveEditor.razor b/LANCommander/Components/ArchiveEditor.razor
index e2716e3..a3f7b3e 100644
--- a/LANCommander/Components/ArchiveEditor.razor
+++ b/LANCommander/Components/ArchiveEditor.razor
@@ -46,15 +46,14 @@
-
+
@code {
[Parameter] public Guid GameId { get; set; }
[Parameter] public Guid RedistributableId { get; set; }
- [Parameter] public ICollection Archives { get; set; }
- [Parameter] public EventCallback> ArchivesChanged { get; set; }
- Archive Archive;
+ ICollection Archives { get; set; }
+
ArchiveUploader Uploader;
protected override async Task OnInitializedAsync()
@@ -70,9 +69,6 @@
Archives = await ArchiveService.Get(a => a.GameId == GameId).ToListAsync();
else if (RedistributableId != Guid.Empty)
Archives = await ArchiveService.Get(a => a.RedistributableId == RedistributableId).ToListAsync();
-
- if (ArchivesChanged.HasDelegate)
- await ArchivesChanged.InvokeAsync(Archives);
}
private async Task Download(Archive archive)
@@ -84,27 +80,7 @@
private async Task UploadArchive()
{
- if (GameId != Guid.Empty)
- Archive = new Archive() { GameId = GameId, Id = Guid.NewGuid() };
-
- if (RedistributableId != Guid.Empty)
- Archive = new Archive() { RedistributableId = RedistributableId, Id = Guid.NewGuid() };
-
- await Uploader.Open(Archive);
- }
-
- private async Task AddArchive(Archive archive)
- {
- var lastArchive = Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault();
-
- Archive = await ArchiveService.Add(archive);
-
- await LoadData();
-
- var settings = SettingService.GetSettings();
-
- if (lastArchive != null && settings.Archives.EnablePatching)
- BackgroundJob.Enqueue(x => x.Execute(lastArchive.Id, Archive.Id));
+ await Uploader.Open();
}
private async Task Delete(Archive archive)
@@ -113,6 +89,8 @@
{
await ArchiveService.Delete(archive);
+ await LoadData();
+
await MessageService.Success("Archive deleted!");
}
catch (Exception ex)
diff --git a/LANCommander/Components/ArchiveUploader.razor b/LANCommander/Components/ArchiveUploader.razor
index e7a5961..a690c4d 100644
--- a/LANCommander/Components/ArchiveUploader.razor
+++ b/LANCommander/Components/ArchiveUploader.razor
@@ -2,6 +2,7 @@
@using System.Diagnostics;
@using Hangfire;
@using LANCommander.Jobs.Background;
+@using Microsoft.EntityFrameworkCore;
@inject HttpClient HttpClient
@inject NavigationManager Navigator
@inject ArchiveService ArchiveService
@@ -62,7 +63,9 @@
@code {
- [Parameter] public EventCallback OnArchiveUploaded { get; set; }
+ [Parameter] public Guid GameId { get; set; }
+ [Parameter] public Guid RedistributableId { get; set; }
+ [Parameter] public EventCallback OnArchiveUploaded { get; set; }
Archive Archive;
@@ -113,9 +116,21 @@
File = args.File;
}
- public async Task Open(Archive archive)
+ public async Task Open(Guid? archiveId = null)
{
- Archive = archive;
+ if (archiveId.HasValue && archiveId != Guid.Empty)
+ {
+ Archive = await ArchiveService.Get(archiveId.Value);
+ }
+ else
+ {
+ Archive = new Archive();
+
+ if (GameId != Guid.Empty)
+ Archive.GameId = GameId;
+ else if (RedistributableId != Guid.Empty)
+ Archive.RedistributableId = RedistributableId;
+ }
Visible = true;
@@ -128,8 +143,8 @@
{
if (FileInput != null)
{
- if (!String.IsNullOrWhiteSpace(archive.ObjectKey) && archive.ObjectKey != Guid.Empty.ToString())
- await JS.InvokeVoidAsync("Uploader.Init", "FileInput", archive.ObjectKey.ToString());
+ if (!String.IsNullOrWhiteSpace(Archive.ObjectKey) && Archive.ObjectKey != Guid.Empty.ToString())
+ await JS.InvokeVoidAsync("Uploader.Init", "FileInput", Archive.ObjectKey.ToString());
else
await JS.InvokeVoidAsync("Uploader.Init", "FileInput", "");
@@ -163,12 +178,32 @@
Archive.ObjectKey = objectKey.ToString();
Archive.CompressedSize = File.Size;
+ if (Archive.Id != Guid.Empty)
+ Archive = await ArchiveService.Update(Archive);
+ else
+ Archive = await ArchiveService.Add(Archive);
+
Visible = false;
await InvokeAsync(StateHasChanged);
+ Archive? lastArchive = null;
+
+ var settings = SettingService.GetSettings();
+
+ if (settings.Archives.EnablePatching)
+ {
+ if (Archive.GameId != Guid.Empty)
+ lastArchive = await ArchiveService.Get(a => a.Id != Archive.Id && a.GameId == Archive.GameId).OrderByDescending(a => a.CreatedOn).FirstOrDefaultAsync();
+ else if (Archive.RedistributableId != Guid.Empty)
+ lastArchive = await ArchiveService.Get(a => a.Id != Archive.Id && a.RedistributableId == Archive.RedistributableId).OrderByDescending(a => a.CreatedOn).FirstOrDefaultAsync();
+
+ if (lastArchive != null && settings.Archives.EnablePatching)
+ BackgroundJob.Enqueue(x => x.Execute(lastArchive.Id, Archive.Id));
+ }
+
if (OnArchiveUploaded.HasDelegate)
- await OnArchiveUploaded.InvokeAsync(Archive);
+ await OnArchiveUploaded.InvokeAsync(Archive.Id);
await MessageService.Success("Archive uploaded!");
}
diff --git a/LANCommander/Pages/Games/Edit.razor b/LANCommander/Pages/Games/Edit.razor
index 4fec672..873cc68 100644
--- a/LANCommander/Pages/Games/Edit.razor
+++ b/LANCommander/Pages/Games/Edit.razor
@@ -132,7 +132,7 @@
}
diff --git a/LANCommander/Pages/Redistributables/Edit.razor b/LANCommander/Pages/Redistributables/Edit.razor
index dd8a87f..f58fb01 100644
--- a/LANCommander/Pages/Redistributables/Edit.razor
+++ b/LANCommander/Pages/Redistributables/Edit.razor
@@ -60,7 +60,7 @@
}
diff --git a/LANCommander/Pages/Settings/Tools/MissingArchives.razor b/LANCommander/Pages/Settings/Tools/MissingArchives.razor
index 4fb9c92..edf2412 100644
--- a/LANCommander/Pages/Settings/Tools/MissingArchives.razor
+++ b/LANCommander/Pages/Settings/Tools/MissingArchives.razor
@@ -34,7 +34,7 @@
-
+
@@ -78,21 +78,7 @@
System.IO.File.Create(archiveFilePath).Close();
- await Uploader.Open(archive);
- }
-
- async Task OnArchiveUploaded(Archive archive)
- {
- try
- {
- await ArchiveService.Update(archive);
-
- await LoadData();
- }
- catch (Exception ex)
- {
- await MessageService.Error("Archive could not be updated.");
- }
+ await Uploader.Open(archive.Id);
}
async Task Delete(Archive archive)