decide which mirror to choose locally and display result

closes #3904
This commit is contained in:
Matthias Mailänder
2014-03-09 16:31:43 +01:00
parent 9c499cc9e5
commit 771638c8e8
5 changed files with 45 additions and 10 deletions

View File

@@ -26,6 +26,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ProgressBarWidget progressBar; ProgressBarWidget progressBar;
LabelWidget statusLabel; LabelWidget statusLabel;
Action afterInstall; Action afterInstall;
string mirror;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public DownloadPackagesLogic(Widget widget, Dictionary<string, string> installData, Action afterInstall) public DownloadPackagesLogic(Widget widget, Dictionary<string, string> installData, Action afterInstall)
@@ -42,14 +43,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void ShowDownloadDialog() void ShowDownloadDialog()
{ {
statusLabel.GetText = () => "Initializing..."; statusLabel.GetText = () => "Fetching list of mirrors...";
progressBar.Indeterminate = true; progressBar.Indeterminate = true;
var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");
retryButton.IsVisible = () => false; retryButton.IsVisible = () => false;
var cancelButton = panel.Get<ButtonWidget>("CANCEL_BUTTON"); var cancelButton = panel.Get<ButtonWidget>("CANCEL_BUTTON");
// Save the package to a temp file var mirrorsFile = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mod.Id, "mirrors.txt" }.Aggregate(Path.Combine);
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var dest = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mod.Id }.Aggregate(Path.Combine); var dest = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mod.Id }.Aggregate(Path.Combine);
@@ -57,7 +59,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{ {
progressBar.Indeterminate = false; progressBar.Indeterminate = false;
progressBar.Percentage = i.ProgressPercentage; progressBar.Percentage = i.ProgressPercentage;
statusLabel.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived / 1024, i.TotalBytesToReceive / 1024); statusLabel.GetText = () => "Downloading from {3} {1}/{2} kB ({0}%)".F(i.ProgressPercentage,
i.BytesReceived / 1024, i.TotalBytesToReceive / 1024,
mirror != null ? new Uri(mirror).Host : "unknown host");
}; };
Action<string> onExtractProgress = s => Action<string> onExtractProgress = s =>
@@ -100,10 +104,41 @@ namespace OpenRA.Mods.RA.Widgets.Logic
} }
}; };
var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete); Action<AsyncCompletedEventArgs, bool> onFetchMirrorsComplete = (i, cancelled) =>
{
progressBar.Indeterminate = true;
if (i.Error != null)
{
onError(Download.FormatErrorMessage(i.Error));
return;
}
else if (cancelled)
{
onError("Download cancelled");
return;
}
var mirrorList = new List<string>();
using (var r = new StreamReader(mirrorsFile))
{
string line;
while ((line = r.ReadLine()) != null)
if (!string.IsNullOrEmpty(line))
mirrorList.Add(line);
}
mirror = mirrorList.Random(new OpenRA.Thirdparty.Random());
// Save the package to a temp file
var dl = new Download(mirror, file, onDownloadProgress, onDownloadComplete);
cancelButton.OnClick = () => { dl.Cancel(); Ui.CloseWindow(); }; cancelButton.OnClick = () => { dl.Cancel(); Ui.CloseWindow(); };
retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); }; retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); };
};
// Get the list of mirrors
var updateMirrors = new Download(installData["PackageMirrorList"], mirrorsFile, onDownloadProgress, onFetchMirrorsComplete);
cancelButton.OnClick = () => { updateMirrors.Cancel(); Ui.CloseWindow(); };
retryButton.OnClick = () => { updateMirrors.Cancel(); ShowDownloadDialog(); };
} }
} }
} }

View File

@@ -130,7 +130,7 @@ LoadScreen: CncLoadScreen
FilesToExtract: speech.mix, tempicnh.mix, transit.mix FilesToExtract: speech.mix, tempicnh.mix, transit.mix
InstallerBackgroundWidget: INSTALL_BACKGROUND InstallerBackgroundWidget: INSTALL_BACKGROUND
TestFiles: conquer.mix, desert.mix, general.mix, sounds.mix, speech.mix, temperat.mix, tempicnh.mix, winter.mix TestFiles: conquer.mix, desert.mix, general.mix, sounds.mix, speech.mix, temperat.mix, tempicnh.mix, winter.mix
PackageURL: http://open-ra.org/download/content/cnc-packages PackageMirrorList: http://open-ra.org/packages/cnc-mirrors.txt
ServerTraits: ServerTraits:
LobbyCommands LobbyCommands

View File

@@ -113,7 +113,7 @@ LoadScreen: DefaultLoadScreen
InstallerMenuWidget: INSTALL_PANEL InstallerMenuWidget: INSTALL_PANEL
# TODO: check if DATA.R8 is at 1.03 patch level with 4840 frames # TODO: check if DATA.R8 is at 1.03 patch level with 4840 frames
TestFiles: BLOXBASE.R8, BLOXBAT.R8, BLOXBGBS.R8, BLOXICE.R8, BLOXTREE.R8, BLOXWAST.R8, DATA.R8, SOUND.RS TestFiles: BLOXBASE.R8, BLOXBAT.R8, BLOXBGBS.R8, BLOXICE.R8, BLOXTREE.R8, BLOXWAST.R8, DATA.R8, SOUND.RS
PackageURL: http://open-ra.org/download/content/d2k-103-packages PackageMirrorList: http://open-ra.org/packages/d2k-103-mirrors.txt
Text: Filling Crates..., Breeding Sandworms... Text: Filling Crates..., Breeding Sandworms...
ServerTraits: ServerTraits:

View File

@@ -129,7 +129,7 @@ LoadScreen: DefaultLoadScreen
Image: mods/ra/uibits/loadscreen.png Image: mods/ra/uibits/loadscreen.png
InstallerMenuWidget: INSTALL_PANEL InstallerMenuWidget: INSTALL_PANEL
TestFiles: allies.mix, conquer.mix, general.mix, interior.mix, redalert.mix, russian.mix, scores.mix, snow.mix, sounds.mix, temperat.mix TestFiles: allies.mix, conquer.mix, general.mix, interior.mix, redalert.mix, russian.mix, scores.mix, snow.mix, sounds.mix, temperat.mix
PackageURL: http://open-ra.org/download/content/ra-packages PackageMirrorList: http://open-ra.org/packages/ra-mirrors.txt
Text: Filling Crates..., Charging Capacitors..., Reticulating Splines..., Planting Trees..., Building Bridges..., Aging Empires..., Compiling EVA..., Constructing Pylons..., Activating Skynet..., Splitting Atoms... Text: Filling Crates..., Charging Capacitors..., Reticulating Splines..., Planting Trees..., Building Bridges..., Aging Empires..., Compiling EVA..., Constructing Pylons..., Activating Skynet..., Splitting Atoms...
ServerTraits: ServerTraits:

View File

@@ -151,7 +151,7 @@ LoadScreen: DefaultLoadScreen
Image: mods/ts/uibits/loadscreen.png Image: mods/ts/uibits/loadscreen.png
InstallerMenuWidget: INSTALL_PANEL InstallerMenuWidget: INSTALL_PANEL
TestFiles: cache.mix, conquer.mix, isosnow.mix, isotemp.mix, local.mix, sidec01.mix, sidec02.mix, sno.mix, snow.mix, sounds.mix, speech01.mix, tem.mix, temperat.mix TestFiles: cache.mix, conquer.mix, isosnow.mix, isotemp.mix, local.mix, sidec01.mix, sidec02.mix, sno.mix, snow.mix, sounds.mix, speech01.mix, tem.mix, temperat.mix
PackageURL: http://open-ra.org/download/content/ts-packages PackageMirrorList: http://open-ra.org/packages/ts-mirrors.txt
Text: Updating EVA installation..., Changing perspective... Text: Updating EVA installation..., Changing perspective...
ServerTraits: ServerTraits: