unify {RA,Cnc}DownloadPackagesLogic
This commit is contained in:
@@ -78,7 +78,6 @@
|
||||
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncConnectionLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncConquestObjectivesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncDownloadPackagesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncDownloadPackagesLogic
|
||||
{
|
||||
Widget panel;
|
||||
Dictionary<string,string> installData;
|
||||
ProgressBarWidget progressBar;
|
||||
LabelWidget statusLabel;
|
||||
Action afterInstall;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncDownloadPackagesLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] Dictionary<string,string> installData,
|
||||
[ObjectCreator.Param] Action afterInstall)
|
||||
{
|
||||
this.installData = installData;
|
||||
this.afterInstall = afterInstall;
|
||||
|
||||
panel = widget.GetWidget("INSTALL_DOWNLOAD_PANEL");
|
||||
progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR");
|
||||
statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
|
||||
|
||||
ShowDownloadDialog();
|
||||
}
|
||||
|
||||
void ShowDownloadDialog()
|
||||
{
|
||||
statusLabel.GetText = () => "Initializing...";
|
||||
progressBar.SetIndeterminate(true);
|
||||
var retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON");
|
||||
retryButton.IsVisible = () => false;
|
||||
|
||||
var cancelButton = panel.GetWidget<ButtonWidget>("CANCEL_BUTTON");
|
||||
|
||||
// Save the package to a temp file
|
||||
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine);
|
||||
|
||||
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
|
||||
{
|
||||
if (progressBar.Indeterminate)
|
||||
progressBar.SetIndeterminate(false);
|
||||
|
||||
progressBar.Percentage = i.ProgressPercentage;
|
||||
statusLabel.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived / 1024, i.TotalBytesToReceive / 1024);
|
||||
};
|
||||
|
||||
Action<string> onExtractProgress = s =>
|
||||
{
|
||||
Game.RunAfterTick(() => statusLabel.GetText = () => s);
|
||||
};
|
||||
|
||||
Action<string> onError = s =>
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
statusLabel.GetText = () => "Error: "+s;
|
||||
retryButton.IsVisible = () => true;
|
||||
});
|
||||
};
|
||||
|
||||
Action<AsyncCompletedEventArgs, bool> onDownloadComplete = (i, cancelled) =>
|
||||
{
|
||||
if (i.Error != null)
|
||||
{
|
||||
onError(Download.FormatErrorMessage(i.Error));
|
||||
return;
|
||||
}
|
||||
else if (cancelled)
|
||||
{
|
||||
onError("Download cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
// Automatically extract
|
||||
statusLabel.GetText = () => "Extracting...";
|
||||
progressBar.SetIndeterminate(true);
|
||||
if (InstallUtils.ExtractZip(file, dest, onExtractProgress, onError))
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
afterInstall();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete);
|
||||
|
||||
cancelButton.OnClick = () => { dl.Cancel(); Widget.CloseWindow(); };
|
||||
retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,7 +343,6 @@
|
||||
<Compile Include="Widgets\Logic\MusicPlayerLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\OrderButtonsChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\PerfDebugLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RADownloadPackagesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\DirectConnectLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallLogic.cs" />
|
||||
@@ -363,6 +362,7 @@
|
||||
<Compile Include="World\PlayMusicOnMapLoad.cs" />
|
||||
<Compile Include="World\SmudgeLayer.cs" />
|
||||
<Compile Include="Widgets\Logic\LobbyUtils.cs" />
|
||||
<Compile Include="Widgets\Logic\DownloadPackagesLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -19,21 +19,21 @@ using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class RADownloadPackagesLogic
|
||||
public class DownloadPackagesLogic
|
||||
{
|
||||
Widget panel;
|
||||
Dictionary<string,string> installData;
|
||||
ProgressBarWidget progressBar;
|
||||
LabelWidget statusLabel;
|
||||
Action continueLoading;
|
||||
Action afterInstall;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public RADownloadPackagesLogic([ObjectCreator.Param] Widget widget,
|
||||
public DownloadPackagesLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] Dictionary<string,string> installData,
|
||||
[ObjectCreator.Param] Action continueLoading)
|
||||
[ObjectCreator.Param] Action afterInstall)
|
||||
{
|
||||
this.installData = installData;
|
||||
this.continueLoading = continueLoading;
|
||||
this.afterInstall = afterInstall;
|
||||
|
||||
panel = widget.GetWidget("INSTALL_DOWNLOAD_PANEL");
|
||||
progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR");
|
||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
// Save the package to a temp file
|
||||
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var dest = new string[] { Platform.SupportDir, "Content", "ra" }.Aggregate(Path.Combine);
|
||||
var dest = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mods[0] }.Aggregate(Path.Combine);
|
||||
|
||||
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
|
||||
{
|
||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
continueLoading();
|
||||
afterInstall();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var panel = widget.GetWidget("INSTALL_PANEL");
|
||||
var args = new WidgetArgs()
|
||||
{
|
||||
{ "continueLoading", () => { Widget.CloseWindow(); continueLoading(); } },
|
||||
{ "afterInstall", () => { Widget.CloseWindow(); continueLoading(); } },
|
||||
{ "installData", installData }
|
||||
};
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ Container@INSTALL_FROMCD_PANEL:
|
||||
|
||||
Container@INSTALL_DOWNLOAD_PANEL:
|
||||
Id:INSTALL_DOWNLOAD_PANEL
|
||||
Logic:CncDownloadPackagesLogic
|
||||
Logic:DownloadPackagesLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - 150)/2
|
||||
Width:640
|
||||
@@ -227,4 +227,4 @@ Container@INSTALL_DOWNLOAD_PANEL:
|
||||
Y:149
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Retry
|
||||
Text:Retry
|
||||
|
||||
@@ -55,7 +55,7 @@ Background@INSTALL_PANEL:
|
||||
|
||||
Background@INSTALL_DOWNLOAD_PANEL:
|
||||
Id:INSTALL_DOWNLOAD_PANEL
|
||||
Logic:RADownloadPackagesLogic
|
||||
Logic:DownloadPackagesLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:500
|
||||
|
||||
Reference in New Issue
Block a user