Enable mod asset package downloading from the modchooser
This commit is contained in:
@@ -9,11 +9,10 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -21,24 +20,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class DownloadPackagesLogic
|
||||
{
|
||||
static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||
readonly Widget panel;
|
||||
readonly string modId;
|
||||
readonly string mirrorListUrl;
|
||||
readonly ProgressBarWidget progressBar;
|
||||
readonly LabelWidget statusLabel;
|
||||
readonly Action afterInstall;
|
||||
string mirror;
|
||||
static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public DownloadPackagesLogic(Widget widget, Action afterInstall, string mirrorListUrl)
|
||||
public DownloadPackagesLogic(Widget widget, Action afterInstall, string mirrorListUrl, string modId)
|
||||
{
|
||||
this.mirrorListUrl = mirrorListUrl;
|
||||
this.afterInstall = afterInstall;
|
||||
this.modId = modId;
|
||||
|
||||
panel = widget.Get("INSTALL_DOWNLOAD_PANEL");
|
||||
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
|
||||
statusLabel = panel.Get<LabelWidget>("STATUS_LABEL");
|
||||
|
||||
var text = "Downloading {0} assets...".F(ModMetadata.AllMods[modId].Title);
|
||||
panel.Get<LabelWidget>("TITLE").Text = text;
|
||||
|
||||
ShowDownloadDialog();
|
||||
}
|
||||
|
||||
@@ -52,9 +56,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var cancelButton = panel.Get<ButtonWidget>("CANCEL_BUTTON");
|
||||
|
||||
var mirrorsFile = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, "mirrors.txt");
|
||||
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id);
|
||||
var dest = Platform.ResolvePath("^", "Content", modId);
|
||||
|
||||
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
|
||||
{
|
||||
@@ -100,7 +103,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
onError(Download.FormatErrorMessage(i.Error));
|
||||
return;
|
||||
}
|
||||
else if (cancelled)
|
||||
|
||||
if (cancelled)
|
||||
{
|
||||
onError("Download cancelled");
|
||||
return;
|
||||
@@ -119,7 +123,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
};
|
||||
|
||||
Action<AsyncCompletedEventArgs, bool> onFetchMirrorsComplete = (i, cancelled) =>
|
||||
Action<DownloadDataCompletedEventArgs, bool> onFetchMirrorsComplete = (i, cancelled) =>
|
||||
{
|
||||
progressBar.Indeterminate = true;
|
||||
|
||||
@@ -128,21 +132,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
onError(Download.FormatErrorMessage(i.Error));
|
||||
return;
|
||||
}
|
||||
else if (cancelled)
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
var data = Encoding.UTF8.GetString(i.Result);
|
||||
var mirrorList = data.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
mirror = mirrorList.Random(new MersenneTwister());
|
||||
|
||||
// Save the package to a temp file
|
||||
@@ -152,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
|
||||
// Get the list of mirrors
|
||||
var updateMirrors = new Download(mirrorListUrl, mirrorsFile, onDownloadProgress, onFetchMirrorsComplete);
|
||||
var updateMirrors = new Download(mirrorListUrl, onDownloadProgress, onFetchMirrorsComplete);
|
||||
cancelButton.OnClick = () => { updateMirrors.Cancel(); Ui.CloseWindow(); };
|
||||
retryButton.OnClick = () => { updateMirrors.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -17,17 +16,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public class InstallLogic : Widget
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public InstallLogic(Widget widget, Action continueLoading)
|
||||
public InstallLogic(Widget widget, Action continueLoading, string mirrorListUrl, string modId)
|
||||
{
|
||||
var installData = Game.ModData.Manifest.Get<ContentInstaller>();
|
||||
var panel = widget.Get("INSTALL_PANEL");
|
||||
var widgetArgs = new WidgetArgs()
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
|
||||
{ "continueLoading", continueLoading },
|
||||
{ "mirrorListUrl", installData.PackageMirrorList },
|
||||
{ "mirrorListUrl", mirrorListUrl },
|
||||
{ "modId", modId }
|
||||
};
|
||||
|
||||
var modName = ModMetadata.AllMods[modId].Title;
|
||||
var text = panel.Get<LabelWidget>("DESC1").Text;
|
||||
panel.Get<LabelWidget>("DESC1").Text = text.F(modName);
|
||||
|
||||
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs);
|
||||
|
||||
|
||||
@@ -167,7 +167,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "continueLoading", () =>
|
||||
Game.RunAfterTick(() => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments())) }
|
||||
Game.RunAfterTick(() => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments())) },
|
||||
{ "mirrorListUrl", mod.Content.PackageMirrorList },
|
||||
{ "modId", mod.Id }
|
||||
};
|
||||
|
||||
Ui.OpenWindow("INSTALL_PANEL", widgetArgs);
|
||||
|
||||
@@ -62,3 +62,59 @@ Container@INSTALL_PANEL:
|
||||
Font: Bold
|
||||
Key: escape
|
||||
|
||||
Container@INSTALL_DOWNLOAD_PANEL:
|
||||
Logic: DownloadPackagesLogic
|
||||
X: (WINDOW_RIGHT - WIDTH)/2
|
||||
Y: (WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width: 500
|
||||
Height: 177
|
||||
Children:
|
||||
Background:
|
||||
Width: PARENT_RIGHT
|
||||
Height: PARENT_BOTTOM
|
||||
Background: panel-bg
|
||||
Background@RULE:
|
||||
X: 30
|
||||
Y: 50
|
||||
Width: 440
|
||||
Height:150
|
||||
Background:panel-rule
|
||||
Label@TITLE:
|
||||
X: 0
|
||||
Y: 12
|
||||
Width: PARENT_RIGHT
|
||||
Height: 25
|
||||
Align: Center
|
||||
Font: MediumBold
|
||||
ProgressBar@PROGRESS_BAR:
|
||||
X: 50
|
||||
Y: 64
|
||||
Width: PARENT_RIGHT - 100
|
||||
Height: 16
|
||||
BarMargin: 0, 0
|
||||
Label@STATUS_LABEL:
|
||||
X: 36
|
||||
Y: 85
|
||||
Width: PARENT_RIGHT - 100
|
||||
Height: 25
|
||||
Align: Left
|
||||
Button@RETRY_BUTTON:
|
||||
X: PARENT_RIGHT - 280
|
||||
Y: PARENT_BOTTOM - 52
|
||||
Background:button-highlighted
|
||||
Width: 120
|
||||
Height: 32
|
||||
Visible: false
|
||||
Text: Retry
|
||||
Font: Bold
|
||||
Key: return
|
||||
Button@CANCEL_BUTTON:
|
||||
X: PARENT_RIGHT - 130
|
||||
Y: PARENT_BOTTOM - 52
|
||||
Background:button-highlighted
|
||||
Width: 110
|
||||
Height: 32
|
||||
Text: Cancel
|
||||
Font: Bold
|
||||
Key: escape
|
||||
|
||||
|
||||
Reference in New Issue
Block a user