diff --git a/OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs index 74d8bf46dc..4e6f704958 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/DownloadPackagesLogic.cs @@ -26,6 +26,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic ProgressBarWidget progressBar; LabelWidget statusLabel; Action afterInstall; + string mirror; [ObjectCreator.UseCtor] public DownloadPackagesLogic(Widget widget, Dictionary installData, Action afterInstall) @@ -42,14 +43,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic void ShowDownloadDialog() { - statusLabel.GetText = () => "Initializing..."; + statusLabel.GetText = () => "Fetching list of mirrors..."; progressBar.Indeterminate = true; + var retryButton = panel.Get("RETRY_BUTTON"); retryButton.IsVisible = () => false; var cancelButton = panel.Get("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 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.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 onExtractProgress = s => @@ -100,10 +104,41 @@ namespace OpenRA.Mods.RA.Widgets.Logic } }; - var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete); + Action onFetchMirrorsComplete = (i, cancelled) => + { + progressBar.Indeterminate = true; - cancelButton.OnClick = () => { dl.Cancel(); Ui.CloseWindow(); }; - retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); }; + if (i.Error != null) + { + onError(Download.FormatErrorMessage(i.Error)); + return; + } + else if (cancelled) + { + onError("Download cancelled"); + return; + } + + var mirrorList = new List(); + 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(); }; + 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(); }; } } } diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 8a9b118f20..035b32a7bb 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -131,7 +131,7 @@ LoadScreen: CncLoadScreen FilesToExtract: speech.mix, tempicnh.mix, transit.mix InstallerBackgroundWidget: INSTALL_BACKGROUND 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: LobbyCommands diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 26226ca239..4fb04f678e 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -115,7 +115,7 @@ LoadScreen: DefaultLoadScreen InstallerMenuWidget: INSTALL_PANEL # 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 - 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... ServerTraits: diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index b9100eb0e0..f6d8ab90a9 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -131,7 +131,7 @@ LoadScreen: DefaultLoadScreen Image: mods/ra/uibits/loadscreen.png InstallerMenuWidget: INSTALL_PANEL 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... ServerTraits: diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 2042f4a465..f981ff4f00 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -155,7 +155,7 @@ LoadScreen: DefaultLoadScreen Image: mods/ts/uibits/loadscreen.png 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 - PackageURL: http://open-ra.org/download/content/ts-packages + PackageMirrorList: http://open-ra.org/packages/ts-mirrors.txt Text: Updating EVA installation..., Changing perspective... ServerTraits: