work toward deferrable start of replay saving

This commit is contained in:
Chris Forbes
2011-12-24 20:39:33 +13:00
parent 4e6ff7616c
commit d61055af8f
2 changed files with 17 additions and 8 deletions

View File

@@ -50,13 +50,8 @@ namespace OpenRA
public static void JoinServer(string host, int port) 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, JoinInner(new OrderManager(host, port,
new ReplayRecorderConnection(new NetworkConnection(host, port), replayFile))); new ReplayRecorderConnection(new NetworkConnection(host, port), ChooseReplayFilename)));
} }
static string ChooseReplayFilename() static string ChooseReplayFilename()

View File

@@ -20,11 +20,25 @@ namespace OpenRA.Network
{ {
IConnection inner; IConnection inner;
BinaryWriter writer; BinaryWriter writer;
Func<string> chooseFilename;
public ReplayRecorderConnection( IConnection inner, FileStream replayFile ) public ReplayRecorderConnection( IConnection inner, Func<string> chooseFilename )
{ {
this.chooseFilename = chooseFilename;
this.inner = inner; 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; } } public int LocalClientId { get { return inner.LocalClientId; } }