Skip to content

Commit

Permalink
Added: 2nd download button popup for files that take too long to prep…
Browse files Browse the repository at this point in the history
…air.
  • Loading branch information
john681611 committed Jan 8, 2025
1 parent 507175d commit 1263852
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Database/Language/de.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Eins bespritzt!
TargetShootdown1=Ziel bespritzt.
TargetShootdown2=Ziel abgeschossen!
Teamkill="Waffenstillstand! Waffenstillstand! Sie schießen auf Freunde!"
Download="Herunterladen"
DownloadTookTooLong="Es tut uns leid, dass die Vorbereitung Ihrer Dateien eine Weile gedauert hat. Aus Sicherheitsgründen müssen Sie auf „Herunterladen“ klicken."

[TransportManager]
TotalTroops=Gesamtzahl der Truppen
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Splashed one!
TargetShootdown1=Target splashed.
TargetShootdown2=Target shot down!
Teamkill="Ceasefire! Ceasefire! You're firing on friendlies!"
Download="Download"
DownloadTookTooLong="Sorry it took a while to prepare your files. Security protocols require you to click download."
[TransportManager]
TotalTroops=Total troops
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/es.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=¡Uno salpicado!
TargetShootdown1=Objetivo salpicado.
TargetShootdown2=¡Objetivo derribado!
Teamkill="¡Alto el fuego! ¡Alto el fuego! ¡Están disparando a los aliados!"
Download="Descargar"
DownloadTookTooLong="Lamentamos que haya tardado un poco en preparar los archivos. Los protocolos de seguridad requieren que haga clic en descargar."

[TransportManager]
TotalTroops=Tropas totales
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/fr.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Éclaboussé !
TargetShootdown1=Cible éclaboussée.
TargetShootdown2=Cible abattue !
Teamkill="Cessez le feu ! Cessez le feu ! Vous tirez sur des ennemis !"
Download="Télécharger"
DownloadTookTooLong="Désolé, il a fallu un certain temps pour préparer vos fichiers. Les protocoles de sécurité vous obligent à cliquer sur télécharger."

[TransportManager]
TotalTroops=Total des troupes
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/it.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Ne ho schiacciato uno!
TargetShootdown1=Bersaglio schizzato.
TargetShootdown2=Bersaglio abbattuto!
Teamkill="Cessate il fuoco! Cessate il fuoco! State sparando agli alleati!"
Download="Scaricamento"
DownloadTookTooLong="Mi dispiace che ci sia voluto un po' per preparare i tuoi file. I protocolli di sicurezza richiedono di cliccare su Scarica."

[TransportManager]
TotalTroops=Truppe totali
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/pt.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Atingido um!
TargetShootdown1=Alvo atingido.
TargetShootdown2=Alvo abatido!
Teamkill="Cessar-fogo! Cessar-fogo! Você está atirando em amigos!"
Download="Download"
DownloadTookTooLong="Desculpe pela demora para preparar seus arquivos. Os protocolos de segurança exigem que você clique em download."

[TransportManager]
TotalTroops=Tropas totais
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/ru.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Один разбрызган!
TargetShootdown1=Цель разлетелась.
TargetShootdown2=Цель сбита!
Teamkill="Прекратить огонь! Прекратить огонь! Вы стреляете по своим!"
Download="Скачать"
DownloadTookTooLong="Извините, подготовка файлов заняла некоторое время. Протоколы безопасности требуют, чтобы вы нажали «загрузить»."

[TransportManager]
TotalTroops=Всего войск
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/tk.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Sıçrayan bir tane!
TargetShootdown1=Hedef sıçradı.
TargetShootdown2=Hedef düşürüldü!
Teamkill="Ateşkes! Ateşkes! Dostlara ateş ediyorsunuz!"
Download="İndirmek"
DownloadTookTooLong="Dosyalarınızı hazırlamamız biraz zaman aldı, özür dileriz. Güvenlik protokolleri indirmeyi tıklamanızı gerektirir."

[TransportManager]
TotalTroops=Toplam birlikler
Expand Down
2 changes: 2 additions & 0 deletions Database/Language/uk.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ Shootdown2=Один забризканий!
TargetShootdown1=Ціль забризкана.
TargetShootdown2=Ціль збита!
Teamkill="Припинення вогню! Припинення вогню! Ти стріляєш по товариським!"
Download="Завантажити"
DownloadTookTooLong="Вибачте, підготовка ваших файлів зайняла деякий час. Протоколи безпеки вимагають натиснути «Завантажити»."

[TransportManager]
TotalTroops=Загальна кількість військ
Expand Down
43 changes: 41 additions & 2 deletions src/CommonGUI/Pages/CampaignBuilder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
@using System.IO
@using Polly
@using System.IO.Compression
@using System.Diagnostics
<LoadingSpinner ON="spinner"/>
<LateDownloadButton Download="LateDownload" ON="showLateDownloadButton" />
<div class="title-bar">
<h1>@briefingRoom.Translate("CampaignGenerator")</h1>
<TemplateButtons LoadTemplate="LoadTemplate" SaveTemplate="SaveTemplate" ClearTemplate="ClearTemplate" AcceptString=".cbrt,.zip" />
Expand Down Expand Up @@ -119,6 +121,7 @@
<div class="generator-group flex-justify-spaced flex-margin-fix">
<div class="form-group flex-block">
<label>@briefingRoom.Translate("MissionCount")</label>
using IronSoftware.DOM;
<InputNumber class="form-control" @bind-Value="Template.MissionsCount"></InputNumber>
</div>
<InputEnum ClassString="flex-block" Label=@briefingRoom.Translate("MissionDifficultyVariation") @bind-Value="Template.MissionsDifficultyVariation" EnumType="CampaignDifficultyVariation"/>
Expand Down Expand Up @@ -590,12 +593,19 @@

