From 603379aa961b6a93493665d11e5f7a29417ce8ee Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 12 May 2011 20:33:53 +1200 Subject: [PATCH] Fix nits --- OpenRA.Game/Game.cs | 3 +- OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs | 20 ++++++---- .../Widgets/CncMusicPlayerLogic.cs | 39 ++++++++++--------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 9f24766de6..f01dddc972 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -276,7 +276,8 @@ namespace OpenRA ConnectionStateChanged = om => {}; BeforeGameStart = () => {}; AfterGameStart = w => {}; - afterTickActions = new ActionQueue(); + while (Widget.WindowList.Count > 0) + Widget.CloseWindow(); worldRenderer = null; if (server != null) diff --git a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs index e76c76facf..5178ca1a6a 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs @@ -112,9 +112,12 @@ namespace OpenRA.Mods.Cnc.Widgets var onError = (Action)(s => { - statusLabel.GetText = () => "Error: "+s; - panel.GetWidget("RETRY_BUTTON").IsVisible = () => true; - panel.GetWidget("BACK_BUTTON").IsVisible = () => true; + Game.RunAfterTick(() => + { + statusLabel.GetText = () => "Error: "+s; + panel.GetWidget("RETRY_BUTTON").IsVisible = () => true; + panel.GetWidget("BACK_BUTTON").IsVisible = () => true; + }); }); string source; @@ -194,13 +197,16 @@ namespace OpenRA.Mods.Cnc.Widgets Action onExtractProgress = s => { - statusLabel.GetText = () => s; + Game.RunAfterTick(() => statusLabel.GetText = () => s); }; Action onError = s => { - statusLabel.GetText = () => "Error: "+s; - retryButton.IsVisible = () => true; + Game.RunAfterTick(() => + { + statusLabel.GetText = () => "Error: "+s; + retryButton.IsVisible = () => true; + }); }; Action onDownloadComplete = (i, cancelled) => @@ -211,8 +217,6 @@ namespace OpenRA.Mods.Cnc.Widgets var except = i.Error as System.Net.WebException; if (except != null) { - Console.WriteLine("{0}",except.Status); - if (except.Status == WebExceptionStatus.ProtocolError) message = "File not found on remote server"; else if (except.Status == WebExceptionStatus.NameResolutionFailure || diff --git a/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs index 526ec65eb3..595fa39681 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMusicPlayerLogic.cs @@ -220,21 +220,25 @@ namespace OpenRA.Mods.Cnc.Widgets { progressBar.SetIndeterminate(true); statusLabel.GetText = () => "Waiting for file"; - Game.Utilities.PromptFilepathAsync("Select SCORES.MIX on the C&C CD", path => Game.RunAfterTick(() => Install(path))); + Game.Utilities.PromptFilepathAsync("Select SCORES.MIX on the C&C CD", path => Install(path)); } - void Install(string path) + public void OnError(string message) { - var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine); - - var onError = (Action)(s => + Game.RunAfterTick(() => { progressBar.SetIndeterminate(false); - statusLabel.GetText = () => "Error: "+s; + statusLabel.GetText = () => "Error: "+message; panel.GetWidget("RETRY_BUTTON").IsVisible = () => true; panel.GetWidget("BACK_BUTTON").IsVisible = () => true; }); - + } + + void Install(string path) + { + var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine); + Game.RunAfterTick(() => statusLabel.GetText = () => "Installing"); + // Mount the package and check that it contains the correct files try { @@ -242,34 +246,33 @@ namespace OpenRA.Mods.Cnc.Widgets if (!mixFile.Exists("aoi.aud")) { - onError("Not the C&C SCORES.MIX"); + OnError("Not the C&C SCORES.MIX"); return; } - statusLabel.GetText = () => "Installing"; var t = new Thread( _ => { var destPath = Path.Combine(dest, "scores.mix"); try { File.Copy(path, destPath, true); + Game.RunAfterTick(() => + { + Widget.CloseWindow(); // Progress panel + afterInstall(destPath); + }); } - catch + catch (Exception e) { - onError("File copy failed"); + OnError("File copy failed"); + Log.Write("debug", e.Message); } - - Game.RunAfterTick(() => - { - Widget.CloseWindow(); // Progress panel - afterInstall(destPath); - }); }) { IsBackground = true }; t.Start(); } catch { - onError("Invalid mix file"); + OnError("Invalid mix file"); } } }