remove redundant install and download logic

This commit is contained in:
Matthias Mailänder
2013-10-05 12:45:20 +02:00
parent 89a6d4f98e
commit cdfc21af2c
13 changed files with 44 additions and 246 deletions

View File

@@ -19,6 +19,25 @@ namespace OpenRA
WebClient wc; WebClient wc;
bool cancelled; bool cancelled;
public static string FormatErrorMessage(Exception e)
{
var ex = e as System.Net.WebException;
if (ex == null)
return e.Message;
switch (ex.Status)
{
case WebExceptionStatus.NameResolutionFailure:
case WebExceptionStatus.Timeout:
case WebExceptionStatus.ConnectFailure:
return "Cannot connect to remote server";
case WebExceptionStatus.ProtocolError:
return "File not found on remote server";
default:
return ex.Message;
}
}
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete) public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
{ {
wc = new WebClient(); wc = new WebClient();
@@ -39,23 +58,5 @@ namespace OpenRA
wc.CancelAsync(); wc.CancelAsync();
cancelled = true; cancelled = true;
} }
public static string FormatErrorMessage(Exception e)
{
var ex = e as System.Net.WebException;
if (ex == null) return e.Message;
switch(ex.Status)
{
case WebExceptionStatus.NameResolutionFailure:
case WebExceptionStatus.Timeout:
case WebExceptionStatus.ConnectFailure:
return "Cannot connect to remote server";
case WebExceptionStatus.ProtocolError:
return "File not found on remote server";
default:
return ex.Message;
}
}
} }
} }

View File

@@ -93,7 +93,6 @@
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" /> <Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" /> <Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" /> <Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\CncInstallLogic.cs" />
<Compile Include="Widgets\Logic\CncMenuLogic.cs" /> <Compile Include="Widgets\Logic\CncMenuLogic.cs" />
<Compile Include="Widgets\Logic\CncSettingsLogic.cs" /> <Compile Include="Widgets\Logic\CncSettingsLogic.cs" />
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" /> <Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />

View File

@@ -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 },
});
};
}
}
}

View File

@@ -76,9 +76,7 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Widgets\Logic\D2kInstallLogic.cs" />
<Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" /> <Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\D2kDownloadPackagesLogic.cs" />
<Compile Include="BuildingCaptureNotification.cs" /> <Compile Include="BuildingCaptureNotification.cs" />
<Compile Include="Render\WithCrumbleOverlay.cs" /> <Compile Include="Render\WithCrumbleOverlay.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -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(); };
}
}
}

View File

@@ -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 },
});
};
}
}
}

View File

@@ -400,7 +400,6 @@
<Compile Include="Widgets\Logic\OrderButtonsChromeLogic.cs" /> <Compile Include="Widgets\Logic\OrderButtonsChromeLogic.cs" />
<Compile Include="Widgets\Logic\PerfDebugLogic.cs" /> <Compile Include="Widgets\Logic\PerfDebugLogic.cs" />
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" /> <Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\RAInstallLogic.cs" />
<Compile Include="Widgets\Logic\ReplayBrowserLogic.cs" /> <Compile Include="Widgets\Logic\ReplayBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ServerBrowserLogic.cs" /> <Compile Include="Widgets\Logic\ServerBrowserLogic.cs" />
<Compile Include="Widgets\Logic\ServerCreationLogic.cs" /> <Compile Include="Widgets\Logic\ServerCreationLogic.cs" />
@@ -471,6 +470,7 @@
<Compile Include="AI\States\GroundStates.cs" /> <Compile Include="AI\States\GroundStates.cs" />
<Compile Include="AI\States\ProtectionStates.cs" /> <Compile Include="AI\States\ProtectionStates.cs" />
<Compile Include="AI\States\AirStates.cs" /> <Compile Include="AI\States\AirStates.cs" />
<Compile Include="Widgets\Logic\InstallLogic.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -14,10 +14,10 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic
{ {
public class RAInstallLogic public class InstallLogic : Widget
{ {
[ObjectCreator.UseCtor] [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 panel = widget.Get("INSTALL_PANEL");
var args = new WidgetArgs() var args = new WidgetArgs()
@@ -30,6 +30,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () => panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); 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 = () => panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Ui.OpenWindow("INSTALL_FROMCD_PANEL", args); Ui.OpenWindow("INSTALL_FROMCD_PANEL", args);

View File

@@ -25,7 +25,7 @@ Container@INSTALL_BACKGROUND:
Background:shellmapborder Background:shellmapborder
Container@INSTALL_PANEL: Container@INSTALL_PANEL:
Logic:CncInstallLogic Logic:InstallLogic
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - 150)/2 Y:(WINDOW_BOTTOM - 150)/2
Width:640 Width:640

View File

@@ -111,6 +111,8 @@ TileSets:
LoadScreen: CncLoadScreen LoadScreen: CncLoadScreen
InstallerMenuWidget: INSTALL_PANEL 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 InstallerBackgroundWidget: INSTALL_BACKGROUND
TestFile: conquer.mix TestFile: conquer.mix
PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages

View File

@@ -1,5 +1,5 @@
Background@INSTALL_PANEL: Background@INSTALL_PANEL:
Logic:D2kInstallLogic Logic:InstallLogic
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:630 Width:630
@@ -41,7 +41,7 @@ Background@INSTALL_PANEL:
Height:25 Height:25
Text:Download Text:Download
Font:Bold Font:Bold
Button@COPY_BUTTON: Button@INSTALL_BUTTON:
X:140 X:140
Y:PARENT_BOTTOM - 45 Y:PARENT_BOTTOM - 45
Width:110 Width:110
@@ -64,7 +64,7 @@ Background@INSTALL_PANEL:
Font:Bold Font:Bold
Background@INSTALL_DOWNLOAD_PANEL: Background@INSTALL_DOWNLOAD_PANEL:
Logic:D2kDownloadPackagesLogic Logic:DownloadPackagesLogic
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:500 Width:500

View File

@@ -1,5 +1,5 @@
Background@INSTALL_PANEL: Background@INSTALL_PANEL:
Logic:RAInstallLogic Logic:InstallLogic
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:510 Width:510

View File

@@ -1,5 +1,5 @@
Background@INSTALL_PANEL: Background@INSTALL_PANEL:
Logic:RAInstallLogic Logic:InstallLogic
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:510 Width:510