From d61055af8ff2acc9ab81a4537f37a312c57db436 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 24 Dec 2011 20:39:33 +1300 Subject: [PATCH] work toward deferrable start of replay saving --- OpenRA.Game/Game.cs | 7 +------ .../Network/ReplayRecorderConnection.cs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 767248ba0e..88b42fa38b 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -50,13 +50,8 @@ namespace OpenRA public static void JoinServer(string host, int port) { - var replayFilename = ChooseReplayFilename(); - string path = Path.Combine( Platform.SupportDir, "Replays" ); - if( !Directory.Exists( path ) ) Directory.CreateDirectory( path ); - var replayFile = File.Create( Path.Combine( path, replayFilename ) ); - JoinInner(new OrderManager(host, port, - new ReplayRecorderConnection(new NetworkConnection(host, port), replayFile))); + new ReplayRecorderConnection(new NetworkConnection(host, port), ChooseReplayFilename))); } static string ChooseReplayFilename() diff --git a/OpenRA.Game/Network/ReplayRecorderConnection.cs b/OpenRA.Game/Network/ReplayRecorderConnection.cs index ffc147678e..4e86039efb 100644 --- a/OpenRA.Game/Network/ReplayRecorderConnection.cs +++ b/OpenRA.Game/Network/ReplayRecorderConnection.cs @@ -20,11 +20,25 @@ namespace OpenRA.Network { IConnection inner; BinaryWriter writer; + Func chooseFilename; - public ReplayRecorderConnection( IConnection inner, FileStream replayFile ) + public ReplayRecorderConnection( IConnection inner, Func chooseFilename ) { + this.chooseFilename = chooseFilename; this.inner = inner; - this.writer = new BinaryWriter( replayFile ); + + StartSavingReplay(); + } + + void StartSavingReplay() + { + var filename = chooseFilename(); + var replayPath = Path.Combine( Platform.SupportDir, "Replays" ); + + if (!Directory.Exists(replayPath)) + Directory.CreateDirectory(replayPath); + + this.writer = new BinaryWriter(File.Create(Path.Combine(replayPath, filename))); } public int LocalClientId { get { return inner.LocalClientId; } }