async Task DownloadCampaign()
{
try {
try {
Stopwatch stopwatch = Stopwatch.StartNew();
spinner = true;
StateHasChanged();
byte[] zipBytes = await campaign.ExportToCompressedByteArray(Template);
if (zipBytes == null) return; // Something went wrong during the .miz export
stopwatch.Stop();
Console.WriteLine($"Download Prep in {stopwatch.Elapsed.Seconds}s");
if(stopwatch.Elapsed.Seconds > 5)
{
ShowLateDownloadButton($"{Template.ContextTheater} - {campaign.Name}.zip", "application/octet-stream", zipBytes);
return;
}
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", $"{Template.ContextTheater} - {campaign.Name}.zip", "application/octet-stream", zipBytes);
} catch (Exception ex){
Console.WriteLine(ex);
Expand All @@ -605,6 +615,35 @@
}
}

private byte[] cachedBytes;
private string cachedName;
private string cachedMimeType;
private Boolean showLateDownloadButton = false;

private void ShowLateDownloadButton(string fileName, string mimeType, byte[] data)
{
cachedBytes = data;
cachedName = fileName;
cachedMimeType = mimeType;
showLateDownloadButton = true;
}

private async Task LateDownload()
{
try {
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", cachedName, cachedMimeType, cachedBytes);

} catch (Exception ex) {
Console.WriteLine(ex);
} finally {
showLateDownloadButton = false;
cachedBytes = null;
cachedName = null;
cachedMimeType = null;
StateHasChanged();
}
}

async Task DownloadBriefing()
{
byte[] zipBytes = campaign.ExportBriefingsToCompressedByteArray();
Expand Down
42 changes: 41 additions & 1 deletion src/CommonGUI/Pages/FullBuilder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
@using System.IO
@using Polly
@using System.IO.Compression
@using System.Diagnostics
<LoadingSpinner ON="spinner"/>
<LateDownloadButton Download="LateDownload" ON="showLateDownloadButton" />
<div class="title-bar">
<h1>@briefingRoom.Translate("FullGenerator")</h1>
<TemplateButtons LoadTemplate="LoadTemplate" SaveTemplate="SaveTemplate" ClearTemplate="ClearTemplate" AcceptString=".brt,.miz" />
Expand Down Expand Up @@ -912,11 +914,19 @@
async Task DownloadMission()
{
try {
Stopwatch stopwatch = Stopwatch.StartNew();
spinner = true;
StateHasChanged();
byte[] zipBytes = await mission.SaveToMizBytes();
if (zipBytes == null) return; // Something went wrong during the .miz export
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", $"{(Template.OptionsMission.Contains("DSMC")? "DSMC_": "")}{Template.ContextTheater} - {mission.Briefing.Name}.miz", "application/octet-stream", zipBytes);
stopwatch.Stop();
Console.WriteLine($"Download Prep in {stopwatch.Elapsed.Seconds}s");
if(stopwatch.Elapsed.Seconds > 5)
{
ShowLateDownloadButton( $"{(Template.OptionsMission.Contains("DSMC")? "DSMC_": "")}{Template.ContextTheater} - {mission.Briefing.Name}.miz", "application/octet-stream", zipBytes);
return;
}
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", $"{(Template.OptionsMission.Contains("DSMC")? "DSMC_": "")}{Template.ContextTheater} - {mission.Briefing.Name}.miz", "application/octet-stream", zipBytes);
} catch (Exception ex){
Console.WriteLine(ex);
} finally {
Expand All @@ -925,6 +935,36 @@
}
}

private byte[] cachedBytes;
private string cachedName;
private string cachedMimeType;
private Boolean showLateDownloadButton = false;

private void ShowLateDownloadButton(string fileName, string mimeType, byte[] data)
{
cachedBytes = data;
cachedName = fileName;
cachedMimeType = mimeType;
showLateDownloadButton = true;
}

private async Task LateDownload()
{
try {
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", cachedName, cachedMimeType, cachedBytes);

} catch (Exception ex) {
Console.WriteLine(ex);
} finally {
showLateDownloadButton = false;
cachedBytes = null;
cachedName = null;
cachedMimeType = null;
StateHasChanged();
}
}


async Task DownloadBriefing()
{
try {
Expand Down
41 changes: 40 additions & 1 deletion src/CommonGUI/Pages/QuickBuilder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
@using System.IO
@using Polly
@using System.IO.Compression
@using System.Diagnostics
<LoadingSpinner ON="spinner"/>
<LateDownloadButton Download="LateDownload" ON="showLateDownloadButton" />
<div class="title-bar">
<h1>@briefingRoom.Translate("QuickGenerator")</h1>
<TemplateButtons LoadTemplate="LoadTemplate" SaveTemplate="SaveTemplate" ClearTemplate="ClearTemplate" AcceptString=".brt,.miz" />
Expand Down Expand Up @@ -525,11 +527,18 @@
async Task DownloadMission()
{
try {
Stopwatch stopwatch = Stopwatch.StartNew();
spinner = true;
StateHasChanged();
byte[] zipBytes = await mission.SaveToMizBytes();
if (zipBytes == null) return; // Something went wrong during the .miz export
stopwatch.Stop();
Console.WriteLine($"Download Prep in {stopwatch.Elapsed.Seconds}s");
if(stopwatch.Elapsed.Seconds > 5)
{
ShowLateDownloadButton( $"{(Template.OptionsMission.Contains("DSMC")? "DSMC_": "")}{Template.ContextTheater} - {mission.Briefing.Name}.miz", "application/octet-stream", zipBytes);
return;
}
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", $"{(Template.OptionsMission.Contains("DSMC")? "DSMC_": "")}{Template.ContextTheater} - {mission.Briefing.Name}.miz", "application/octet-stream", zipBytes);
} catch (Exception ex){
Console.WriteLine(ex);
Expand All @@ -539,6 +548,36 @@
}
}

private byte[] cachedBytes;
private string cachedName;
private string cachedMimeType;
private Boolean showLateDownloadButton = false;

private void ShowLateDownloadButton(string fileName, string mimeType, byte[] data)
{
cachedBytes = data;
cachedName = fileName;
cachedMimeType = mimeType;
showLateDownloadButton = true;
}

private async Task LateDownload()
{
try {
await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", cachedName, cachedMimeType, cachedBytes);

} catch (Exception ex) {
Console.WriteLine(ex);
} finally {
showLateDownloadButton = false;
cachedBytes = null;
cachedName = null;
cachedMimeType = null;
StateHasChanged();
}
}


async Task DownloadBriefing()
{
byte[] zipBytes = Encoding.ASCII.GetBytes(mission.Briefing.GetBriefingAsHTML(mission));
Expand Down
18 changes: 18 additions & 0 deletions src/CommonGUI/Shared/LateDownloadButton.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@inject BriefingRoom4DCS.BriefingRoom briefingRoom
<div class="late_download_overlay">
@if (ON)
{
<div class="late_download">
<button class="btn btn-warning late_download_button" @onclick="() => Download()">
<span class="oi oi-data-transfer-download"></span>
@briefingRoom.Translate("Download")
</button>
<p class="custom-warning"><span class="oi oi-info"></span>&nbsp;@briefingRoom.Translate("DownloadTookTooLong")</p>
</div>
}
</div>

@code {
[Parameter] public bool ON { get; set; }
[Parameter] public Func<Task> Download { get; set; }
}
22 changes: 22 additions & 0 deletions src/CommonGUI/Shared/LateDownloadButton.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.late_download_overlay {
position: relative;
}

.late_download {
top: 200px;
position: absolute;
text-align: center;
margin: 0 auto;
left: 0;
right: 0;
z-index: 999999;
background-color: #020A10;
border: 1px solid white;
width: fit-content;
}

.late_download_button {
height: 10vh;
width: 20vw;
margin: 10vh;
}

0 comments on commit 1263852

Please sign in to comment.