From 4e65103390808c456c05dc01463db6a81d304fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Pivo=C5=88ka?= Date: Fri, 6 Dec 2024 20:56:30 +0100 Subject: [PATCH] Add "Download all claimed init items" button --- .../Components/Pages/Dashboard.razor | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/Src/NationsConverterWeb/NationsConverterWeb/Components/Pages/Dashboard.razor b/Src/NationsConverterWeb/NationsConverterWeb/Components/Pages/Dashboard.razor index 26347a07..433b55ba 100644 --- a/Src/NationsConverterWeb/NationsConverterWeb/Components/Pages/Dashboard.razor +++ b/Src/NationsConverterWeb/NationsConverterWeb/Components/Pages/Dashboard.razor @@ -104,6 +104,8 @@ Bulk fix } + + Download converter Download all init items Download TMUF GameData @@ -211,14 +213,14 @@ currentDiscordUser = discordUsers.FirstOrDefault(x => x.Id == snowflake); - /*blocks = db.Blocks + /*blocks = db.Blocks .Where(x => x.Name.Contains(searchValue)) .Where(x => x.EnvironmentId.Contains(Environment ?? "")) .Include(x => x.AssignedTo) .ThenInclude(x => x!.DiscordUser) .AsNoTracking() - .Select(x => new BlockDto - { + .Select(x => new BlockDto + { Id = x.Id, Name = x.Name, AssignedTo = x.AssignedTo, @@ -289,6 +291,44 @@ await JS.InvokeVoidAsync("downloadFileFromStream", "UserData.zip", streamRef); } + private async Task DownloadClaimedInitItemsAsync() + { + if (currentDiscordUser is null) + { + return; + } + + await using var db = DbFactory.CreateDbContext(); + + var claimedBlocks = await db.Blocks + .Where(x => x.AssignedToId == currentDiscordUser.UserId && !x.IsDone) + .Include(x => x.Items) + .ToListAsync(); + + await using var ms = new MemoryStream(); + + using (var zip = new System.IO.Compression.ZipArchive(ms, ZipArchiveMode.Create, leaveOpen: true)) + { + foreach (var block in claimedBlocks) + { + foreach (var item in block.Items) + { + var entry = zip.CreateEntry(Path.Combine("ClaimedInits", block.Name, item.FileName)); + await using var entryStream = entry.Open(); + + var blockDirBasePath = Path.Combine(AppContext.BaseDirectory, "Data", "items", "NC2", block.CategoryId, block.SubCategoryId, "MM_Collision", block.EnvironmentId, block.PageName, block.Name); + await using var fs = new FileStream(Path.Combine(blockDirBasePath, item.FileName), FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true); + await fs.CopyToAsync(entryStream); + } + } + } + + ms.Position = 0; + + using var streamRef = new DotNetStreamReference(ms); + await JS.InvokeVoidAsync("downloadFileFromStream", "ClaimedInits.zip", streamRef); + } + private async Task DownloadValueReviewItemsAsync() { await using var db = DbFactory.CreateDbContext();