Merge pull request #3903 from Mailaender/gameinit-redundancy
Removed the now redundant per mod Install/DownloadPackagesLogic
This commit is contained in:
@@ -19,33 +19,13 @@ namespace OpenRA
|
||||
WebClient wc;
|
||||
bool cancelled;
|
||||
|
||||
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
|
||||
{
|
||||
wc = new WebClient();
|
||||
wc.Proxy = null;
|
||||
|
||||
wc.DownloadProgressChanged += (_,a) => onProgress(a);
|
||||
wc.DownloadFileCompleted += (_,a) => onComplete(a, cancelled);
|
||||
|
||||
Game.OnQuit += () => Cancel();
|
||||
wc.DownloadFileCompleted += (_,a) => {Game.OnQuit -= () => Cancel();};
|
||||
|
||||
wc.DownloadFileAsync(new Uri(url), path);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Game.OnQuit -= () => Cancel();
|
||||
wc.CancelAsync();
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
public static string FormatErrorMessage(Exception e)
|
||||
{
|
||||
var ex = e as System.Net.WebException;
|
||||
if (ex == null) return e.Message;
|
||||
if (ex == null)
|
||||
return e.Message;
|
||||
|
||||
switch(ex.Status)
|
||||
switch (ex.Status)
|
||||
{
|
||||
case WebExceptionStatus.NameResolutionFailure:
|
||||
case WebExceptionStatus.Timeout:
|
||||
@@ -57,5 +37,26 @@ namespace OpenRA
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
|
||||
{
|
||||
wc = new WebClient();
|
||||
wc.Proxy = null;
|
||||
|
||||
wc.DownloadProgressChanged += (_, a) => onProgress(a);
|
||||
wc.DownloadFileCompleted += (_, a) => onComplete(a, cancelled);
|
||||
|
||||
Game.OnQuit += () => Cancel();
|
||||
wc.DownloadFileCompleted += (_, a) => { Game.OnQuit -= () => Cancel(); };
|
||||
|
||||
wc.DownloadFileAsync(new Uri(url), path);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Game.OnQuit -= () => Cancel();
|
||||
wc.CancelAsync();
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,6 @@
|
||||
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncInstallLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncMenuLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\CncSettingsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />
|
||||
|
||||
@@ -1,52 +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 OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncInstallLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncInstallLogic(Widget widget, Dictionary<string, string> installData, Action continueLoading)
|
||||
{
|
||||
var panel = widget.Get("INSTALL_PANEL");
|
||||
var args = new WidgetArgs()
|
||||
{
|
||||
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
|
||||
{ "installData", installData }
|
||||
};
|
||||
|
||||
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
|
||||
|
||||
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs(args)
|
||||
{
|
||||
{ "filesToCopy", new[] { "CONQUER.MIX", "DESERT.MIX", "SCORES.MIX",
|
||||
"SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX" } },
|
||||
{ "filesToExtract", new[] { "speech.mix", "tempicnh.mix", "transit.mix" } },
|
||||
});
|
||||
|
||||
panel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
|
||||
panel.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
|
||||
{
|
||||
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => { } },
|
||||
{ "onSwitch", Ui.CloseWindow },
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,9 +76,7 @@
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Widgets\Logic\D2kInstallLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\D2kDownloadPackagesLogic.cs" />
|
||||
<Compile Include="BuildingCaptureNotification.cs" />
|
||||
<Compile Include="Render\WithCrumbleOverlay.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2012 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.D2k.Widgets.Logic
|
||||
{
|
||||
public class D2kDownloadPackagesLogic
|
||||
{
|
||||
Widget panel;
|
||||
Dictionary<string, string> installData;
|
||||
ProgressBarWidget progressBar;
|
||||
LabelWidget statusLabel;
|
||||
Action afterInstall;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public D2kDownloadPackagesLogic(Widget widget, Dictionary<string, string> installData, Action afterInstall)
|
||||
{
|
||||
this.installData = installData;
|
||||
this.afterInstall = afterInstall;
|
||||
|
||||
panel = widget.Get("INSTALL_DOWNLOAD_PANEL");
|
||||
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
|
||||
statusLabel = panel.Get<LabelWidget>("STATUS_LABEL");
|
||||
|
||||
ShowDownloadDialog();
|
||||
}
|
||||
|
||||
void ShowDownloadDialog()
|
||||
{
|
||||
statusLabel.GetText = () => "Initializing...";
|
||||
progressBar.SetIndeterminate(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 file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var dest = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mods[0] }.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(() =>
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
afterInstall();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete);
|
||||
|
||||
cancelButton.OnClick = () => { dl.Cancel(); Ui.CloseWindow(); };
|
||||
retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2012 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 OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Widgets.Logic
|
||||
{
|
||||
public class D2kInstallLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public D2kInstallLogic(Widget widget, Dictionary<string, string> installData, Action continueLoading)
|
||||
{
|
||||
var panel = widget.Get("INSTALL_PANEL");
|
||||
var args = new WidgetArgs()
|
||||
{
|
||||
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
|
||||
{ "installData", installData },
|
||||
{ "continueLoading", continueLoading }
|
||||
};
|
||||
|
||||
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
|
||||
|
||||
panel.Get<ButtonWidget>("COPY_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_FROMCD_PANEL", args);
|
||||
|
||||
panel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
|
||||
panel.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
|
||||
{
|
||||
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => { } },
|
||||
{ "onSwitch", Ui.CloseWindow },
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,7 +400,6 @@
|
||||
<Compile Include="Widgets\Logic\OrderButtonsChromeLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\PerfDebugLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ReplayBrowserLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ServerBrowserLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ServerCreationLogic.cs" />
|
||||
@@ -471,6 +470,7 @@
|
||||
<Compile Include="AI\States\GroundStates.cs" />
|
||||
<Compile Include="AI\States\ProtectionStates.cs" />
|
||||
<Compile Include="AI\States\AirStates.cs" />
|
||||
<Compile Include="Widgets\Logic\InstallLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -14,10 +14,10 @@ using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class RAInstallLogic
|
||||
public class InstallLogic : Widget
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public RAInstallLogic(Widget widget, Dictionary<string, string> installData, Action continueLoading)
|
||||
public InstallLogic(Widget widget, Dictionary<string, string> installData, Action continueLoading)
|
||||
{
|
||||
var panel = widget.Get("INSTALL_PANEL");
|
||||
var args = new WidgetArgs()
|
||||
@@ -30,6 +30,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
|
||||
|
||||
if (installData.ContainsKey("FilesToCopy") && !string.IsNullOrEmpty(installData["FilesToCopy"]) &&
|
||||
installData.ContainsKey("FilesToExtract") && !string.IsNullOrEmpty(installData["FilesToExtract"]))
|
||||
{
|
||||
args = new WidgetArgs(args)
|
||||
{
|
||||
{ "filesToCopy", installData["FilesToCopy"].Split(',') },
|
||||
{ "filesToExtract", installData["FilesToExtract"].Split(',') },
|
||||
};
|
||||
}
|
||||
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_FROMCD_PANEL", args);
|
||||
|
||||
@@ -25,7 +25,7 @@ Container@INSTALL_BACKGROUND:
|
||||
Background:shellmapborder
|
||||
|
||||
Container@INSTALL_PANEL:
|
||||
Logic:CncInstallLogic
|
||||
Logic:InstallLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - 150)/2
|
||||
Width:640
|
||||
|
||||
@@ -111,6 +111,8 @@ TileSets:
|
||||
|
||||
LoadScreen: CncLoadScreen
|
||||
InstallerMenuWidget: INSTALL_PANEL
|
||||
FilesToCopy: CONQUER.MIX, DESERT.MIX, SCORES.MIX, SOUNDS.MIX, TEMPERAT.MIX, WINTER.MIX
|
||||
FilesToExtract: speech.mix, tempicnh.mix, transit.mix
|
||||
InstallerBackgroundWidget: INSTALL_BACKGROUND
|
||||
TestFile: conquer.mix
|
||||
PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Background@INSTALL_PANEL:
|
||||
Logic:D2kInstallLogic
|
||||
Logic:InstallLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:630
|
||||
@@ -41,7 +41,7 @@ Background@INSTALL_PANEL:
|
||||
Height:25
|
||||
Text:Download
|
||||
Font:Bold
|
||||
Button@COPY_BUTTON:
|
||||
Button@INSTALL_BUTTON:
|
||||
X:140
|
||||
Y:PARENT_BOTTOM - 45
|
||||
Width:110
|
||||
@@ -64,7 +64,7 @@ Background@INSTALL_PANEL:
|
||||
Font:Bold
|
||||
|
||||
Background@INSTALL_DOWNLOAD_PANEL:
|
||||
Logic:D2kDownloadPackagesLogic
|
||||
Logic:DownloadPackagesLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:500
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Background@INSTALL_PANEL:
|
||||
Logic:RAInstallLogic
|
||||
Logic:InstallLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:510
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Background@INSTALL_PANEL:
|
||||
Logic:RAInstallLogic
|
||||
Logic:InstallLogic
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
||||
Width:510
|
||||
|
||||
Reference in New Issue
Block a user