Merge pull request #4843 from Mailaender/local-mirrors

Moved mirror selection to the client
This commit is contained in:
Paul Chote
2014-05-09 19:51:52 +12:00
5 changed files with 45 additions and 10 deletions

View File

@@ -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<string, string> 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<ButtonWidget>("RETRY_BUTTON");
retryButton.IsVisible = () => false;
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 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<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;
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<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(); };
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

@@ -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

View File

@@ -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:

View File

@@ -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:

View File

@@ -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: