From 97e0224e77d42d30251728069ebcf2b6bc2128cf Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 20 Sep 2021 20:03:16 +0200 Subject: [PATCH] Display Update avanzamento download --- MP.Land/MP.Land.csproj | 2 +- MP.Land/Pages/UpdateManager.razor | 11 ++++- MP.Land/Pages/UpdateManager.razor.cs | 71 +++++++++++++++++++++++++++- MP.Land/Resources/ChangeLog.html | 2 +- MP.Land/Resources/VersNum.txt | 2 +- MP.Land/Resources/manifest.xml | 2 +- 6 files changed, 84 insertions(+), 6 deletions(-) diff --git a/MP.Land/MP.Land.csproj b/MP.Land/MP.Land.csproj index 85d4b197..d27dfb30 100644 --- a/MP.Land/MP.Land.csproj +++ b/MP.Land/MP.Land.csproj @@ -3,7 +3,7 @@ net5.0 MP.Land - 1.1.2109.2019 + 1.1.2109.2020 diff --git a/MP.Land/Pages/UpdateManager.razor b/MP.Land/Pages/UpdateManager.razor index 9fd8b77b..da2a94d0 100644 --- a/MP.Land/Pages/UpdateManager.razor +++ b/MP.Land/Pages/UpdateManager.razor @@ -19,7 +19,16 @@
ALL Packages
- + + +
+ @if (showProgress) + { +
+
+
+ } +

@outMessages

diff --git a/MP.Land/Pages/UpdateManager.razor.cs b/MP.Land/Pages/UpdateManager.razor.cs index a868aabc..183c4a62 100644 --- a/MP.Land/Pages/UpdateManager.razor.cs +++ b/MP.Land/Pages/UpdateManager.razor.cs @@ -1,7 +1,10 @@ using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Configuration; +using MP.AppAuth; using MP.Land.Data; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; @@ -17,8 +20,14 @@ namespace MP.Land.Pages #region Protected Fields + protected int numDone = 0; + protected int numTot = 0; protected int totalCount = 0; + protected double TotalMb = 0; + + protected UpdateMan updateManAuth = new UpdateMan("SWDownloader", "viaD@nte16"); + #endregion Protected Fields #region Protected Properties @@ -26,18 +35,78 @@ namespace MP.Land.Pages [Inject] protected MessageService AppMService { get; set; } + [Inject] + protected IConfiguration Configuration { get; set; } + [Inject] protected AppAuthService DataService { get; set; } + protected string outMessages { get; set; } = ""; + + protected int percLoading { get; set; } = 0; + + protected bool showProgress { get; set; } = false; + #endregion Protected Properties + #region Private Methods + + private async Task scaricaSingolo(AppAuth.Models.UpdMan item) + { + long size = 0; + if (item.IsAuth) + { + size = updateManAuth.downloadLatest(item.ManifestUrl, localPath(item.LocalRepo), item.PackName); + } + else + { + size = UpdateMan.obj.downloadLatest(item.ManifestUrl, localPath(item.LocalRepo), item.PackName); + } + numDone++; + percLoading = 100 * numDone / numTot; + return await Task.FromResult(size); + } + + #endregion Private Methods + #region Protected Methods /// /// Cicla su tutti i record ed effettua il download /// - protected void DownloadAll() + protected async Task DownloadAll() { + // init progress... + showProgress = true; + StateHasChanged(); + percLoading = 0; + TotalMb = 0; + numDone = 0; + numTot = ListRecords.Count; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + // ciclo su tutti + foreach (var item in ListRecords) + { + long size = 0; + size = await scaricaSingolo(item); + TotalMb += (double)size / (1024 * 1024); + outMessages = $"Scaricati {numDone}/{numTot} update per {TotalMb:N2}"; + StateHasChanged(); + await Task.Delay(1); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + outMessages = $"Effettuato download di {numDone} update per {TotalMb:N2} mb in {ts.TotalSeconds:N2} s"; + StateHasChanged(); + await Task.Delay(2000); + showProgress = false; + StateHasChanged(); + } + + protected string localPath(string localRepo) + { + return @$"{Configuration["downloadPath"]}\{localRepo}\{Configuration["appVers"]}"; ; } protected override void OnInitialized() diff --git a/MP.Land/Resources/ChangeLog.html b/MP.Land/Resources/ChangeLog.html index 5b062486..c66e4236 100644 --- a/MP.Land/Resources/ChangeLog.html +++ b/MP.Land/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo gestione Programmi MAPO -

Versione: 1.1.2109.2019

+

Versione: 1.1.2109.2020


Note di rilascio:
    diff --git a/MP.Land/Resources/VersNum.txt b/MP.Land/Resources/VersNum.txt index f70d4f1a..3f079529 100644 --- a/MP.Land/Resources/VersNum.txt +++ b/MP.Land/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2109.2019 +1.1.2109.2020 diff --git a/MP.Land/Resources/manifest.xml b/MP.Land/Resources/manifest.xml index e50b6b2b..a88c76d9 100644 --- a/MP.Land/Resources/manifest.xml +++ b/MP.Land/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2109.2019 + 1.1.2109.2020 https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/MP.Land.zip https://nexus.steamware.net/repository/SWS/MP-PROG/stable/LAST/ChangeLog.html false