Fix: Display progress message properly when download size missing (#1)

When I downloaded the assets for Red Alert through the Quick Install I noticed the progress bar proceed and display a recognizable message: `Downloading from … 1.47/12 MB (12%)`. This was fine.

When I downloaded the assets for one of the other games, maybe Dune 2000, there was obviously no total download size available. I was an unexpected message: `Downloading from … 1.47/NaN (NaN%)`

The code handling network progress events seems to be aware of the possibility that no full download size exists but it doesn't update the message. In this path I'm proposing that we display a separate messaging indicating that we don't know how much more we have to download for these cases.

Of the alternative ways to implement this I chose to move the reassignment of `getStatusText` into the conditional structures to preserve the existing choice. The message was qualitatively different and so I felt it worthwhile to create entirely different closures vs. doing something like this…

```cs
getStatusText = () => ( Double.isNaN( dataTotal ) ? "Downloading {1} of unknown amount" : "Downloading {1}/{2}" ).F( … );
```
This commit is contained in:
Dennis Snell
2018-09-05 10:25:17 +01:00
committed by Matthias Mailänder
parent ef7c49c116
commit 95558a36ab

View File

@@ -85,6 +85,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
dataTotal = float.NaN;
dataReceived = i.BytesReceived;
dataSuffix = SizeSuffixes[0];
getStatusText = () => "Downloading from {2} {0:0.00} {1} (unknown size)".F(dataReceived,
dataSuffix,
downloadHost ?? "unknown host");
}
else
{
@@ -92,14 +96,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
dataTotal = i.TotalBytesToReceive / (float)(1L << (mag * 10));
dataReceived = i.BytesReceived / (float)(1L << (mag * 10));
dataSuffix = SizeSuffixes[mag];
getStatusText = () => "Downloading from {4} {1:0.00}/{2:0.00} {3} ({0}%)".F(i.ProgressPercentage,
dataReceived, dataTotal, dataSuffix,
downloadHost ?? "unknown host");
}
progressBar.Indeterminate = false;
progressBar.Percentage = i.ProgressPercentage;
getStatusText = () => "Downloading from {4} {1:0.00}/{2:0.00} {3} ({0}%)".F(i.ProgressPercentage,
dataReceived, dataTotal, dataSuffix,
downloadHost ?? "unknown host");
};
Action<string> onExtractProgress = s => Game.RunAfterTick(() => getStatusText = () => s);